Repository navigation
Crate name found in --extern gets suggested verbatim on unresolved import #113035
Description
Activity
- addedA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
on Jun 25, 2023 Rustc could in fact issue an error if an invalid identifier is passed as extern name, because there is no way this identifier can be used by the program anyways (outside of the
forceoption on--externadded by #109421 there is no use case). The only issue with that is that it's going to be a breaking change so needs to be phased in gradually. Alternatively, one could just issue a warning lint.Reacted by León Orell Valerian Liehr and jynSounds even better! For some reason that didn't come to my mind when opening this issue
MCP is accepted now. Now, one could file a pull request. It should be pretty simple.
Reacted by León Orell Valerian Liehr@rustbot claim
A low-level check would be to use rustc_lexer::is_ident. Of course, if you have any better ideas, write me.
I'm sorry for not getting back to you. There's
validate_crate_namewhich I plan on using if possible. Hoping to send a PR soon-ish, couldn't be as active in the project in the last few weeks as I wanted.@fmease no pressure! I'm in a similar situation in fact. Thanks for the heads up. Yeah,
validate_crate_namelooks like a good candidate, definitely worth to explore it. I think in addition theis_identcheck would still help, asvalidate_crate_namedoes not reject names starting with numbers. But we can discuss details when you send the PR.Reacted by León Orell Valerian Liehr- added a commit that references this issue
on Sep 22, 2023
Given the code in file
user.rsas shown below:rustc outputs the following when invoked via
rustc user.rs --crate-type=lib --edition=2021 --extern=a-great-crate=liba_great_crate.rlib:While ideally, in this specific case it should either suggest nothing of if feasible suggest changing the
--externflag to--extern=a_great_crate=liba_great_crate.rlib(the latter is probably P-low). I did actually get confused by the suggestion when I originally faced it.In fact, rustc suggests whatever garbage you put in the flag (e.g. on
rustc … '--extern=a&-gre?t#crate=xxx'). In these cases it shouldn't consider the name at all (I realize though that this might be a case of garbage in, garbage out).@rustbot label T-compiler A-diagnostics A-suggestion-diagnostics D-invalid-suggestion