forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
in which inferable outlives-requirements are linted
RFC 2093 (tracking issue rust-lang#44493) lets us leave off commonsensically inferable `T: 'a` outlives requirements. (A separate feature-gate was split off for the case of 'static lifetimes, for which questions still remain.) Detecting these was requested as an idioms-2018 lint. It turns out that issuing a correct, autofixable suggestion here is somewhat subtle in the presence of other bounds and generic parameters. Basically, we want to handle these three cases: • One outlives-bound. We want to drop the bound altogether, including the colon— MyStruct<'a, T: 'a> ^^^^ help: remove this bound • An outlives bound first, followed by a trait bound. We want to delete the outlives bound and the following plus sign (and hopefully get the whitespace right, too)— MyStruct<'a, T: 'a + MyTrait> ^^^^^ help: remove this bound • An outlives bound after a trait bound. We want to delete the outlives lifetime and the preceding plus sign— MyStruct<'a, T: MyTrait + 'a> ^^^^^ help: remove this bound This gets (slightly) even more complicated in the case of where clauses, where we want to drop the where clause altogether if there's just the one bound. Hopefully the comments are enough to explain what's going on! A script (in Python, sorry) was used to generate the hopefully-sufficiently-exhaustive UI test input. Some of these are split off into a different file because rust-lang/rustfix#141 (and, causally upstream of that, rust-lang#53934) prevents them from being `run-rustfix`-tested. We also make sure to include a UI test of a case (copied from RFC 2093) where the outlives-bound can't be inferred. Special thanks to Niko Matsakis for pointing out the `inferred_outlives_of` query, rather than blindly stripping outlives requirements as if we weren't a production compiler and didn't care. This concerns rust-lang#52042.
- Loading branch information
1 parent
7d52cbc
commit 032d97f
Showing
9 changed files
with
1,095 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
src/test/ui/rust-2018/edition-lint-infer-outlives-multispan.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![allow(unused)] | ||
#![deny(explicit_outlives_requirements)] | ||
|
||
use std::fmt::{Debug, Display}; | ||
|
||
// These examples should live in edition-lint-infer-outlives.rs, but are split | ||
// into this separate file because they can't be `rustfix`'d (and thus, can't | ||
// be part of a `run-rustfix` test file) until rust-lang-nursery/rustfix#141 | ||
// is solved | ||
|
||
struct TeeOutlivesAyIsDebugBee<'a, 'b, T: 'a + Debug + 'b> { | ||
//~^ ERROR outlives requirements can be inferred | ||
tee: &'a &'b T | ||
} | ||
|
||
struct TeeWhereOutlivesAyIsDebugBee<'a, 'b, T> where T: 'a + Debug + 'b { | ||
//~^ ERROR outlives requirements can be inferred | ||
tee: &'a &'b T | ||
} | ||
|
||
struct TeeYooOutlivesAyIsDebugBee<'a, 'b, T, U: 'a + Debug + 'b> { | ||
//~^ ERROR outlives requirements can be inferred | ||
tee: T, | ||
yoo: &'a &'b U | ||
} | ||
|
||
struct TeeOutlivesAyYooBeeIsDebug<'a, 'b, T: 'a, U: 'b + Debug> { | ||
//~^ ERROR outlives requirements can be inferred | ||
tee: &'a T, | ||
yoo: &'b U | ||
} | ||
|
||
struct TeeOutlivesAyYooIsDebugBee<'a, 'b, T: 'a, U: Debug + 'b> { | ||
//~^ ERROR outlives requirements can be inferred | ||
tee: &'a T, | ||
yoo: &'b U | ||
} | ||
|
||
struct TeeOutlivesAyYooWhereBee<'a, 'b, T: 'a, U> where U: 'b { | ||
//~^ ERROR outlives requirements can be inferred | ||
tee: &'a T, | ||
yoo: &'b U | ||
} | ||
|
||
struct TeeYooWhereOutlivesAyIsDebugBee<'a, 'b, T, U> where U: 'a + Debug + 'b { | ||
//~^ ERROR outlives requirements can be inferred | ||
tee: T, | ||
yoo: &'a &'b U | ||
} | ||
|
||
struct TeeOutlivesAyYooWhereBeeIsDebug<'a, 'b, T: 'a, U> where U: 'b + Debug { | ||
//~^ ERROR outlives requirements can be inferred | ||
tee: &'a T, | ||
yoo: &'b U | ||
} | ||
|
||
struct TeeOutlivesAyYooWhereIsDebugBee<'a, 'b, T: 'a, U> where U: Debug + 'b { | ||
//~^ ERROR outlives requirements can be inferred | ||
tee: &'a T, | ||
yoo: &'b U | ||
} | ||
|
||
struct TeeWhereOutlivesAyYooWhereBeeIsDebug<'a, 'b, T, U> where T: 'a, U: 'b + Debug { | ||
//~^ ERROR outlives requirements can be inferred | ||
tee: &'a T, | ||
yoo: &'b U | ||
} | ||
|
||
struct TeeWhereOutlivesAyYooWhereIsDebugBee<'a, 'b, T, U> where T: 'a, U: Debug + 'b { | ||
//~^ ERROR outlives requirements can be inferred | ||
tee: &'a T, | ||
yoo: &'b U | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.