summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_hir_analysis/src/structured_errors
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_hir_analysis/src/structured_errors
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_hir_analysis/src/structured_errors')
-rw-r--r--compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs70
1 files changed, 41 insertions, 29 deletions
diff --git a/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs b/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs
index ee3457282..61b182b1b 100644
--- a/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs
+++ b/compiler/rustc_hir_analysis/src/structured_errors/wrong_number_of_generic_args.rs
@@ -360,9 +360,11 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
&[]
};
ret.extend(params.iter().filter_map(|p| {
- let hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit }
- = p.kind
- else { return None };
+ let hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit } =
+ p.kind
+ else {
+ return None;
+ };
let hir::ParamName::Plain(name) = p.name else { return None };
Some(name.to_string())
}));
@@ -472,7 +474,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
verb
)
} else {
- format!("missing generics for {} `{}`", def_kind, def_path)
+ format!("missing generics for {def_kind} `{def_path}`")
}
}
@@ -576,6 +578,9 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
MissingTypesOrConsts { .. } => {
self.suggest_adding_type_and_const_args(err);
}
+ ExcessTypesOrConsts { .. } => {
+ // this can happen with `~const T` where T isn't a const_trait.
+ }
_ => unreachable!(),
}
}
@@ -597,7 +602,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
let span = self.path_segment.ident.span;
// insert a suggestion of the form "Y<'a, 'b>"
- let sugg = format!("<{}>", suggested_args);
+ let sugg = format!("<{suggested_args}>");
debug!("sugg: {:?}", sugg);
err.span_suggestion_verbose(
@@ -622,7 +627,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
let sugg_suffix =
if is_first && (has_non_lt_args || has_bindings) { ", " } else { "" };
- let sugg = format!("{}{}{}", sugg_prefix, suggested_args, sugg_suffix);
+ let sugg = format!("{sugg_prefix}{suggested_args}{sugg_suffix}");
debug!("sugg: {:?}", sugg);
err.span_suggestion_verbose(sugg_span, msg, sugg, Applicability::HasPlaceholders);
@@ -647,7 +652,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
let span = self.path_segment.ident.span;
// insert a suggestion of the form "Y<T, U>"
- let sugg = format!("<{}>", suggested_args);
+ let sugg = format!("<{suggested_args}>");
debug!("sugg: {:?}", sugg);
err.span_suggestion_verbose(
@@ -680,7 +685,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
let sugg_suffix =
if is_first && !self.gen_args.bindings.is_empty() { ", " } else { "" };
- let sugg = format!("{}{}{}", sugg_prefix, suggested_args, sugg_suffix);
+ let sugg = format!("{sugg_prefix}{suggested_args}{sugg_suffix}");
debug!("sugg: {:?}", sugg);
err.span_suggestion_verbose(sugg_span, msg, sugg, Applicability::HasPlaceholders);
@@ -793,29 +798,36 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
num_trait_generics_except_self: usize,
) {
let sm = self.tcx.sess.source_map();
- let hir::ExprKind::MethodCall(_, rcvr, args, _) = expr.kind else { return; };
+ let hir::ExprKind::MethodCall(_, rcvr, args, _) = expr.kind else {
+ return;
+ };
if num_assoc_fn_excess_args != num_trait_generics_except_self {
return;
}
- let Some(gen_args) = self.gen_args.span_ext() else { return; };
- let Ok(generics) = sm.span_to_snippet(gen_args) else { return; };
- let Ok(rcvr) = sm.span_to_snippet(
- rcvr.span.find_ancestor_inside(expr.span).unwrap_or(rcvr.span)
- ) else { return; };
- let Ok(rest) =
- (match args {
- [] => Ok(String::new()),
- [arg] => sm.span_to_snippet(
- arg.span.find_ancestor_inside(expr.span).unwrap_or(arg.span),
- ),
- [first, .., last] => {
- let first_span =
- first.span.find_ancestor_inside(expr.span).unwrap_or(first.span);
- let last_span =
- last.span.find_ancestor_inside(expr.span).unwrap_or(last.span);
- sm.span_to_snippet(first_span.to(last_span))
- }
- }) else { return; };
+ let Some(gen_args) = self.gen_args.span_ext() else {
+ return;
+ };
+ let Ok(generics) = sm.span_to_snippet(gen_args) else {
+ return;
+ };
+ let Ok(rcvr) =
+ sm.span_to_snippet(rcvr.span.find_ancestor_inside(expr.span).unwrap_or(rcvr.span))
+ else {
+ return;
+ };
+ let Ok(rest) = (match args {
+ [] => Ok(String::new()),
+ [arg] => {
+ sm.span_to_snippet(arg.span.find_ancestor_inside(expr.span).unwrap_or(arg.span))
+ }
+ [first, .., last] => {
+ let first_span = first.span.find_ancestor_inside(expr.span).unwrap_or(first.span);
+ let last_span = last.span.find_ancestor_inside(expr.span).unwrap_or(last.span);
+ sm.span_to_snippet(first_span.to(last_span))
+ }
+ }) else {
+ return;
+ };
let comma = if args.len() > 0 { ", " } else { "" };
let trait_path = self.tcx.def_path_str(trait_def_id);
let method_name = self.tcx.item_name(self.def_id);
@@ -1015,7 +1027,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
.collect::<Vec<_>>()
.join(", ");
- format!(": {}", params)
+ format!(": {params}")
};
format!(