Skip to content

Bringing a trait alias into scope doesn't allow calling methods from its component traits #56485

Closed
@Nemo157

Description

@Nemo157
#![feature(trait_alias)]

mod some_module {
    pub trait Foo {
        fn foo(&self);
    }
    
    pub struct Qux;
    
    impl Foo for Qux {
        fn foo(&self) {}
    }
    
    pub trait Bar = Foo;
}

use some_module::{Bar, Qux};

fn use_baz(object: Qux) {
    // Should this work because Bar is in scope?
    object.foo();
}

(playground) currently produces an error:

error[E0599]: no method named `foo` found for type `some_module::Qux` in the current scope
  --> src/lib.rs:21:12
   |
8  |     pub struct Qux;
   |     --------------- method `foo` not found for this
...
21 |     object.foo();
   |            ^^^
   |
   = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope, perhaps add a `use` for it:
   |
17 | use some_module::Foo;
   |

cc #41517

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-resolveArea: Name/path resolution done by `rustc_resolve` specificallyA-trait-systemArea: Trait systemI-needs-decisionIssue: In need of a decision.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions