-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Don't probe InferConst
in fold_const
if self.infcx
is None
, deeply_normalize
tys in check_tys_might_be_eq
#124526
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//! Issue #119381: encountering `ty::ConstKind::Infer(InferConst::Var(_))` inside a `ParamEnv` | ||
|
||
#![feature(with_negative_coherence)] | ||
trait Trait {} | ||
impl<const N: u8> Trait for [(); N] {} | ||
impl<const N: i8> Trait for [(); N] {} | ||
//~^ conflicting implementations of trait `Trait` for type `[(); _]` | ||
//~| mismatched types | ||
//~^^^^ mismatched types | ||
|
||
fn main() {} |
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,24 @@ | ||
error[E0119]: conflicting implementations of trait `Trait` for type `[(); _]` | ||
--> $DIR/infer-const-in-param-env.rs:6:1 | ||
| | ||
LL | impl<const N: u8> Trait for [(); N] {} | ||
| ----------------------------------- first implementation here | ||
LL | impl<const N: i8> Trait for [(); N] {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `[(); _]` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/infer-const-in-param-env.rs:5:34 | ||
| | ||
LL | impl<const N: u8> Trait for [(); N] {} | ||
| ^ expected `usize`, found `u8` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/infer-const-in-param-env.rs:6:34 | ||
| | ||
LL | impl<const N: i8> Trait for [(); N] {} | ||
| ^ expected `usize`, found `i8` | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
Some errors have detailed explanations: E0119, E0308. | ||
For more information about an 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//! Issue #114456: `deeply_normalize` tys in `check_tys_might_be_eq` | ||
//@ check-pass | ||
#![feature(adt_const_params)] | ||
#![allow(incomplete_features)] | ||
|
||
enum Type {} | ||
trait Trait { type Matrix; } | ||
impl Trait for Type { type Matrix = [usize; 1]; } | ||
|
||
struct Walk<const REMAINING: <Type as Trait>::Matrix> {} | ||
|
||
impl Walk<{ [0; 1] }> { | ||
pub const fn new() -> Self { | ||
Self {} | ||
} | ||
} | ||
|
||
fn main() { | ||
let _ = Walk::new(); | ||
} |
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,17 @@ | ||
//! Issue #114456: `deeply_normalize` tys in `check_tys_might_be_eq` | ||
//@ check-pass | ||
#![feature(adt_const_params, lazy_type_alias)] | ||
#![allow(incomplete_features)] | ||
|
||
type Matrix = [usize; 1]; | ||
struct Walk<const REMAINING: Matrix> {} | ||
|
||
impl Walk<{ [0; 1] }> { | ||
pub const fn new() -> Self { | ||
Self {} | ||
} | ||
} | ||
|
||
fn main() { | ||
let _ = Walk::new(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've avoided to review this PR for a while as this feels very suspicious to me but I wasn't able to explain why without a significant time investment. sorry 😅
The ICE occurs in
equate_impl_headers
which is used to compute the constraints we can assume. We cannot eagerly replace infer vars with placeholders at this pointrust/compiler/rustc_trait_selection/src/traits/coherence.rs
Line 449 in d86e122
We should use an
infcx
when encountering inference varialbes to make sure these infer vars do not resolve to any other types. I would personally prefer to only do thedeeply_normalize
change in this PR and fix thenegative_coherence
issue by cleaning up our const handling in general.While your approach does work and may at worst slightly worsen type inference here, this change does cause the code to be "conceptionally broken"1, so I would prefer to not land it, esp given that it's an ICE which only occurs with a nightly feature enabled.
Footnotes
this is mostly just vibe based 🤔 using it here as the way to rationalize this change is "yes, this may cause unexpected and wrong results in rare cases, but it's not unsound, so it's fine". It's somewhat difficult to explain exactly what I mean here ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For context, I tried to add a subdiagnostic “if there's a conflicting implementation and if using negative coherence solves it, suggests adding
#![feature(with_negative_coherence)]
” but it ICEd some tests, and I may have been too hasty in my attempt to fix it. I’ll try to come up with a nicer approach when I have time.