-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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 #52069 - zackmdavis:elided_states_of_america—and_to_the…
…_re-pub-lic, r=nikomatsakis add structured suggestions and fix false-positive for elided-lifetimes-in-paths lint This adds structured suggestions to the elided-lifetimes-in-paths lint (introduced in Nov. 2017's #46254), prevents it from emitting a false-positive on anonymous (underscore) lifetimes (!), and adds it to the idioms-2018 group (#52041). ~~As an aside, "elided-lifetimes-in-paths" seems like an unfortunate name, because it's not clear exactly what "elided" means. The motivation for this lint (see original issue #45992, and [RFC 2115](https://github.com/rust-lang/rfcs/blob/e978a8d3017a01d632f916140c98802505cd1324/text/2115-argument-lifetimes.md#motivation)) seems to be specifically about not supplying angle-bracketed lifetime arguments to non-`&` types, but (1) the phrase "lifetime elision" has historically also referred to the ability to not supply a lifetime name to `&` references, and (2) an `is_elided` method in the HIR returns true for anoymous/underscore lifetimes, which is _not_ what we're trying to lint here. (That naming confusion is almost certainly what led to the false positive addressed here.) Given that the lint is relatively new and is allow-by-default, is it too late to rename it ... um, _again_ (#50879)?~~ ~~This does _not_ address a couple of other false positives discovered in #52041 (comment) ![elided_states](https://user-images.githubusercontent.com/1076988/42302137-2bf9479c-7fce-11e8-8bd0-f29aefc802b6.png) r? @nikomatsakis cc @nrc @petrochenkov
- Loading branch information
Showing
9 changed files
with
324 additions
and
53 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// 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. | ||
|
||
// run-rustfix | ||
// compile-flags: --edition 2018 | ||
|
||
#![allow(unused)] | ||
#![deny(elided_lifetimes_in_paths)] | ||
//~^ NOTE lint level defined here | ||
|
||
use std::cell::{RefCell, Ref}; | ||
|
||
|
||
struct Foo<'a> { x: &'a u32 } | ||
|
||
fn foo(x: &Foo<'_>) { | ||
//~^ ERROR hidden lifetime parameters in types are deprecated | ||
//~| HELP indicate the anonymous lifetime | ||
} | ||
|
||
fn bar(x: &Foo<'_>) {} | ||
|
||
|
||
struct Wrapped<'a>(&'a str); | ||
|
||
struct WrappedWithBow<'a> { | ||
gift: &'a str | ||
} | ||
|
||
struct MatchedSet<'a, 'b> { | ||
one: &'a str, | ||
another: &'b str, | ||
} | ||
|
||
fn wrap_gift(gift: &str) -> Wrapped<'_> { | ||
//~^ ERROR hidden lifetime parameters in types are deprecated | ||
//~| HELP indicate the anonymous lifetime | ||
Wrapped(gift) | ||
} | ||
|
||
fn wrap_gift_with_bow(gift: &str) -> WrappedWithBow<'_> { | ||
//~^ ERROR hidden lifetime parameters in types are deprecated | ||
//~| HELP indicate the anonymous lifetime | ||
WrappedWithBow { gift } | ||
} | ||
|
||
fn inspect_matched_set(set: MatchedSet<'_, '_>) { | ||
//~^ ERROR hidden lifetime parameters in types are deprecated | ||
//~| HELP indicate the anonymous lifetime | ||
println!("{} {}", set.one, set.another); | ||
} | ||
|
||
macro_rules! autowrapper { | ||
($type_name:ident, $fn_name:ident, $lt:lifetime) => { | ||
struct $type_name<$lt> { | ||
gift: &$lt str | ||
} | ||
|
||
fn $fn_name(gift: &str) -> $type_name<'_> { | ||
//~^ ERROR hidden lifetime parameters in types are deprecated | ||
//~| HELP indicate the anonymous lifetime | ||
$type_name { gift } | ||
} | ||
} | ||
} | ||
|
||
autowrapper!(Autowrapped, autowrap_gift, 'a); | ||
//~^ NOTE in this expansion of autowrapper! | ||
//~| NOTE in this expansion of autowrapper! | ||
|
||
macro_rules! anytuple_ref_ty { | ||
($($types:ty),*) => { | ||
Ref<'_, ($($types),*)> | ||
//~^ ERROR hidden lifetime parameters in types are deprecated | ||
//~| HELP indicate the anonymous lifetime | ||
} | ||
} | ||
|
||
fn main() { | ||
let honesty = RefCell::new((4, 'e')); | ||
let loyalty: Ref<'_, (u32, char)> = honesty.borrow(); | ||
//~^ ERROR hidden lifetime parameters in types are deprecated | ||
//~| HELP indicate the anonymous lifetime | ||
let generosity = Ref::map(loyalty, |t| &t.0); | ||
|
||
let laughter = RefCell::new((true, "magic")); | ||
let yellow: anytuple_ref_ty!(bool, &str) = laughter.borrow(); | ||
//~^ NOTE in this expansion of anytuple_ref_ty! | ||
//~| NOTE in this expansion of anytuple_ref_ty! | ||
} |
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,97 @@ | ||
// 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. | ||
|
||
// run-rustfix | ||
// compile-flags: --edition 2018 | ||
|
||
#![allow(unused)] | ||
#![deny(elided_lifetimes_in_paths)] | ||
//~^ NOTE lint level defined here | ||
|
||
use std::cell::{RefCell, Ref}; | ||
|
||
|
||
struct Foo<'a> { x: &'a u32 } | ||
|
||
fn foo(x: &Foo) { | ||
//~^ ERROR hidden lifetime parameters in types are deprecated | ||
//~| HELP indicate the anonymous lifetime | ||
} | ||
|
||
fn bar(x: &Foo<'_>) {} | ||
|
||
|
||
struct Wrapped<'a>(&'a str); | ||
|
||
struct WrappedWithBow<'a> { | ||
gift: &'a str | ||
} | ||
|
||
struct MatchedSet<'a, 'b> { | ||
one: &'a str, | ||
another: &'b str, | ||
} | ||
|
||
fn wrap_gift(gift: &str) -> Wrapped { | ||
//~^ ERROR hidden lifetime parameters in types are deprecated | ||
//~| HELP indicate the anonymous lifetime | ||
Wrapped(gift) | ||
} | ||
|
||
fn wrap_gift_with_bow(gift: &str) -> WrappedWithBow { | ||
//~^ ERROR hidden lifetime parameters in types are deprecated | ||
//~| HELP indicate the anonymous lifetime | ||
WrappedWithBow { gift } | ||
} | ||
|
||
fn inspect_matched_set(set: MatchedSet) { | ||
//~^ ERROR hidden lifetime parameters in types are deprecated | ||
//~| HELP indicate the anonymous lifetime | ||
println!("{} {}", set.one, set.another); | ||
} | ||
|
||
macro_rules! autowrapper { | ||
($type_name:ident, $fn_name:ident, $lt:lifetime) => { | ||
struct $type_name<$lt> { | ||
gift: &$lt str | ||
} | ||
|
||
fn $fn_name(gift: &str) -> $type_name { | ||
//~^ ERROR hidden lifetime parameters in types are deprecated | ||
//~| HELP indicate the anonymous lifetime | ||
$type_name { gift } | ||
} | ||
} | ||
} | ||
|
||
autowrapper!(Autowrapped, autowrap_gift, 'a); | ||
//~^ NOTE in this expansion of autowrapper! | ||
//~| NOTE in this expansion of autowrapper! | ||
|
||
macro_rules! anytuple_ref_ty { | ||
($($types:ty),*) => { | ||
Ref<($($types),*)> | ||
//~^ ERROR hidden lifetime parameters in types are deprecated | ||
//~| HELP indicate the anonymous lifetime | ||
} | ||
} | ||
|
||
fn main() { | ||
let honesty = RefCell::new((4, 'e')); | ||
let loyalty: Ref<(u32, char)> = honesty.borrow(); | ||
//~^ ERROR hidden lifetime parameters in types are deprecated | ||
//~| HELP indicate the anonymous lifetime | ||
let generosity = Ref::map(loyalty, |t| &t.0); | ||
|
||
let laughter = RefCell::new((true, "magic")); | ||
let yellow: anytuple_ref_ty!(bool, &str) = laughter.borrow(); | ||
//~^ NOTE in this expansion of anytuple_ref_ty! | ||
//~| NOTE in this expansion of anytuple_ref_ty! | ||
} |
Oops, something went wrong.