Skip to content

Cannot implement simple trait #15316

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mdias opened this issue Jul 1, 2014 · 3 comments
Closed

Cannot implement simple trait #15316

mdias opened this issue Jul 1, 2014 · 3 comments

Comments

@mdias
Copy link

mdias commented Jul 1, 2014

I've got a simple trait that isn't being implemented somehow, and that compiles fine even though it shouldn't:

MyProject/MyFramework/base.rs

pub trait Base
{
    fn run(&self);
}

MyProject/MyFramework/mod.rs

pub use self::base::Base;

mod base;

MyProject/MyApp/main.rs

#[path="../MyFramework/mod.rs"]
mod myFramework;

struct MyApp;

impl myFramework::Base for MyApp
{
    // notice that there's no implementation for run()
}

fn main()
{
}

This compiles fine even though it shouldn't.
If I put the trait declaration inside the main.rs file, the compiler outputs the proper error, as expected.
Also, if I create an instance of MyApp inside main() and try to call Run() it says the type doesn't have that method, which I believe is because the trait isn't being implemented at all, hence no errors compiling...

I'm sorry if I should be more descriptive, but this is my first time trying rust and I don't know what else is important.

[edit]
I compiled rust from git, revision ff94f86.

@alexcrichton
Copy link
Member

This compiles fine even though it shouldn't.

What makes you think it shouldn't?

Also, if I create an instance of MyApp inside main() and try to call Run() it says the type doesn't have that method

This is actually indicative of the trait needing to be imported, not just referenced (as you did in the impl block)

@mdias
Copy link
Author

mdias commented Jul 2, 2014

What makes you think it shouldn't?

Because MyApp has (supposedly) a pure abstract method.

This is actually indicative of the trait needing to be imported, not just referenced (as you did in the impl block)

If the trait needs to be imported (very weird), the compiler should complain instead of acting like everything's fine and just ignoring the trait implementation...

@alexcrichton
Copy link
Member

Closing as intended behavior. If you'd like to open an issue about improving the error message, please feel free to!

bors added a commit to rust-lang-ci/rust that referenced this issue Jul 24, 2023
Pass `TraitEnvironment` into `layout_ty` and `const_eval`

We need to do either this or get rid of trait environment in `normalize_ty`. Let's go with this for now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants