annotate stricter lifetimes on LateLintPass methods to allow them to forward to a Visitor #38191

Merged
merged 3 commits into from Dec 8, 2016

Projects

None yet

6 participants

@oli-obk
Contributor
oli-obk commented Dec 6, 2016

this unblocks clippy (rustup blocked after #37918)

clippy has lots of lints that internally call an intravisit::Visitor, but the current lifetimes on LateLintPass methods conflicted with the required lifetimes (there was no connection between the HIR elements and the TyCtxt)

r? @Manishearth

@oli-obk oli-obk annotate stricter lifetimes on LateLintPass methods to allow them to …
…forward to a Visitor
5e51edb
@oli-obk oli-obk referenced this pull request in Manishearth/rust-clippy Dec 6, 2016
Merged

WIP: rustup #1373

@Manishearth
Member

r? @eddyb

Not sure of this. Sort of makes sense.

@rust-highfive rust-highfive assigned eddyb and unassigned Manishearth Dec 6, 2016
src/librustc/lint/mod.rs
@@ -131,51 +131,104 @@ pub trait LintPass {
// contains a few lint-specific methods with no equivalent in `Visitor`.
pub trait LateLintPass: LintPass {
@eddyb
eddyb Dec 6, 2016 Member

Could you add the lifetimes to the trait? That way they don't pollute the method generics.
I'm not sure in what conditions they don't need to show up in types in the method signatures in an impl - see how some of the Visitor impls get away with it, although here it's trickier - it'd be nice if most of them didn't need to be changed.

@oli-obk
oli-obk Dec 7, 2016 Contributor

I might just be failing at HKL, but I can't create a Box<for<'a, 'tcx: 'a> LateLintPass<'a, 'tcx>>, because the outlives bound is ignored

I have a workaround, but it'll require an intermediate helper trait. (see minimal example of workaround: https://is.gd/OnC7RS)

@eddyb
eddyb Dec 7, 2016 Member

Bleah I forgot about trait objects. Can the Helper trait have a single blanket impl proxying to the trait with the lifetime paramters?

@oli-obk
oli-obk Dec 7, 2016 Contributor

I can almost do it (https://is.gd/TrZudu), I'm not sure why Rust can't figure out that a lifetime on a generic bound in the trait generics will outlive the lifetime of a method argument:

impl<'b, 'tcx: 'b, T: Foo<'b, 'tcx>> Helper<'tcx> for T {
    fn as_foo<'a>(&'a mut self) -> &'a mut Foo<'a, 'tcx> where 'tcx: 'a {
        self
    }
}
note: the lifetime 'a as defined on the block at 17:72...
note: ...does not necessarily outlive the lifetime 'b as defined on the block at 17:72
@oli-obk oli-obk remove useless lifetime outlives bounds 5beeb1e
@oli-obk
Contributor
oli-obk commented Dec 7, 2016 edited

it works now, I tested it against clippy, ./x.py test still running though everything works now

src/librustc_lint/bad_style.rs
- fn check_generics(&mut self, cx: &LateContext, it: &hir::Generics) {
+ fn check_generics(&mut self,
+ cx: &LateContext<'a, 'tcx>,
+ it: &'tcx hir::Generics) {
@eddyb
eddyb Dec 7, 2016 Member

Indentation looks off here.

@eddyb
Member
eddyb commented Dec 7, 2016

I think some of the indentation changes from adding <'a, 'tcx> generics everywhere weren't rolled back.

@oli-obk oli-obk remove useless lifetimes on LateLintPass impl methods
0f7a18b
@oli-obk
Contributor
oli-obk commented Dec 7, 2016

cleaned up all the <'a, 'tcx> generics and the indentation problems

@nox
Contributor
nox commented Dec 7, 2016

This also blocks Servo.

@Ms2ger
Contributor
Ms2ger commented Dec 7, 2016

Would appreciate a quick review here :)

@Ms2ger
Contributor
Ms2ger commented Dec 7, 2016

@nikomatsakis this was what I was just talking about

@eddyb
Member
eddyb commented Dec 7, 2016

@bors r+ p=1 (unbreaking Servo)

@bors
Contributor
bors commented Dec 7, 2016

📌 Commit 0f7a18b has been approved by eddyb

@bors
Contributor
bors commented Dec 7, 2016

⌛️ Testing commit 0f7a18b with merge 7b06438...

@bors bors added a commit that referenced this pull request Dec 7, 2016
@bors bors Auto merge of #38191 - oli-obk:clippy_is_sad, r=eddyb
annotate stricter lifetimes on LateLintPass methods to allow them to forward to a Visitor

this unblocks clippy (rustup blocked after #37918)

clippy has lots of lints that internally call an `intravisit::Visitor`, but the current lifetimes on `LateLintPass` methods conflicted with the required lifetimes (there was no connection between the HIR elements and the `TyCtxt`)

r? @Manishearth
7b06438
@bors bors merged commit 0f7a18b into rust-lang:master Dec 8, 2016

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details
@oli-obk oli-obk deleted the oli-obk:clippy_is_sad branch Dec 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment