-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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
Add REDUNDANT_LIFETIMES
lint to detect lifetimes which are semantically redundant
#118391
Conversation
The only wrinkle is that this approach may be detrimental to performance... @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Extend `UNUSED_LIFETIMES` lint to detect lifetimes which are semantically redundant There already is a `UNUSED_LIFETIMES` lint which is fired when we detect where clause bounds like `where 'a: 'static`, however, it doesn't use the full power of lexical region resolution to detect failures. Right now `UNUSED_LIFETIMES` is an `Allow` lint, though presumably we could bump it to warn? I can (somewhat) easily implement a structured suggestion so this can be rustfix'd automatically, since we can just walk through the HIR body, replacing instances of the redundant lifetime. Fixes rust-lang#118376 r? lcnr
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
@bors try |
Extend `UNUSED_LIFETIMES` lint to detect lifetimes which are semantically redundant There already is a `UNUSED_LIFETIMES` lint which is fired when we detect where clause bounds like `where 'a: 'static`, however, it doesn't use the full power of lexical region resolution to detect failures. Right now `UNUSED_LIFETIMES` is an `Allow` lint, though presumably we could bump it to warn? I can (somewhat) easily implement a structured suggestion so this can be rustfix'd automatically, since we can just walk through the HIR body, replacing instances of the redundant lifetime. Fixes rust-lang#118376 r? lcnr
☀️ Try build successful - checks-actions |
This comment has been minimized.
This comment has been minimized.
Finished benchmarking commit (7a2c7d7): comparison URL. Overall result: ❌ regressions - ACTION NEEDEDBenchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 675.422s -> 674.91s (-0.08%) |
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.
few notes:
- I think we should not lint if the "victim" lifetime is elided. The current impl lints in this case but it should not imo:
struct Ty<T: static>(T);
fn test(_: Ty<&str>) {}
-
There is no need to fork the inference context and do region resolution for each check, you can simply use
outlives_env.free_region_map.sub_free_regions()
to check for equality. -
To avoid the perf impact, can you try to run the lint in
enter_wf_checking_ctxt
where we've already got the OutlivesEnvironment?
d528fad
to
b09e25e
Compare
I will try adding this into WF if perf still comes back bad... @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Extend `UNUSED_LIFETIMES` lint to detect lifetimes which are semantically redundant There already is a `UNUSED_LIFETIMES` lint which is fired when we detect where clause bounds like `where 'a: 'static`, however, it doesn't use the full power of lexical region resolution to detect failures. Right now `UNUSED_LIFETIMES` is an `Allow` lint, though presumably we could bump it to warn? I can (somewhat) easily implement a structured suggestion so this can be rustfix'd automatically, since we can just walk through the HIR body, replacing instances of the redundant lifetime. Fixes rust-lang#118376 r? lcnr
b222147
to
d5cdea7
Compare
The final comment period, with a disposition to merge, as per the review above, is now complete. As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed. This will be merged soon. |
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.
r=me after nits
How different is this implementation from the preexisting |
this is about named lifetimes which are equal to other named lifetimes, e.g. in the followiuinig example struct Foo<'a>(&'a ());
impl<'a> Foo<'a> {
fn use<'b: 'a>(&'b self, s: &'b str) {}
} |
d5cdea7
to
da2b714
Compare
thank you for implementing this ❤️ I would like to move both lifetime lints to @bors r+ rollup |
…llaumeGomez Rollup of 7 pull requests Successful merges: - rust-lang#118391 (Add `REDUNDANT_LIFETIMES` lint to detect lifetimes which are semantically redundant) - rust-lang#123534 (Windows: set main thread name without re-encoding) - rust-lang#123659 (Add support to intrinsics fallback body) - rust-lang#123689 (Add const generics support for pattern types) - rust-lang#123701 (Only assert for child/parent projection compatibility AFTER checking that theyre coming from the same place) - rust-lang#123702 (Further cleanup cfgs in the UI test suite) - rust-lang#123706 (rustdoc: reduce per-page HTML overhead) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#118391 - compiler-errors:lifetimes-eq, r=lcnr Add `REDUNDANT_LIFETIMES` lint to detect lifetimes which are semantically redundant There already is a `UNUSED_LIFETIMES` lint which is fired when we detect where clause bounds like `where 'a: 'static`, however, it doesn't use the full power of lexical region resolution to detect failures. Right now `UNUSED_LIFETIMES` is an `Allow` lint, though presumably we could bump it to warn? I can (somewhat) easily implement a structured suggestion so this can be rustfix'd automatically, since we can just walk through the HIR body, replacing instances of the redundant lifetime. Fixes rust-lang#118376 r? lcnr
There already is a
UNUSED_LIFETIMES
lint which is fired when we detect where clause bounds likewhere 'a: 'static
, however, it doesn't use the full power of lexical region resolution to detect failures.Right now
UNUSED_LIFETIMES
is anAllow
lint, though presumably we could bump it to warn? I can (somewhat) easily implement a structured suggestion so this can be rustfix'd automatically, since we can just walk through the HIR body, replacing instances of the redundant lifetime.Fixes #118376
r? lcnr