You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code compiles on stable/beta/nightly:
#![allow(unused)]structS<T:Clone>{a:T}structNoClone;// Okay, this is https://github.com/rust-lang/rust/issues/21903typeA = S<NoClone>;fnmain(){// But this is something new.// I'd expect an error "the trait bound `NoClone: std::clone::Clone` is not satisfied", but nothing is reported.let s = A{a:NoClone};// The error is properly reported when type alias is not used.// let s = S { a: NoClone }; // ERROR: the trait bound `NoClone: std::clone::Clone` is not satisfied}
The text was updated successfully, but these errors were encountered:
Support `Self` in struct expressions and patterns
Struct expressions and patterns generally support type aliases `Alias { field: 10 }` i.e. they already have to work with `ty::Ty` to do their job. `Self` is a type alias (when it's not a type parameter) => struct expressions and patterns should support `Self`.
Typical example:
```
impl MyStruct {
fn new() -> Self {
Self { a: 10, b: "Hello" }
}
}
```
The first commit does some preparations and cleanups, see the commit message for details.
This also fixes couple of bugs related to aliases in struct paths (fixes#36286).
EDIT:
Since struct expressions and patterns always work with `ty::Ty` now, associated paths in them are also supported. If associated type `A::B` successfully resolves to a struct (or union) type, then `A::B { /* fields */ }` is a valid expression/pattern. This will become more important when enum variants are treated as [associated items](#26264 (comment)).
r? @eddyb
The following code compiles on stable/beta/nightly:
The text was updated successfully, but these errors were encountered: