1
Fork 0

rustc_resolve: Use #![feature(format_args_capture)]

This commit is contained in:
Vadim Petrochenkov 2020-11-08 01:38:11 +03:00
parent b2d115f6db
commit 907b87fafa
3 changed files with 13 additions and 38 deletions

View file

@ -1021,17 +1021,11 @@ impl<'a> Resolver<'a> {
("", "") ("", "")
}; };
let article = if built_in.is_empty() { res.article() } else { "a" }; let a = if built_in.is_empty() { res.article() } else { "a" };
format!( format!("{a}{built_in} {thing}{from}", thing = res.descr())
"{a}{built_in} {thing}{from}",
a = article,
thing = res.descr(),
built_in = built_in,
from = from
)
} else { } else {
let introduced = if b.is_import() { "imported" } else { "defined" }; let introduced = if b.is_import() { "imported" } else { "defined" };
format!("the {thing} {introduced} here", thing = res.descr(), introduced = introduced) format!("the {thing} {introduced} here", thing = res.descr())
} }
} }
@ -1049,19 +1043,13 @@ impl<'a> Resolver<'a> {
ident.span, ident.span,
E0659, E0659,
"`{ident}` is ambiguous ({why})", "`{ident}` is ambiguous ({why})",
ident = ident,
why = kind.descr() why = kind.descr()
); );
err.span_label(ident.span, "ambiguous name"); err.span_label(ident.span, "ambiguous name");
let mut could_refer_to = |b: &NameBinding<'_>, misc: AmbiguityErrorMisc, also: &str| { let mut could_refer_to = |b: &NameBinding<'_>, misc: AmbiguityErrorMisc, also: &str| {
let what = self.binding_description(b, ident, misc == AmbiguityErrorMisc::FromPrelude); let what = self.binding_description(b, ident, misc == AmbiguityErrorMisc::FromPrelude);
let note_msg = format!( let note_msg = format!("`{ident}` could{also} refer to {what}");
"`{ident}` could{also} refer to {what}",
ident = ident,
also = also,
what = what
);
let thing = b.res().descr(); let thing = b.res().descr();
let mut help_msgs = Vec::new(); let mut help_msgs = Vec::new();
@ -1071,30 +1059,18 @@ impl<'a> Resolver<'a> {
|| kind == AmbiguityKind::GlobVsOuter && swapped != also.is_empty()) || kind == AmbiguityKind::GlobVsOuter && swapped != also.is_empty())
{ {
help_msgs.push(format!( help_msgs.push(format!(
"consider adding an explicit import of \ "consider adding an explicit import of `{ident}` to disambiguate"
`{ident}` to disambiguate",
ident = ident
)) ))
} }
if b.is_extern_crate() && ident.span.rust_2018() { if b.is_extern_crate() && ident.span.rust_2018() {
help_msgs.push(format!( help_msgs.push(format!("use `::{ident}` to refer to this {thing} unambiguously"))
"use `::{ident}` to refer to this {thing} unambiguously",
ident = ident,
thing = thing,
))
} }
if misc == AmbiguityErrorMisc::SuggestCrate { if misc == AmbiguityErrorMisc::SuggestCrate {
help_msgs.push(format!( help_msgs
"use `crate::{ident}` to refer to this {thing} unambiguously", .push(format!("use `crate::{ident}` to refer to this {thing} unambiguously"))
ident = ident,
thing = thing,
))
} else if misc == AmbiguityErrorMisc::SuggestSelf { } else if misc == AmbiguityErrorMisc::SuggestSelf {
help_msgs.push(format!( help_msgs
"use `self::{ident}` to refer to this {thing} unambiguously", .push(format!("use `self::{ident}` to refer to this {thing} unambiguously"))
ident = ident,
thing = thing,
))
} }
err.span_note(b.span, &note_msg); err.span_note(b.span, &note_msg);
@ -1167,12 +1143,10 @@ impl<'a> Resolver<'a> {
}; };
let first = ptr::eq(binding, first_binding); let first = ptr::eq(binding, first_binding);
let descr = get_descr(binding);
let msg = format!( let msg = format!(
"{and_refers_to}the {item} `{name}`{which} is defined here{dots}", "{and_refers_to}the {item} `{name}`{which} is defined here{dots}",
and_refers_to = if first { "" } else { "...and refers to " }, and_refers_to = if first { "" } else { "...and refers to " },
item = descr, item = get_descr(binding),
name = name,
which = if first { "" } else { " which" }, which = if first { "" } else { " which" },
dots = if next_binding.is_some() { "..." } else { "" }, dots = if next_binding.is_some() { "..." } else { "" },
); );

View file

@ -865,7 +865,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
err.span_suggestion( err.span_suggestion(
span, span,
&format!("use struct {} syntax instead", descr), &format!("use struct {} syntax instead", descr),
format!("{} {{{pad}{}{pad}}}", path_str, fields, pad = pad), format!("{path_str} {{{pad}{fields}{pad}}}"),
applicability, applicability,
); );
} }

View file

@ -11,6 +11,7 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] #![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(bool_to_option)] #![feature(bool_to_option)]
#![feature(crate_visibility_modifier)] #![feature(crate_visibility_modifier)]
#![feature(format_args_capture)]
#![feature(nll)] #![feature(nll)]
#![feature(or_patterns)] #![feature(or_patterns)]
#![recursion_limit = "256"] #![recursion_limit = "256"]