summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_resolve/src/late
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /compiler/rustc_resolve/src/late
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_resolve/src/late')
-rw-r--r--compiler/rustc_resolve/src/late/diagnostics.rs257
1 files changed, 150 insertions, 107 deletions
diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs
index c0e3f1aaf..c34b7df9b 100644
--- a/compiler/rustc_resolve/src/late/diagnostics.rs
+++ b/compiler/rustc_resolve/src/late/diagnostics.rs
@@ -332,15 +332,11 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
pub(crate) fn smart_resolve_partial_mod_path_errors(
&mut self,
prefix_path: &[Segment],
- path: &[Segment],
+ following_seg: Option<&Segment>,
) -> Vec<ImportSuggestion> {
- let next_seg = if path.len() >= prefix_path.len() + 1 && prefix_path.len() == 1 {
- path.get(prefix_path.len())
- } else {
- None
- };
if let Some(segment) = prefix_path.last() &&
- let Some(next_seg) = next_seg {
+ let Some(following_seg) = following_seg
+ {
let candidates = self.r.lookup_import_candidates(
segment.ident,
Namespace::TypeNS,
@@ -353,9 +349,10 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
.filter(|candidate| {
if let Some(def_id) = candidate.did &&
let Some(module) = self.r.get_module(def_id) {
- self.r.resolutions(module).borrow().iter().any(|(key, _r)| {
- key.ident.name == next_seg.ident.name
- })
+ Some(def_id) != self.parent_scope.module.opt_def_id() &&
+ self.r.resolutions(module).borrow().iter().any(|(key, _r)| {
+ key.ident.name == following_seg.ident.name
+ })
} else {
false
}
@@ -371,7 +368,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
pub(crate) fn smart_resolve_report_errors(
&mut self,
path: &[Segment],
- full_path: &[Segment],
+ following_seg: Option<&Segment>,
span: Span,
source: PathSource<'_>,
res: Option<Res>,
@@ -412,8 +409,15 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
return (err, Vec::new());
}
- let (found, candidates) =
- self.try_lookup_name_relaxed(&mut err, source, path, full_path, span, res, &base_error);
+ let (found, candidates) = self.try_lookup_name_relaxed(
+ &mut err,
+ source,
+ path,
+ following_seg,
+ span,
+ res,
+ &base_error,
+ );
if found {
return (err, candidates);
}
@@ -422,7 +426,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
// if we have suggested using pattern matching, then don't add needless suggestions
// for typos.
- fallback |= self.suggest_typo(&mut err, source, path, span, &base_error);
+ fallback |= self.suggest_typo(&mut err, source, path, following_seg, span, &base_error);
if fallback {
// Fallback label.
@@ -442,20 +446,29 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
err: &mut Diagnostic,
base_error: &BaseError,
) {
- let Some(ty) = self.diagnostic_metadata.current_type_path else { return; };
- let TyKind::Path(_, path) = &ty.kind else { return; };
+ let Some(ty) = self.diagnostic_metadata.current_type_path else {
+ return;
+ };
+ let TyKind::Path(_, path) = &ty.kind else {
+ return;
+ };
for segment in &path.segments {
- let Some(params) = &segment.args else { continue; };
- let ast::GenericArgs::AngleBracketed(ref params) = params.deref() else { continue; };
+ let Some(params) = &segment.args else {
+ continue;
+ };
+ let ast::GenericArgs::AngleBracketed(ref params) = params.deref() else {
+ continue;
+ };
for param in &params.args {
- let ast::AngleBracketedArg::Constraint(constraint) = param else { continue; };
+ let ast::AngleBracketedArg::Constraint(constraint) = param else {
+ continue;
+ };
let ast::AssocConstraintKind::Bound { bounds } = &constraint.kind else {
continue;
};
for bound in bounds {
- let ast::GenericBound::Trait(trait_ref, ast::TraitBoundModifier::None)
- = bound else
- {
+ let ast::GenericBound::Trait(trait_ref, ast::TraitBoundModifier::None) = bound
+ else {
continue;
};
if base_error.span == trait_ref.span {
@@ -519,7 +532,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
err: &mut Diagnostic,
source: PathSource<'_>,
path: &[Segment],
- full_path: &[Segment],
+ following_seg: Option<&Segment>,
span: Span,
res: Option<Res>,
base_error: &BaseError,
@@ -542,7 +555,6 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
}
})
.collect::<Vec<_>>();
- let crate_def_id = CRATE_DEF_ID.to_def_id();
// Try to filter out intrinsics candidates, as long as we have
// some other candidates to suggest.
let intrinsic_candidates: Vec<_> = candidates
@@ -553,8 +565,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
.collect();
if candidates.is_empty() {
// Put them back if we have no more candidates to suggest...
- candidates.extend(intrinsic_candidates);
+ candidates = intrinsic_candidates;
}
+ let crate_def_id = CRATE_DEF_ID.to_def_id();
if candidates.is_empty() && is_expected(Res::Def(DefKind::Enum, crate_def_id)) {
let mut enum_candidates: Vec<_> = self
.r
@@ -572,13 +585,13 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
let others = match enum_candidates.len() {
1 => String::new(),
2 => " and 1 other".to_owned(),
- n => format!(" and {} others", n),
+ n => format!(" and {n} others"),
};
format!("there is an enum variant `{}`{}; ", enum_candidates[0].0, others)
} else {
String::new()
};
- let msg = format!("{}try using the variant's enum", preamble);
+ let msg = format!("{preamble}try using the variant's enum");
err.span_suggestions(
span,
@@ -590,8 +603,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
}
// Try finding a suitable replacement.
- let typo_sugg =
- self.lookup_typo_candidate(path, source.namespace(), is_expected).to_opt_suggestion();
+ let typo_sugg = self
+ .lookup_typo_candidate(path, following_seg, source.namespace(), is_expected)
+ .to_opt_suggestion();
if path.len() == 1 && self.self_type_is_available() {
if let Some(candidate) =
self.lookup_assoc_candidate(ident, ns, is_expected, source.is_call())
@@ -682,7 +696,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
ident.name == path[0].ident.name {
err.span_help(
ident.span,
- format!("the binding `{}` is available in a different scope in the same function", path_str),
+ format!("the binding `{path_str}` is available in a different scope in the same function"),
);
return (true, candidates);
}
@@ -690,7 +704,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
}
if candidates.is_empty() {
- candidates = self.smart_resolve_partial_mod_path_errors(path, full_path);
+ candidates = self.smart_resolve_partial_mod_path_errors(path, following_seg);
}
return (false, candidates);
@@ -776,12 +790,14 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
err: &mut Diagnostic,
source: PathSource<'_>,
path: &[Segment],
+ following_seg: Option<&Segment>,
span: Span,
base_error: &BaseError,
) -> bool {
let is_expected = &|res| source.is_expected(res);
let ident_span = path.last().map_or(span, |ident| ident.ident.span);
- let typo_sugg = self.lookup_typo_candidate(path, source.namespace(), is_expected);
+ let typo_sugg =
+ self.lookup_typo_candidate(path, following_seg, source.namespace(), is_expected);
let is_in_same_file = &|sp1, sp2| {
let source_map = self.r.tcx.sess.source_map();
let file1 = source_map.span_to_filename(sp1);
@@ -842,7 +858,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
for label_rib in &self.label_ribs {
for (label_ident, node_id) in &label_rib.bindings {
let ident = path.last().unwrap().ident;
- if format!("'{}", ident) == label_ident.to_string() {
+ if format!("'{ident}") == label_ident.to_string() {
err.span_label(label_ident.span, "a label with a similar name exists");
if let PathSource::Expr(Some(Expr {
kind: ExprKind::Break(None, Some(_)),
@@ -967,7 +983,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
if let Some(ident) = fn_kind.ident() {
err.span_label(
ident.span,
- format!("this function {} have a `self` parameter", doesnt),
+ format!("this function {doesnt} have a `self` parameter"),
);
}
}
@@ -1141,10 +1157,14 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
&poly_trait_ref.trait_ref.path.segments[..]
{
if ident.span == span {
- let Some(new_where_bound_predicate) = mk_where_bound_predicate(path, poly_trait_ref, ty) else { return false; };
+ let Some(new_where_bound_predicate) =
+ mk_where_bound_predicate(path, poly_trait_ref, ty)
+ else {
+ return false;
+ };
err.span_suggestion_verbose(
*where_span,
- format!("constrain the associated type to `{}`", ident),
+ format!("constrain the associated type to `{ident}`"),
where_bound_predicate_to_string(&new_where_bound_predicate),
Applicability::MaybeIncorrect,
);
@@ -1160,37 +1180,34 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
/// return the span of whole call and the span for all arguments expect the first one (`self`).
fn call_has_self_arg(&self, source: PathSource<'_>) -> Option<(Span, Option<Span>)> {
let mut has_self_arg = None;
- if let PathSource::Expr(Some(parent)) = source {
- match &parent.kind {
- ExprKind::Call(_, args) if !args.is_empty() => {
- let mut expr_kind = &args[0].kind;
- loop {
- match expr_kind {
- ExprKind::Path(_, arg_name) if arg_name.segments.len() == 1 => {
- if arg_name.segments[0].ident.name == kw::SelfLower {
- let call_span = parent.span;
- let tail_args_span = if args.len() > 1 {
- Some(Span::new(
- args[1].span.lo(),
- args.last().unwrap().span.hi(),
- call_span.ctxt(),
- None,
- ))
- } else {
- None
- };
- has_self_arg = Some((call_span, tail_args_span));
- }
- break;
+ if let PathSource::Expr(Some(parent)) = source
+ && let ExprKind::Call(_, args) = &parent.kind
+ && !args.is_empty() {
+ let mut expr_kind = &args[0].kind;
+ loop {
+ match expr_kind {
+ ExprKind::Path(_, arg_name) if arg_name.segments.len() == 1 => {
+ if arg_name.segments[0].ident.name == kw::SelfLower {
+ let call_span = parent.span;
+ let tail_args_span = if args.len() > 1 {
+ Some(Span::new(
+ args[1].span.lo(),
+ args.last().unwrap().span.hi(),
+ call_span.ctxt(),
+ None,
+ ))
+ } else {
+ None
+ };
+ has_self_arg = Some((call_span, tail_args_span));
}
- ExprKind::AddrOf(_, _, expr) => expr_kind = &expr.kind,
- _ => break,
+ break;
}
+ ExprKind::AddrOf(_, _, expr) => expr_kind = &expr.kind,
+ _ => break,
}
}
- _ => (),
- }
- };
+ }
has_self_arg
}
@@ -1200,15 +1217,15 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
// where a brace being opened means a block is being started. Look
// ahead for the next text to see if `span` is followed by a `{`.
let sm = self.r.tcx.sess.source_map();
- let sp = sm.span_look_ahead(span, None, Some(50));
- let followed_by_brace = matches!(sm.span_to_snippet(sp), Ok(ref snippet) if snippet == "{");
- // In case this could be a struct literal that needs to be surrounded
- // by parentheses, find the appropriate span.
- let closing_span = sm.span_look_ahead(span, Some("}"), Some(50));
- let closing_brace: Option<Span> = sm
- .span_to_snippet(closing_span)
- .map_or(None, |s| if s == "}" { Some(span.to(closing_span)) } else { None });
- (followed_by_brace, closing_brace)
+ if let Some(followed_brace_span) = sm.span_look_ahead(span, "{", Some(50)) {
+ // In case this could be a struct literal that needs to be surrounded
+ // by parentheses, find the appropriate span.
+ let close_brace_span = sm.span_look_ahead(followed_brace_span, "}", Some(50));
+ let closing_brace = close_brace_span.map(|sp| span.to(sp));
+ (true, closing_brace)
+ } else {
+ (false, None)
+ }
}
/// Provides context-dependent help for errors reported by the `smart_resolve_path_fragment`
@@ -1318,8 +1335,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
span, // Note the parentheses surrounding the suggestion below
format!(
"you might want to surround a struct literal with parentheses: \
- `({} {{ /* fields */ }})`?",
- path_str
+ `({path_str} {{ /* fields */ }})`?"
),
);
}
@@ -1353,7 +1369,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
.map(|(idx, new)| (new, old_fields.get(idx)))
.map(|(new, old)| {
let new = new.to_ident_string();
- if let Some(Some(old)) = old && new != *old { format!("{}: {}", new, old) } else { new }
+ if let Some(Some(old)) = old && new != *old { format!("{new}: {old}") } else { new }
})
.collect::<Vec<String>>()
} else {
@@ -1370,7 +1386,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
};
err.span_suggestion(
span,
- format!("use struct {} syntax instead", descr),
+ format!("use struct {descr} syntax instead"),
format!("{path_str} {{{pad}{fields}{pad}}}"),
applicability,
);
@@ -1403,7 +1419,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
(Res::Def(DefKind::Macro(MacroKind::Bang), _), _) => {
err.span_label(span, fallback_label.to_string());
}
- (Res::Def(DefKind::TyAlias, def_id), PathSource::Trait(_)) => {
+ (Res::Def(DefKind::TyAlias { .. }, def_id), PathSource::Trait(_)) => {
err.span_label(span, "type aliases cannot be used as traits");
if self.r.tcx.sess.is_nightly_build() {
let msg = "you might have meant to use `#![feature(trait_alias)]` instead of a \
@@ -1564,7 +1580,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
err.span_suggestion(
span,
"use the tuple variant pattern syntax instead",
- format!("{}({})", path_str, fields),
+ format!("{path_str}({fields})"),
Applicability::HasPlaceholders,
);
}
@@ -1572,7 +1588,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
err.span_label(span, fallback_label.to_string());
err.note("can't use `Self` as a constructor, you must use the implemented struct");
}
- (Res::Def(DefKind::TyAlias | DefKind::AssocTy, _), _) if ns == ValueNS => {
+ (Res::Def(DefKind::TyAlias { .. } | DefKind::AssocTy, _), _) if ns == ValueNS => {
err.note("can't use a type alias as a constructor");
}
_ => return false,
@@ -1715,6 +1731,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
fn lookup_typo_candidate(
&mut self,
path: &[Segment],
+ following_seg: Option<&Segment>,
ns: Namespace,
filter_fn: &impl Fn(Res) -> bool,
) -> TypoCandidate {
@@ -1793,6 +1810,26 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
}
}
+ // if next_seg is present, let's filter everything that does not continue the path
+ if let Some(following_seg) = following_seg {
+ names.retain(|suggestion| match suggestion.res {
+ Res::Def(DefKind::Struct | DefKind::Enum | DefKind::Union, _) => {
+ // FIXME: this is not totally accurate, but mostly works
+ suggestion.candidate != following_seg.ident.name
+ }
+ Res::Def(DefKind::Mod, def_id) => self.r.get_module(def_id).map_or_else(
+ || false,
+ |module| {
+ self.r
+ .resolutions(module)
+ .borrow()
+ .iter()
+ .any(|(key, _)| key.ident.name == following_seg.ident.name)
+ },
+ ),
+ _ => true,
+ });
+ }
let name = path[path.len() - 1].ident.name;
// Make sure error reporting is deterministic.
names.sort_by(|a, b| a.candidate.as_str().cmp(b.candidate.as_str()));
@@ -1803,7 +1840,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
None,
) {
Some(found) => {
- let Some(sugg) = names.into_iter().find(|suggestion| suggestion.candidate == found) else {
+ let Some(sugg) = names.into_iter().find(|suggestion| suggestion.candidate == found)
+ else {
return TypoCandidate::None;
};
if found == name {
@@ -1952,9 +1990,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
if !suggestable_variants.is_empty() {
let msg = if non_suggestable_variant_count == 0 && suggestable_variants.len() == 1 {
- format!("try {} the enum's variant", source_msg)
+ format!("try {source_msg} the enum's variant")
} else {
- format!("try {} one of the enum's variants", source_msg)
+ format!("try {source_msg} one of the enum's variants")
};
err.span_suggestions(
@@ -1967,19 +2005,15 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
// If the enum has no tuple variants..
if non_suggestable_variant_count == variants.len() {
- err.help(format!("the enum has no tuple variants {}", source_msg));
+ err.help(format!("the enum has no tuple variants {source_msg}"));
}
// If there are also non-tuple variants..
if non_suggestable_variant_count == 1 {
- err.help(format!(
- "you might have meant {} the enum's non-tuple variant",
- source_msg
- ));
+ err.help(format!("you might have meant {source_msg} the enum's non-tuple variant"));
} else if non_suggestable_variant_count >= 1 {
err.help(format!(
- "you might have meant {} one of the enum's non-tuple variants",
- source_msg
+ "you might have meant {source_msg} one of the enum's non-tuple variants"
));
}
} else {
@@ -1999,7 +2033,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
.map(|(variant, _, kind)| (path_names_to_string(variant), kind))
.map(|(variant, kind)| match kind {
CtorKind::Const => variant,
- CtorKind::Fn => format!("({}())", variant),
+ CtorKind::Fn => format!("({variant}())"),
})
.collect::<Vec<_>>();
let no_suggestable_variant = suggestable_variants.is_empty();
@@ -2024,7 +2058,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
.filter(|(_, def_id, kind)| needs_placeholder(*def_id, *kind))
.map(|(variant, _, kind)| (path_names_to_string(variant), kind))
.filter_map(|(variant, kind)| match kind {
- CtorKind::Fn => Some(format!("({}(/* fields */))", variant)),
+ CtorKind::Fn => Some(format!("({variant}(/* fields */))")),
_ => None,
})
.collect::<Vec<_>>();
@@ -2306,13 +2340,20 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
let mut should_continue = true;
match rib.kind {
LifetimeRibKind::Generics { binder: _, span, kind } => {
+ // Avoid suggesting placing lifetime parameters on constant items unless the relevant
+ // feature is enabled. Suggest the parent item as a possible location if applicable.
+ if let LifetimeBinderKind::ConstItem = kind
+ && !self.r.tcx().features().generic_const_items
+ {
+ continue;
+ }
+
if !span.can_be_used_for_suggestions() && suggest_note && let Some(name) = name {
suggest_note = false; // Avoid displaying the same help multiple times.
err.span_label(
span,
format!(
- "lifetime `{}` is missing in item created through this procedural macro",
- name,
+ "lifetime `{name}` is missing in item created through this procedural macro",
),
);
continue;
@@ -2356,14 +2397,14 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
);
} else if let Some(name) = name {
let message =
- Cow::from(format!("consider introducing lifetime `{}` here", name));
+ Cow::from(format!("consider introducing lifetime `{name}` here"));
should_continue = suggest(err, false, span, message, sugg);
} else {
let message = Cow::from("consider introducing a named lifetime parameter");
should_continue = suggest(err, false, span, message, sugg);
}
}
- LifetimeRibKind::Item => break,
+ LifetimeRibKind::Item | LifetimeRibKind::ConstParamTy => break,
_ => {}
}
if !should_continue {
@@ -2469,7 +2510,9 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
.lifetime_ribs
.iter()
.rev()
- .take_while(|rib| !matches!(rib.kind, LifetimeRibKind::Item))
+ .take_while(|rib| {
+ !matches!(rib.kind, LifetimeRibKind::Item | LifetimeRibKind::ConstParamTy)
+ })
.flat_map(|rib| rib.bindings.iter())
.map(|(&ident, &res)| (ident, res))
.filter(|(ident, _)| ident.name != kw::UnderscoreLifetime)
@@ -2500,7 +2543,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
}
let help_name = if let Some(ident) = ident {
- format!("`{}`", ident)
+ format!("`{ident}`")
} else {
format!("argument {}", index + 1)
};
@@ -2508,7 +2551,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
if lifetime_count == 1 {
m.push_str(&help_name[..])
} else {
- m.push_str(&format!("one of {}'s {} lifetimes", help_name, lifetime_count)[..])
+ m.push_str(&format!("one of {help_name}'s {lifetime_count} lifetimes")[..])
}
}
@@ -2538,14 +2581,12 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
} else if num_params == 1 {
err.help(format!(
"this function's return type contains a borrowed value, \
- but the signature does not say which {} it is borrowed from",
- m
+ but the signature does not say which {m} it is borrowed from"
));
} else {
err.help(format!(
"this function's return type contains a borrowed value, \
- but the signature does not say whether it is borrowed from {}",
- m
+ but the signature does not say whether it is borrowed from {m}"
));
}
}
@@ -2564,7 +2605,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
}
MissingLifetimeKind::Ampersand => {
debug_assert_eq!(lt.count, 1);
- (lt.span.shrink_to_hi(), format!("{} ", existing_name))
+ (lt.span.shrink_to_hi(), format!("{existing_name} "))
}
MissingLifetimeKind::Comma => {
let sugg: String = std::iter::repeat([existing_name.as_str(), ", "])
@@ -2611,7 +2652,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
}
1 => {
err.multipart_suggestion_verbose(
- format!("consider using the `{}` lifetime", existing_name),
+ format!("consider using the `{existing_name}` lifetime"),
spans_suggs,
Applicability::MaybeIncorrect,
);
@@ -2649,7 +2690,9 @@ fn mk_where_bound_predicate(
use rustc_span::DUMMY_SP;
let modified_segments = {
let mut segments = path.segments.clone();
- let [preceding @ .., second_last, last] = segments.as_mut_slice() else { return None; };
+ let [preceding @ .., second_last, last] = segments.as_mut_slice() else {
+ return None;
+ };
let mut segments = ThinVec::from(preceding);
let added_constraint = ast::AngleBracketedArg::Constraint(ast::AssocConstraint {
@@ -2726,9 +2769,9 @@ pub(super) fn signal_label_shadowing(sess: &Session, orig: Span, shadower: Ident
let shadower = shadower.span;
let mut err = sess.struct_span_warn(
shadower,
- format!("label name `{}` shadows a label name that is already in scope", name),
+ format!("label name `{name}` shadows a label name that is already in scope"),
);
err.span_label(orig, "first declared here");
- err.span_label(shadower, format!("label `{}` already in scope", name));
+ err.span_label(shadower, format!("label `{name}` already in scope"));
err.emit();
}