Rename Res::kind_name to Res::descr for consistency

This commit is contained in:
Vadim Petrochenkov 2019-05-04 15:22:00 +03:00
parent 917a0fbc1b
commit 85ddd1dc58
8 changed files with 17 additions and 17 deletions

View File

@ -370,7 +370,7 @@ impl<Id> Res<Id> {
}
/// A human readable name for the res kind ("function", "module", etc.).
pub fn kind_name(&self) -> &'static str {
pub fn descr(&self) -> &'static str {
match *self {
Res::Def(kind, _) => kind.descr(),
Res::SelfCtor(..) => "self constructor",

View File

@ -286,7 +286,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> {
PatKind::Path(hir::QPath::Resolved(None, ref path))
if path.segments.len() == 1 && path.segments[0].args.is_none() => {
format!("interpreted as {} {} pattern, not new variable",
path.res.article(), path.res.kind_name())
path.res.article(), path.res.descr())
}
_ => format!("pattern `{}` not covered", pattern_string),
};

View File

@ -41,7 +41,7 @@ impl<'a> Resolver<'a> {
let item_str = path.last().unwrap().ident;
let code = source.error_code(res.is_some());
let (base_msg, fallback_label, base_span) = if let Some(res) = res {
(format!("expected {}, found {} `{}`", expected, res.kind_name(), path_str),
(format!("expected {}, found {} `{}`", expected, res.descr(), path_str),
format!("not a {}", expected),
span)
} else {

View File

@ -1532,7 +1532,7 @@ impl<'a> NameBinding<'a> {
}
fn descr(&self) -> &'static str {
if self.is_extern_crate() { "extern crate" } else { self.res().kind_name() }
if self.is_extern_crate() { "extern crate" } else { self.res().descr() }
}
fn article(&self) -> &'static str {
@ -3868,7 +3868,7 @@ impl<'a> Resolver<'a> {
"`{}` is {} {}, not a module",
ident,
res.article(),
res.kind_name(),
res.descr(),
);
return PathResult::Failed {
@ -4220,7 +4220,7 @@ impl<'a> Resolver<'a> {
names.push(TypoSuggestion {
candidate: ident.name,
article: binding.res().article(),
kind: binding.res().kind_name(),
kind: binding.res().descr(),
});
}
}
@ -4238,7 +4238,7 @@ impl<'a> Resolver<'a> {
names.push(TypoSuggestion {
candidate: ident.name,
article: res.article(),
kind: res.kind_name(),
kind: res.descr(),
});
}
}

View File

@ -333,7 +333,7 @@ impl<'a> Resolver<'a> {
// Not only attributes, but anything in macro namespace can result in
// `Res::NonMacroAttr` definition (e.g., `inline!()`), so we must report
// an error for those cases.
let msg = format!("expected a macro, found {}", res.kind_name());
let msg = format!("expected a macro, found {}", res.descr());
self.session.span_err(path.span, &msg);
return Err(Determinacy::Determined);
}
@ -913,7 +913,7 @@ impl<'a> Resolver<'a> {
// (which is a best effort error recovery tool, basically), so we can't
// promise their resolution won't change later.
let msg = format!("inconsistent resolution for a macro: first {}, then {}",
initial_res.kind_name(), res.kind_name());
initial_res.descr(), res.descr());
this.session.span_err(span, &msg);
} else {
span_bug!(span, "inconsistent resolution for a macro");

View File

@ -884,7 +884,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
};
let report_unexpected_res = |res: Res| {
let msg = format!("expected tuple struct/variant, found {} `{}`",
res.kind_name(),
res.descr(),
hir::print::to_string(tcx.hir(), |s| s.print_qpath(qpath, false)));
struct_span_err!(tcx.sess, pat.span, E0164, "{}", msg)
.span_label(pat.span, "not a tuple variant or struct").emit();
@ -947,7 +947,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects");
let fields_ending = if variant.fields.len() == 1 { "" } else { "s" };
struct_span_err!(tcx.sess, pat.span, E0023,
"this pattern has {} field{}, but the corresponding {} has {} field{}",
subpats.len(), subpats_ending, res.kind_name(),
subpats.len(), subpats_ending, res.descr(),
variant.fields.len(), fields_ending)
.span_label(pat.span, format!("expected {} field{}, found {}",
variant.fields.len(), fields_ending, subpats.len()))

View File

@ -1902,7 +1902,7 @@ fn report_unexpected_variant_res<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
qpath: &QPath) {
span_err!(tcx.sess, span, E0533,
"expected unit struct/variant or constant, found {} `{}`",
res.kind_name(),
res.descr(),
hir::print::to_string(tcx.hir(), |s| s.print_qpath(qpath, false)));
}

View File

@ -513,18 +513,18 @@ fn ambiguity_error(
msg += &format!(
"both {} {} and {} {}",
first_def.article(),
first_def.kind_name(),
first_def.descr(),
second_def.article(),
second_def.kind_name(),
second_def.descr(),
);
}
_ => {
let mut candidates = candidates.iter().peekable();
while let Some((res, _)) = candidates.next() {
if candidates.peek().is_some() {
msg += &format!("{} {}, ", res.article(), res.kind_name());
msg += &format!("{} {}, ", res.article(), res.descr());
} else {
msg += &format!("and {} {}", res.article(), res.kind_name());
msg += &format!("and {} {}", res.article(), res.descr());
}
}
}
@ -575,7 +575,7 @@ fn ambiguity_error(
diag.span_suggestion(
sp,
&format!("to link to the {}, {}", res.kind_name(), action),
&format!("to link to the {}, {}", res.descr(), action),
suggestion,
Applicability::MaybeIncorrect,
);