Skip to content

Trait aliases should not bring supertraits into scope #107747

Closed
@eggyal

Description

@eggyal

In-scope trait aliases bring into scope (methods of) the aliased trait and all of its supertraits. I can understand the rationale for bringing (methods of) the aliased trait into scope (namely to fix #56485), but also bringing into scope (methods of) that trait's supertraits is both inconsistent (compared with bringing the aliased trait itself into scope) and surprising:

#![feature(trait_alias)]

use std::fmt;

trait Foo: fmt::Debug {}

// uncommenting the following line brings Debug into scope, which
// in turn causes the (unrelated) Display impl below to become ambiguous

// trait Bar = Foo;

#[derive(Debug)]
struct Qux(bool);

impl fmt::Display for Qux {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        self.0.fmt(f)
    }
}

Playground.

(For the avoidance of doubt, only the methods are brought into scope—not the trait itself: thus, in the above example with the Bar alias uncommented, one cannot use an unqualified Debug).

cc #41517

@rustbot label A-resolve A-traits C-bug F-trait_alias

Metadata

Metadata

Assignees

Labels

A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyA-trait-systemArea: Trait systemC-bugCategory: This is a bug.F-trait_alias`#![feature(trait_alias)]`

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions