-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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 #56460 - davidtwco:issue-55850, r=pnkfelix
Fix ICE with generators and NLL Fix #55850. This PR stops an ICE in #55850 by not panicking when a region cannot be named. However, this PR does not (yet) fix the underlying issue that the correct name for the test case provided for the issue (in this instance, `'a`) was not found. This PR also lays a little bit of groundwork by categorizing yields separately from returns so that region naming can be specialized for this case. r? @pnkfelix
- Loading branch information
Showing
9 changed files
with
104 additions
and
22 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
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 @@ | ||
error[E0597]: `s` does not live long enough | ||
--> $DIR/issue-55850.rs:38:16 | ||
| | ||
LL | yield &s[..] //~ ERROR `s` does not live long enough [E0597] | ||
| ^ borrowed value does not live long enough | ||
LL | }) | ||
| - `s` dropped here while still borrowed | ||
|
||
error[E0626]: borrow may still be in use when generator yields | ||
--> $DIR/issue-55850.rs:38:16 | ||
| | ||
LL | yield &s[..] //~ ERROR `s` does not live long enough [E0597] | ||
| -------^---- possible yield occurs here | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors occurred: E0597, E0626. | ||
For more information about an 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,44 @@ | ||
// Copyright 2016 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_mut)] | ||
#![feature(generators, generator_trait)] | ||
|
||
use std::ops::Generator; | ||
use std::ops::GeneratorState::Yielded; | ||
|
||
pub struct GenIter<G>(G); | ||
|
||
impl <G> Iterator for GenIter<G> | ||
where | ||
G: Generator, | ||
{ | ||
type Item = G::Yield; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
unsafe { | ||
match self.0.resume() { | ||
Yielded(y) => Some(y), | ||
_ => None | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn bug<'a>() -> impl Iterator<Item = &'a str> { | ||
GenIter(move || { | ||
let mut s = String::new(); | ||
yield &s[..] //~ ERROR `s` does not live long enough [E0597] | ||
}) | ||
} | ||
|
||
fn main() { | ||
bug(); | ||
} |
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,17 @@ | ||
error[E0597]: `s` does not live long enough | ||
--> $DIR/issue-55850.rs:38:16 | ||
| | ||
LL | yield &s[..] //~ ERROR `s` does not live long enough [E0597] | ||
| ^ borrowed value does not live long enough | ||
LL | }) | ||
| - borrowed value only lives until here | ||
| | ||
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 35:8... | ||
--> $DIR/issue-55850.rs:35:8 | ||
| | ||
LL | fn bug<'a>() -> impl Iterator<Item = &'a str> { | ||
| ^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0597`. |