-
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.
Report a specialized error when a
'static
obligation comes from an …
…`impl dyn Trait` ```text error: lifetime may not live long enough --> $DIR/static-impl-obligation.rs:8:27 | LL | fn bar<'a>(x: &'a &'a u32) { | -- lifetime `'a` defined here LL | let y: &dyn Foo = x; | ^ cast requires that `'a` must outlive `'static` LL | y.hello(); | --------- calling this method introduces a `'static` lifetime requirement | help: relax the implicit `'static` bound on the impl | LL | impl dyn Foo + '_ { | ++++ ``` ```text error: lifetime may not live long enough --> $DIR/static-impl-obligation.rs:173:27 | LL | fn bar<'a>(x: &'a &'a u32) { | -- lifetime `'a` defined here LL | let y: &dyn Foo = x; | ^ cast requires that `'a` must outlive `'static` LL | y.hello(); | --------- calling this method introduces a `'static` lifetime requirement | note: the `impl` on `(dyn p::Foo + 'static)` has `'static` lifetime requirements --> $DIR/static-impl-obligation.rs:169:20 | LL | impl dyn Foo + 'static where Self: 'static { | ^^^^^^^ ^^^^^^^ LL | fn hello(&self) where Self: 'static {} | ^^^^^^^ ```
- Loading branch information
Showing
11 changed files
with
834 additions
and
55 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
306 changes: 262 additions & 44 deletions
306
compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,210 @@ | ||
mod a { | ||
trait Foo {} | ||
impl<'a> Foo for &'a u32 {} | ||
impl dyn Foo { //~ HELP consider relaxing the implicit `'static` requirement | ||
fn hello(&self) {} | ||
} | ||
fn bar<'a>(x: &'a &'a u32) { | ||
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough | ||
y.hello(); | ||
} | ||
} | ||
mod b { | ||
trait Foo {} | ||
impl<'a> Foo for &'a u32 {} | ||
impl dyn Foo { | ||
fn hello(&'static self) {} | ||
} | ||
fn bar<'a>(x: &'a &'a u32) { | ||
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough | ||
y.hello(); | ||
} | ||
} | ||
mod c { | ||
trait Foo {} | ||
impl<'a> Foo for &'a u32 {} | ||
impl dyn Foo { | ||
fn hello(&'static self) where Self: 'static {} | ||
} | ||
fn bar<'a>(x: &'a &'a u32) { | ||
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough | ||
y.hello(); | ||
} | ||
} | ||
mod d { | ||
trait Foo {} | ||
impl<'a> Foo for &'a u32 {} | ||
impl dyn Foo { | ||
fn hello(&self) where Self: 'static {} | ||
} | ||
fn bar<'a>(x: &'a &'a u32) { | ||
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough | ||
y.hello(); | ||
} | ||
} | ||
mod e { | ||
trait Foo {} | ||
impl<'a> Foo for &'a u32 {} | ||
impl dyn Foo + 'static { //~ HELP consider replacing this `'static` requirement | ||
fn hello(&self) {} | ||
} | ||
fn bar<'a>(x: &'a &'a u32) { | ||
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough | ||
y.hello(); | ||
} | ||
} | ||
mod f { | ||
trait Foo {} | ||
impl<'a> Foo for &'a u32 {} | ||
impl dyn Foo + 'static { | ||
fn hello(&'static self) {} | ||
} | ||
fn bar<'a>(x: &'a &'a u32) { | ||
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough | ||
y.hello(); | ||
} | ||
} | ||
mod g { | ||
trait Foo {} | ||
impl<'a> Foo for &'a u32 {} | ||
impl dyn Foo + 'static { | ||
fn hello(&'static self) where Self: 'static {} | ||
} | ||
fn bar<'a>(x: &'a &'a u32) { | ||
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough | ||
y.hello(); | ||
} | ||
} | ||
mod h { | ||
trait Foo {} | ||
impl<'a> Foo for &'a u32 {} | ||
impl dyn Foo + 'static { | ||
fn hello(&self) where Self: 'static {} | ||
} | ||
fn bar<'a>(x: &'a &'a u32) { | ||
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough | ||
y.hello(); | ||
} | ||
} | ||
mod i { | ||
trait Foo {} | ||
impl<'a> Foo for &'a u32 {} | ||
impl dyn Foo where Self: 'static { | ||
fn hello(&self) {} | ||
} | ||
fn bar<'a>(x: &'a &'a u32) { | ||
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough | ||
y.hello(); | ||
} | ||
} | ||
mod j { | ||
trait Foo {} | ||
impl<'a> Foo for &'a u32 {} | ||
impl dyn Foo where Self: 'static { | ||
fn hello(&'static self) {} | ||
} | ||
fn bar<'a>(x: &'a &'a u32) { | ||
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough | ||
y.hello(); | ||
} | ||
} | ||
mod k { | ||
trait Foo {} | ||
impl<'a> Foo for &'a u32 {} | ||
impl dyn Foo where Self: 'static { | ||
fn hello(&'static self) where Self: 'static {} | ||
} | ||
fn bar<'a>(x: &'a &'a u32) { | ||
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough | ||
y.hello(); | ||
} | ||
} | ||
mod l { | ||
trait Foo {} | ||
impl<'a> Foo for &'a u32 {} | ||
impl dyn Foo where Self: 'static { | ||
fn hello(&self) where Self: 'static {} | ||
} | ||
fn bar<'a>(x: &'a &'a u32) { | ||
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough | ||
y.hello(); | ||
} | ||
} | ||
mod m { | ||
trait Foo {} | ||
impl<'a> Foo for &'a u32 {} | ||
impl dyn Foo + 'static where Self: 'static { | ||
fn hello(&self) {} | ||
} | ||
fn bar<'a>(x: &'a &'a u32) { | ||
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough | ||
y.hello(); | ||
} | ||
} | ||
mod n { | ||
trait Foo {} | ||
impl<'a> Foo for &'a u32 {} | ||
impl dyn Foo + 'static where Self: 'static { | ||
fn hello(&'static self) {} | ||
} | ||
fn bar<'a>(x: &'a &'a u32) { | ||
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough | ||
y.hello(); | ||
} | ||
} | ||
mod o { | ||
trait Foo {} | ||
impl<'a> Foo for &'a u32 {} | ||
impl dyn Foo + 'static where Self: 'static { | ||
fn hello(&'static self) where Self: 'static {} | ||
} | ||
fn bar<'a>(x: &'a &'a u32) { | ||
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough | ||
y.hello(); | ||
} | ||
} | ||
mod p { | ||
trait Foo {} | ||
impl<'a> Foo for &'a u32 {} | ||
impl dyn Foo + 'static where Self: 'static { | ||
fn hello(&self) where Self: 'static {} | ||
} | ||
fn bar<'a>(x: &'a &'a u32) { | ||
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough | ||
y.hello(); | ||
} | ||
} | ||
mod q { | ||
struct Foo {} | ||
impl Foo { | ||
fn hello(&'static self) {} | ||
} | ||
fn bar<'a>(x: &'a &'a Foo) { | ||
x.hello(); //~ ERROR borrowed data escapes outside of function | ||
} | ||
} | ||
mod r { | ||
struct Foo {} | ||
impl Foo { | ||
fn hello(&'static self) where Self: 'static {} | ||
} | ||
fn bar<'a>(x: &'a &'a Foo) { | ||
x.hello(); //~ ERROR borrowed data escapes outside of function | ||
} | ||
} | ||
mod s { | ||
trait Foo {} | ||
impl<'a> Foo for &'a u32 {} | ||
|
||
trait Trait { fn hello(&self) {} } | ||
|
||
impl Trait for dyn Foo { //~ HELP consider relaxing the implicit `'static` requirement on the impl | ||
fn hello(&self) {} | ||
|
||
} | ||
fn convert<'a>(x: &'a &'a u32) { | ||
let y: &dyn Foo = x; //~ ERROR lifetime may not live long enough | ||
y.hello(); | ||
} | ||
} | ||
fn main() {} |
Oops, something went wrong.