-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tail expression behind terminating scope
- Loading branch information
1 parent
b092569
commit 2f0ad0d
Showing
9 changed files
with
123 additions
and
23 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
8 changes: 8 additions & 0 deletions
8
tests/ui/feature-gates/feature-gate-shorter_tail_lifetimes.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,8 @@ | ||
fn f() -> usize { | ||
let c = std::cell::RefCell::new(".."); | ||
c.borrow().len() //~ ERROR: `c` does not live long enough | ||
} | ||
|
||
fn main() { | ||
let _ = f(); | ||
} |
26 changes: 26 additions & 0 deletions
26
tests/ui/feature-gates/feature-gate-shorter_tail_lifetimes.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,26 @@ | ||
error[E0597]: `c` does not live long enough | ||
--> $DIR/feature-gate-shorter_tail_lifetimes.rs:3:5 | ||
| | ||
LL | let c = std::cell::RefCell::new(".."); | ||
| - binding `c` declared here | ||
LL | c.borrow().len() | ||
| ^--------- | ||
| | | ||
| borrowed value does not live long enough | ||
| a temporary with access to the borrow is created here ... | ||
LL | } | ||
| - | ||
| | | ||
| `c` dropped here while still borrowed | ||
| ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `Ref<'_, &str>` | ||
| | ||
= note: the temporary is part of an expression at the end of a block; | ||
consider forcing this temporary to be dropped sooner, before the block's local variables are dropped | ||
help: for example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block | ||
| | ||
LL | let x = c.borrow().len(); x | ||
| +++++++ +++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0597`. |
26 changes: 26 additions & 0 deletions
26
tests/ui/lifetimes/shorter-tail-expr-lifetime.edition2021.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,26 @@ | ||
error[E0597]: `c` does not live long enough | ||
--> $DIR/shorter-tail-expr-lifetime.rs:10:5 | ||
| | ||
LL | let c = std::cell::RefCell::new(".."); | ||
| - binding `c` declared here | ||
LL | c.borrow().len() | ||
| ^--------- | ||
| | | ||
| borrowed value does not live long enough | ||
| a temporary with access to the borrow is created here ... | ||
LL | } | ||
| - | ||
| | | ||
| `c` dropped here while still borrowed | ||
| ... and the borrow might be used here, when that temporary is dropped and runs the destructor for type `Ref<'_, &str>` | ||
| | ||
= note: the temporary is part of an expression at the end of a block; | ||
consider forcing this temporary to be dropped sooner, before the block's local variables are dropped | ||
help: for example, you could save the expression's value in a new local variable `x` and then make `x` be the expression at the end of the block | ||
| | ||
LL | let x = c.borrow().len(); x | ||
| +++++++ +++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0597`. |
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,15 @@ | ||
//@ revisions: edition2021 edition2024 | ||
//@ [edition2024] compile-flags: -Zunstable-options | ||
//@ [edition2024] edition: 2024 | ||
//@ [edition2024] run-pass | ||
|
||
#![cfg_attr(edition2024, feature(shorter_tail_lifetimes))] | ||
|
||
fn f() -> usize { | ||
let c = std::cell::RefCell::new(".."); | ||
c.borrow().len() //[edition2021]~ ERROR: `c` does not live long enough | ||
} | ||
|
||
fn main() { | ||
let _ = f(); | ||
} |
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