-
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.
ignore higher-ranked WF requirements for trait objects
In the `issue-53548` test added in this commit, the `Box<dyn Trait>` type is expanded to `Box<dyn Trait + 'static>`, but the generator "witness" that results is `for<'r> { Box<dyn Trait + 'r> }`. The WF code was encountering an ICE (when debug-assertions were enabled) and an unexpected compilation error (without debug-asserions) when trying to process this `'r` region bound. In particular, to be WF, the region bound must meet the requirements of the trait, and hence we got `for<'r> { 'r: 'static }`. This would ICE because the `Binder` constructor we were using was assering that no higher-ranked regions were involved (because the WF code is supposed to skip those). The error (if debug-asserions were disabled) came because we obviously cannot prove that `'r: 'static` for any region `'r`. Pursuant with our "lazy WF" strategy for higher-ranked regions, the fix is not to require that `for<'r> { 'r: 'static }` holds (this is also analogous to what we would do for higher-ranked regions appearing within the trait in other positions).
- Loading branch information
1 parent
4632e33
commit 261daf2
Showing
3 changed files
with
60 additions
and
2 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,20 @@ | ||
// A variant of #53548 that does not actually require generators, | ||
// but which encountered the same ICE/error. See `issue-53548.rs` | ||
// for details. | ||
// | ||
// compile-pass | ||
|
||
use std::cell::RefCell; | ||
use std::rc::Rc; | ||
|
||
trait Trait: 'static {} | ||
|
||
struct Store<C> { | ||
inner: Rc<RefCell<Option<C>>>, | ||
} | ||
|
||
fn main() { | ||
let store = Store::<Box<for<'a> fn(&(dyn Trait + 'a))>> { | ||
inner: Default::default(), | ||
}; | ||
} |
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,39 @@ | ||
// Regression test for #53548. The `Box<dyn Trait>` type below is | ||
// expanded to `Box<dyn Trait + 'static>`, but the generator "witness" | ||
// that results is `for<'r> { Box<dyn Trait + 'r> }`. The WF code was | ||
// encountering an ICE (when debug-assertions were enabled) and an | ||
// unexpected compilation error (without debug-asserions) when trying | ||
// to process this `'r` region bound. In particular, to be WF, the | ||
// region bound must meet the requirements of the trait, and hence we | ||
// got `for<'r> { 'r: 'static }`. This would ICE because the `Binder` | ||
// constructor we were using was assering that no higher-ranked | ||
// regions were involved (because the WF code is supposed to skip | ||
// those). The error (if debug-asserions were disabled) came because | ||
// we obviously cannot prove that `'r: 'static` for any region `'r`. | ||
// Pursuant with our "lazy WF" strategy for higher-ranked regions, the | ||
// fix is not to require that `for<'r> { 'r: 'static }` holds (this is | ||
// also analogous to what we would do for higher-ranked regions | ||
// appearing within the trait in other positions). | ||
// | ||
// compile-pass | ||
|
||
#![feature(generators)] | ||
|
||
use std::cell::RefCell; | ||
use std::rc::Rc; | ||
|
||
trait Trait: 'static {} | ||
|
||
struct Store<C> { | ||
inner: Rc<RefCell<Option<C>>>, | ||
} | ||
|
||
fn main() { | ||
Box::new(static move || { | ||
let store = Store::<Box<dyn Trait>> { | ||
inner: Default::default(), | ||
}; | ||
yield (); | ||
}); | ||
} | ||
|