Skip to content
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

Do not check outlives when explicit bound contains escaping regions #53736

Closed
wants to merge 1 commit into from
Closed
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
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() {}