Skip to content

where_clauses_object_safety warning does not identify the offending line #102546

New issue

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

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

Already on GitHub? # to your account

Open
jruderman opened this issue Oct 1, 2022 · 0 comments
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jruderman
Copy link
Contributor

Given the following code (playground):

trait A {}

trait B {
    fn f(&self)
    where
        Self: A,
    {
    }
}

struct S;

impl B for S {}

fn main() {
    let _p = &S as &dyn B;
}

The current output is:

warning: the trait `B` cannot be made into an object
 --> src/main.rs:4:8
  |
4 |     fn f(&self)
  |        ^
  |
  = note: `#[warn(where_clauses_object_safety)]` on by default
  = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
  = note: for more information, see issue #51443 <https://github.com/rust-lang/rust/issues/51443>
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
 --> src/main.rs:4:8
  |
3 | trait B {
  |       - this trait cannot be made into an object...
4 |     fn f(&self)
  |        ^ ...because method `f` references the `Self` type in its `where` clause
  = help: consider moving `f` to another trait

The first part of the error message should refer to line 16, in main(), where the program tries to make a trait B object. Other 'object safety' errors do this correctly (e.g. if trait B is not object-safe because one of its methods has Self in return position).

S: #51443

@jruderman jruderman added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 1, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

1 participant