-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't suggest impl Trait
in path position
#113310
Don't suggest impl Trait
in path position
#113310
Conversation
r? @TaKO8Ki (rustbot has picked a reviewer for you, use r? to override) |
Some changes occurred in need_type_info.rs cc @lcnr |
let ty_var_is_impl_trait = move |ty_vid| { | ||
let mut infcx_inner = self.infcx.inner.borrow_mut(); | ||
let ty_vars = infcx_inner.type_variables(); | ||
let var_origin = ty_vars.var_origin(ty_vid); | ||
if let TypeVariableOriginKind::TypeParameterDefinition(name, _) = var_origin.kind | ||
&& name.as_str().starts_with("impl ") | ||
{ | ||
true | ||
} else { | ||
false | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a less hacky way to do this check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to change fn fmt_printer
to not use the name ofTypeVariableOriginKind::TypeParameterDefinition
if the DefId
is from an argument position impl trait instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think reaching 11 indentation levels might be justification to refactor some of this to a function anyway 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to change
fn fmt_printer
to not use the name ofTypeVariableOriginKind::TypeParameterDefinition
if theDefId
is from an argument position impl trait instead.
How do you check if a DefId
is from an arg position impl Trait
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tcx.generics_of(tcx.parent(def_id))
, look at the https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/generics/struct.GenericParamDef.html for whether the type param is synthetic.
I am not 10% sure whether the parent
is necessary 🤷 try it without, if it ices, add tcx.parent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I think that works, but I'm not sure if it's 100% correct.
78874c7
to
aaf1a13
Compare
…iler-errors `TypeParameterDefinition` always require a `DefId` the `None` case never actually reaches diagnostics so it feels better for diagnostics to be able to rely on the `DefId` being there, cc rust-lang#113310
…iler-errors `TypeParameterDefinition` always require a `DefId` the `None` case never actually reaches diagnostics so it feels better for diagnostics to be able to rely on the `DefId` being there, cc rust-lang#113310
aaf1a13
to
fafc689
Compare
compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one nit, after that r=me
fafc689
to
e6b9a55
Compare
if let Some(idx) = generics.param_def_id_to_index(infcx.tcx, def_id) | ||
&& let generic_param_def = generics.param_at(idx as usize, infcx.tcx) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please unwrap
instead of using if let
. Not getting Some
here indicates a bug
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
very astute! #113610
e6b9a55
to
b5208b3
Compare
@bors r+ rollup |
…iaskrgr Rollup of 4 pull requests Successful merges: - rust-lang#112717 (Implement a few more rvalue translation to smir) - rust-lang#113310 (Don't suggest `impl Trait` in path position) - rust-lang#113497 (Support explicit 32-bit MIPS ABI for the synthetic object) - rust-lang#113560 (Lint against misplaced where-clauses on associated types in traits) r? `@ghost` `@rustbot` modify labels: rollup
Fixes #113264.