Don't suggest impl Trait
in path position
This commit is contained in:
parent
1a449dcfd2
commit
b5208b3611
@ -162,10 +162,18 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
|
|||||||
let mut infcx_inner = infcx.inner.borrow_mut();
|
let mut infcx_inner = infcx.inner.borrow_mut();
|
||||||
let ty_vars = infcx_inner.type_variables();
|
let ty_vars = infcx_inner.type_variables();
|
||||||
let var_origin = ty_vars.var_origin(ty_vid);
|
let var_origin = ty_vars.var_origin(ty_vid);
|
||||||
if let TypeVariableOriginKind::TypeParameterDefinition(name, _) = var_origin.kind
|
if let TypeVariableOriginKind::TypeParameterDefinition(name, def_id) = var_origin.kind
|
||||||
&& !var_origin.span.from_expansion()
|
&& !var_origin.span.from_expansion()
|
||||||
{
|
{
|
||||||
|
let generics = infcx.tcx.generics_of(infcx.tcx.parent(def_id));
|
||||||
|
let idx = generics.param_def_id_to_index(infcx.tcx, def_id).unwrap();
|
||||||
|
let generic_param_def = generics.param_at(idx as usize, infcx.tcx);
|
||||||
|
if let ty::GenericParamDefKind::Type { synthetic: true, .. } = generic_param_def.kind
|
||||||
|
{
|
||||||
|
None
|
||||||
|
} else {
|
||||||
Some(name)
|
Some(name)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,12 @@
|
|||||||
|
trait T {}
|
||||||
|
|
||||||
|
struct S {}
|
||||||
|
|
||||||
|
impl S {
|
||||||
|
fn owo(&self, _: Option<&impl T>) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
(S {}).owo(None)
|
||||||
|
//~^ ERROR type annotations needed
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
error[E0282]: type annotations needed
|
||||||
|
--> $DIR/issue-113264-incorrect-impl-trait-in-path-suggestion.rs:10:16
|
||||||
|
|
|
||||||
|
LL | (S {}).owo(None)
|
||||||
|
| ^^^^ cannot infer type of the type parameter `T` declared on the enum `Option`
|
||||||
|
|
|
||||||
|
help: consider specifying the generic argument
|
||||||
|
|
|
||||||
|
LL | (S {}).owo(None::<&_>)
|
||||||
|
| ++++++
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0282`.
|
Loading…
x
Reference in New Issue
Block a user