]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_typeck/src/check/method/suggest.rs
fix: wrong trait import suggestion for T:
[rust.git] / compiler / rustc_typeck / src / check / method / suggest.rs
index ecc2996593704a85e15cf76a3c163b32d9688a99..e6560ca4d9b90e7827e30827220cb075ade931cc 100644 (file)
@@ -1880,9 +1880,15 @@ fn suggest_traits_to_import(
                                 };
                             let sp = hir.span(id);
                             let sp = if let Some(first_bound) = has_bounds {
-                                // `sp` only covers `T`, change it so that it covers
-                                // `T:` when appropriate
                                 sp.until(first_bound.span())
+                            } else if let Some(colon_sp) =
+                                // If the generic param is declared with a colon but without bounds:
+                                // fn foo<T:>(t: T) { ... }
+                                param.colon_span_for_suggestions(
+                                    self.inh.tcx.sess.source_map(),
+                                )
+                            {
+                                sp.to(colon_sp)
                             } else {
                                 sp
                             };