forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 rust-lang#117209.
- Loading branch information
Showing
3 changed files
with
53 additions
and
4 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
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`. |