-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Fix ICE: Restrict param constraint suggestion #117246
Merged
Merged
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
28 changes: 28 additions & 0 deletions
28
...e-bounds/do-not-look-at-parent-item-in-suggestion-for-type-param-of-current-assoc-item.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,28 @@ | ||
use std::collections::HashMap; | ||
use std::hash::Hash; | ||
|
||
trait LowT: Identify {} | ||
|
||
trait Identify { | ||
type Id: Clone + Hash + PartialEq + Eq; | ||
fn identify(&self) -> Self::Id; | ||
} | ||
|
||
struct MapStore<L, I> | ||
where | ||
L: LowT + Identify<Id = I>, | ||
{ | ||
lows: HashMap<I, L>, | ||
} | ||
|
||
impl<L, I> MapStore<L, I> | ||
where | ||
L: LowT + Identify<Id = I>, | ||
I: Clone + Hash + PartialEq + Eq, | ||
{ | ||
fn remove_low(&mut self, low: &impl LowT) { | ||
let _low = self.lows.remove(low.identify()).unwrap(); //~ ERROR mismatched types | ||
} | ||
} | ||
|
||
fn main() {} |
18 changes: 18 additions & 0 deletions
18
...unds/do-not-look-at-parent-item-in-suggestion-for-type-param-of-current-assoc-item.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,18 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/do-not-look-at-parent-item-in-suggestion-for-type-param-of-current-assoc-item.rs:24:37 | ||
| | ||
LL | let _low = self.lows.remove(low.identify()).unwrap(); | ||
| ------ ^^^^^^^^^^^^^^ expected `&I`, found associated type | ||
| | | ||
| arguments to this method are incorrect | ||
| | ||
= note: expected reference `&I` | ||
found associated type `<impl LowT as Identify>::Id` | ||
= help: consider constraining the associated type `<impl LowT as Identify>::Id` to `&I` | ||
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html | ||
note: method defined here | ||
--> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL | ||
|
||
error: aborting due to previous error | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
struct A<B>(B); | ||
impl<B>A<B>{fn d(){fn d(){Self(1)}}} | ||
//~^ ERROR the size for values of type `B` cannot be known at compilation time | ||
//~| ERROR the size for values of type `B` cannot be known at compilation time | ||
//~| ERROR mismatched types | ||
//~| ERROR mismatched types | ||
//~| ERROR `main` function not found in crate |
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,79 @@ | ||
error[E0601]: `main` function not found in crate `do_not_ice_on_note_and_explain` | ||
--> $DIR/do-not-ice-on-note_and_explain.rs:2:37 | ||
| | ||
LL | impl<B>A<B>{fn d(){fn d(){Self(1)}}} | ||
| ^ consider adding a `main` function to `$DIR/do-not-ice-on-note_and_explain.rs` | ||
|
||
error[E0277]: the size for values of type `B` cannot be known at compilation time | ||
--> $DIR/do-not-ice-on-note_and_explain.rs:2:32 | ||
| | ||
LL | impl<B>A<B>{fn d(){fn d(){Self(1)}}} | ||
| - ---- ^ doesn't have a size known at compile-time | ||
| | | | ||
| | required by a bound introduced by this call | ||
| this type parameter needs to be `Sized` | ||
| | ||
note: required by a bound in `A` | ||
--> $DIR/do-not-ice-on-note_and_explain.rs:1:10 | ||
| | ||
LL | struct A<B>(B); | ||
| ^ required by this bound in `A` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/do-not-ice-on-note_and_explain.rs:2:32 | ||
| | ||
LL | impl<B>A<B>{fn d(){fn d(){Self(1)}}} | ||
| ---- ^ expected type parameter `B`, found integer | ||
| | | ||
| arguments to this function are incorrect | ||
| | ||
= note: expected type parameter `B` | ||
found type `{integer}` | ||
note: tuple struct defined here | ||
--> $DIR/do-not-ice-on-note_and_explain.rs:1:8 | ||
| | ||
LL | struct A<B>(B); | ||
| ^ | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/do-not-ice-on-note_and_explain.rs:2:27 | ||
| | ||
LL | impl<B>A<B>{fn d(){fn d(){Self(1)}}} | ||
| ^^^^^^^ expected `()`, found `A<B>` | ||
| | ||
= note: expected unit type `()` | ||
found struct `A<B>` | ||
help: consider using a semicolon here | ||
| | ||
LL | impl<B>A<B>{fn d(){fn d(){Self(1);}}} | ||
| + | ||
help: try adding a return type | ||
| | ||
LL | impl<B>A<B>{fn d(){fn d() -> A<B>{Self(1)}}} | ||
| +++++++ | ||
|
||
error[E0277]: the size for values of type `B` cannot be known at compilation time | ||
--> $DIR/do-not-ice-on-note_and_explain.rs:2:27 | ||
| | ||
LL | impl<B>A<B>{fn d(){fn d(){Self(1)}}} | ||
| - ^^^^^^^ doesn't have a size known at compile-time | ||
| | | ||
| this type parameter needs to be `Sized` | ||
| | ||
note: required by a bound in `A` | ||
--> $DIR/do-not-ice-on-note_and_explain.rs:1:10 | ||
| | ||
LL | struct A<B>(B); | ||
| ^ required by this bound in `A` | ||
help: you could relax the implicit `Sized` bound on `B` if it were used through indirection like `&B` or `Box<B>` | ||
--> $DIR/do-not-ice-on-note_and_explain.rs:1:10 | ||
| | ||
LL | struct A<B>(B); | ||
| ^ - ...if indirection were used here: `Box<B>` | ||
| | | ||
| this could be changed to `B: ?Sized`... | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
Some errors have detailed explanations: E0277, E0308, E0601. | ||
For more information about an error, try `rustc --explain E0277`. |
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 feel like this is not the right way of fixing this bug?
Why do we allow
Self
constructors from outer items that reference parameters that aren't in scope anyways? Like, we're referencing a type parameter that doesn't exist here, right?I feel like this also may cause strange behavior (or unsoundness? not exactly sure, depends on when we compare params by name or by index) when we actually do have a substitutable param here:
cc @cjgillot who tried this and had to unland it in #111557
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.
#111020 was reverted due to a regression, but it was probably a right thing to do in general.
Maybe we should do the usual bugfix process with a crater run, deprecation lint, and a tracking issue here.
In the meantime this PR could be merged to avoid the ICE.