-
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.
Suggest constraining assoc types in more cases
Fix #46969.
- Loading branch information
Showing
4 changed files
with
104 additions
and
44 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
15 changes: 15 additions & 0 deletions
15
tests/ui/associated-type-bounds/suggest-contraining-assoc-type-because-of-assoc-const.fixed
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,15 @@ | ||
// run-rustfix | ||
trait O { | ||
type M; | ||
} | ||
trait U<A: O> { | ||
const N: A::M; | ||
} | ||
impl<D> O for D { | ||
type M = u8; | ||
} | ||
impl<C: O<M = u8>> U<C> for u16 { | ||
const N: C::M = 4u8; //~ ERROR mismatched types | ||
} | ||
fn main() {} | ||
|
15 changes: 15 additions & 0 deletions
15
tests/ui/associated-type-bounds/suggest-contraining-assoc-type-because-of-assoc-const.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,15 @@ | ||
// run-rustfix | ||
trait O { | ||
type M; | ||
} | ||
trait U<A: O> { | ||
const N: A::M; | ||
} | ||
impl<D> O for D { | ||
type M = u8; | ||
} | ||
impl<C: O> U<C> for u16 { | ||
const N: C::M = 4u8; //~ ERROR mismatched types | ||
} | ||
fn main() {} | ||
|
16 changes: 16 additions & 0 deletions
16
tests/ui/associated-type-bounds/suggest-contraining-assoc-type-because-of-assoc-const.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,16 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/suggest-contraining-assoc-type-because-of-assoc-const.rs:12:21 | ||
| | ||
LL | const N: C::M = 4u8; | ||
| ^^^ expected associated type, found `u8` | ||
| | ||
= note: expected associated type `<C as O>::M` | ||
found type `u8` | ||
help: consider constraining the associated type `<C as O>::M` to `u8` | ||
| | ||
LL | impl<C: O<M = u8>> U<C> for u16 { | ||
| ++++++++ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0308`. |