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

added more context for duplicate lang item errors (fixes #60561) #64678

Merged
merged 1 commit into from
Sep 29, 2019

Conversation

tomtau
Copy link
Contributor

@tomtau tomtau commented Sep 22, 2019

Some more information about #60561 -- these errors are pretty common when one works in restrictive environments with no_std or customized std, but they don't provide much context for debugging, as any transitive dependency could have brought in std crate. With that, currently, one needs to use something like cargo tree and investigate transitive dependencies one by one.

It'll be more helpful to know at least the crate that uses std (which cargo tree doesn't show) to pin down this investigation when debugging.

I'm not sure what the best way to get this context is inside rustc internals (I'm new to them). I found that all_crate_nums query returns the crates in some dependency order, so printing out the name of the preceding crate seems to do the trick. But I welcome suggestions if this can be done in a better way.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @matthewjasper (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 22, 2019
@matthewjasper
Copy link
Contributor

CrateNums are assigned in load order, so while crates are after the crate that first depends on them, there's no guarantee that a crate is depended on by the previous crate.

Changing direct here to be the CrateNum of the crate that depends on this crate, and then accessing it via the extern_crate query seems like the easiest way to get an accurate dependency graph.

pub direct: bool,

@tomtau
Copy link
Contributor Author

tomtau commented Sep 26, 2019

@matthewjasper thanks a lot! I tried to preserve what direct was doing before, so I changed its type to Option<CrateNum>: df72c45

Copy link
Contributor

@matthewjasper matthewjasper left a comment

Choose a reason for hiding this comment

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

Can you squash your commits?

src/librustc/middle/cstore.rs Outdated Show resolved Hide resolved
@tomtau tomtau force-pushed the fix/no-std-error branch 2 times, most recently from 4af63be to acf8053 Compare September 27, 2019 13:41
@tomtau
Copy link
Contributor Author

tomtau commented Sep 27, 2019

@matthewjasper I squashed the commits.

@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-6.0 of your PR failed (pretty log, raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
2019-09-27T13:41:56.4376100Z ##[command]git remote add origin https://github.com/rust-lang/rust
2019-09-27T13:41:56.4600836Z ##[command]git config gc.auto 0
2019-09-27T13:41:56.4666118Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-09-27T13:41:56.4716458Z ##[command]git config --get-all http.proxy
2019-09-27T13:41:57.1552969Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin +refs/heads/*:refs/remotes/origin/* +refs/pull/64678/merge:refs/remotes/pull/64678/merge
---
2019-09-27T14:38:59.7840595Z .................................................................................................... 1500/9046
2019-09-27T14:39:05.1507249Z .................................................................................................... 1600/9046
2019-09-27T14:39:16.6546947Z .........................................................................i...............i.......... 1700/9046
2019-09-27T14:39:22.8108079Z .................................................................................................... 1800/9046
2019-09-27T14:39:30.3224050Z ................................................................iiiii............................... 1900/9046
2019-09-27T14:39:48.0472160Z .................................................................................................... 2100/9046
2019-09-27T14:39:50.1887258Z .................................................................................................... 2200/9046
2019-09-27T14:39:53.0547110Z .................................................................................................... 2300/9046
2019-09-27T14:40:00.5574653Z .................................................................................................... 2400/9046
---
2019-09-27T14:42:40.4372780Z ....................................................i...............i............................... 4700/9046
2019-09-27T14:42:48.7630217Z .................................................................................................... 4800/9046
2019-09-27T14:42:56.3446587Z .................................................................................................... 4900/9046
2019-09-27T14:43:03.0566922Z .................................................................................................... 5000/9046
2019-09-27T14:43:11.6239736Z ........................................ii.ii....................................................... 5100/9046
2019-09-27T14:43:20.4331840Z .................................................................................................... 5300/9046
2019-09-27T14:43:29.8978807Z .................................................................................................... 5400/9046
2019-09-27T14:43:36.7012499Z .....i.............................................................................................. 5500/9046
2019-09-27T14:43:41.3162913Z .................................................................................................... 5600/9046
2019-09-27T14:43:41.3162913Z .................................................................................................... 5600/9046
2019-09-27T14:43:52.1387625Z .................................................................................................... 5700/9046
2019-09-27T14:44:03.8692633Z ii...i..ii...........i.............................................................................. 5800/9046
2019-09-27T14:44:22.8484848Z .................................................................................................... 6000/9046
2019-09-27T14:44:28.3338627Z .................................................................................................... 6100/9046
2019-09-27T14:44:28.3338627Z .................................................................................................... 6100/9046
2019-09-27T14:44:40.7745376Z ...i..ii............................................................................................ 6200/9046
2019-09-27T14:44:49.3838639Z .................................................................................................F.. 6300/9046
2019-09-27T14:44:59.3607434Z .................................................................................................... 6500/9046
2019-09-27T14:45:01.5324690Z ...................................i................................................................ 6600/9046
2019-09-27T14:45:05.1314974Z .................................................................................................... 6700/9046
2019-09-27T14:45:18.2467829Z .................................................................................................... 6800/9046
---
2019-09-27T14:48:41.2381561Z 
2019-09-27T14:48:41.2381673Z 7 LL | | }
2019-09-27T14:48:41.2381803Z 8    | |_^
2019-09-27T14:48:41.2381912Z 9    |
2019-09-27T14:48:41.2382239Z -    = note: first defined in crate `std`.
2019-09-27T14:48:41.2382399Z +    = note: first defined in crate `std` (which `duplicate_entry_error` depends on).
2019-09-27T14:48:41.2382676Z 12 error: aborting due to previous error
2019-09-27T14:48:41.2382791Z 13 
2019-09-27T14:48:41.2382886Z 
2019-09-27T14:48:41.2382980Z 
2019-09-27T14:48:41.2382980Z 
2019-09-27T14:48:41.2383114Z The actual stderr differed from the expected stderr.
2019-09-27T14:48:41.2383484Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/duplicate_entry_error/duplicate_entry_error.stderr
2019-09-27T14:48:41.2383864Z To update references, rerun the tests and pass the `--bless` flag
2019-09-27T14:48:41.2384219Z To only update this specific test, also pass `--test-args duplicate_entry_error.rs`
2019-09-27T14:48:41.2384501Z error: 1 errors occurred comparing output.
2019-09-27T14:48:41.2384614Z status: exit code: 1
2019-09-27T14:48:41.2384614Z status: exit code: 1
2019-09-27T14:48:41.2385293Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/duplicate_entry_error.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/duplicate_entry_error" "-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/duplicate_entry_error/auxiliary" "-A" "unused"
2019-09-27T14:48:41.2385987Z ------------------------------------------
2019-09-27T14:48:41.2386298Z 
2019-09-27T14:48:41.2387368Z ------------------------------------------
2019-09-27T14:48:41.2387600Z stderr:
2019-09-27T14:48:41.2387600Z stderr:
2019-09-27T14:48:41.2387973Z ------------------------------------------
2019-09-27T14:48:41.2388162Z error[E0152]: duplicate lang item found: `panic_impl`.
2019-09-27T14:48:41.2388737Z    |
2019-09-27T14:48:41.2388737Z    |
2019-09-27T14:48:41.2389096Z LL | / fn panic_impl(info: &PanicInfo) -> ! {
2019-09-27T14:48:41.2389304Z LL | | //~^ ERROR: duplicate lang item found: `panic_impl`.
2019-09-27T14:48:41.2389472Z LL | |     loop {}
2019-09-27T14:48:41.2389767Z    | |_^
2019-09-27T14:48:41.2389903Z    |
2019-09-27T14:48:41.2389903Z    |
2019-09-27T14:48:41.2390217Z    = note: first defined in crate `std` (which `duplicate_entry_error` depends on).
2019-09-27T14:48:41.2390452Z error: aborting due to previous error
2019-09-27T14:48:41.2390545Z 
2019-09-27T14:48:41.2390869Z For more information about this error, try `rustc --explain E0152`.
2019-09-27T14:48:41.2391003Z 
---
2019-09-27T14:48:41.2392547Z 
2019-09-27T14:48:41.2392654Z 6 LL | | }
2019-09-27T14:48:41.2392928Z 7    | |_^
2019-09-27T14:48:41.2393050Z 8    |
2019-09-27T14:48:41.2393321Z -    = note: first defined in crate `std`.
2019-09-27T14:48:41.2393639Z +    = note: first defined in crate `std` (which `panic_handler_std` depends on).
2019-09-27T14:48:41.2393882Z 11 error: argument should be `&PanicInfo`
2019-09-27T14:48:41.2394181Z 12   --> $DIR/panic-handler-std.rs:7:16
2019-09-27T14:48:41.2395372Z 
2019-09-27T14:48:41.2395410Z 
2019-09-27T14:48:41.2395410Z 
2019-09-27T14:48:41.2395448Z The actual stderr differed from the expected stderr.
2019-09-27T14:48:41.2395879Z Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/panic-handler/panic-handler-std/panic-handler-std.stderr
2019-09-27T14:48:41.2396291Z To update references, rerun the tests and pass the `--bless` flag
2019-09-27T14:48:41.2396961Z To only update this specific test, also pass `--test-args panic-handler/panic-handler-std.rs`
2019-09-27T14:48:41.2397067Z error: 1 errors occurred comparing output.
2019-09-27T14:48:41.2397113Z status: exit code: 1
2019-09-27T14:48:41.2397113Z status: exit code: 1
2019-09-27T14:48:41.2397892Z command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/panic-handler/panic-handler-std.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "-Zui-testing" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/panic-handler/panic-handler-std" "-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/panic-handler/panic-handler-std/auxiliary" "-A" "unused"
2019-09-27T14:48:41.2398238Z ------------------------------------------
2019-09-27T14:48:41.2398271Z 
2019-09-27T14:48:41.2398484Z ------------------------------------------
2019-09-27T14:48:41.2398547Z stderr:
2019-09-27T14:48:41.2398547Z stderr:
2019-09-27T14:48:41.2398756Z ------------------------------------------
2019-09-27T14:48:41.2398807Z error[E0152]: duplicate lang item found: `panic_impl`.
2019-09-27T14:48:41.2399128Z    |
2019-09-27T14:48:41.2399128Z    |
2019-09-27T14:48:41.2399349Z LL | / fn panic(info: PanicInfo) -> ! {
2019-09-27T14:48:41.2399396Z LL | |     loop {}
2019-09-27T14:48:41.2399496Z    | |_^
2019-09-27T14:48:41.2399536Z    |
2019-09-27T14:48:41.2399536Z    |
2019-09-27T14:48:41.2399604Z    = note: first defined in crate `std` (which `panic_handler_std` depends on).
2019-09-27T14:48:41.2399682Z error: argument should be `&PanicInfo`
2019-09-27T14:48:41.2400095Z   --> /checkout/src/test/ui/panic-handler/panic-handler-std.rs:7:16
2019-09-27T14:48:41.2400150Z    |
2019-09-27T14:48:41.2400150Z    |
2019-09-27T14:48:41.2400316Z LL | fn panic(info: PanicInfo) -> ! {
2019-09-27T14:48:41.2400376Z 
2019-09-27T14:48:41.2400426Z error: aborting due to 2 previous errors
2019-09-27T14:48:41.2400448Z 
2019-09-27T14:48:41.2400631Z For more information about this error, try `rustc --explain E0152`.
---
2019-09-27T14:48:41.2413873Z thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:537:22
2019-09-27T14:48:41.2413960Z note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
2019-09-27T14:48:41.2430899Z 
2019-09-27T14:48:41.2430996Z 
2019-09-27T14:48:41.2432845Z 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" "--mode" "ui" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-6.0/bin/FileCheck" "--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/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "6.0.0\n" "--system-llvm" "--cc" "" "--cxx" "" "--cflags" "" "--llvm-components" "" "--llvm-cxxflags" "" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
2019-09-27T14:48:41.2433147Z 
2019-09-27T14:48:41.2433171Z 
2019-09-27T14:48:41.2440482Z failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
2019-09-27T14:48:41.2440721Z Build completed unsuccessfully in 0:59:55
2019-09-27T14:48:41.2440721Z Build completed unsuccessfully in 0:59:55
2019-09-27T14:48:41.2484300Z == clock drift check ==
2019-09-27T14:48:41.2501321Z   local time: Fri Sep 27 14:48:41 UTC 2019
2019-09-27T14:48:41.3613672Z   network time: Fri, 27 Sep 2019 14:48:41 GMT
2019-09-27T14:48:41.3618156Z == end clock drift check ==
2019-09-27T14:48:42.9095458Z ##[error]Bash exited with code '1'.
2019-09-27T14:48:42.9135158Z ##[section]Starting: Checkout
2019-09-27T14:48:42.9137508Z ==============================================================================
2019-09-27T14:48:42.9137584Z Task         : Get sources
2019-09-27T14:48:42.9137631Z Description  : Get sources from a repository. Supports Git, TfsVC, and SVN repositories.

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

Where possible, the error message includes the name of the crate
that brought in the crate with duplicate lang items (which
helps with debugging). This information is passed on from cstore
using the `extern_crate` query.
@matthewjasper
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Sep 28, 2019

📌 Commit ac9aed5 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 28, 2019
Centril added a commit to Centril/rust that referenced this pull request Sep 28, 2019
…asper

added more context for duplicate lang item errors (fixes rust-lang#60561)

Some more information about rust-lang#60561 -- these errors are pretty common when one works in restrictive environments with `no_std` or customized `std`, but they don't provide much context for debugging, as any transitive dependency could have brought in `std` crate. With that, currently, one needs to use something like `cargo tree` and investigate transitive dependencies one by one.

It'll be more helpful to know at least the crate that uses `std` (which `cargo tree` doesn't show) to pin down this investigation when debugging.

I'm not sure what the best way to get this context is inside rustc internals (I'm new to them). I found that `all_crate_nums` query returns the crates in some dependency order, so printing out the name of the preceding crate seems to do the trick. But I welcome suggestions if this can be done in a better way.
bors added a commit that referenced this pull request Sep 28, 2019
Rollup of 10 pull requests

Successful merges:

 - #64131 (data_structures: Add deterministic FxHashMap and FxHashSet wrappers)
 - #64387 (Fix redundant semicolon lint interaction with proc macro attributes)
 - #64678 (added more context for duplicate lang item errors (fixes #60561))
 - #64763 (Add E0734 and its long explanation)
 - #64793 (Fix format macro expansions spans to be macro-generated)
 - #64837 (Improve wording in documentation of MaybeUninit)
 - #64852 (Print ParamTy span when accessing a field (#52082))
 - #64875 (Upgrade async/await to "used" keywords.)
 - #64876 (Fix typo in intrinsics op safety)
 - #64880 (Slice docs: fix typo)

Failed merges:

r? @ghost
@bors bors merged commit ac9aed5 into rust-lang:master Sep 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants