-
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 #117246 - estebank:issue-117209, r=petrochenkov
Fix ICE: Restrict param constraint suggestion When encountering an associated item with a type param that could be constrained, do not look at the parent item if the type param comes from the associated item. Fix #117209, fix #89868.
- Loading branch information
Showing
6 changed files
with
227 additions
and
46 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
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`. |