diagnostics: if AssocFn has self argument, describe as method
Discussed in https://rust-lang.zulipchat.com/#narrow/stream/147480-t-compiler.2Fwg-diagnostics/topic/.22associated.20function.22.20vs.20.22method.22/near/329265515 This commit also changes the tooltips on rustdoc intra-doc links targeting methods.
This commit is contained in:
parent
3b4d6e0804
commit
3d056c3125
25 changed files with 91 additions and 58 deletions
|
@ -304,10 +304,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
if let Some(did) = adt_did {
|
||||
err.span_label(
|
||||
tcx.def_span(did),
|
||||
format!(
|
||||
"associated item `{name}` not found for this {}",
|
||||
tcx.def_kind(did).descr(did)
|
||||
),
|
||||
format!("associated item `{name}` not found for this {}", tcx.def_descr(did)),
|
||||
);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1217,7 +1217,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
| (hir::def::DefKind::AssocConst, ty::TermKind::Const(_)) => (),
|
||||
(_, _) => {
|
||||
let got = if let Some(_) = term.ty() { "type" } else { "constant" };
|
||||
let expected = def_kind.descr(assoc_item_def_id);
|
||||
let expected = tcx.def_descr(assoc_item_def_id);
|
||||
let mut err = tcx.sess.struct_span_err(
|
||||
binding.span,
|
||||
&format!("expected {expected} bound, found {got}"),
|
||||
|
@ -1552,7 +1552,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
i.bottom().1,
|
||||
E0038,
|
||||
"the {} `{}` cannot be made into an object",
|
||||
tcx.def_kind(def_id).descr(def_id),
|
||||
tcx.def_descr(def_id),
|
||||
tcx.item_name(def_id),
|
||||
);
|
||||
err.note(
|
||||
|
@ -2174,7 +2174,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
"`{}` could{} refer to the {} defined here",
|
||||
assoc_ident,
|
||||
also,
|
||||
kind.descr(def_id)
|
||||
tcx.def_kind_descr(kind, def_id)
|
||||
);
|
||||
lint.span_note(tcx.def_span(def_id), ¬e_msg);
|
||||
};
|
||||
|
@ -2350,7 +2350,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
let kind = DefKind::AssocTy;
|
||||
|
||||
if !tcx.visibility(item).is_accessible_from(def_scope, tcx) {
|
||||
let kind = kind.descr(item);
|
||||
let kind = tcx.def_kind_descr(kind, item);
|
||||
let msg = format!("{kind} `{name}` is private");
|
||||
let def_span = tcx.def_span(item);
|
||||
tcx.sess
|
||||
|
|
|
@ -1460,7 +1460,7 @@ fn opaque_type_cycle_error(
|
|||
span,
|
||||
format!(
|
||||
"{} captures itself here",
|
||||
tcx.def_kind(closure_def_id).descr(closure_def_id)
|
||||
tcx.def_descr(closure_def_id)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>(
|
|||
|
||||
let drop_impl_span = tcx.def_span(drop_impl_did);
|
||||
let item_span = tcx.def_span(self_type_did);
|
||||
let self_descr = tcx.def_kind(self_type_did).descr(self_type_did);
|
||||
let self_descr = tcx.def_descr(self_type_did);
|
||||
let mut err =
|
||||
struct_span_err!(tcx.sess, drop_impl_span, E0366, "`Drop` impls cannot be specialized");
|
||||
match arg {
|
||||
|
@ -217,7 +217,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
|
|||
|
||||
if !assumptions_in_impl_context.iter().copied().any(predicate_matches_closure) {
|
||||
let item_span = tcx.def_span(self_type_did);
|
||||
let self_descr = tcx.def_kind(self_type_did).descr(self_type_did.to_def_id());
|
||||
let self_descr = tcx.def_descr(self_type_did.to_def_id());
|
||||
let reported = struct_span_err!(
|
||||
tcx.sess,
|
||||
predicate_sp,
|
||||
|
|
|
@ -531,7 +531,7 @@ fn lint_auto_trait_impl<'tcx>(
|
|||
}),
|
||||
|lint| {
|
||||
let item_span = tcx.def_span(self_type_did);
|
||||
let self_descr = tcx.def_kind(self_type_did).descr(self_type_did);
|
||||
let self_descr = tcx.def_descr(self_type_did);
|
||||
match arg {
|
||||
ty::util::NotUniqueParam::DuplicateParam(arg) => {
|
||||
lint.note(&format!("`{}` is mentioned multiple times", arg));
|
||||
|
|
|
@ -439,7 +439,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
|
||||
fn create_error_message(&self) -> String {
|
||||
let def_path = self.tcx.def_path_str(self.def_id);
|
||||
let def_kind = self.tcx.def_kind(self.def_id).descr(self.def_id);
|
||||
let def_kind = self.tcx.def_descr(self.def_id);
|
||||
let (quantifier, bound) = self.get_quantifier_and_bound();
|
||||
let kind = self.kind();
|
||||
let provided_lt_args = self.num_provided_lifetime_args();
|
||||
|
@ -990,7 +990,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
|||
};
|
||||
|
||||
let msg = {
|
||||
let def_kind = self.tcx.def_kind(self.def_id).descr(self.def_id);
|
||||
let def_kind = self.tcx.def_descr(self.def_id);
|
||||
let (quantifier, bound) = self.get_quantifier_and_bound();
|
||||
|
||||
let params = if bound == 0 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue