Commit Graph

595 Commits

Author SHA1 Message Date
Nicholas Nethercote
2598e89f8a Simplify query stack printing
Currently it uses `eprintln!` for the "query stack during panic" header
and "end of query stack" footer and
`struct_failure_note(..).with_span(..).emit()` for the stack frames. The
difference is curious.

Looking more closely:
- failure notes lack a leading label (e.g. no "note: ");
- although the failure note is given a span, the span never renders
  because the `AnnotateSnippetEmitter` used for the query stack has an
  empty source map field;
- the JSON emitter is never involved here.

Therefore, the only difference between using `struct_failure_note` and
`eprintln!` is that the former prints in bold. But boldness for frames
isn't important; indeed, normal backtrace frames don't use bold.

So the commit changes query stack frame printing to use `eprintln!`,
removes some now unnecessary `dcx` arguments, and also removes
`struct_failure_note`. That leaves "For more information about an error,
try `rustc --explain {}`" as the only use of `FailureNote`.
2026-09-18 18:47:07 +10:00
Jonathan Brouwer
ce606c6186 Rollup merge of #160544 - zachs18:stabilize-trim_prefix_suffix, r=clarfonthey
Stabilize `feature(trim_prefix_suffix)` (`{str, [T], Path}::trim_prefix` and `{str, [T]}::trim_suffix`)

Closes rust-lang/rust#142312 (tracking issue)

FCP completed [here](https://github.com/rust-lang/rust/issues/142312#issuecomment-4920020056). There was discussion during FCP about a possibly adding `strip_circumfix`, but that wasn't mentioned as blocking.

r? libs-api
2026-09-17 16:50:48 +02:00
Zachary S
9559b382e8 Stabilize trim_prefix_suffix 2026-09-15 15:23:26 -05:00
mejrs
6aaabbb863 compiler: fix bug and span_bug imports 2026-09-15 16:20:18 +02:00
Nicholas Nethercote
d1d3129ad1 Improve the "no space between flag name and value" warning
A command like `rustc -optimize a.rs` currently gives this:
```
warning: option `-o` has no space between flag name and value, which can be confusing

note: output filename `-o ptimize` is applied instead of a flag named `optimize`

help: insert a space between `-o` and `ptimize` if this is intentional: `-o ptimize`
```

A top-level warning, then a top-level note, then a top-level help.
Weird!

This commit converts the note and the help into children of the warning,
which looks better and matches how things are normally done, giving
this:
```
warning: option `-o` has no space between flag name and value, which can be confusing
  |
  = note: output filename `-o ptimize` is applied instead of a flag named `optimize`
  = help: insert a space between `-o` and `ptimize` if this is intentional: `-o ptimize`
```
Much better.
2026-09-12 11:07:16 +10:00
Nicholas Nethercote
d571cae83e Minimize DiagCtxt methods
We have `DiagCtxt`, `DiagCtxtInner`, and `DiagCtxtHandle`. They're all
necessary, but the method placement is inconsistent. This commit
establishes a clearer rule: methods should *not* go on `DiagCtxt`
whenever possible.

Benefits:

- Simpler rule for deciding where to put a method.

- `impl Deref for DiagCtxtHandle` can be removed, including its
  non-standard double-reference `&&'a DiagCtxt` return value.
  This makes it impossible to accidentally discard a taint target by
  calling `handle` on a `DiagCtxtHandle`.

- Catches some places where we were calling `dcx.handle()` when `dcx`
  was already a handle.
2026-09-08 15:25:09 +10:00
Jonathan Brouwer
549f475a13 Rollup merge of #151618 - ShE3py:rustdoc-print, r=notriddle
rustdoc: add `--print` option

Context: `--print crate-root-lint-levels` (rust-lang/rust#139180) is only available for `rustc` and `clippy-driver`, while it would make sense for it to also be available for `rustdoc` (à la rust-lang/rust#83895.)

Not too sure about the stability of `rustdoc --print=any` or if this needs a MCP; strictly speaking, only `rustdoc +nightly -Z unstable-options --print=crate-root-lint-levels` would be required (and the `rustdoc --print` would be stabilized together with `crate-root-lint-levels`), but I guess that makes sense to have all the `--print`s for consistency.

For regression tests, not sure if ui or run-make is preferable, as run-make would need some sort of trait to avoid duplicating code between `rustc()` and `rustdoc()` (or just test `rustdoc` as it delegates to `rustc`):
021fc25b7a/tests/run-make/print-crate-root-lint-levels/rmake.rs (L82-L88)

@rustbot label +A-CLI +A-print-requests
2026-09-01 21:26:10 +02:00
Lieselotte
57cc38f1d6 rustdoc: add --print option 2026-08-31 18:00:51 +02:00
Nicholas Nethercote
60be5628af Simplify find_gated_cfg
Every caller passes a predicate that just does a name comparison.
2026-08-31 19:59:03 +10:00
Jacob Pratt
2502d8fe6c Rollup merge of #161320 - ChrisDenton:so, r=TaKO8Ki
Only suggest `RUST_MIN_STACK` if maybe stack overflow

Alternatively we could make the wording of the help message note the uncertainty.
2026-08-21 08:43:49 -04:00
Jacob Pratt
cc58c4218f Rollup merge of #161259 - mejrs:attr_structures, r=JonathanBrouwer
move some attribute related structs out of rustc_attr_ir

This changes it so that

- rustc_session no longer depends on rustc_attr_ir
- rustc_attr_ir no longer depends on rustc_target (which is a fairly sizeable crate)
- rustc_attr_ir and rustc_target can compile in parallel

Previous graph:
<img width="985" height="512" alt="image" src="https://github.com/user-attachments/assets/cbde2414-043e-45f2-88a2-f77a5c9df60c" />

Graph with this PR:
<img width="1248" height="474" alt="image" src="https://github.com/user-attachments/assets/e0e13794-b17b-4337-8768-f0191cb1c0e6" />

r? @JonathanBrouwer
2026-08-21 08:43:39 -04:00
mejrs
38af4a23c2 move CrateType 2026-08-21 10:35:02 +02:00
bors
16a623ad67 Auto merge of #161434 - jhpratt:rollup-hq3P7uc, r=jhpratt
Rollup of 25 pull requests

Successful merges:

 - rust-lang/rust#152617 (std: implement `sleep_until` for Fuchsia)
 - rust-lang/rust#158934 (diagnostics: fix `let x: vec![]` suggestion pointing into stdlib)
 - rust-lang/rust#160995 (Tiny readability cleanups for initialization dataflow analyses)
 - rust-lang/rust#161277 (bootstrap: Move all non-module items out of the crate root)
 - rust-lang/rust#161295 (std: don't panic on long-elapsed deadlines for `sleep_until`)
 - rust-lang/rust#161368 (Double-word align `_Unwind_Exception`)
 - rust-lang/rust#161370 (Uplift rustfmt macro formatting fix)
 - rust-lang/rust#161378 (`FlowSensitiveAnalysis` cleanups)
 - rust-lang/rust#161420 (Bump wasm-component-ld to 0.5.30)
 - rust-lang/rust#161429 (Tighten allocator `Send`/`Sync` requirements for `Arc` in preparation for refactor)
 - rust-lang/rust#158032 (Offload expose device selection)
 - rust-lang/rust#158855 (Add `desktop` method to `CommandExt`)
 - rust-lang/rust#160299 (Stabilize `bool::toggle`)
 - rust-lang/rust#160842 (Apply `&[T]` visualizer to `*const [T]`, `*mut [T]` and `Box<[T]>`)
 - rust-lang/rust#160981 (Partially support building and locating wasm proc-macros)
 - rust-lang/rust#161199 (Add regression test for non lifetime binders)
 - rust-lang/rust#161212 (rust-installer/install-template.sh: catch cp(1) error when installing…)
 - rust-lang/rust#161302 (Add regression test for inconsistent import resolution from issue 147208)
 - rust-lang/rust#161329 (Add regression tests for a few fixed issues with E-needs-test)
 - rust-lang/rust#161330 (Add regression test for nested RPIT not an iterator ICE)
 - rust-lang/rust#161331 (Bitset simplifications)
 - rust-lang/rust#161340 (rustdoc: enable scrolling only on table/code)
 - rust-lang/rust#161351 (Cleanup: Move impl of `#[rustc_dump_object_lifetime_defaults]`)
 - rust-lang/rust#161355 (Add file path to some archive build errors)
 - rust-lang/rust#161373 (Allow running EC2 jobs locally)
2026-08-21 06:25:29 +00:00
mejrs
7cd9c920cd rustc_session; remove rustc_lint_defs rex-exports 2026-08-20 23:02:49 +02:00
Chris Denton
7b7dffb301 Only suggest RUST_MIN_STACK if stack overflow 2026-08-18 19:29:29 +00:00
bjorn3
ea4e56a52a Add --print wasm-proc-macro-tuple
This can be used by cargo to determine the target for which wasm
proc-macros should be compiled.
2026-08-17 16:50:26 +02:00
Jonathan Brouwer
f03631c43d Rename rustc_driver_impl/session_diagnostics.rs to diagnostics.rs 2026-08-08 14:58:18 +02:00
Jonathan Brouwer
900f0bcb32 Rollup merge of #159225 - bjorn3:split_incr_comp_session, r=oli-obk
Split IncrCompSession out of Session

This will allow introducing a separate incr comp session dir for the post LTO artifacts in the future. In addition it statically encodes the lifetime of the incr comp session rather than requiring an enum behind a mutex stored in the Session.

Based on https://github.com/rust-lang/rust/pull/159000
Part of https://github.com/rust-lang/compiler-team/issues/908
2026-08-05 13:36:11 +02:00
Jonathan Brouwer
cf80286afb Rollup merge of #160360 - mejrs:hir_pretty, r=nnethercote
Remove rustc_middle dependency on rustc_hir_pretty

There is a `impl PpAnn for TyCtxt`  that is unneeded. None of the big crates (middle, trait_selection) actually do any hir pretty printing so it can be removed and can either be implemented for local structs elsewhere or done by casting to `&dyn PpAnn` instead.

This probably doesn't have any perf effects (its not bottlenecking in timings) but I expect it to compose with https://github.com/rust-lang/rust/pull/160336 and its followup works quite well.

Old graph:
<img width="1999" height="2171" alt="graph" src="https://github.com/user-attachments/assets/756e6a50-a413-4a8d-a0f3-7bbf4de07933" />

New graph:
<img width="1853" height="2171" alt="graph_hir_pretty" src="https://github.com/user-attachments/assets/f9607e5a-d00b-4a86-8f6a-cefb45b75ad7" />
2026-08-05 13:36:05 +02:00
mejrs
180c6379b8 Remove rustc_middle dependency on rustc_hir_pretty
There is a `impl PpAnn for TyCtxt`  that is unneeded. None of the big crates (middle, trait_selection) actually do any hir pretty printing so it can be removed and can either be implemented for local structs elsewhere or done by casting to `&dyn PpAnn` instead.
2026-08-04 19:04:34 +02:00
John Kåre Alsaker
5aff738d05 Derive the allocator used by tools from rustc's allocator 2026-08-03 22:39:22 +02:00
Jonathan Brouwer
581f75e736 Rollup merge of #158460 - ZuseZ4:simplify-enzyme-feature, r=bjorn3
Remove llvm_enzyme feature outside of bootstrap

r? bjorn3
I think you were the one who did the last refactoring on how we pass this feature.

We originally introduced and used this compile-time cfg since we were suspecting that some of the work we did for autodiff was causing a compile time regression even when no autodiff was used. It turned out later that we just did extra work due to a bug, which was fixed.

Thanks to the dlopen work our checks are now much simpler. We only do autodiff work if the -Zautodiff=Enable flag was set. If the flag is set we also just check if libEnzyme is in the sysroot, and if we can not find it, we error out.

I noticed it while fixing some related checks in https://github.com/rust-lang/rust/pull/158333
2026-07-29 14:10:29 +02:00
Manuel Drehwald
ba877845ee Remove llvm_enzyme feature outside of bootstrap 2026-07-28 16:11:31 -04:00
Gary Guo
75999c498f Split register_tool into register_attribute_tool and register_lint_tool
This splits the functionality to two parts per RFC. The `#![register_tool]`
attribute registers the tool in both ways.

Semantics remain unchanged and will be adjusted in later commit.
2026-07-27 19:06:33 +01:00
bjorn3
f9679fa4df Split IncrCompSession out of Session
This will allow introducing a separate incr comp session dir for the
post LTO artifacts in the future. In addition it statically encodes the
lifetime of the incr comp session rather than requiring an enum behind a
mutex stored in the Session.
2026-07-23 12:14:56 +02:00
Nicholas Nethercote
a235d0d0d0 Use two local variables 2026-07-21 18:16:18 +10:00
Nicholas Nethercote
b663a947c7 Remove early_exit closures
There are two `early_exit` closures in `run_compiler` that ensure
`abort_if_errors` is called on all the early exit paths.

However, these early exit paths all occur in the closure passed to
`interface::run_compiler`. And what does `interface::run_compiler` do
after calling the passed-in closure? It calls `finish_diagnostic`
(always) and then `abort_if_errors` (if the closure didn't panic).
So we can drop the `early_exit` calls and get the same behaviour.
2026-07-21 18:16:08 +10:00
reidliu
bc585ed04e Fix the stale metrics directory warning 2026-07-15 19:39:01 +08:00
blyxyas
8ecf21cdb0 Propagate error downwards and emit it, even if not related to file
extension. Fix tests and update docs.
2026-07-09 12:19:01 +00:00
Alejandra Gonzalez
90496ea27d fix: Actually take error and panic by default, only emitting a custom
error if file ends in .rs
2026-07-08 18:40:44 +02:00
blyxyas
bbba4966b2 Propagate errors from list_file_metadata into list_metadata
Update unstable book with ls valid values
2026-07-07 12:29:51 +00:00
Alejandra Gonzalez
ae82b10c36 Improve error message on -Zls, to direct the user to input .rmeta files instead of .rs files 2026-07-06 19:34:38 +02:00
Camille GILLOT
5464994cdd Split-up the AST to index it. 2026-06-16 00:10:07 +00:00
Camille Gillot
334a95f9f4 Make lowering incremental.
Co-authored-by: Camille Gillot <gillot.camille@gmail.com>
2026-06-16 00:08:10 +00:00
Camille Gillot
bfe40ed753 Stop stealing ResolverAstLowering. 2026-06-15 23:24:10 +00:00
fallofpheonix
5a93cdbc09 Remove useless -Zunpretty=identified option
Fixes #10671

The `-Zunpretty=identified` option (without `expanded`) is effectively
useless because `NodeId`s are unassigned prior to macro expansion,
leading them to just be `NodeId::MAX_AS_U32`.

This commit removes the `Identified` variant from `PpSourceMode` and
removes `-Zunpretty=identified` from the command-line options. Users
should use `-Zunpretty=expanded,identified` instead (which is retained)
if they want to inspect `NodeId`s.
2026-05-24 17:36:25 +05:30
Guillaume Gomez
1f5737c853 Rollup merge of #156564 - nnethercote:LevelSpec, r=GuillaumeGomez
Lint level cleanups

Some naming improvements, some type safety improvements, and some simplifications. Details in individual commits.

r? @GuillaumeGomez
2026-05-14 16:51:08 +02:00
Nicholas Nethercote
530a73f17e Prevent invalid LevelSpec values
`LevelSpec` has two related fields, `level` and `lint_id`. This commit
makes the fields private (and introduces getters) to ensure they are set
together using only valid combinations.

The commit also introduces `is_allow` and `is_expect` methods because
those are useful.
2026-05-14 16:28:50 +10:00
Nicholas Nethercote
ccfac5469a Rename LevelAndSource
It is misnamed, given that it has three fields: `level`, `lint_id`, and
`src`. (Presumably the `lint_id` was added later.)

This commit renames it as `LevelSpec`. (I also considered `LevelInfo`
but that's very generic. `Spec` has pre-existing uses in
`LintLevelsProvider::current_specs` and `LintSet::specs` and
`ShallowLintLevelMap::specs`.)

Related things renamed as well:
- `level` -> `level_spec` (where appropriate)
- `lint_levels` -> `lint_level_specs`
- `get_lint_level` -> `get_lint_level_spec`
- `level_and_source` -> `level_spec`
- `CodegenLintLevels` -> `CodegenLintLevelSpecs`
- `raw_lint_id_level` -> `raw_lint_level_spec`
- `lint_level_at_node` -> `lint_level_spec_at_node`
- `reveal_actual_level` -> `reveal_actual_level_spec`
- `probe_for_lint_level` -> `probe_for_lint_level_spec`

This clears up a lot of `Level` vs. `LevelSpec` ambiguity. E.g. no more
`level.level` expressions.
2026-05-14 13:20:57 +10:00
Jonathan Brouwer
f24b05a9d2 Rollup merge of #156344 - estebank:issue-156326, r=petrochenkov
Do not index past end of buffer when checking heuristic in error index syntax highlighter

When checking whether the current token is a function indentifier by inspecting the syntax, do not attempt to access past the end of the code buffer.

Fix rust-lang/rust#156326.
2026-05-14 00:35:36 +02:00
Esteban Küber
530c69bbc2 Do not index past end of buffer when checking heuristic in error index syntax highlighter
When checking whether the current token is a function indentifier by inspecting the syntax, do not attempt to access past the end of the code buffer.
2026-05-13 17:52:04 +00:00
Zalathar
ccb9305e20 Move emit_mir out of rustc_mir_transform::dump_mir
This function doesn't have an obvious home, but there's little reason for it to
be in mir-transform, and having it in `rustc_driver_impl::pretty` at least puts
it near other callers of `write_mir_pretty`.
2026-05-13 14:54:31 +10:00
Jonathan Brouwer
7843355462 Rollup merge of #156384 - Zalathar:pretty-def-id, r=tiif
Remove some dead code for dumping MIR for a single DefId

The functions that call `dump_mir_def_ids` are themselves never called with a specific DefId; they always dump MIR for the entire crate.
2026-05-11 10:29:20 +02:00
Zalathar
9d01bf83f9 Remove some dead code for dumping MIR for a single DefId 2026-05-10 17:18:35 +10:00
bjorn3
c2ab95fb61 Handle --print=backend-has-mnemonic in cg_clif
And introduce a has_mnemonic method on CodegenBackend just like
--print=backend-has-zstd
2026-05-08 16:08:56 +02:00
Nicholas Nethercote
01e933f888 Move four fields from ParseSess to Session.
`ParseSess` is separate from, but sits within, `Session`. The separation
is because there are some places (e.g. `Parser` methods) where
`ParseSess` is available but `Session` is not.

However, `ParseSess` has four fields that are only accessed from places
where `Session` is also available. This commit moves those fields to
`Session`. This means that `ParseSess` only contains the fields it
genuinely needs, and various `sess.psess.foo` occurrences are reduced to
`sess.foo`.
2026-04-29 09:27:04 +10:00
Eddy (Eduard) Stefes
2a8e588c90 Add --print=backend-has-mnemonic and needs-asm-mnemonic directive
Add infrastructure to query LLVM backend for specific assembly mnemonics
and use it in compiletest to conditionally run tests based on instruction
availability.

This fixes test failures with naked-dead-code-elimination which requires
the `RET` mnemonic.

Co-authored-by: Folkert de Vries <flokkievids@gmail.com>
2026-04-28 10:21:15 +02:00
Jonathan Brouwer
c5f6afc3e8 Remove target arguments & features from parse_limited 2026-04-18 19:13:30 +02:00
Nicholas Nethercote
9b64d52d78 Reduce diagnostic type visibilities.
Most diagnostic types are only used within their own crate, and so have
a `pub(crate)` visibility. We have some diagnostic types that are
unnecessarily `pub`. This is bad because (a) information hiding, and (b)
if a `pub(crate)` type becomes unused the compiler will warn but it
won't warn for a `pub` type.

This commit eliminates unnecessary `pub` visibilities for some
diagnostic types, and also some related things due to knock-on effects.
(I found these types with some ad hoc use of `grep`.)
2026-04-16 07:42:17 +10:00
Nicholas Nethercote
0db4e3a883 De-pluralize the names of two error enums.
Error enum names should not be plural. Even though there are multiple
possible errors, each instance of an error enum describes a single
error. There are dozens of singular error enum names, and only two
plural error enum names. This commit makes them both singular.
2026-03-30 14:15:44 +11:00