-
Notifications
You must be signed in to change notification settings - Fork 14k
Lint unused associated types #148654
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
base: master
Are you sure you want to change the base?
Lint unused associated types #148654
Conversation
|
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
This comment has been minimized.
This comment has been minimized.
|
does this handle assoc types used only from item signatures and not from within bodies? |
This comment was marked as outdated.
This comment was marked as outdated.
4c52c25 to
55bec1d
Compare
|
Some changes occurred in tests/ui/sanitizer cc @rcvalle |
She meant the exact opposite. Assoc tys only used in non-bodies (aka "item signatures", i.e., places where we don't infer types, i.e., not fn or const bodies, but e.g., inside ADTs, type aliases, impl headers, etc.). |
55bec1d to
f9cd465
Compare
|
@fmease Hi, I add some tests for such cases but I'm not sure they are right or good enough. Could you have a look or give some examples? Thanks! |
|
Personally speaking, I was thinking of trait Trait { type Ty; }
impl Trait for () { type Ty = (); }
pub struct Wrap(<() as Trait>::Ty); // <- use of QPath::Resolved `Ty` in a non-body only
impl Wrap {
pub fn live(self) { _ = self.0; }
}or trait Trait { type Ty; }
impl Trait for () { type Ty = (); }
pub struct Wrap(Inner<()>);
struct Inner<T: Trait>(T::Ty); // <- use of QPath::TypeRelative `Ty` in a non-body only
impl Wrap {
pub fn live(self) { _ = self.0; }
}I'm sure my examples can be simplified. Also, I haven't really thought much about all of this yet as I'm just drive-by reviewing, so feel free to correct me anywhere :) |
6a4d4a2 to
4f6cdd6
Compare
|
@fmease Added and passed. But current implementation for struct fields is special. Simply speaking, types of fields in used struct will be marked live directly whether the field self is used or not. The detail is described in https://github.com/rust-lang/rust/pull/148654/files#diff-719b4f36bbbf3b3bf48683429408f5d27e5633f70c1144a93554bd536d5bf655R753-R764 |
Yes, such assoc types are handled by visiting predicates of the source items. |
4f6cdd6 to
76e9cec
Compare
This PR lints unused associated types, like associated consts and fns.
Different from assoc consts and fns, associated types correspond to
QPath::TypeRelative, andRes::Errwill be obtained in HIR. Therefore, it is necessary to traverserustc_middle::ty::Tyto help propagate liveness to the corresponding associated type.Fixes #127673