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

Improve unknown external crate error #81046

Merged
merged 2 commits into from
Jan 21, 2021

Conversation

rylev
Copy link
Member

@rylev rylev commented Jan 15, 2021

This improves error messages when unknown items in the crate root are encountered.

Fixes #63799

r? @estebank

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 15, 2021
@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
configure: rust.channel         := nightly
configure: rust.debug-assertions := True
configure: llvm.assertions      := True
configure: dist.missing-tools   := True
configure: build.configure-args := ['--enable-sccache', '--disable-manage-submodu ...
configure: writing `config.toml` in current directory
configure: 
configure: run `python /checkout/x.py --help`
configure: 
---
skip untracked path src/llvm-project/ during rustfmt invocations
Diff in /checkout/compiler/rustc_resolve/src/lib.rs at line 2459:
                         }
                     } else {
                         let parent = path[i - 1].ident.name;
-                        let parent =
-                            if parent == kw::PathRoot { "crate root".to_owned() } else { format!("`{}`", parent) };
+                        let parent = if parent == kw::PathRoot {
+                            "crate root".to_owned()
+                        } else {
+                            format!("`{}`", parent)
 
 
                         let mut msg = format!("could not find `{}` in {}", ident, parent);
Running `"/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/rustfmt" "--config-path" "/checkout" "--edition" "2018" "--unstable-features" "--skip-children" "--check" "/checkout/compiler/rustc_resolve/src/lib.rs"` failed.
If you're running `tidy`, try again with `--bless`. Or, if you just want to format code, run `./x.py fmt` instead.
                         if ns == TypeNS || ns == ValueNS {
Build completed unsuccessfully in 0:00:15

@rylev rylev force-pushed the unknown-external-crate branch from 28d9ee4 to d51df05 Compare January 15, 2021 17:23
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-9 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

---- [ui] ui/issues/issue-71406.rs stdout ----
diff of stderr:

- error[E0433]: failed to resolve: expected type, found function `channel` in `mpsc`
+ error[E0433]: failed to resolve: expected type, found function `channel` in ``mpsc``
3    |
3    |
4 LL |     let (tx, rx) = mpsc::channel::new(1);

-    |                          ^^^^^^^ expected type, found function `channel` in `mpsc`
+    |                          ^^^^^^^ expected type, found function `channel` in ``mpsc``
7 error: aborting due to previous error
8 



The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/issues/issue-71406/issue-71406.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args issues/issue-71406.rs`
error: 1 errors occurred comparing output.
status: exit code: 1
status: exit code: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/issues/issue-71406.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zemit-future-incompat-report" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/issues/issue-71406" "-A" "unused" "-Crpath" "-O" "-Cdebuginfo=0" "-Zunstable-options" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/issues/issue-71406/auxiliary"
------------------------------------------

------------------------------------------
stderr:
stderr:
------------------------------------------
error[E0433]: failed to resolve: expected type, found function `channel` in ``mpsc``
   |
   |
LL |     let (tx, rx) = mpsc::channel::new(1);
   |                          ^^^^^^^ expected type, found function `channel` in ``mpsc``
error: aborting due to previous error

For more information about this error, try `rustc --explain E0433`.

---

Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu


command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/ui" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--suite" "ui" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-9/bin/FileCheck" "--nodejs" "/usr/bin/node" "--host-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--target-rustcflags" "-Crpath -O -Cdebuginfo=0 -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python3" "--lldb-python" "/usr/bin/python3" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "9.0.0" "--llvm-components" "aarch64 aarch64asmparser aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils aggressiveinstcombine all all-targets amdgpu amdgpuasmparser amdgpucodegen amdgpudesc amdgpudisassembler amdgpuinfo amdgpuutils analysis arm armasmparser armcodegen armdesc armdisassembler arminfo armutils asmparser asmprinter avr avrasmparser avrcodegen avrdesc avrdisassembler avrinfo binaryformat bitreader bitstreamreader bitwriter bpf bpfasmparser bpfcodegen bpfdesc bpfdisassembler bpfinfo codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfogsym debuginfomsf debuginfopdb demangle dlltooldriver engine executionengine fuzzmutate globalisel hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo instcombine instrumentation interpreter ipo irreader jitlink lanai lanaiasmparser lanaicodegen lanaidesc lanaidisassembler lanaiinfo libdriver lineeditor linker lto mc mca mcdisassembler mcjit mcparser mips mipsasmparser mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmparser msp430codegen msp430desc msp430disassembler msp430info native nativecodegen nvptx nvptxcodegen nvptxdesc nvptxinfo objcarcopts object objectyaml option orcjit passes perfjitevents powerpc powerpcasmparser powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata remarks riscv riscvasmparser riscvcodegen riscvdesc riscvdisassembler riscvinfo riscvutils runtimedyld scalaropts selectiondag sparc sparcasmparser sparccodegen sparcdesc sparcdisassembler sparcinfo support symbolize systemz systemzasmparser systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target textapi transformutils vectorize webassembly webassemblyasmparser webassemblycodegen webassemblydesc webassemblydisassembler webassemblyinfo windowsmanifest x86 x86asmparser x86codegen x86desc x86disassembler x86info x86utils xcore xcorecodegen xcoredesc xcoredisassembler xcoreinfo xray" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"


failed to run: /checkout/obj/build/bootstrap/debug/bootstrap --stage 2 test --exclude src/tools/tidy
Build completed unsuccessfully in 0:17:48

Comment on lines +2462 to +2466
let parent = if parent == kw::PathRoot {
"crate root".to_owned()
} else {
format!("`{}`", parent)
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than special casing this here, does it make sense to change in impl Display for Symbol instead? Then you don't have to worry about missing it somewhere (and everyone else using this benefits as well).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is certainly a possibility. I didn't do this because I was unsure of the ramifications of renaming the symbol's string representation (particularly around json serialization/deserialization). The change I made seems to be the central place for diagnostics around path resolution (i.e., there are not UI tests that still reference {{root}}).

compiler/rustc_resolve/src/lib.rs Show resolved Hide resolved
@jyn514 jyn514 added A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name resolution T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 15, 2021
format!("could not find `{}` in `{}`", ident, path[i - 1].ident);
let parent = path[i - 1].ident.name;
let parent = if parent == kw::PathRoot {
"crate root".to_owned()
Copy link
Contributor

@estebank estebank Jan 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it be root crate instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, the path root is normally referred to as the crate root as you can see here. root crate makes it sound like this refers to a crate itself but it does not, it's the root of the namespace hierarchy.

@rylev rylev force-pushed the unknown-external-crate branch from d51df05 to d829e40 Compare January 18, 2021 11:05
@estebank
Copy link
Contributor

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jan 19, 2021

📌 Commit 38b7742 has been approved by estebank

@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 Jan 19, 2021
m-ou-se added a commit to m-ou-se/rust that referenced this pull request Jan 20, 2021
…ebank

Improve unknown external crate error

This improves error messages when unknown items in the crate root are encountered.

Fixes rust-lang#63799

r? `@estebank`
m-ou-se added a commit to m-ou-se/rust that referenced this pull request Jan 20, 2021
…ebank

Improve unknown external crate error

This improves error messages when unknown items in the crate root are encountered.

Fixes rust-lang#63799

r? ``@estebank``
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 21, 2021
Rollup of 11 pull requests

Successful merges:

 - rust-lang#79655 (Add Vec visualization to understand capacity)
 - rust-lang#80172 (Use consistent punctuation for 'Prelude contents' docs)
 - rust-lang#80429 (Add regression test for mutual recursion in obligation forest)
 - rust-lang#80601 (Improve grammar in documentation of format strings)
 - rust-lang#81046 (Improve unknown external crate error)
 - rust-lang#81178 (Visit only terminators when removing landing pads)
 - rust-lang#81179 (Fix broken links with `--document-private-items` in the standard library)
 - rust-lang#81184 (Remove unnecessary `after_run` function)
 - rust-lang#81185 (Fix ICE in mir when evaluating SizeOf on unsized type)
 - rust-lang#81187 (Fix typo in counters.rs)
 - rust-lang#81219 (Document security implications of std::env::temp_dir)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a77c1d8 into rust-lang:master Jan 21, 2021
@rustbot rustbot added this to the 1.51.0 milestone Jan 21, 2021
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 resolution 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.

Confusing E0425 error when referencing undefined name with ::foo
7 participants