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
|
@ -2135,7 +2135,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||||
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
|
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
|
||||||
let tcx = self.infcx.tcx;
|
let tcx = self.infcx.tcx;
|
||||||
|
|
||||||
let (_, escapes_from) = tcx.article_and_description(self.mir_def_id().to_def_id());
|
let escapes_from = tcx.def_descr(self.mir_def_id().to_def_id());
|
||||||
|
|
||||||
let mut err =
|
let mut err =
|
||||||
borrowck_errors::borrowed_data_escapes_closure(tcx, escape_span, escapes_from);
|
borrowck_errors::borrowed_data_escapes_closure(tcx, escape_span, escapes_from);
|
||||||
|
|
|
@ -660,10 +660,8 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
errci.outlived_fr,
|
errci.outlived_fr,
|
||||||
);
|
);
|
||||||
|
|
||||||
let (_, escapes_from) = self
|
let escapes_from =
|
||||||
.infcx
|
self.infcx.tcx.def_descr(self.regioncx.universal_regions().defining_ty.def_id());
|
||||||
.tcx
|
|
||||||
.article_and_description(self.regioncx.universal_regions().defining_ty.def_id());
|
|
||||||
|
|
||||||
// Revert to the normal error in these cases.
|
// Revert to the normal error in these cases.
|
||||||
// Assignments aren't "escapes" in function items.
|
// Assignments aren't "escapes" in function items.
|
||||||
|
@ -757,8 +755,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
||||||
..
|
..
|
||||||
} = errci;
|
} = errci;
|
||||||
|
|
||||||
let (_, mir_def_name) =
|
let mir_def_name = self.infcx.tcx.def_descr(self.mir_def_id().to_def_id());
|
||||||
self.infcx.tcx.article_and_description(self.mir_def_id().to_def_id());
|
|
||||||
|
|
||||||
let err = LifetimeOutliveErr { span: *span };
|
let err = LifetimeOutliveErr { span: *span };
|
||||||
let mut diag = self.infcx.tcx.sess.create_err(err);
|
let mut diag = self.infcx.tcx.sess.create_err(err);
|
||||||
|
|
|
@ -124,6 +124,11 @@ pub enum DefKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DefKind {
|
impl DefKind {
|
||||||
|
/// Get an English description for the item's kind.
|
||||||
|
///
|
||||||
|
/// If you have access to `TyCtxt`, use `TyCtxt::def_descr` or
|
||||||
|
/// `TyCtxt::def_kind_descr` instead, because they give better
|
||||||
|
/// information for generators and associated functions.
|
||||||
pub fn descr(self, def_id: DefId) -> &'static str {
|
pub fn descr(self, def_id: DefId) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
DefKind::Fn => "function",
|
DefKind::Fn => "function",
|
||||||
|
@ -166,6 +171,10 @@ impl DefKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets an English article for the definition.
|
/// Gets an English article for the definition.
|
||||||
|
///
|
||||||
|
/// If you have access to `TyCtxt`, use `TyCtxt::def_descr_article` or
|
||||||
|
/// `TyCtxt::def_kind_descr_article` instead, because they give better
|
||||||
|
/// information for generators and associated functions.
|
||||||
pub fn article(&self) -> &'static str {
|
pub fn article(&self) -> &'static str {
|
||||||
match *self {
|
match *self {
|
||||||
DefKind::AssocTy
|
DefKind::AssocTy
|
||||||
|
|
|
@ -304,10 +304,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
if let Some(did) = adt_did {
|
if let Some(did) = adt_did {
|
||||||
err.span_label(
|
err.span_label(
|
||||||
tcx.def_span(did),
|
tcx.def_span(did),
|
||||||
format!(
|
format!("associated item `{name}` not found for this {}", tcx.def_descr(did)),
|
||||||
"associated item `{name}` not found for this {}",
|
|
||||||
tcx.def_kind(did).descr(did)
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1217,7 +1217,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
| (hir::def::DefKind::AssocConst, ty::TermKind::Const(_)) => (),
|
| (hir::def::DefKind::AssocConst, ty::TermKind::Const(_)) => (),
|
||||||
(_, _) => {
|
(_, _) => {
|
||||||
let got = if let Some(_) = term.ty() { "type" } else { "constant" };
|
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(
|
let mut err = tcx.sess.struct_span_err(
|
||||||
binding.span,
|
binding.span,
|
||||||
&format!("expected {expected} bound, found {got}"),
|
&format!("expected {expected} bound, found {got}"),
|
||||||
|
@ -1552,7 +1552,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
i.bottom().1,
|
i.bottom().1,
|
||||||
E0038,
|
E0038,
|
||||||
"the {} `{}` cannot be made into an object",
|
"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),
|
tcx.item_name(def_id),
|
||||||
);
|
);
|
||||||
err.note(
|
err.note(
|
||||||
|
@ -2174,7 +2174,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||||
"`{}` could{} refer to the {} defined here",
|
"`{}` could{} refer to the {} defined here",
|
||||||
assoc_ident,
|
assoc_ident,
|
||||||
also,
|
also,
|
||||||
kind.descr(def_id)
|
tcx.def_kind_descr(kind, def_id)
|
||||||
);
|
);
|
||||||
lint.span_note(tcx.def_span(def_id), ¬e_msg);
|
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;
|
let kind = DefKind::AssocTy;
|
||||||
|
|
||||||
if !tcx.visibility(item).is_accessible_from(def_scope, tcx) {
|
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 msg = format!("{kind} `{name}` is private");
|
||||||
let def_span = tcx.def_span(item);
|
let def_span = tcx.def_span(item);
|
||||||
tcx.sess
|
tcx.sess
|
||||||
|
|
|
@ -1460,7 +1460,7 @@ fn opaque_type_cycle_error(
|
||||||
span,
|
span,
|
||||||
format!(
|
format!(
|
||||||
"{} captures itself here",
|
"{} 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 drop_impl_span = tcx.def_span(drop_impl_did);
|
||||||
let item_span = tcx.def_span(self_type_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 =
|
let mut err =
|
||||||
struct_span_err!(tcx.sess, drop_impl_span, E0366, "`Drop` impls cannot be specialized");
|
struct_span_err!(tcx.sess, drop_impl_span, E0366, "`Drop` impls cannot be specialized");
|
||||||
match arg {
|
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) {
|
if !assumptions_in_impl_context.iter().copied().any(predicate_matches_closure) {
|
||||||
let item_span = tcx.def_span(self_type_did);
|
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!(
|
let reported = struct_span_err!(
|
||||||
tcx.sess,
|
tcx.sess,
|
||||||
predicate_sp,
|
predicate_sp,
|
||||||
|
|
|
@ -531,7 +531,7 @@ fn lint_auto_trait_impl<'tcx>(
|
||||||
}),
|
}),
|
||||||
|lint| {
|
|lint| {
|
||||||
let item_span = tcx.def_span(self_type_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);
|
||||||
match arg {
|
match arg {
|
||||||
ty::util::NotUniqueParam::DuplicateParam(arg) => {
|
ty::util::NotUniqueParam::DuplicateParam(arg) => {
|
||||||
lint.note(&format!("`{}` is mentioned multiple times", 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 {
|
fn create_error_message(&self) -> String {
|
||||||
let def_path = self.tcx.def_path_str(self.def_id);
|
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 (quantifier, bound) = self.get_quantifier_and_bound();
|
||||||
let kind = self.kind();
|
let kind = self.kind();
|
||||||
let provided_lt_args = self.num_provided_lifetime_args();
|
let provided_lt_args = self.num_provided_lifetime_args();
|
||||||
|
@ -990,7 +990,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let msg = {
|
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 (quantifier, bound) = self.get_quantifier_and_bound();
|
||||||
|
|
||||||
let params = if bound == 0 {
|
let params = if bound == 0 {
|
||||||
|
|
|
@ -671,7 +671,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
&& !self.type_is_sized_modulo_regions(self.param_env, output_ty, callee_expr.span)
|
&& !self.type_is_sized_modulo_regions(self.param_env, output_ty, callee_expr.span)
|
||||||
{
|
{
|
||||||
let descr = match maybe_def {
|
let descr = match maybe_def {
|
||||||
DefIdOrName::DefId(def_id) => self.tcx.def_kind(def_id).descr(def_id),
|
DefIdOrName::DefId(def_id) => self.tcx.def_descr(def_id),
|
||||||
DefIdOrName::Name(name) => name,
|
DefIdOrName::Name(name) => name,
|
||||||
};
|
};
|
||||||
err.span_label(
|
err.span_label(
|
||||||
|
|
|
@ -2448,7 +2448,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
return_ty: Option<Ty<'tcx>>,
|
return_ty: Option<Ty<'tcx>>,
|
||||||
) {
|
) {
|
||||||
let struct_path = self.tcx().def_path_str(base_did);
|
let struct_path = self.tcx().def_path_str(base_did);
|
||||||
let kind_name = self.tcx().def_kind(base_did).descr(base_did);
|
let kind_name = self.tcx().def_descr(base_did);
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self.tcx().sess,
|
self.tcx().sess,
|
||||||
field.span,
|
field.span,
|
||||||
|
|
|
@ -1938,8 +1938,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
spans.push_span_label(param.span, "");
|
spans.push_span_label(param.span, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
let def_kind = self.tcx.def_kind(def_id);
|
err.span_note(spans, &format!("{} defined here", self.tcx.def_descr(def_id)));
|
||||||
err.span_note(spans, &format!("{} defined here", def_kind.descr(def_id)));
|
|
||||||
} else if let Some(hir::Node::Expr(e)) = self.tcx.hir().get_if_local(def_id)
|
} else if let Some(hir::Node::Expr(e)) = self.tcx.hir().get_if_local(def_id)
|
||||||
&& let hir::ExprKind::Closure(hir::Closure { body, .. }) = &e.kind
|
&& let hir::ExprKind::Closure(hir::Closure { body, .. }) = &e.kind
|
||||||
{
|
{
|
||||||
|
@ -1952,10 +1951,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
};
|
};
|
||||||
err.span_note(span, &format!("{} defined here", kind));
|
err.span_note(span, &format!("{} defined here", kind));
|
||||||
} else {
|
} else {
|
||||||
let def_kind = self.tcx.def_kind(def_id);
|
|
||||||
err.span_note(
|
err.span_note(
|
||||||
self.tcx.def_span(def_id),
|
self.tcx.def_span(def_id),
|
||||||
&format!("{} defined here", def_kind.descr(def_id)),
|
&format!("{} defined here", self.tcx.def_descr(def_id)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
DefIdOrName::DefId(def_id) => match self.tcx.def_kind(def_id) {
|
DefIdOrName::DefId(def_id) => match self.tcx.def_kind(def_id) {
|
||||||
DefKind::Ctor(CtorOf::Struct, _) => "construct this tuple struct".to_string(),
|
DefKind::Ctor(CtorOf::Struct, _) => "construct this tuple struct".to_string(),
|
||||||
DefKind::Ctor(CtorOf::Variant, _) => "construct this tuple variant".to_string(),
|
DefKind::Ctor(CtorOf::Variant, _) => "construct this tuple variant".to_string(),
|
||||||
kind => format!("call this {}", kind.descr(def_id)),
|
kind => format!("call this {}", self.tcx.def_kind_descr(kind, def_id)),
|
||||||
},
|
},
|
||||||
DefIdOrName::Name(name) => format!("call this {name}"),
|
DefIdOrName::Name(name) => format!("call this {name}"),
|
||||||
};
|
};
|
||||||
|
@ -339,7 +339,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
CtorOf::Variant => "an enum variant",
|
CtorOf::Variant => "an enum variant",
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
let descr = kind.descr(def_id);
|
let descr = self.tcx.def_kind_descr(kind, def_id);
|
||||||
err.span_label(sp, format!("{descr} `{name}` defined here"));
|
err.span_label(sp, format!("{descr} `{name}` defined here"));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -1366,8 +1366,8 @@ impl<'tcx> Pick<'tcx> {
|
||||||
span,
|
span,
|
||||||
format!(
|
format!(
|
||||||
"{} {} with this name may be added to the standard library in the future",
|
"{} {} with this name may be added to the standard library in the future",
|
||||||
def_kind.article(),
|
tcx.def_kind_descr_article(def_kind, self.item.def_id),
|
||||||
def_kind.descr(self.item.def_id),
|
tcx.def_kind_descr(def_kind, self.item.def_id),
|
||||||
),
|
),
|
||||||
|lint| {
|
|lint| {
|
||||||
match (self.item.kind, self.item.container) {
|
match (self.item.kind, self.item.container) {
|
||||||
|
|
|
@ -160,7 +160,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
MethodError::PrivateMatch(kind, def_id, out_of_scope_traits) => {
|
MethodError::PrivateMatch(kind, def_id, out_of_scope_traits) => {
|
||||||
let kind = kind.descr(def_id);
|
let kind = self.tcx.def_kind_descr(kind, def_id);
|
||||||
let mut err = struct_span_err!(
|
let mut err = struct_span_err!(
|
||||||
self.tcx.sess,
|
self.tcx.sess,
|
||||||
item_name.span,
|
item_name.span,
|
||||||
|
@ -1062,8 +1062,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
span,
|
span,
|
||||||
&format!(
|
&format!(
|
||||||
"there is {} {} with a similar name",
|
"there is {} {} with a similar name",
|
||||||
def_kind.article(),
|
self.tcx.def_kind_descr_article(def_kind, similar_candidate.def_id),
|
||||||
def_kind.descr(similar_candidate.def_id),
|
self.tcx.def_kind_descr(def_kind, similar_candidate.def_id)
|
||||||
),
|
),
|
||||||
similar_candidate.name,
|
similar_candidate.name,
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
|
@ -1172,7 +1172,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
path,
|
path,
|
||||||
ty,
|
ty,
|
||||||
item.kind,
|
item.kind,
|
||||||
item.def_id,
|
self.tcx.def_kind_descr(item.kind.as_def_kind(), item.def_id),
|
||||||
sugg_span,
|
sugg_span,
|
||||||
idx,
|
idx,
|
||||||
self.tcx.sess.source_map(),
|
self.tcx.sess.source_map(),
|
||||||
|
@ -1208,7 +1208,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
path,
|
path,
|
||||||
rcvr_ty,
|
rcvr_ty,
|
||||||
item.kind,
|
item.kind,
|
||||||
item.def_id,
|
self.tcx.def_kind_descr(item.kind.as_def_kind(), item.def_id),
|
||||||
sugg_span,
|
sugg_span,
|
||||||
idx,
|
idx,
|
||||||
self.tcx.sess.source_map(),
|
self.tcx.sess.source_map(),
|
||||||
|
@ -2853,7 +2853,7 @@ fn print_disambiguation_help<'tcx>(
|
||||||
trait_name: String,
|
trait_name: String,
|
||||||
rcvr_ty: Ty<'_>,
|
rcvr_ty: Ty<'_>,
|
||||||
kind: ty::AssocKind,
|
kind: ty::AssocKind,
|
||||||
def_id: DefId,
|
def_kind_descr: &'static str,
|
||||||
span: Span,
|
span: Span,
|
||||||
candidate: Option<usize>,
|
candidate: Option<usize>,
|
||||||
source_map: &source_map::SourceMap,
|
source_map: &source_map::SourceMap,
|
||||||
|
@ -2886,7 +2886,7 @@ fn print_disambiguation_help<'tcx>(
|
||||||
span,
|
span,
|
||||||
&format!(
|
&format!(
|
||||||
"disambiguate the {} for {}",
|
"disambiguate the {} for {}",
|
||||||
kind.as_def_kind().descr(def_id),
|
def_kind_descr,
|
||||||
if let Some(candidate) = candidate {
|
if let Some(candidate) = candidate {
|
||||||
format!("candidate #{}", candidate)
|
format!("candidate #{}", candidate)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -122,7 +122,7 @@ impl InferenceDiagnosticsParentData {
|
||||||
tcx.def_key(parent_def_id).disambiguated_data.data.get_opt_name()?.to_string();
|
tcx.def_key(parent_def_id).disambiguated_data.data.get_opt_name()?.to_string();
|
||||||
|
|
||||||
Some(InferenceDiagnosticsParentData {
|
Some(InferenceDiagnosticsParentData {
|
||||||
prefix: tcx.def_kind(parent_def_id).descr(parent_def_id),
|
prefix: tcx.def_descr(parent_def_id),
|
||||||
name: parent_name,
|
name: parent_name,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,7 +255,7 @@ fn late_report_deprecation(
|
||||||
let method_span = method_span.unwrap_or(span);
|
let method_span = method_span.unwrap_or(span);
|
||||||
tcx.struct_span_lint_hir(lint, hir_id, method_span, message, |diag| {
|
tcx.struct_span_lint_hir(lint, hir_id, method_span, message, |diag| {
|
||||||
if let hir::Node::Expr(_) = tcx.hir().get(hir_id) {
|
if let hir::Node::Expr(_) = tcx.hir().get(hir_id) {
|
||||||
let kind = tcx.def_kind(def_id).descr(def_id);
|
let kind = tcx.def_descr(def_id);
|
||||||
deprecation_suggestion(diag, kind, suggestion, method_span);
|
deprecation_suggestion(diag, kind, suggestion, method_span);
|
||||||
}
|
}
|
||||||
diag
|
diag
|
||||||
|
@ -392,7 +392,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
let lint = deprecation_lint(is_in_effect);
|
let lint = deprecation_lint(is_in_effect);
|
||||||
if self.lint_level_at_node(lint, id).0 != Level::Allow {
|
if self.lint_level_at_node(lint, id).0 != Level::Allow {
|
||||||
let def_path = with_no_trimmed_paths!(self.def_path_str(def_id));
|
let def_path = with_no_trimmed_paths!(self.def_path_str(def_id));
|
||||||
let def_kind = self.def_kind(def_id).descr(def_id);
|
let def_kind = self.def_descr(def_id);
|
||||||
|
|
||||||
late_report_deprecation(
|
late_report_deprecation(
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -1200,13 +1200,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
|
|
||||||
/// Returns a displayable description and article for the given `def_id` (e.g. `("a", "struct")`).
|
/// Returns a displayable description and article for the given `def_id` (e.g. `("a", "struct")`).
|
||||||
pub fn article_and_description(self, def_id: DefId) -> (&'static str, &'static str) {
|
pub fn article_and_description(self, def_id: DefId) -> (&'static str, &'static str) {
|
||||||
match self.def_kind(def_id) {
|
let kind = self.def_kind(def_id);
|
||||||
DefKind::Generator => match self.generator_kind(def_id).unwrap() {
|
(self.def_kind_descr_article(kind, def_id), self.def_kind_descr(kind, def_id))
|
||||||
rustc_hir::GeneratorKind::Async(..) => ("an", "async closure"),
|
|
||||||
rustc_hir::GeneratorKind::Gen => ("a", "generator"),
|
|
||||||
},
|
|
||||||
def_kind => (def_kind.article(), def_kind.descr(def_id)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn type_length_limit(self) -> Limit {
|
pub fn type_length_limit(self) -> Limit {
|
||||||
|
|
|
@ -761,6 +761,40 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
(generator_layout, generator_saved_local_names)
|
(generator_layout, generator_saved_local_names)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Query and get an English description for the item's kind.
|
||||||
|
pub fn def_descr(self, def_id: DefId) -> &'static str {
|
||||||
|
self.def_kind_descr(self.def_kind(def_id), def_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get an English description for the item's kind.
|
||||||
|
pub fn def_kind_descr(self, def_kind: DefKind, def_id: DefId) -> &'static str {
|
||||||
|
match def_kind {
|
||||||
|
DefKind::AssocFn if self.associated_item(def_id).fn_has_self_parameter => "method",
|
||||||
|
DefKind::Generator => match self.generator_kind(def_id).unwrap() {
|
||||||
|
rustc_hir::GeneratorKind::Async(..) => "async closure",
|
||||||
|
rustc_hir::GeneratorKind::Gen => "generator",
|
||||||
|
},
|
||||||
|
_ => def_kind.descr(def_id),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets an English article for the [`TyCtxt::def_descr`].
|
||||||
|
pub fn def_descr_article(self, def_id: DefId) -> &'static str {
|
||||||
|
self.def_kind_descr_article(self.def_kind(def_id), def_id)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Gets an English article for the [`TyCtxt::def_kind_descr`].
|
||||||
|
pub fn def_kind_descr_article(self, def_kind: DefKind, def_id: DefId) -> &'static str {
|
||||||
|
match def_kind {
|
||||||
|
DefKind::AssocFn if self.associated_item(def_id).fn_has_self_parameter => "a",
|
||||||
|
DefKind::Generator => match self.generator_kind(def_id).unwrap() {
|
||||||
|
rustc_hir::GeneratorKind::Async(..) => "an",
|
||||||
|
rustc_hir::GeneratorKind::Gen => "a",
|
||||||
|
},
|
||||||
|
_ => def_kind.article(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct OpaqueTypeExpander<'tcx> {
|
struct OpaqueTypeExpander<'tcx> {
|
||||||
|
|
|
@ -691,7 +691,7 @@ impl<'tcx> DeadVisitor<'tcx> {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let descr = tcx.def_kind(first_id).descr(first_id.to_def_id());
|
let descr = tcx.def_descr(first_id.to_def_id());
|
||||||
let num = dead_codes.len();
|
let num = dead_codes.len();
|
||||||
let multiple = num > 6;
|
let multiple = num > 6;
|
||||||
let name_list = names.into();
|
let name_list = names.into();
|
||||||
|
@ -703,7 +703,7 @@ impl<'tcx> DeadVisitor<'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let parent_info = if let Some(parent_item) = parent_item {
|
let parent_info = if let Some(parent_item) = parent_item {
|
||||||
let parent_descr = tcx.def_kind(parent_item).descr(parent_item.to_def_id());
|
let parent_descr = tcx.def_descr(parent_item.to_def_id());
|
||||||
Some(ParentInfo {
|
Some(ParentInfo {
|
||||||
num,
|
num,
|
||||||
descr,
|
descr,
|
||||||
|
|
|
@ -523,7 +523,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> {
|
||||||
&& stab.is_none()
|
&& stab.is_none()
|
||||||
&& self.effective_visibilities.is_reachable(def_id)
|
&& self.effective_visibilities.is_reachable(def_id)
|
||||||
{
|
{
|
||||||
let descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id());
|
let descr = self.tcx.def_descr(def_id.to_def_id());
|
||||||
self.tcx.sess.emit_err(errors::MissingStabilityAttr { span, descr });
|
self.tcx.sess.emit_err(errors::MissingStabilityAttr { span, descr });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -551,7 +551,7 @@ impl<'tcx> MissingStabilityAnnotations<'tcx> {
|
||||||
let is_reachable = self.effective_visibilities.is_reachable(def_id);
|
let is_reachable = self.effective_visibilities.is_reachable(def_id);
|
||||||
|
|
||||||
if is_const && is_stable && missing_const_stability_attribute && is_reachable {
|
if is_const && is_stable && missing_const_stability_attribute && is_reachable {
|
||||||
let descr = self.tcx.def_kind(def_id).descr(def_id.to_def_id());
|
let descr = self.tcx.def_descr(def_id.to_def_id());
|
||||||
self.tcx.sess.emit_err(errors::MissingConstStabAttr { span, descr });
|
self.tcx.sess.emit_err(errors::MissingConstStabAttr { span, descr });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1329,7 +1329,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
|
||||||
hir::QPath::Resolved(_, path) => Some(self.tcx.def_path_str(path.res.def_id())),
|
hir::QPath::Resolved(_, path) => Some(self.tcx.def_path_str(path.res.def_id())),
|
||||||
hir::QPath::TypeRelative(_, segment) => Some(segment.ident.to_string()),
|
hir::QPath::TypeRelative(_, segment) => Some(segment.ident.to_string()),
|
||||||
};
|
};
|
||||||
let kind = kind.descr(def_id);
|
let kind = self.tcx.def_descr(def_id);
|
||||||
let sess = self.tcx.sess;
|
let sess = self.tcx.sess;
|
||||||
let _ = match name {
|
let _ = match name {
|
||||||
Some(name) => {
|
Some(name) => {
|
||||||
|
|
|
@ -189,7 +189,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let container = match parent.kind {
|
let container = match parent.kind {
|
||||||
ModuleKind::Def(kind, _, _) => kind.descr(parent.def_id()),
|
ModuleKind::Def(kind, _, _) => self.tcx.def_kind_descr(kind, parent.def_id()),
|
||||||
ModuleKind::Block => "block",
|
ModuleKind::Block => "block",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1804,7 +1804,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
found("module")
|
found("module")
|
||||||
} else {
|
} else {
|
||||||
match binding.res() {
|
match binding.res() {
|
||||||
Res::Def(kind, id) => found(kind.descr(id)),
|
Res::Def(kind, id) => found(self.tcx.def_kind_descr(kind, id)),
|
||||||
_ => found(ns_to_try.descr()),
|
_ => found(ns_to_try.descr()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -927,7 +927,10 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
DefKind::Ctor(CtorOf::Variant, _) => {
|
DefKind::Ctor(CtorOf::Variant, _) => {
|
||||||
"use parentheses to construct this tuple variant".to_string()
|
"use parentheses to construct this tuple variant".to_string()
|
||||||
}
|
}
|
||||||
kind => format!("use parentheses to call this {}", kind.descr(def_id)),
|
kind => format!(
|
||||||
|
"use parentheses to call this {}",
|
||||||
|
self.tcx.def_kind_descr(kind, def_id)
|
||||||
|
),
|
||||||
},
|
},
|
||||||
DefIdOrName::Name(name) => format!("use parentheses to call this {name}"),
|
DefIdOrName::Name(name) => format!("use parentheses to call this {name}"),
|
||||||
};
|
};
|
||||||
|
@ -2139,7 +2142,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||||
err.note(&format!(
|
err.note(&format!(
|
||||||
"{}s cannot be accessed directly on a `trait`, they can only be \
|
"{}s cannot be accessed directly on a `trait`, they can only be \
|
||||||
accessed through a specific `impl`",
|
accessed through a specific `impl`",
|
||||||
assoc_item.kind.as_def_kind().descr(item_def_id)
|
self.tcx.def_kind_descr(assoc_item.kind.as_def_kind(), item_def_id)
|
||||||
));
|
));
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
span,
|
span,
|
||||||
|
|
|
@ -775,7 +775,7 @@ pub(crate) fn link_tooltip(did: DefId, fragment: &Option<UrlFragment>, cx: &Cont
|
||||||
let fqp = fqp.iter().map(|sym| sym.as_str()).join("::");
|
let fqp = fqp.iter().map(|sym| sym.as_str()).join("::");
|
||||||
if let &Some(UrlFragment::Item(id)) = fragment {
|
if let &Some(UrlFragment::Item(id)) = fragment {
|
||||||
let name = cx.tcx().item_name(id);
|
let name = cx.tcx().item_name(id);
|
||||||
let descr = cx.tcx().def_kind(id).descr(id);
|
let descr = cx.tcx().def_descr(id);
|
||||||
format!("{descr} {fqp}::{name}")
|
format!("{descr} {fqp}::{name}")
|
||||||
} else {
|
} else {
|
||||||
format!("{shortty} {fqp}")
|
format!("{shortty} {fqp}")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue