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
|
@ -255,7 +255,7 @@ fn late_report_deprecation(
|
|||
let method_span = method_span.unwrap_or(span);
|
||||
tcx.struct_span_lint_hir(lint, hir_id, method_span, message, |diag| {
|
||||
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);
|
||||
}
|
||||
diag
|
||||
|
@ -392,7 +392,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
let lint = deprecation_lint(is_in_effect);
|
||||
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_kind = self.def_kind(def_id).descr(def_id);
|
||||
let def_kind = self.def_descr(def_id);
|
||||
|
||||
late_report_deprecation(
|
||||
self,
|
||||
|
|
|
@ -1200,13 +1200,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
|
||||
/// 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) {
|
||||
match self.def_kind(def_id) {
|
||||
DefKind::Generator => match self.generator_kind(def_id).unwrap() {
|
||||
rustc_hir::GeneratorKind::Async(..) => ("an", "async closure"),
|
||||
rustc_hir::GeneratorKind::Gen => ("a", "generator"),
|
||||
},
|
||||
def_kind => (def_kind.article(), def_kind.descr(def_id)),
|
||||
}
|
||||
let kind = self.def_kind(def_id);
|
||||
(self.def_kind_descr_article(kind, def_id), self.def_kind_descr(kind, def_id))
|
||||
}
|
||||
|
||||
pub fn type_length_limit(self) -> Limit {
|
||||
|
|
|
@ -761,6 +761,40 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||
}
|
||||
(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> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue