Skip to content

ignore higher-ranked object bound conditions created by WF #59132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/librustc/traits/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
self.selcx.infcx().resolve_type_vars_if_possible(&obligation.predicate);
}

debug!("process_obligation: obligation = {:?}", obligation);

match obligation.predicate {
ty::Predicate::Trait(ref data) => {
let trait_obligation = obligation.with(data.clone());
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/ty/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,7 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> {
//
// Note: in fact we only permit builtin traits, not `Bar<'d>`, I
// am looking forward to the future here.

if !data.has_escaping_bound_vars() {
if !data.has_escaping_bound_vars() && !region.has_escaping_bound_vars() {
let implicit_bounds =
object_region_bounds(self.infcx.tcx, data);

Expand Down
20 changes: 20 additions & 0 deletions src/test/ui/generator/issue-53548-1.rs
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(),
};
}
39 changes: 39 additions & 0 deletions src/test/ui/generator/issue-53548.rs
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 ();
});
}