-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #108947 - compiler-errors:ct-infer-no-shapeshifting, …
…r=BoxyUwU Don't even try to combine consts with incompatible types ~I left a more detailed explanation for why this fixes this issue in the UI test, but in general, we should not try to unify const infer vars and rigid consts if they have incompatible types. That's because we don't want something like a `ConstArgHasType` predicate to suddenly go from passing to failing, or vice versa, due to a shallow resolve.~ 1. Use the `type_of` for a parameter in `try_eval_lit_or_param`, instead of the "expected" type from a `WithOptConstParam` def id. 2. Don't combine consts that have incompatible types. Fixes #108781
- Loading branch information
Showing
11 changed files
with
74 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
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 |
---|---|---|
@@ -1,23 +1,35 @@ | ||
error: the constant `N` is not of type `u8` | ||
--> $DIR/type_mismatch.rs:2:5 | ||
| | ||
LL | bar::<N>() | ||
| ^^^^^^^^ | ||
| | ||
note: required by a bound in `bar` | ||
--> $DIR/type_mismatch.rs:6:8 | ||
| | ||
LL | fn bar<const N: u8>() -> [u8; N] {} | ||
| ^^^^^^^^^^^ required by this bound in `bar` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/type_mismatch.rs:2:11 | ||
| | ||
LL | bar::<N>() | ||
| ^ expected `u8`, found `usize` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/type_mismatch.rs:5:26 | ||
--> $DIR/type_mismatch.rs:6:26 | ||
| | ||
LL | fn bar<const N: u8>() -> [u8; N] {} | ||
| --- ^^^^^^^ expected `[u8; N]`, found `()` | ||
| | | ||
| implicitly returns `()` as its body has no tail or `return` expression | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/type_mismatch.rs:5:31 | ||
--> $DIR/type_mismatch.rs:6:31 | ||
| | ||
LL | fn bar<const N: u8>() -> [u8; N] {} | ||
| ^ expected `usize`, found `u8` | ||
|
||
error: aborting due to 3 previous errors | ||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
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
12 changes: 12 additions & 0 deletions
12
tests/ui/specialization/min_specialization/bad-const-wf-doesnt-specialize.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,12 @@ | ||
#![feature(min_specialization)] | ||
|
||
// An impl that has an erroneous const substitution should not specialize one | ||
// that is well-formed. | ||
|
||
struct S<const L: usize>; | ||
|
||
impl<const N: i32> Copy for S<N> {} | ||
impl<const M: usize> Copy for S<M> {} | ||
//~^ ERROR conflicting implementations of trait `Copy` for type `S<_>` | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
tests/ui/specialization/min_specialization/bad-const-wf-doesnt-specialize.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,11 @@ | ||
error[E0119]: conflicting implementations of trait `Copy` for type `S<_>` | ||
--> $DIR/bad-const-wf-doesnt-specialize.rs:9:1 | ||
| | ||
LL | impl<const N: i32> Copy for S<N> {} | ||
| -------------------------------- first implementation here | ||
LL | impl<const M: usize> Copy for S<M> {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `S<_>` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0119`. |
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