Stream: t-compiler/wg-diagnostics

Topic: bad note for non-object-safe method in another module


Jake Goulding (Jun 04 2019 at 17:50, on Zulip):
pub trait Example {
    fn query<Q>(self, q: Q);
}

impl Example for i32 {
    fn query<Q>(self, _: Q) {
        unimplemented!()
    }
}

mod nested {
    use super::Example;
    fn example() {
        1.query::<ToString>("")
    }
}
error: the `query` method cannot be invoked on a trait object
  --> src/lib.rs:14:11
   |
14 |         1.query::<ToString>("")
   |           ^^^^^
   |
   = note: another candidate was found in the following trait, perhaps add a `use` for it:
           `use crate::Example;`

The error message is good, but the note is not — that's the trait we are already using.

Jake Goulding (Jun 04 2019 at 17:51, on Zulip):

@Esteban Küber should I file this?

Jake Goulding (Jun 04 2019 at 17:52, on Zulip):

Actually, is the error correct? 1 isn't a trait object.

Esteban Küber (Jun 04 2019 at 17:56, on Zulip):

I think that the _error_ might be correct, in that rustc correctly complains, but the exposed message is incorrect

Esteban Küber (Jun 04 2019 at 17:56, on Zulip):

go ahead and file

Esteban Küber (Jun 04 2019 at 17:56, on Zulip):

we either have to make this compile _or_ handle the case in the emitted diagnostic

Esteban Küber (Jun 04 2019 at 17:58, on Zulip):

@Jake Goulding just realized the problem. It's not that i32 is a trait object, is that ToString is.
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=091474ba4cbe4a91a5f731427e31dbc4

Esteban Küber (Jun 04 2019 at 17:59, on Zulip):

So yes, the error is "correct", but we need to differentiate the problem originating from self and from type arguments

Jake Goulding (Jun 04 2019 at 18:10, on Zulip):

@Esteban Küber Should I file as two things? One for the note and one for distinguishing?

Esteban Küber (Jun 04 2019 at 18:32, on Zulip):

Na, just one ticket should be fine

Jake Goulding (Jun 04 2019 at 18:47, on Zulip):

https://github.com/rust-lang/rust/issues/61525

Thanks!

Last update: Nov 15 2019 at 09:40UTC