-
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 nicer lifetime errors for specialization
Add an obligation cause for these error so that the error points to the implementations that caused the error.
- Loading branch information
1 parent
fafe9e7
commit f46eabb
Showing
7 changed files
with
132 additions
and
10 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
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
50 changes: 50 additions & 0 deletions
50
tests/ui/specialization/min_specialization/specialize_with_generalize_lifetimes.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,50 @@ | ||
// Regression test for #79457. | ||
|
||
#![feature(min_specialization)] | ||
|
||
use std::any::Any; | ||
|
||
pub trait Tr { | ||
fn method(self) -> Box<dyn Any + 'static>; | ||
fn other(self); | ||
} | ||
|
||
impl<T: Any + 'static> Tr for T { | ||
default fn method(self) -> Box<dyn Any + 'static> { | ||
Box::new(self) | ||
} | ||
|
||
default fn other(self) {} | ||
} | ||
|
||
impl<'a> Tr for &'a i32 { | ||
//~^ ERROR does not fulfill the required lifetime | ||
fn other(self) {} | ||
} | ||
|
||
fn promote_to_static<'a>(i: &'a i32) -> &'static i32 { | ||
*i.method().downcast().unwrap() | ||
} | ||
|
||
struct Wrapper<'a>(&'a i32); | ||
|
||
impl<'a> Tr for Wrapper<'a> { | ||
//~^ ERROR does not fulfill the required lifetime | ||
fn other(self) {} | ||
} | ||
|
||
fn promote_to_static_2<'a>(w: Wrapper<'a>) -> Wrapper<'static> { | ||
*w.method().downcast().unwrap() | ||
} | ||
|
||
fn main() { | ||
let i = Box::new(100_i32); | ||
let static_i: &'static i32 = promote_to_static(&*i); | ||
drop(i); | ||
println!("{}", *static_i); | ||
|
||
let j = Box::new(200_i32); | ||
let static_w: Wrapper<'static> = promote_to_static_2(Wrapper(&*j)); | ||
drop(j); | ||
println!("{}", *static_w.0); | ||
} |
27 changes: 27 additions & 0 deletions
27
tests/ui/specialization/min_specialization/specialize_with_generalize_lifetimes.stderr
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,27 @@ | ||
error[E0477]: the type `&'a i32` does not fulfill the required lifetime | ||
--> $DIR/specialize_with_generalize_lifetimes.rs:20:1 | ||
| | ||
LL | impl<'a> Tr for &'a i32 { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: type must satisfy the static lifetime as required by this binding | ||
--> $DIR/specialize_with_generalize_lifetimes.rs:12:15 | ||
| | ||
LL | impl<T: Any + 'static> Tr for T { | ||
| ^^^^^^^ | ||
|
||
error[E0477]: the type `Wrapper<'a>` does not fulfill the required lifetime | ||
--> $DIR/specialize_with_generalize_lifetimes.rs:31:1 | ||
| | ||
LL | impl<'a> Tr for Wrapper<'a> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: type must satisfy the static lifetime as required by this binding | ||
--> $DIR/specialize_with_generalize_lifetimes.rs:12:15 | ||
| | ||
LL | impl<T: Any + 'static> Tr for T { | ||
| ^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0477`. |