summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src
diff options
context:
space:
mode:
authorArthur Carcano <arthur.carcano@ocamlpro.com>2024-12-13 12:32:35 +0100
committerArthur Carcano <arthur.carcano@ocamlpro.com>2024-12-13 13:07:07 +0100
commitaf530c4927d4b6018662c092ebcf629f17eb7191 (patch)
tree965f4e4ef3e35e39611cce4a7b3cc0df3f3d60f2 /compiler/rustc_hir_analysis/src
parent3da8bfb87f2bdcff56ed845383aa1c4fcd2c8705 (diff)
downloadrust-af530c4927d4b6018662c092ebcf629f17eb7191.tar.gz
rust-af530c4927d4b6018662c092ebcf629f17eb7191.zip
Use a more precise span in placeholder_type_error_diag
Closes: https://github.com/rust-lang/rust/issues/123861
Diffstat (limited to 'compiler/rustc_hir_analysis/src')
-rw-r--r--compiler/rustc_hir_analysis/src/collect.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs
index 96d2714252a..0bbf6aa5116 100644
--- a/compiler/rustc_hir_analysis/src/collect.rs
+++ b/compiler/rustc_hir_analysis/src/collect.rs
@@ -201,12 +201,13 @@ pub(crate) fn placeholder_type_error_diag<'cx, 'tcx>(
         placeholder_types.iter().map(|sp| (*sp, (*type_name).to_string())).collect();
 
     if let Some(generics) = generics {
-        if let Some(arg) = params.iter().find(|arg| {
-            matches!(arg.name, hir::ParamName::Plain(Ident { name: kw::Underscore, .. }))
+        if let Some(span) = params.iter().find_map(|arg| match arg.name {
+            hir::ParamName::Plain(Ident { name: kw::Underscore, span }) => Some(span),
+            _ => None,
         }) {
             // Account for `_` already present in cases like `struct S<_>(_);` and suggest
             // `struct S<T>(T);` instead of `struct S<_, T>(T);`.
-            sugg.push((arg.span, (*type_name).to_string()));
+            sugg.push((span, (*type_name).to_string()));
         } else if let Some(span) = generics.span_for_param_suggestion() {
             // Account for bounds, we want `fn foo<T: E, K>(_: K)` not `fn foo<T, K: E>(_: K)`.
             sugg.push((span, format!(", {type_name}")));