Handle fully-qualified paths and add test cases
This commit is contained in:
parent
3712dfc677
commit
53d96b5159
8 changed files with 404 additions and 98 deletions
|
|
@ -0,0 +1,37 @@
|
|||
error[E0597]: `val` does not live long enough
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:22:9
|
||||
|
|
||||
LL | fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32>>) -> impl OtherTrait<'a> {
|
||||
| -- lifetime `'a` defined here ------------------- opaque type requires that `val` is borrowed for `'a`
|
||||
LL | val.use_self()
|
||||
| ^^^ borrowed value does not live long enough
|
||||
LL | }
|
||||
| - `val` dropped here while still borrowed
|
||||
|
|
||||
help: you can add a bound to the opaque type to make it last less than `'static` and match `'a`
|
||||
|
|
||||
LL | fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32>>) -> impl OtherTrait<'a> + 'a {
|
||||
| ^^^^
|
||||
|
||||
error[E0515]: cannot return value referencing function parameter `val`
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:44:9
|
||||
|
|
||||
LL | val.use_self()
|
||||
| ---^^^^^^^^^^^
|
||||
| |
|
||||
| returns a value referencing data owned by the current function
|
||||
| `val` is borrowed here
|
||||
|
||||
error[E0515]: cannot return value referencing function parameter `val`
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:110:9
|
||||
|
|
||||
LL | val.use_self()
|
||||
| ---^^^^^^^^^^^
|
||||
| |
|
||||
| returns a value referencing data owned by the current function
|
||||
| `val` is borrowed here
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0515, E0597.
|
||||
For more information about an error, try `rustc --explain E0515`.
|
||||
|
|
@ -0,0 +1,114 @@
|
|||
|
||||
// FIXME: the following cases need to suggest more things to make users reach a working end state.
|
||||
|
||||
mod bav {
|
||||
trait OtherTrait<'a> {}
|
||||
impl<'a> OtherTrait<'a> for &'a () {}
|
||||
|
||||
trait ObjectTrait {
|
||||
type Assoc: Bar;
|
||||
}
|
||||
trait MyTrait {
|
||||
fn use_self(&self) -> &() { panic!() }
|
||||
}
|
||||
trait Bar {}
|
||||
|
||||
impl MyTrait for Box<dyn ObjectTrait<Assoc = i32>> {
|
||||
fn use_self(&self) -> &() { panic!() }
|
||||
}
|
||||
impl Bar for i32 {}
|
||||
|
||||
fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32>>) -> impl OtherTrait<'a> {
|
||||
val.use_self() //~ ERROR E0597
|
||||
}
|
||||
}
|
||||
|
||||
mod bap {
|
||||
trait OtherTrait<'a> {}
|
||||
impl<'a> OtherTrait<'a> for &'a () {}
|
||||
|
||||
trait ObjectTrait {
|
||||
type Assoc: Bar;
|
||||
}
|
||||
trait MyTrait {
|
||||
fn use_self(&self) -> &() { panic!() }
|
||||
}
|
||||
trait Bar {}
|
||||
|
||||
impl MyTrait for Box<dyn ObjectTrait<Assoc = i32>> {
|
||||
fn use_self(&self) -> &() { panic!() }
|
||||
}
|
||||
impl Bar for i32 {}
|
||||
|
||||
fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32>>) -> impl OtherTrait<'a> + 'a {
|
||||
val.use_self() //~ ERROR E0515
|
||||
}
|
||||
}
|
||||
|
||||
// This case in particular requires the user to write all of the bounds we have in `mod bax`.
|
||||
mod bay {
|
||||
trait OtherTrait<'a> {}
|
||||
impl<'a> OtherTrait<'a> for &'a () {}
|
||||
|
||||
trait ObjectTrait {
|
||||
type Assoc: Bar;
|
||||
}
|
||||
trait MyTrait {
|
||||
fn use_self(&self) -> &() { panic!() }
|
||||
}
|
||||
trait Bar {}
|
||||
|
||||
impl MyTrait for Box<dyn ObjectTrait<Assoc = i32>> {
|
||||
fn use_self(&self) -> &() { panic!() }
|
||||
}
|
||||
impl Bar for i32 {}
|
||||
|
||||
fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32> + 'a>) -> &'a () {
|
||||
val.use_self() //~ ERROR E0767
|
||||
}
|
||||
}
|
||||
|
||||
mod bax {
|
||||
trait OtherTrait<'a> {}
|
||||
impl<'a> OtherTrait<'a> for &'a () {}
|
||||
|
||||
trait ObjectTrait {
|
||||
type Assoc: Bar;
|
||||
}
|
||||
trait MyTrait<'a> {
|
||||
fn use_self(&'a self) -> &'a () { panic!() }
|
||||
}
|
||||
trait Bar {}
|
||||
|
||||
impl<'a> MyTrait<'a> for Box<dyn ObjectTrait<Assoc = i32> + 'a> {
|
||||
fn use_self(&'a self) -> &'a () { panic!() }
|
||||
}
|
||||
impl Bar for i32 {}
|
||||
|
||||
fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32> + 'a>) -> &'a () {
|
||||
val.use_self()
|
||||
}
|
||||
}
|
||||
|
||||
mod baw {
|
||||
trait OtherTrait<'a> {}
|
||||
impl<'a> OtherTrait<'a> for &'a () {}
|
||||
|
||||
trait ObjectTrait {
|
||||
type Assoc: Bar;
|
||||
}
|
||||
trait MyTrait {
|
||||
fn use_self(&self) -> &() { panic!() }
|
||||
}
|
||||
trait Bar {}
|
||||
|
||||
impl<'a> MyTrait for Box<dyn ObjectTrait<Assoc = Box<dyn Bar>>> {
|
||||
fn use_self(&self) -> &() { panic!() }
|
||||
}
|
||||
|
||||
fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = Box<dyn Bar>>>) -> impl OtherTrait<'a> + 'a{
|
||||
val.use_self() //~ ERROR E0515
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,57 @@
|
|||
error[E0597]: `val` does not live long enough
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:22:9
|
||||
|
|
||||
LL | fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32>>) -> impl OtherTrait<'a> {
|
||||
| -- lifetime `'a` defined here ------------------- opaque type requires that `val` is borrowed for `'a`
|
||||
LL | val.use_self()
|
||||
| ^^^ borrowed value does not live long enough
|
||||
LL | }
|
||||
| - `val` dropped here while still borrowed
|
||||
|
|
||||
help: you can add a bound to the opaque type to make it last less than `'static` and match `'a`
|
||||
|
|
||||
LL | fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32>>) -> impl OtherTrait<'a> + 'a {
|
||||
| ^^^^
|
||||
|
||||
error[E0515]: cannot return value referencing function parameter `val`
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:44:9
|
||||
|
|
||||
LL | val.use_self()
|
||||
| ---^^^^^^^^^^^
|
||||
| |
|
||||
| returns a value referencing data owned by the current function
|
||||
| `val` is borrowed here
|
||||
|
||||
error[E0515]: cannot return value referencing function parameter `val`
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:110:9
|
||||
|
|
||||
LL | val.use_self()
|
||||
| ---^^^^^^^^^^^
|
||||
| |
|
||||
| returns a value referencing data owned by the current function
|
||||
| `val` is borrowed here
|
||||
|
||||
error[E0767]: `val` has lifetime `'a` but calling `use_self` introduces an implicit `'static` lifetime requirement
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:67:13
|
||||
|
|
||||
LL | fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32> + 'a>) -> &'a () {
|
||||
| -------------------------------------- this data with lifetime `'a`...
|
||||
LL | val.use_self()
|
||||
| ^^^^^^^^ ...is captured and required to live as long as `'static` here
|
||||
|
|
||||
note: the used `impl` has a `'static` requirement
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:61:30
|
||||
|
|
||||
LL | impl MyTrait for Box<dyn ObjectTrait<Assoc = i32>> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^ this has an implicit `'static` lifetime requirement
|
||||
LL | fn use_self(&self) -> &() { panic!() }
|
||||
| -------- calling this method introduces the `impl`'s 'static` requirement
|
||||
help: consider relaxing the implicit `'static` requirement
|
||||
|
|
||||
LL | impl MyTrait for Box<dyn ObjectTrait<Assoc = i32> + '_> {
|
||||
| ^^^^
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0515, E0597.
|
||||
For more information about an error, try `rustc --explain E0515`.
|
||||
|
|
@ -78,14 +78,35 @@ mod ban {
|
|||
trait MyTrait {
|
||||
fn use_self(&self) -> &() { panic!() }
|
||||
}
|
||||
trait Irrelevant {}
|
||||
trait Irrelevant {
|
||||
fn use_self(&self) -> &() { panic!() }
|
||||
}
|
||||
|
||||
impl MyTrait for dyn ObjectTrait + '_ {}
|
||||
impl Irrelevant for dyn ObjectTrait {}
|
||||
|
||||
fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
|
||||
val.use_self() //~ ERROR E0759
|
||||
}
|
||||
}
|
||||
|
||||
mod bal {
|
||||
trait OtherTrait<'a> {}
|
||||
impl<'a> OtherTrait<'a> for &'a () {}
|
||||
|
||||
trait ObjectTrait {}
|
||||
trait MyTrait {
|
||||
fn use_self(&self) -> &() { panic!() }
|
||||
}
|
||||
trait Irrelevant {
|
||||
fn use_self(&self) -> &() { panic!() }
|
||||
}
|
||||
|
||||
impl MyTrait for dyn ObjectTrait + '_ {}
|
||||
impl Irrelevant for dyn ObjectTrait {}
|
||||
|
||||
fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
|
||||
MyTrait::use_self(val) //~ ERROR E0759
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ LL | val.use_self()
|
|||
= help: consider replacing `'a` with `'static`
|
||||
|
||||
error[E0521]: borrowed data escapes outside of function
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:87:9
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:88:9
|
||||
|
|
||||
LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> {
|
||||
| --- `val` is a reference that is only valid in the function body
|
||||
|
|
@ -28,5 +28,15 @@ LL | val.use_self()
|
|||
|
|
||||
= help: consider replacing `'a` with `'static`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error[E0521]: borrowed data escapes outside of function
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:108:9
|
||||
|
|
||||
LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
|
||||
| --- `val` is a reference that is only valid in the function body
|
||||
LL | MyTrait::use_self(val)
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ `val` escapes the function body here
|
||||
|
|
||||
= help: consider replacing `'a` with `'static`
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -78,14 +78,35 @@ mod ban {
|
|||
trait MyTrait {
|
||||
fn use_self(&self) -> &() { panic!() }
|
||||
}
|
||||
trait Irrelevant {}
|
||||
trait Irrelevant {
|
||||
fn use_self(&self) -> &() { panic!() }
|
||||
}
|
||||
|
||||
impl MyTrait for dyn ObjectTrait {}
|
||||
impl Irrelevant for dyn ObjectTrait {}
|
||||
|
||||
fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> {
|
||||
val.use_self() //~ ERROR E0759
|
||||
}
|
||||
}
|
||||
|
||||
mod bal {
|
||||
trait OtherTrait<'a> {}
|
||||
impl<'a> OtherTrait<'a> for &'a () {}
|
||||
|
||||
trait ObjectTrait {}
|
||||
trait MyTrait {
|
||||
fn use_self(&self) -> &() { panic!() }
|
||||
}
|
||||
trait Irrelevant {
|
||||
fn use_self(&self) -> &() { panic!() }
|
||||
}
|
||||
|
||||
impl MyTrait for dyn ObjectTrait {}
|
||||
impl Irrelevant for dyn ObjectTrait {}
|
||||
|
||||
fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
|
||||
MyTrait::use_self(val) //~ ERROR E0759
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ LL | fn use_it<'a, T>(val: &'a dyn ObjectTrait<T>) -> impl OtherTrait<'a> +
|
|||
LL | val.use_self::<T>()
|
||||
| ^^^^^^^^ ...is captured and required to live as long as `'static` here
|
||||
|
|
||||
note: `impl` of `foo::MyTrait` has a `'static` requirement
|
||||
note: the used `impl` has a `'static` requirement
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:14:32
|
||||
|
|
||||
LL | impl<T> MyTrait<T> for dyn ObjectTrait<T> {
|
||||
|
|
@ -26,7 +26,7 @@ LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
|
|||
LL | val.use_self()
|
||||
| ^^^^^^^^ ...is captured and required to live as long as `'static` here because of an implicit lifetime bound on the inherent `impl`
|
||||
|
|
||||
note: inherent `impl` has a `'static` requirement
|
||||
note: the used `impl` has a `'static` requirement
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:64:14
|
||||
|
|
||||
LL | impl dyn ObjectTrait {
|
||||
|
|
@ -39,15 +39,15 @@ LL | impl dyn ObjectTrait + '_ {
|
|||
| ^^^^
|
||||
|
||||
error[E0759]: `val` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:87:13
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:88:13
|
||||
|
|
||||
LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> {
|
||||
| ------------------- this data with lifetime `'a`...
|
||||
LL | val.use_self()
|
||||
| ^^^^^^^^ ...is captured and required to live as long as `'static` here
|
||||
|
|
||||
note: `impl` of `ban::MyTrait` has a `'static` requirement
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:83:26
|
||||
note: the used `impl` has a `'static` requirement
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:85:26
|
||||
|
|
||||
LL | fn use_self(&self) -> &() { panic!() }
|
||||
| -------- calling this method introduces the `impl`'s 'static` requirement
|
||||
|
|
@ -63,15 +63,41 @@ help: to declare that the `impl Trait` captures data from argument `val`, you ca
|
|||
LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
|
||||
| ^^^^
|
||||
|
||||
error[E0759]: `val` has lifetime `'a` but it needs to satisfy a `'static` lifetime requirement
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:108:27
|
||||
|
|
||||
LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
|
||||
| ------------------- this data with lifetime `'a`...
|
||||
LL | MyTrait::use_self(val)
|
||||
| ^^^ ...is captured here...
|
||||
|
|
||||
note: ...and is required to live as long as `'static` here
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:108:9
|
||||
|
|
||||
LL | MyTrait::use_self(val)
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
note: the used `impl` has a `'static` requirement
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:104:26
|
||||
|
|
||||
LL | fn use_self(&self) -> &() { panic!() }
|
||||
| -------- calling this method introduces the `impl`'s 'static` requirement
|
||||
...
|
||||
LL | impl MyTrait for dyn ObjectTrait {}
|
||||
| ^^^^^^^^^^^ this has an implicit `'static` lifetime requirement
|
||||
help: consider relaxing the implicit `'static` requirement
|
||||
|
|
||||
LL | impl MyTrait for dyn ObjectTrait + '_ {}
|
||||
| ^^^^
|
||||
|
||||
error[E0767]: `val` has lifetime `'a` but calling `use_self` introduces an implicit `'static` lifetime requirement
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:37:13
|
||||
|
|
||||
LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> &'a () {
|
||||
| ------------------- this data with lifetime `'a`...
|
||||
LL | val.use_self()
|
||||
| ^^^^^^^^ ...is captured and required to live as long as `'static` here because of an implicit lifetime on the `impl` of `bar::MyTrait`
|
||||
| ^^^^^^^^ ...is captured and required to live as long as `'static` here
|
||||
|
|
||||
note: `impl` of `bar::MyTrait` has a `'static` requirement
|
||||
note: the used `impl` has a `'static` requirement
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:31:26
|
||||
|
|
||||
LL | impl MyTrait for dyn ObjectTrait {
|
||||
|
|
@ -89,9 +115,9 @@ error[E0767]: `val` has lifetime `'a` but calling `use_self` introduces an impli
|
|||
LL | fn use_it<'a>(val: &'a Box<dyn ObjectTrait + 'a>) -> &'a () {
|
||||
| ----------------------------- this data with lifetime `'a`...
|
||||
LL | val.use_self()
|
||||
| ^^^^^^^^ ...is captured and required to live as long as `'static` here because of an implicit lifetime on the `impl` of `baz::MyTrait`
|
||||
| ^^^^^^^^ ...is captured and required to live as long as `'static` here
|
||||
|
|
||||
note: `impl` of `baz::MyTrait` has a `'static` requirement
|
||||
note: the used `impl` has a `'static` requirement
|
||||
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:48:30
|
||||
|
|
||||
LL | impl MyTrait for Box<dyn ObjectTrait> {
|
||||
|
|
@ -103,6 +129,6 @@ help: consider relaxing the implicit `'static` requirement
|
|||
LL | impl MyTrait for Box<dyn ObjectTrait + '_> {
|
||||
| ^^^^
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0759`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue