-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Avoid path to macro-generated extern crate in error messages #46991
Comments
#[no_std]
crate hijack {
pub use core::option::Option;
}
|
Disregard the above. rustc can certainly emit "phantom" crate paths if there is a "voldemort re-export" of an item from another crate, aka crate foo: #[derive(Default)]
pub struct Type; crate bar: extern crate foo;
pub fn my_fn() -> foo::Type { foo::Type::default(); } crate main: extern crate bar;
let () = bar::my_fn(); //~ ERROR mismatched types
//~| expected `foo::Type`
// ^ this is the case, even if there is no `foo` in the crate `bar` The logic for choosing the path to display a crate from is this: rust/src/librustc/ty/item_path.rs Lines 86 to 124 in 0cd6758
That logic could be smarter:
|
One strategy I can think of for implementing this (I'm not 100% sure it's a good idea in practice, I haven't tried this):
Then you could pass the Afterward, you could allow a If
If it is not, we could have this error:
|
Still seeing the same unhelpful path in 2018 edition as of rustc 1.35.0-nightly (3eb4890 2019-03-19). use serde::Deserialize;
#[derive(Deserialize)]
struct S;
fn main() {
serde_json::to_string(&S);
} error[E0277]: the trait bound `S: _IMPL_DESERIALIZE_FOR_S::_serde::Serialize` is not satisfied
--> src/main.rs:7:5
|
7 | serde_json::to_string(&S);
| ^^^^^^^^^^^^^^^^^^^^^ the trait `_IMPL_DESERIALIZE_FOR_S::_serde::Serialize` is not implemented for `S`
|
= note: required by `serde_json::ser::to_string` |
@dtolnay you could use Fixing this in a general way will be hard to accomplish in the short term. |
Summary: Without this line, Rust error messages involving types from Serde get associated with a somewhat surprising/misleading trait path. This is a compiler bug (rust-lang/rust#46991) but it's easy to work around here. Reviewed By: yfeldblum Differential Revision: D23326186 fbshipit-source-id: 0bb2c3e905a6545dd8abc8f0746c7bce838272c1
The message as of rustc 1.24.0-nightly (c284f88 2017-12-24):
In this case it would be more desirable for the error message to refer to
serde::Serialize
rather than_IMPL_DESERIALIZE_FOR_S::_serde::Serialize
. The extern crate means that the user's Cargo.toml includes theserde
crate under[dependencies]
, so showingserde::Serialize
as the path seems reasonable.I understand that
serde::Serialize
could be ambiguous if the user's crate includesmod serde
at the top level. For now we could ignore that case and showserde::Serialize
anyway, or treat it as a special case and not showserde::Serialize
if they have amod serde
. The special case would go away with rust-lang/rfcs#2126 by showingcrate::serde::Serialize
.Fixing this would be valuable in allowing us to reinstate the lint against unused extern crate by addressing the usability issue reported in #44294.
Mentioning @pnkfelix who worked on #46112.
The text was updated successfully, but these errors were encountered: