about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/traits
diff options
context:
space:
mode:
authorYiming Lei <yiming.lei@futurewei.com>2022-09-28 09:59:03 -0700
committerYiming Lei <yiming.lei@futurewei.com>2022-09-29 14:24:24 -0700
commit523a76a2ebd5c1763665e2d51fa65f8304fc46af (patch)
tree785f6f1eabb89e8ebf313cd87a67a340f613f1f5 /compiler/rustc_trait_selection/src/traits
parent09ae7846a272a500ff7145255f0de5556c0b8949 (diff)
downloadrust-523a76a2ebd5c1763665e2d51fa65f8304fc46af.tar.gz
rust-523a76a2ebd5c1763665e2d51fa65f8304fc46af.zip
remove the unused :: between trait and type to give user correct diagnostic information
	modified:   compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
	new file:   src/test/ui/type/issue-101866.rs
	new file:   src/test/ui/type/issue-101866.stderr
Diffstat (limited to 'compiler/rustc_trait_selection/src/traits')
-rw-r--r--compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs19
1 files changed, 14 insertions, 5 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
index b0cabc6275f..5fdadd0b4b4 100644
--- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
+++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
@@ -2263,13 +2263,22 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
                                     trait_impls.non_blanket_impls().len()
                                 )
                             };
-
+                            let mut suggestions = vec![(
+                                trait_path_segment.ident.span.shrink_to_lo(),
+                                format!("<{} as ", self.tcx.def_path(impl_def_id).to_string_no_crate_verbose())
+                            )];
+                            if let Some(generic_arg) = trait_path_segment.args {
+                                let between_span = trait_path_segment.ident.span.between(generic_arg.span_ext);
+                                // get rid of :: between Trait and <type>
+                                // must be '::' between them, otherwise the parser won't accept the code
+                                suggestions.push((between_span, "".to_string(),));
+                                suggestions.push((generic_arg.span_ext.shrink_to_hi(), format!(">")));
+                            } else {
+                                suggestions.push((trait_path_segment.ident.span.shrink_to_hi(), format!(">")));
+                            }
                             err.multipart_suggestion(
                                 message,
-                                vec![
-                                    (trait_path_segment.ident.span.shrink_to_lo(), format!("<{} as ", self.tcx.def_path(impl_def_id).to_string_no_crate_verbose())),
-                                    (trait_path_segment.ident.span.shrink_to_hi(), format!(">"))
-                                ],
+                                suggestions,
                                 Applicability::MaybeIncorrect
                             );
                         }