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 we decline to suggest the anonymous lifetime in declarations
The elided-lifetimes-in-path lint (part of our suite of Rust 2018 idiom lints which we are hoping to promote to Warn status) was firing with an illegal suggestion to write an anonymous lifetime in a struct/item declaration (where we don't allow it). The linting code was already deciding whether to act on the basis of a `ParamMode` enum, indicating whether the present path-segment was part of an expression, or anywhere else. The present case seemed to be part of the "anywhere else", and yet meriting different rules as far as the lint was concerned, so it seemed expedient to introduce a new enum member. We yank out a `TyKind::Path` arm into its own method so that we can call it with our new `ParamMode` specifically when lowering struct fields. (The alternative strategy of changing the signature of `lower_ty` to take a `ParamMode` would be inelegant given that most of the `TyKind` match arm bodies therein don't concern themselves with `ParamMode`.) Resolves rust-lang#61124.
- Loading branch information
1 parent
cdd7437
commit 7a3184a
Showing
3 changed files
with
52 additions
and
8 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
10 changes: 10 additions & 0 deletions
10
src/test/ui/in-band-lifetimes/issue-61124-anon-lifetime-in-struct-declaration.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,10 @@ | ||
#![deny(elided_lifetimes_in_paths)] | ||
|
||
// Previously, the elided-lifetimes-in-path lint would fire, but we don't want | ||
// that, because `'_` isn't legal in struct declarations. | ||
|
||
struct Betrayal<'a> { x: &'a u8 } | ||
|
||
struct Heartbreak(Betrayal); //~ ERROR missing lifetime specifier | ||
|
||
fn main() {} |
9 changes: 9 additions & 0 deletions
9
src/test/ui/in-band-lifetimes/issue-61124-anon-lifetime-in-struct-declaration.stderr
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,9 @@ | ||
error[E0106]: missing lifetime specifier | ||
--> $DIR/issue-61124-anon-lifetime-in-struct-declaration.rs:8:19 | ||
| | ||
LL | struct Heartbreak(Betrayal); | ||
| ^^^^^^^^ expected lifetime parameter | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0106`. |