Skip to content

Invalid suggest for methods in auto trait #105788

Closed
@chenyukang

Description

@chenyukang

Given the following code

#![feature(auto_traits)]

auto trait Foo {
    fn g(&self);
}

trait Bar  {
    fn f(&self) {
        self.g();
    }
}

fn main() {}

The current output is:

error[E0380]: auto traits cannot have associated items
 --> src/main.rs:4:8
  |
3 | auto trait Foo {
  |            --- auto trait cannot have associated items
4 |     fn g(&self);
  |     ---^-------- help: remove these associated items

error[E0554]: `#![feature]` may not be used on the stable release channel
 --> src/main.rs:1:1
  |
1 | #![feature(auto_traits)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^

error[E0599]: the method `g` exists for reference `&Self`, but its trait bounds were not satisfied
 --> src/main.rs:9:14
  |
9 |         self.g();
  |              ^
  |
note: trait bound `&Self: Foo` was not satisfied
  = note: the following trait bounds were not satisfied:
          `Self: Foo`
          which is required by `&Self: Foo`
  = help: items from traits can only be used if the type parameter is bounded by the trait
help: the following trait defines an item `g`, perhaps you need to add a supertrait for it:
  |
7 | trait Bar: Foo  {
  |          +++++

Some errors have detailed explanations: E0380, E0554, E0599.
For more information about an error, try `rustc --explain E0380`.
error: could not compile `playground` due to 3 previous errors

The second error is not reasonable, since we don't allow associated items in auto trait.
Ideally the output should look like:

error[E0599]: no method named `g` found for reference `&Self` in the current scope
 --> ./p/e.rs:9:14
  |
9 |         self.g();
  |

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsF-auto_traits`#![feature(auto_traits)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions