Skip to content
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

invalid suggestions when the name could not be resolved in derive macro output #133344

Open
nagisa opened this issue Nov 22, 2024 · 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

@nagisa
Copy link
Member

nagisa commented Nov 22, 2024

Code

// cargo new banana
// cd banana
// cargo add [email protected]
// cat src/main.rs

#[derive(rkyv::bytecheck::CheckBytes)]
#[repr(u8)]
enum Fruit { Apple, Banana }

fn main() {
    println!("Hello, world!");
}

Current output

error[E0433]: failed to resolve: could not find `bytecheck` in the list of imported crates
 --> src/main.rs:1:10
  |
1 | #[derive(rkyv::bytecheck::CheckBytes)]
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `bytecheck` in the list of imported crates
  |
  = note: this error originates in the derive macro `rkyv::bytecheck::CheckBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this crate
  |
1 + use rkyv::bytecheck;
  |

error[E0433]: failed to resolve: could not find `bytecheck` in the list of imported crates
 --> src/main.rs:1:10
  |
1 | #[derive(rkyv::bytecheck::CheckBytes)]
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `bytecheck` in the list of imported crates
  |
  = note: this error originates in the derive macro `rkyv::bytecheck::CheckBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing this crate
  |
1 + use rkyv::rancor;
  |

and then after adding use rkyv::bytecheck:

error[E0433]: failed to resolve: could not find `bytecheck` in the list of imported crates
 --> src/main.rs:3:10
  |
3 | #[derive(rkyv::bytecheck::CheckBytes)]
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `bytecheck` in the list of imported crates
  |
  = note: this error originates in the derive macro `rkyv::bytecheck::CheckBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing one of these crates
  |
1 + use crate::bytecheck;
  |
1 + use rkyv::bytecheck;
  |

error[E0433]: failed to resolve: could not find `bytecheck` in the list of imported crates
 --> src/main.rs:3:10
  |
3 | #[derive(rkyv::bytecheck::CheckBytes)]
  |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^ could not find `bytecheck` in the list of imported crates
  |
  = note: this error originates in the derive macro `rkyv::bytecheck::CheckBytes` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider importing one of these crates
  |
1 + use crate::bytecheck::rancor;
  |
1 + use rkyv::rancor;
  |

warning: unused import: `rkyv::bytecheck`
 --> src/main.rs:1:5
  |
1 | use rkyv::bytecheck;
  |     ^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

Desired output

Perhaps in this case use-ing crates should not be suggested. What's even weirder is the compiler suggesting an import of rancor which is unrelated to the error!

Rationale and extra context

It looks like for this derive macro to be usable the crate must be made available as a proper crate (i.e. --extern or extern crate.)

Other cases

Rust Version

rustc 1.81.0 (eeb90cda1 2024-09-04)
binary: rustc
commit-hash: eeb90cda1969383f56a2637cbd3037bdf598841c
commit-date: 2024-09-04
host: x86_64-unknown-linux-gnu
release: 1.81.0
LLVM version: 18.1.7


and


rustc 1.84.0-nightly (b19329a37 2024-11-21)
binary: rustc
commit-hash: b19329a37cedf2027517ae22c87cf201f93d776e
commit-date: 2024-11-21
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.4

Anything else?

No response

@nagisa nagisa 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 Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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