mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-29 16:13:40 +00:00
Rollup merge of #102421 - lyming2007:issue-101866, r=lcnr
remove the unused :: between trait and type to give user correct diag… …nostic 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
This commit is contained in:
commit
f7f253ea47
@ -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
|
||||
);
|
||||
}
|
||||
|
15
src/test/ui/type/issue-101866.rs
Normal file
15
src/test/ui/type/issue-101866.rs
Normal file
@ -0,0 +1,15 @@
|
||||
trait TraitA<T> {
|
||||
fn func();
|
||||
}
|
||||
|
||||
struct StructA {}
|
||||
|
||||
impl TraitA<i32> for StructA {
|
||||
fn func() {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
TraitA::<i32>::func();
|
||||
//~^ ERROR: cannot call associated function on trait without specifying the corresponding `impl` type [E0790]
|
||||
//~| help: use the fully-qualified path to the only available implementation
|
||||
}
|
18
src/test/ui/type/issue-101866.stderr
Normal file
18
src/test/ui/type/issue-101866.stderr
Normal file
@ -0,0 +1,18 @@
|
||||
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type
|
||||
--> $DIR/issue-101866.rs:12:5
|
||||
|
|
||||
LL | fn func();
|
||||
| ---------- `TraitA::func` defined here
|
||||
...
|
||||
LL | TraitA::<i32>::func();
|
||||
| ^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait
|
||||
|
|
||||
help: use the fully-qualified path to the only available implementation
|
||||
|
|
||||
LL - TraitA::<i32>::func();
|
||||
LL + <::StructA as TraitA<i32>>::func();
|
||||
|
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0790`.
|
Loading…
Reference in New Issue
Block a user