-
Notifications
You must be signed in to change notification settings - Fork 13.8k
fix APITIT being treated as a normal generic parameter in suggestions #145929
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
Conversation
c990a56
to
25d7d76
Compare
This comment has been minimized.
This comment has been minimized.
25d7d76
to
ac15a62
Compare
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 this function fundamentally works the wrong way (not ur fault, it's prexisting).
It seems to:
- Iterate over the list of where clauses on an item
- Look at where clauses that are either
Type<...>: Trait<..>
orType<...>: Trait<..., Assoc<...> = ...>
- Collect a map (
types
) of all thoseType<...>
to the trait on the rhs of the:
. e.g. if we havewhere u32: Trait, u64: OtherTrait, T: Trait + OtherTrait
, we'd wind up with[u32 => Trait, u64 => OtherTrait, T => { Trait, OtherTrait }]
- We then iterate that map filtering to only keys that are type parameters, and use that to reconstruct the list of generic parameters defined on the item.
this is completely incoherent. it assumes multiple things that aren't true:
- Type parameters are the only kind of generic parameters. You can't have
const N: usize
as the self type of a trait bound, so it never winds up intypes
so we'll never wind up putting const generics in the finalgenerics
string. playground (runtest
) - Type parameters are always used in the self type of a trait bound. This was not true on stable until very recently when we made
T: ?Sized
be sugar forT: MetaSized
. You can still observe this with therustc_no_implicit_bounds
attr: playground (runtest
). Also this means that right nowT: ?Sized
on stable gets re-sugared asT: MetaSized
which is wrong
Instead, we should unconditionally accept an AssocItem
so that we can always call generics_of
to get the list of generic parameters defined on the item.
You can then independently construct the types_str
by iterating over the generic parameters from generics_of
and fetching any bounds on them from the types
map.
The existing for loop over types
can be left mostly as-is, just removing the parts of it that mutate types_str.
ac15a62
to
2f0c103
Compare
@rustbot ready |
@bors r+ rollup thanks :3 if you want to fix some of the other diagnostic bugs in this fn (ignoring non-type parameters, or us resugaring T: ?Sized as T: MetaSized) then feel free to r? me on a PR doing that |
Failed to set assignee to
|
Rollup of 6 pull requests Successful merges: - #145463 (Reject invalid literal suffixes in tuple indexing, tuple struct indexing, and struct field name position) - #145929 (fix APITIT being treated as a normal generic parameter in suggestions) - #146001 (Update getopts to remove unicode-width dependency) - #146365 (triagebot: warn about #[rustc_intrinsic_const_stable_indirect]) - #146366 (add approx_delta to all gamma tests) - #146373 (fix comments about trait solver cycle heads) r? `@ghost` `@rustbot` modify labels: rollup
Bors, this has already been merged. @bors r- |
…, r=BoxyUwU Display ?Sized, const, and lifetime parameters in trait item suggestions across a crate boundary context: rust-lang#145929 This fixes the MetaSized issue and adds const generics and early bound lifetimes. Late bound lifetimes are harder because they aren't returned by `generics_of`. I'm going to look into it, but there's no guarantee I'll be successful. Fixes rust-lang#146404. r? `@BoxyUwu`
Rollup merge of #146442 - Qelxiros:trait-suggestion-generics, r=BoxyUwU Display ?Sized, const, and lifetime parameters in trait item suggestions across a crate boundary context: #145929 This fixes the MetaSized issue and adds const generics and early bound lifetimes. Late bound lifetimes are harder because they aren't returned by `generics_of`. I'm going to look into it, but there's no guarantee I'll be successful. Fixes #146404. r? `@BoxyUwu`
closes #126395