forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#56755 - estebank:impl-trait-lt-sugg, r=cram…
…ertj Account for `impl Trait` when suggesting lifetime Fix rust-lang#56745
- Loading branch information
Showing
4 changed files
with
75 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// run-rustfix | ||
|
||
use std::fmt::Debug; | ||
|
||
fn foo(d: impl Debug + 'static) { | ||
//~^ HELP consider adding an explicit lifetime bound `'static` to `impl Debug` | ||
bar(d); | ||
//~^ ERROR the parameter type `impl Debug` may not live long enough | ||
//~| NOTE ...so that the type `impl Debug` will meet its required lifetime bounds | ||
} | ||
|
||
fn bar(d: impl Debug + 'static) { | ||
println!("{:?}", d) | ||
} | ||
|
||
fn main() { | ||
foo("hi"); | ||
} |
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,18 @@ | ||
// run-rustfix | ||
|
||
use std::fmt::Debug; | ||
|
||
fn foo(d: impl Debug) { | ||
//~^ HELP consider adding an explicit lifetime bound `'static` to `impl Debug` | ||
bar(d); | ||
//~^ ERROR the parameter type `impl Debug` may not live long enough | ||
//~| NOTE ...so that the type `impl Debug` will meet its required lifetime bounds | ||
} | ||
|
||
fn bar(d: impl Debug + 'static) { | ||
println!("{:?}", d) | ||
} | ||
|
||
fn main() { | ||
foo("hi"); | ||
} |
19 changes: 19 additions & 0 deletions
19
src/test/ui/suggestions/suggest-impl-trait-lifetime.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,19 @@ | ||
error[E0310]: the parameter type `impl Debug` may not live long enough | ||
--> $DIR/suggest-impl-trait-lifetime.rs:7:5 | ||
| | ||
LL | bar(d); | ||
| ^^^ | ||
| | ||
note: ...so that the type `impl Debug` will meet its required lifetime bounds | ||
--> $DIR/suggest-impl-trait-lifetime.rs:7:5 | ||
| | ||
LL | bar(d); | ||
| ^^^ | ||
help: consider adding an explicit lifetime bound `'static` to `impl Debug`... | ||
| | ||
LL | fn foo(d: impl Debug + 'static) { | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0310`. |