-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Consistently use subtyping in method resolution #126128
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
struct Fail<T>; | ||
//~^ ERROR: type parameter `T` is never used | ||
|
||
impl Fail<i32> { | ||
const C: () = (); | ||
} | ||
|
||
fn main() { | ||
Fail::<()>::C | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0392]: type parameter `T` is never used | ||
--> $DIR/wrong-projection-self-ty-invalid-bivariant-arg.rs:1:13 | ||
| | ||
LL | struct Fail<T>; | ||
| ^ unused type parameter | ||
| | ||
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData` | ||
= help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0392`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
trait Proj { | ||
type Assoc; | ||
} | ||
impl<T> Proj for T { | ||
type Assoc = T; | ||
} | ||
|
||
struct Fail<T: Proj<Assoc = U>, U>(T); | ||
|
||
impl Fail<i32, i32> { | ||
const C: () = (); | ||
} | ||
|
||
fn main() { | ||
Fail::<i32, u32>::C | ||
//~^ ERROR: type mismatch | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error[E0271]: type mismatch resolving `<i32 as Proj>::Assoc == u32` | ||
--> $DIR/wrong-projection-self-ty-invalid-bivariant-arg2.rs:15:5 | ||
| | ||
LL | Fail::<i32, u32>::C | ||
| ^^^^^^^^^^^^^^^^ type mismatch resolving `<i32 as Proj>::Assoc == u32` | ||
| | ||
note: expected this to be `u32` | ||
--> $DIR/wrong-projection-self-ty-invalid-bivariant-arg2.rs:5:18 | ||
| | ||
LL | type Assoc = T; | ||
| ^ | ||
note: required by a bound in `Fail` | ||
--> $DIR/wrong-projection-self-ty-invalid-bivariant-arg2.rs:8:21 | ||
| | ||
LL | struct Fail<T: Proj<Assoc = U>, U>(T); | ||
| ^^^^^^^^^ required by this bound in `Fail` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0271`. |
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0277]: the trait bound `(): std::error::Error` is not satisfied | ||
--> $DIR/coerce-issue-49593-box-never.rs:18:5 | ||
| | ||
LL | Box::<_ /* ! */>::new(x) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `std::error::Error` is not implemented for `()` | ||
| | ||
= note: required for the cast from `Box<()>` to `Box<(dyn std::error::Error + 'static)>` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
//@ revisions: nofallback fallback | ||
//@ ignore-windows - the number of `Error` impls is platform-dependent | ||
//@[fallback] check-pass | ||
//@[nofallback] check-fail | ||
//@check-fail | ||
|
||
#![feature(never_type)] | ||
#![cfg_attr(fallback, feature(never_type_fallback))] | ||
|
@@ -15,18 +13,21 @@ fn raw_ptr_box<T>(t: T) -> *mut T { | |
} | ||
|
||
fn foo(x: !) -> Box<dyn Error> { | ||
/* *mut $0 is coerced to Box<dyn Error> here */ Box::<_ /* ! */>::new(x) | ||
//[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied | ||
// Subtyping during method resolution will generate new inference vars and | ||
// subtype them. Thus fallback will not fall back to `!`, but `()` instead. | ||
Box::<_ /* ! */>::new(x) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this change? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of merging the two infer vars, we now create a subtyping relation for them, so they aren't the same. Never type fallback will still fall back to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh lel, you didn't change the UI test, you just reformatted it |
||
//~^ ERROR trait bound `(): std::error::Error` is not satisfied | ||
} | ||
|
||
fn foo_raw_ptr(x: !) -> *mut dyn Error { | ||
/* *mut $0 is coerced to *mut Error here */ raw_ptr_box::<_ /* ! */>(x) | ||
/* *mut $0 is coerced to *mut Error here */ | ||
raw_ptr_box::<_ /* ! */>(x) | ||
//[nofallback]~^ ERROR trait bound `(): std::error::Error` is not satisfied | ||
} | ||
|
||
fn no_coercion(d: *mut dyn Error) -> *mut dyn Error { | ||
/* an unsize coercion won't compile here, and it is indeed not used | ||
because there is nothing requiring the _ to be Sized */ | ||
because there is nothing requiring the _ to be Sized */ | ||
d as *mut _ | ||
} | ||
|
||
|
@@ -49,10 +50,9 @@ fn foo_no_never() { | |
first_iter = true; | ||
} | ||
|
||
let mut y : Option<S> = None; | ||
let mut y: Option<S> = None; | ||
// assert types are equal | ||
mem::swap(&mut x, &mut y); | ||
} | ||
|
||
fn main() { | ||
} | ||
fn main() {} |
Uh oh!
There was an error while loading. Please reload this page.