-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #53013 - zackmdavis:infer_outlints, r=nikomatsakis
in which inferable outlives-requirements are linted RFC 2093 (tracking issue #44493) lets us leave off these 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. Resolves #52042, an item under the fabulous metaïssue #52047. It's plausible that this shouldn't land until after `infer_outlives_requirements` has been stabilized ([final comment period started](#44493 (comment)) 4 days ago), but I think there's also a strong case to not-wait in order to maximize the time that [Edition Preview 2](https://internals.rust-lang.org/t/rust-2018-release-schedule-and-extended-beta/8076) users have to kick at it. (It's allow by default, so there's no impact unless you explicitly turn it or the rust-2018-idioms group up to `warn` or higher.) Questions— * Is `explicit-outlives-requirements` a good name? (I chose it as an [RFC 344](/~https://github.com/rust-lang/rfcs/blob/master/text/0344-conventions-galore.md#lints)-compliant "inversion" of the feature-gate name, `infer_outlives_requirements`, but I could imagine someone arguing that the word `struct` should be part of the name somewhere, for specificity.) * Are there any false-positives or false-negatives? @nikomatsakis [said that](#52042 (comment)) getting this right would be "fairly hard", which makes me nervous that I'm missing something. The UI test in the initial submission of this pull request just exercises the examples [given in the Edition Guide](https://rust-lang-nursery.github.io/edition-guide/2018/transitioning/ownership-and-lifetimes/struct-inference.html). ![infer_outlints](https://user-images.githubusercontent.com/1076988/43625740-6bf43dca-96a3-11e8-9dcf-793ac83d424d.png) r? @alexcrichton
- Loading branch information
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.