Skip to content

Conversation

kornelski
Copy link
Contributor

@kornelski kornelski commented Aug 27, 2020

"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.

@rust-highfive
Copy link
Contributor

r? @matthewjasper

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 27, 2020
@kornelski
Copy link
Contributor Author

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)
}

@estebank
Copy link
Contributor

WDYT?

That might not work well with unicode_identifiers when it is stabilized, but that can be a problem for "future us". This logic would be in the "happy path", right? Looking at the code it seems we would only hit this in the case of Err(Determined) which I would expect (but don't know for sure) would an "always emit an error path".

It seems like the new sample for E0433 is giving an E0432:

failures:

---- /checkout/obj/build/x86_64-unknown-linux-gnu/test/error-index.md - Rust_Compiler_Error_Index::E0433 (line 7746) stdout ----
error[E0432]: unresolved import `rand`
 --> /checkout/obj/build/x86_64-unknown-linux-gnu/test/error-index.md:7747:5
  |
3 | use rand::Rng;
  |     ^^^^ maybe a missing crate `rand`?

error: aborting due to previous error

For more information about this error, try `rustc --explain E0432`.
Some expected error codes were not found: ["E0433"]

failures:
    /checkout/obj/build/x86_64-unknown-linux-gnu/test/error-index.md - Rust_Compiler_Error_Index::E0433 (line 7746)

You probably want to use some long-ish unlikely to ever exist crate name.

@kornelski kornelski force-pushed the typeormodule branch 3 times, most recently from 76394cf to 7ccf922 Compare August 28, 2020 11:33
@kornelski
Copy link
Contributor Author

@estebank since that didn't sound like an objection to the principle, I've included the heuristic.

@bors
Copy link
Collaborator

bors commented Aug 30, 2020

☔ The latest upstream changes (presumably #74862) made this pull request unmergeable. Please resolve the merge conflicts.

@kornelski kornelski force-pushed the typeormodule branch 2 times, most recently from 815c194 to a0a0ef4 Compare September 1, 2020 16:47
@kornelski
Copy link
Contributor Author

kornelski commented Sep 1, 2020

There's something odd with the build checking whether expected error happens in error documentation:

CI check sees this:

use ferris_wheel::BigO;
  |     ^^^^^^^^^^^^ maybe a missing crate `ferris_wheel`?

Rust playground sees this:

use ferris_wheel::BigO;
  |     ^^^^^^^^^^^^ use of undeclared type or module `ferris_wheel`

The difference is due to the check:

let (label, suggestion) = if module_res == self.graph_root.res() {

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.

@jyn514 jyn514 added A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 3, 2020
@matthewjasper
Copy link
Contributor

@bors r+

@bors
Copy link
Collaborator

bors commented Sep 9, 2020

📌 Commit 7ec1de0 has been approved by matthewjasper

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 9, 2020
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 9, 2020
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`
@bors bors merged commit 5ea5551 into rust-lang:master Sep 10, 2020
@rustbot rustbot added this to the 1.48.0 milestone Sep 10, 2020
@kornelski kornelski deleted the typeormodule branch September 10, 2020 14:03
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 A-resolve Area: Name/path resolution done by `rustc_resolve` specifically S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants