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 doesn't complain if extern rlib is missing #68417

Closed
andir opened this issue Jan 21, 2020 · 4 comments
Closed

rustc doesn't complain if extern rlib is missing #68417

andir opened this issue Jan 21, 2020 · 4 comments
Labels
A-frontend Area: frontend (errors, parsing and HIR) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@andir
Copy link

andir commented Jan 21, 2020

I just came across a weird case where rustc would not warn that a given extern dependency could not be found. I believe it should just warn the user or throw an error in that case instead of silently ignoring the error. It seems like the dependencies are only checked on a per-use basis whereas I believe being more strict here would probably not harm and help users find issues earlier.

Reproducer

$ echo 'fn main() {}' > foo.rs
$ rustc foo.rs --extern something=asdlflaksdjfljsaljfdlaskjdf

What happened

It did compile my trivial program without any issues.

Expected output

The compiler should have warned or thrown an error about the missing something dependency. Alternatively warned about an unused dependency that was provided.

@jonas-schievink jonas-schievink added A-frontend Area: frontend (errors, parsing and HIR) 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 Jan 21, 2020
@nagisa
Copy link
Member

nagisa commented Jan 21, 2020

Likely an oversight in implementation of Rust 2018 implicit extern crate mechanism.

echo 'extern crate banana; fn main(){}' | rustc --edition=2015 --extern banana=fooooooo -

behaves just as you'd expect.

@nagisa nagisa added C-bug Category: This is a bug. and removed C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Jan 21, 2020
@petrochenkov
Copy link
Contributor

This is by design.
Crates from --extern are looked up on the filesystem and loaded lazily, so if they are never used from source code, then they are never loaded and not put into dependency info.

Sometimes the number of crates on the command line is much larger than the number of actually used crates, so we don't want to load, or even search and touch them.

@petrochenkov
Copy link
Contributor

Alternatively warned about an unused dependency that was provided.

This, on the other hand, would be a nice lint.
(And not requiring going to filesystem.)

@nagisa
Copy link
Member

nagisa commented Jan 21, 2020

A lint for unused crates is being tracked #57274 AFAIK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: frontend (errors, parsing and HIR) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants