forked from rust-lang/rust
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
report an error if we see an unexpected lifetime in impl Trait
But leave closure substs alone.
- Loading branch information
1 parent
a9cbfaa
commit fc3c90c
Showing
5 changed files
with
291 additions
and
34 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
35 changes: 35 additions & 0 deletions
35
src/test/ui/impl-trait/region-escape-via-bound-contravariant.rs
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,35 @@ | ||
// 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. | ||
|
||
// In contrast to `region-escape-via-bound-invariant`, in this case we | ||
// *can* return a value of type `&'x u32`, even though `'x` does not | ||
// appear in the bounds. This is because `&` is contravariant, and so | ||
// we are *actually* returning a `&'y u32`. | ||
// | ||
// See https://github.com/rust-lang/rust/issues/46541 for more details. | ||
|
||
// run-pass | ||
|
||
#![allow(dead_code)] | ||
#![feature(conservative_impl_trait)] | ||
#![feature(in_band_lifetimes)] | ||
#![feature(nll)] | ||
|
||
trait Trait<'a> { } | ||
|
||
impl Trait<'b> for &'a u32 { } | ||
|
||
fn foo(x: &'x u32) -> impl Trait<'y> | ||
where 'x: 'y | ||
{ | ||
x | ||
} | ||
|
||
fn main() { } |
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,34 @@ | ||
// 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. | ||
|
||
// Test that we do not allow the region `'x` to escape in the impl | ||
// trait **even though** `'y` escapes, which outlives `'x`. | ||
// | ||
// See https://github.com/rust-lang/rust/issues/46541 for more details. | ||
|
||
#![allow(dead_code)] | ||
#![feature(conservative_impl_trait)] | ||
#![feature(in_band_lifetimes)] | ||
#![feature(nll)] | ||
|
||
use std::cell::Cell; | ||
|
||
trait Trait<'a> { } | ||
|
||
impl Trait<'b> for Cell<&'a u32> { } | ||
|
||
fn foo(x: Cell<&'x u32>) -> impl Trait<'y> | ||
//~^ ERROR hidden type for `impl Trait` captures lifetime that does not appear in bounds [E0909] | ||
where 'x: 'y | ||
{ | ||
x | ||
} | ||
|
||
fn main() { } |
Oops, something went wrong.