-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Improve unresolved use error message #75984
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
10ec91c
to
9e6ff20
Compare
WDYT? if ident.name.with(|n| n.chars().next().map_or(false, |c| c.is_ascii_uppercase())) {
(format!("use of undeclared type `{}`", ident), None)
} else {
(format!("use of undeclared crate or module `{}`", ident), None)
} |
9e6ff20
to
02f95ac
Compare
That might not work well with It seems like the new sample for E0433 is giving an E0432:
You probably want to use some long-ish unlikely to ever exist crate name. |
76394cf
to
7ccf922
Compare
@estebank since that didn't sound like an objection to the principle, I've included the heuristic. |
☔ The latest upstream changes (presumably #74862) made this pull request unmergeable. Please resolve the merge conflicts. |
815c194
to
a0a0ef4
Compare
a0a0ef4
to
7ec1de0
Compare
There's something odd with the build checking whether expected error happens in error documentation: CI check sees this:
Rust playground sees this:
The difference is due to the check: rust/compiler/rustc_resolve/src/lib.rs Line 2383 in 7ec1de0
where the graph_root is documented as "// For rustdoc.". I don't know what that's supposed to be. The playground consistently shows a different error than Rust's CI, in all of: bin crate, lib crate, regular rustdoc comment, and compile_fail test. For now I've relaxed the documentation compile_fail check. The docs reflect what Rust does outside the CI environment, because that's the version that is relevant to users. |
@bors r+ |
📌 Commit 7ec1de0 has been approved by |
Rollup of 14 pull requests Successful merges: - rust-lang#75094 (Add `-Z combine_cgu` flag) - rust-lang#75984 (Improve unresolved use error message) - rust-lang#76141 (Address review comments about config.toml from rustc-dev-guide PR) - rust-lang#76313 (Improved the MIR spanview output) - rust-lang#76430 (Add align to rustc-attrs unstable book) - rust-lang#76465 (Add a script to automatically update Rust/Clang versions in documentation) - rust-lang#76473 (Add missed spaces to GCC-WARNING.txt) - rust-lang#76481 (Convert repetitive target_pointer_width checks to const solution.) - rust-lang#76493 (Remove a stray ignore-tidy-undocumented-unsafe) - rust-lang#76504 (Capitalize safety comments) - rust-lang#76515 (SessionDiagnostic: Fix non-determinism in generated format string.) - rust-lang#76516 (Enable GitHub Releases synchronization) - rust-lang#76522 (remove redundant clones) - rust-lang#76523 (Remove unused PlaceContext::NonUse(NonUseContext::Coverage)) Failed merges: r? `@ghost`
"use of undeclared type or module
foo
" doesn't mention that it could be a crate.This error can happen when users forget to add a dependency to
Cargo.toml
, so I think it's important to mention that it could be a missing crate.I've used a heuristic based on Rust's naming conventions. It complains about an unknown type if the ident starts with an upper-case letter, and crate or module otherwise. It seems to work very well. The expanded error help covers both an unknown type and a missing crate case.