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

rustc could provide more help for debugging no_std duplicate_lang item errors #60561

Closed
brenzi opened this issue May 5, 2019 · 1 comment · Fixed by #64883
Closed

rustc could provide more help for debugging no_std duplicate_lang item errors #60561

brenzi opened this issue May 5, 2019 · 1 comment · Fixed by #64883
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-lang-item Area: lang items C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@brenzi
Copy link

brenzi commented May 5, 2019

I'm currently porting crates to support no_std to use them with https://github.com/baidu/rust-sgx-sdk

The Problem:
any sub-dependency can break no_std, resulting in an error like this:

error: duplicate lang item in crate `std`: `f32_runtime`.
  |
  = note: first defined in crate `sgx_tstd`.

error: duplicate lang item in crate `std`: `f64_runtime`.
  |
  = note: first defined in crate `sgx_tstd`.

error: duplicate lang item in crate `std`: `panic_impl`.
  |
  = note: first defined in crate `sgx_tstd`.

error: duplicate lang item in crate `std`: `oom`.
  |
  = note: first defined in crate `sgx_trts`.

The compiler doesn't give me any hint, which (sub)dependency causes this issue. Like this it is very annoying and time-consuming to sort out such errors.

Would it be possible that rustc gives us a hint to colliding crates?

Maybe something like https://github.com/sfackler/cargo-tree could help visualizing no_std crates automatically?

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 5, 2019
@varkor varkor added the A-lang-item Area: lang items label May 8, 2019
@BaoshanPang
Copy link
Contributor

I am seeing this problem too, it is really painful to figure out what's the problem.

Centril added a commit to Centril/rust that referenced this issue 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 issue 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 closed this as completed in ac9aed5 Sep 29, 2019
andjo403 pushed a commit to andjo403/rust that referenced this issue Oct 4, 2019
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.
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-lang-item Area: lang items C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants