Skip to content

Trait bounds are not respected when type aliases are used in struct expressions #36286

Closed
@petrochenkov

Description

@petrochenkov

The following code compiles on stable/beta/nightly:

#![allow(unused)]

struct S<T: Clone> { a: T }

struct NoClone;
// Okay, this is https://github.com/rust-lang/rust/issues/21903
type A = S<NoClone>; 

fn main() {
    // 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
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions