Skip to content

When compiling without a specified --edition, emit a note - #158102

Open
estebank wants to merge 2 commits into
rust-lang:mainfrom
estebank:note-default-edition
Open

estebank wants to merge 2 commits into
rust-lang:mainfrom
estebank:note-default-edition

Conversation

@estebank

@estebank estebank commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

@rustbot rustbot added A-compiletest Area: The compiletest test runner A-run-make Area: port run-make Makefiles to rmake.rs A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jun 18, 2026
@rust-log-analyzer

This comment was marked as resolved.

@estebank

Copy link
Copy Markdown
Contributor Author

I'll try to write an MCP later (unless someone does it for me). This change was motivated after seeing https://internals.rust-lang.org/t/code-compiles-on-playground-but-fails-when-passed-via-stdin-to-rustc/24393 where the different defaults between cargo, playground and rustc caused people to get confused.

@estebank
estebank force-pushed the note-default-edition branch from b923a75 to 2a486d3 Compare June 18, 2026 20:41
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@estebank
estebank force-pushed the note-default-edition branch from 4241536 to d71c2fa Compare July 21, 2026 02:17
@estebank estebank added the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Jul 21, 2026
@estebank
estebank marked this pull request as ready for review July 21, 2026 02:25
@rustbot

rustbot commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in src/tools/compiletest

cc @jieyouxu

@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 Jul 21, 2026
@rustbot

rustbot commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

r? @jieyouxu

rustbot has assigned @jieyouxu.
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 74 candidates
  • Random selection from 18 candidates

@rust-log-analyzer

This comment has been minimized.

@jieyouxu jieyouxu removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 25, 2026
@estebank
estebank force-pushed the note-default-edition branch from d71c2fa to a1d6de2 Compare July 27, 2026 06:56
@rustbot

This comment has been minimized.

@estebank estebank added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels Aug 3, 2026

@jieyouxu jieyouxu 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.


fn main() {
rustc().input("foo-prev.rs").run();
rustc().edition("2015").input("foo-prev.rs").run();

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.

Remark: we could consider default setting edition but allow overriding, but explicit is fine

@rust-bors

rust-bors Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

📌 Commit a1d6de2 has been approved by jieyouxu

It is now in the queue for this repository.

@estebank estebank added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 19, 2026
@rust-log-analyzer

This comment has been minimized.

@estebank
estebank force-pushed the note-default-edition branch from 5c5d580 to fb94f61 Compare September 20, 2026 00:31
@rust-log-analyzer

This comment has been minimized.

@jieyouxu jieyouxu 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.

Thanks, re. the run-make-cargo test. You can r=me after fixing it or just dropping it, I realize it doesn't add much if a successful run hides the note anyway.

View changes since this review

Comment thread tests/run-make-cargo/no-edition/cargo-formatted-rustc-error.stderr Outdated
@estebank
estebank force-pushed the note-default-edition branch from fb94f61 to b4c367e Compare September 20, 2026 04:05
Use same wording as cargo does when `package.edition` is unspecified.

Do not suggest `--edition=future` on stable.
@estebank
estebank force-pushed the note-default-edition branch from b4c367e to 5c0fee6 Compare September 20, 2026 04:15
Comment thread compiler/rustc_session/src/session.rs Outdated
Comment on lines +1891 to +1895
/// We should not be emitting notes during compiles, with the *only* exception of missing
/// `--edition` when calling `rustc` directly.
pub fn early_note_for_missing_crate_edition(&self, msg: impl Into<DiagMessage>) {
self.dcx.handle().note(msg)
}

@estebank estebank Sep 20, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Heads up @nnethercote, who's been removing weird diagnostics APIs. I'm re-adding this because the complaing about --edition not being set for rustc must be a note. Let me know if there's an alternative to doing this that I should pursue instead. We might want to just use eprintln!() instead 🤔

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Or a warning?

More generally, what exactly is a note? I see it as some additional information about a top-level error or warning, which is why it makes sense as a subdiagnostic but not as a top-level diagnostic.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I generally agree, it's just that this case in particular we want to provide feedback to users but not make it seem like it is a bug of some kind (which is what both errors and warnings communicate). Regardless, I think that using eprintln for this makes sense. We don't need a header for the message, we don't want colors in it. It just has to be somewhere visible for a naïve use of rustc.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a case where it's not an error, but also probably doesn't do what you expect. That seems to me like a good fit for a warning.

@jieyouxu jieyouxu Sep 20, 2026

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.

Won't eprintln! then also mix into --message-format=json output1? I guess cargo / dev tools already parse json lines so this might not be a problem? I'm also fine with either a note or a warning, both seem sensible.

Footnotes

  1. In unrelated note, we currently paper over rustc eprintln! issues re. failing to write out stderr, like broken pipes, with -Zon-broken-pipe=kill

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jieyouxu just tested and cargo swallows the eprintln (as expected) the same way as the note.

@nnethercote I know what you mean, but I'm trying to navigate making this something very lightweight. It's not only a semantic/technical issue, this will be visible to a lot of people and the more annoying we make it (which having bright yellow on every compile would accomplish for some) the more likely it is people will come in my general direction with pitchforks :)

@estebank

Copy link
Copy Markdown
Contributor Author

@bors r=jieyouxu

I'll merge with the eprintln approach, and we can iterate on it afterwards.

@rust-bors

rust-bors Bot commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 2784d28 has been approved by jieyouxu

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 Sep 20, 2026
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 21, 2026
…ieyouxu

When compiling without a specified `--edition`, emit a note

Implement rust-lang/compiler-team#1019.
rust-bors Bot pushed a commit that referenced this pull request Sep 21, 2026
Rollup of 15 pull requests

Successful merges:

 - #161051 (When error from local macro, include macro def span)
 - #162750 (add case mapping fast paths for Latin-1)
 - #162831 (Do not continue past `rustc_resolve` when encountering duplicated items)
 - #162835 (rustdoc: account for nested parens and split text events in bare urls lint)
 - #163044 (Report runtime range endpoints for runtime values)
 - #163062 (Use x30 register name with LLVM 23+)
 - #158102 (When compiling without a specified `--edition`, emit a note)
 - #162984 (Windows: don't error if `access_mode` is set on `OpenOptions`)
 - #163005 (Avoid unreachable integer underflow check in `CStr::count_bytes()`)
 - #163019 (Prepare for the introduction of forced keywords (`k#`))
 - #163020 (Dir: fix fallback impl for remove_dir)
 - #163047 (Use verbose suggestion for `mut binding` instead of `&mut binding`)
 - #163075 (Fix ArgAttributes mismatches in ABI UI tests for LoongArch64 and RiscV64)
 - #163079 (enable `f128` from `u64`/`i64` test)
 - #163082 (Remove `TypeChecker::root_cx`)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 21, 2026
…ieyouxu

When compiling without a specified `--edition`, emit a note

Implement rust-lang/compiler-team#1019.
@Zalathar

Zalathar commented Sep 21, 2026

Copy link
Copy Markdown
Member

Checking whether this caused a weird failure in rollup: #163086 (comment)

@bors try jobs=test-x86_64-gnu-aux

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 21, 2026
When compiling without a specified `--edition`, emit a note


try-job: test-x86_64-gnu-aux
@rust-bors rust-bors Bot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Sep 21, 2026
@rust-bors

rust-bors Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

💔 Test for a8946ca failed: CI. Failed job:

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job test-x86_64-gnu-aux failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@jieyouxu

Copy link
Copy Markdown
Member

Huh?

rust-bors Bot pushed a commit that referenced this pull request Sep 21, 2026
…uwer

Rollup of 18 pull requests

Successful merges:

 - #161051 (When error from local macro, include macro def span)
 - #161629 (Streamline `StateDiffCollector`)
 - #162750 (add case mapping fast paths for Latin-1)
 - #162831 (Do not continue past `rustc_resolve` when encountering duplicated items)
 - #162835 (rustdoc: account for nested parens and split text events in bare urls lint)
 - #162952 (Depend on lockfiles to prevent GC of the current session)
 - #163044 (Report runtime range endpoints for runtime values)
 - #163062 (Use x30 register name with LLVM 23+)
 - #158102 (When compiling without a specified `--edition`, emit a note)
 - #162939 (Declare multi-kind constants for MacroKinds)
 - #162984 (Windows: don't error if `access_mode` is set on `OpenOptions`)
 - #163005 (Avoid unreachable integer underflow check in `CStr::count_bytes()`)
 - #163019 (Prepare for the introduction of forced keywords (`k#`))
 - #163020 (Dir: fix fallback impl for remove_dir)
 - #163047 (Use verbose suggestion for `mut binding` instead of `&mut binding`)
 - #163075 (Fix ArgAttributes mismatches in ABI UI tests for LoongArch64 and RiscV64)
 - #163079 (enable `f128` from `u64`/`i64` test)
 - #163082 (Remove `TypeChecker::root_cx`)
@JonathanBrouwer

Copy link
Copy Markdown
Member

@bors r-

@rust-bors rust-bors Bot removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Sep 21, 2026
@rust-bors

rust-bors Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in the following rollups:

View changes since this unapproval

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-compiletest Area: The compiletest test runner A-run-make Area: port run-make Makefiles to rmake.rs A-testsuite Area: The testsuite used to check the correctness of rustc S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants