Skip to content

Improve missing extern crate diagnostics in Rust 2015 - #161210

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
chenyukang:yukang-fix-160026-extern-crate-edition-help
Aug 27, 2026
Merged

Improve missing extern crate diagnostics in Rust 2015#161210
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
chenyukang:yukang-fix-160026-extern-crate-edition-help

Conversation

@chenyukang

@chenyukang chenyukang commented Aug 17, 2026

Copy link
Copy Markdown
Member

Fixes #160026

closes #112809

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 17, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Aug 17, 2026
@rustbot

rustbot commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

r? @jackh726

rustbot has assigned @jackh726.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 17 candidates

@rustbot

This comment has been minimized.

@chenyukang
chenyukang force-pushed the yukang-fix-160026-extern-crate-edition-help branch from 706a67a to 1367919 Compare August 17, 2026 04:04

@mejrs mejrs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Comment thread compiler/rustc_resolve/src/lib.rs Outdated
Relative2018(Span, ast::Path),
AncestorOnly(Span),
FailedToResolve(Span, Symbol, String, Option<Suggestion>, String),
FailedToResolve(Span, Symbol, String, Option<Suggestion>, Option<String>, String),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a comment about what all these fields are?

Or maybe even better, turn these into named fields? At your option :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

updated.

Comment on lines +291 to +297
diag.span_suggestions_with_style(
Span::default(),
help,
std::iter::empty::<String>(),
Applicability::Unspecified,
SuggestionStyle::HideCodeAlways,
);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can't this just be diag.help(help)? Same for the other ones.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

if we use diag.help(help), there be a order change on output:

Image

i think the left one seems better, since we first show a possible code suggestion and then a help message for more guidance.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the option SuggestionStyle::HideCodeAlways is for this order.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't disagree that this output is better, but what you're doing to emit it that way is not OK; the suggestion diagnostics machinery has a bunch of debug assertions for empty suggestions and this is just one particular code path that happens to evade all of them. So to me this feels like a hack, and I don't really want to add any of those here.

I recommend rewriting the help message so it can stand alone and doesn't need to reference another help message for context. Perhaps something like "if you're trying to use a dependency named dep, upgrade your edition to be able to reference it with a use declaration"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Consider also amending the existing extern crate is required on Rust 2015 message like that;

on Rust 2015, `extern crate` is required to specifiy a dependency on an external crate

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Make sense, I updated it.

@rustbot rustbot assigned mejrs and unassigned jackh726 Aug 18, 2026
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 18, 2026
@chenyukang
chenyukang force-pushed the yukang-fix-160026-extern-crate-edition-help branch from 1367919 to 6b6690e Compare August 20, 2026 14:11
@chenyukang

Copy link
Copy Markdown
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 25, 2026
@chenyukang
chenyukang force-pushed the yukang-fix-160026-extern-crate-edition-help branch from 6b6690e to 0152f8a Compare August 26, 2026 15:04

@mejrs mejrs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@rust-bors

rust-bors Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 0152f8a has been approved by mejrs

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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 Aug 26, 2026
rust-bors Bot pushed a commit that referenced this pull request Aug 26, 2026
Rollup of 5 pull requests

Successful merges:

 - #159502 (Enhance suggestions for unresolved links with typos path)
 - #161052 (Add regression test for generic inference)
 - #161210 (Improve missing extern crate diagnostics in Rust 2015)
 - #161818 (Fix long type on diagnostics for conditionally implemented traits)
 - #161839 (Fix doc link to pointer::addr)
@rust-bors
rust-bors Bot merged commit 0591d9a into rust-lang:main Aug 27, 2026
@rustbot rustbot added this to the 1.100.0 milestone Aug 27, 2026
rust-bors Bot pushed a commit that referenced this pull request Aug 27, 2026
Rollup merge of #161210 - chenyukang:yukang-fix-160026-extern-crate-edition-help, r=mejrs

Improve missing extern crate diagnostics in Rust 2015

Fixes #160026

closes #112809
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

4 participants