Closed
Description
I tried this code:
#![feature(inherent_associated_types)]
#![allow(incomplete_features)]
struct S<T>(T);
impl<T: O> S<T> {
type P = <T as O>::P;
}
trait O {
type P;
}
impl O for i32 {
type P = String;
}
fn main() {
let _: S<i32>::P = String::new();
}
I expected to see it compile successfully.
Instead, it was rejected with the following error message:
error[E0308]: mismatched types
--> p0.rs:15:24
|
15 | let _: S<i32>::P = String::new();
| --------- ^^^^^^^^^^^^^ expected associated type, found struct `String`
| |
| expected due to this
|
= note: expected associated type `<i32 as O>::P`
found struct `String`
= help: consider constraining the associated type `<i32 as O>::P` to `String` or calling a method that returns `<i32 as O>::P`
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
help: call `Into::into` on this expression to convert `String` into `<i32 as O>::P`
|
15 | let _: S<i32>::P = String::new().into();
| +++++++
Meta
rustc -Vv
:
rustc 1.67.0-nightly (53e4b9dd7 2022-12-04)
binary: rustc
commit-hash: 53e4b9dd74c29cc9308b8d0f10facac70bb101a7
commit-date: 2022-12-04
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4