Skip to content

Commit

Permalink
Do not check outlives when explicit bound contains escaping regions
Browse files Browse the repository at this point in the history
This makes the code similar to the handling of `ty::Ref` in
`src/librustc/ty/wf.rs`, except checking for non-escaping-regions
somewhere down the call chain instead of at the root.

Fixes rust-lang#53548
  • Loading branch information
Ekleog committed Aug 27, 2018
1 parent 63d6649 commit 7345333
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/librustc/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,8 @@ impl<T> Binder<T> {
pub fn dummy<'tcx>(value: T) -> Binder<T>
where T: TypeFoldable<'tcx>
{
debug_assert!(!value.has_escaping_regions());
debug_assert!(!value.has_escaping_regions(),
"Value has unexpected escaping regions: {:?}", value);
Binder(value)
}

Expand Down
4 changes: 3 additions & 1 deletion src/librustc/ty/wf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,14 +487,16 @@ 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_regions() {
if !data.has_escaping_regions() && !region.has_escaping_regions() {
let implicit_bounds =
object_region_bounds(self.infcx.tcx, data);

let explicit_bound = region;

for implicit_bound in implicit_bounds {
let cause = self.cause(traits::ObjectTypeBound(ty, explicit_bound));
debug!("Testing implicit bound {:?} with explicit bound {:?}, cause {:?}",
implicit_bound, explicit_bound, cause);
let outlives = ty::Binder::dummy(
ty::OutlivesPredicate(explicit_bound, implicit_bound));
self.out.push(traits::Obligation::new(cause,
Expand Down
40 changes: 40 additions & 0 deletions src/test/run-pass/issue-53548.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2018 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.

// Regression test for #53548: having a 'static bound on a trait
// made it impossible to keep a trait object to it across an
// await point inside a closure

#![feature(arbitrary_self_types, async_await, await_macro, futures_api, pin)]

use std::future::Future;
use std::mem::PinMut;
use std::task::{Poll, Context};

// A trait with 'static bound
trait Trait: 'static {}

// Anything we can give to await!()
struct DummyFut();
impl Future for DummyFut {
type Output = ();
fn poll(self: PinMut<Self>, _ctx: &mut Context) -> Poll<()> {
Poll::Pending
}
}

// The actual reproducer, requires that Trait is 'static and a trait
// object to it is captured in a closure for successful reproduction.
async fn foo(b: Box<Trait + 'static>) -> () {
let _bar = move || { b; () };
await!(DummyFut())
}

pub fn main() {}

0 comments on commit 7345333

Please sign in to comment.