Commit graph

23293 commits

Author SHA1 Message Date
Jonathan Brouwer
ca2be71a18
Add verification for inline fluent messages 2026-02-01 11:12:10 +01:00
Jonathan Brouwer
523d9d9200
Uitests for subdiagnostics 2026-02-01 11:12:04 +01:00
Jonathan Brouwer
378c6fc6fe
Uitests for #[diagnostic] 2026-02-01 11:12:03 +01:00
Stuart Cook
dcc74dd6e3
Rollup merge of #151817 - aytey:fix_lifetime_unpretty_hygiene, r=jdonszelmann
Fix missing syntax context in lifetime hygiene debug output

`-Zunpretty=expanded,hygiene` was not printing the syntax context for lifetimes. For example, two macro-generated lifetimes `'a` with different hygiene would both print as `/* 2538 */` instead of `/* 2538#0 */` and `/* 2538#1 */`, making it impossible to distinguish them.

This was fixed by changing `print_lifetime` to call `ann_post()` with the full `Ident`, matching how regular identifiers are handled in `print_ident`.

Closes: rust-lang/rust#151797
2026-01-30 17:41:07 +11:00
Stuart Cook
45009749b5
Rollup merge of #151811 - chenyukang:yukang-fix-143256-unused-parens-labeled-loops, r=Kivooeo
Fix false positive in unused_parens caused by break

Fixes rust-lang/rust#143256
2026-01-30 17:41:07 +11:00
bors
ef2657cbaf Auto merge of #151168 - petrochenkov:rprivtit, r=eholk
privacy: Fix privacy lints in RPITITs

Visit RPITITs and report `private_interfaces`, `private_bounds` and `exported_private_dependencies` in them (these are regular, non-deprecation lints).
New hard errors are not reported, https://github.com/rust-lang/rust/pull/146470 is for hard errors.
So this PR doesn't contain any breakage or language changes.
2026-01-30 01:45:52 +00:00
bors
35a31ba763 Auto merge of #140283 - adwinwhite:fn-pointer-coercion, r=jackh726
Fix accidental type inference in array coercion


Fixes rust-lang/rust#136420.

If the expectation of array element is a type variable, we should avoid resolving it to the first element's type and wait until LUB coercion is completed.
We create a free type variable instead which is only used in this `CoerceMany`.

[`check_expr_match`](847e3ee6b0/compiler/rustc_hir_typeck/src/_match.rs (L72)) and [`check_expr_if`](847e3ee6b0/compiler/rustc_hir_typeck/src/expr.rs (L1329)) where `CoerceMany` is also used do the [same](847e3ee6b0/compiler/rustc_hir_typeck/src/expectation.rs (L50)). 

### [FCP Proposal](https://github.com/rust-lang/rust/pull/140283#issuecomment-2933771068):
> Array expressions normally lub their element expressions' types to ensure that things like `[5, 5_u8]` work and don't result in type mismatches. When invoking a generic function `fn foo<T>(_: [T; N])` with an array expression, we end up with an infer var for the element type of the array in the signature. So when typecking the first array element we compare its type with the infer var and thus subsequently require all other elements to be the same type.
> 
> This PR changes that to instead fall back to "not knowing" that the argument type is array of infer var, but just having an infer var for the entire argument. Thus we typeck the array expression normally, lubbing the element expressions, and then in the end comparing the array expression's type with the array of infer var type.
> 
> Things like
> 
> ```rust
> fn foo() {}
> fn bar() {} 
> fn f<T>(_: [T; 2]) {}
> 
> f([foo, bar]);
> ```
> 
> and
> 
> ```rust
> struct Foo;
> struct Bar;
> trait Trait {}
> impl Trait for Foo {}
> impl Trait for Bar {} 
> fn f<T>(_: [T; 2]) {}
> 
> f([&Foo, &Bar as &dyn Trait]);
> ```

### Remaining inconsistency with `if` and `match`(rust-lang/rust#145048):
The typeck of array always uses the element coercion target type as the expectation of element exprs while `if` and `match` use `NoExpectation` if the expected type is an infer var.
This causes that array doesn't support nested coercion. 
```rust
fn foo() {}
fn bar() {}
fn main() {
    let _ =  [foo, if false { bar } else { foo }]; // type mismatch when trying to coerce `bar` into `foo` in if-then branch coercion.
}
```
But we can't simply change this behavior to be the same as `if` and `match` since [many code](https://github.com/rust-lang/rust/pull/140283#issuecomment-3190564399) depends on using the first element's type as expectation.
2026-01-29 21:36:31 +00:00
Jonathan Brouwer
eeb3a24813
Rollup merge of #151833 - clubby789:union-adt, r=JonathanBrouwer
Treat unions as 'data types' in attr parsing diagnostics

I found 'data types _and_ unions' to be a little surprising
2026-01-29 17:47:32 +01:00
Jonathan Brouwer
adcdb6c2c3
Rollup merge of #151283 - chenyukang:yukang-fix-macro-unused, r=petrochenkov
Suggest ignore returning value inside macro for unused_must_use lint

Fixes rust-lang/rust#151269

The first commit fix the original issue,
the second commit is a code refactoring in this lint.
2026-01-29 17:47:30 +01:00
Jamie Hill-Daniel
b226583d94 Treat unions as 'data types' in attr parsing diagnostics 2026-01-29 15:51:43 +00:00
yukang
87f75df0b8 Fix unused lint error in macro 2026-01-29 23:10:46 +08:00
Vadim Petrochenkov
7c9d149936 Add 2 more test cases from 151284 and 151479 2026-01-29 16:47:02 +03:00
Vadim Petrochenkov
7b5a4d8653 privacy: Synchronize PrivateItemsInPublicInterfacesChecker and EmbargoVisitor 2026-01-29 16:34:17 +03:00
Vadim Petrochenkov
88f2e79b77 Add test case from issue 151284 2026-01-29 16:34:17 +03:00
Vadim Petrochenkov
1ce89c0449 privacy: Close one more hole in associated type visiting 2026-01-29 16:34:16 +03:00
Vadim Petrochenkov
989568a79f privacy: Fix privacy lints in RPITITs 2026-01-29 16:34:16 +03:00
Andrew V. Teylu
a333f6f93c Fix missing syntax context in lifetime hygiene debug output
`-Zunpretty=expanded,hygiene` was not printing the syntax context for
lifetimes. For example, two macro-generated lifetimes `'a` with different
hygiene would both print as `/* 2538 */` instead of `/* 2538#0 */` and
`/* 2538#1 */`, making it impossible to distinguish them.

This was fixed by changing `print_lifetime` to call `ann_post()` with
the full `Ident`, matching how regular identifiers are handled in
`print_ident`.
2026-01-29 12:07:01 +00:00
bors
370143facf Auto merge of #151816 - Zalathar:rollup-z5YytdB, r=Zalathar
Rollup of 5 pull requests

Successful merges:

 - rust-lang/rust#151775 (Portable SIMD subtree update)
 - rust-lang/rust#151488 (Tweak E0599 to consolidate unsatisfied trait bound messages)
 - rust-lang/rust#149823 (fix(parser): Disallow CR in frontmatter )
 - rust-lang/rust#151475 (add foregin type tests for issue 64458)
 - rust-lang/rust#151657 (Cleanup of `#[derive(Diagnostic)]` attribute parsers)
2026-01-29 11:49:06 +00:00
Stuart Cook
617288eb58
Rollup merge of #151657 - JonathanBrouwer:diag2, r=Kivooeo
Cleanup of `#[derive(Diagnostic)]` attribute parsers

This PR does a lot of refactoring on the implementation of `#[derive(Diagnostic)]`. It should have no observable effect other than error messages for incorrect usage of the attributes. In general, I think the error messages got better.

This PR can be reviewed commit by commit, each commit passes the tests.
- [Convert parse_nested_meta to parse_args_with for #[diagnostic]](https://github.com/rust-lang/rust/pull/151657/changes/9e61014a8a0bb1f1d7911511c303a7ae2a9c2a7d)
  Start parsing `#[diagnostic]` using `syn`'s `parse_args_with` function instead of `parse_nested_meta`. This improves error messages and prepares for the new syntax needed for https://github.com/rust-lang/rust/issues/151366 which cannot be parsed using `parse_args_with`.
- [Convert parse_nested_meta to parse_args_with for #[subdiagnostic]](https://github.com/rust-lang/rust/pull/151657/changes/5d21a21695d56b74ea249f269ee10195251008b7)
  Same as above but for `#[subdiagnostic]`
- [Remove unused no_span option](https://github.com/rust-lang/rust/pull/151657/changes/0bf3f5d51cb853884240792818d81e70daec6ab7)
  Removes the `no_span` option of `#[suggestion]`, which there were no tests for and which seems to have been unused. If needed again in the future, this can be re-added pretty easily, but I find that unlikely.
- [Remove HasFieldMap trait in favour of passing FieldMap directly](https://github.com/rust-lang/rust/pull/151657/changes/2e8347abf4147d2bffe4d7989a21b17ae04cdb57)
  Removes the `HasFieldMap` trait, because I don't really see the point of having a trait "has a field map" if we can just pass the fieldmap itself instead.

r? @Kivooeo
(Thanks for reviewing my PRs so far :3)
2026-01-29 22:34:10 +11:00
Stuart Cook
36a2726bb4
Rollup merge of #151475 - KaiTomotake:add-foreign-type-tests, r=Kivooeo
add foregin type tests for issue 64458

add tests/ui/rfcs/rfc-1861-extern-types/comparison.rs

close rust-lang/rust#64458
2026-01-29 22:34:09 +11:00
Stuart Cook
b6ce0c0028
Rollup merge of #149823 - epage:f, r=Kivooeo
fix(parser): Disallow CR in frontmatter

T-lang came back on the stabilization PR (rust-lang/rust#148051) asking for CR to be disallowed
to leave room for all stray CRs to be rejected in the future.
At that point, the test can remain but the implementation can be
removed.

If that plan does not go through, we'll need to re-evaluate
- whether this is more lint-like and should defer to the calling tool
  that is managing the frontmatter
- how much Rust should treat the frontmatter as Rust and apply the same
  grammar restrictions of "no stray CR" (like raw string literals)

Part of rust-lang/rust#136889
2026-01-29 22:34:09 +11:00
Stuart Cook
2b899b07f0
Rollup merge of #151488 - JohnTitor:issue-114430, r=estebank
Tweak E0599 to consolidate unsatisfied trait bound messages

Fixes rust-lang/rust#114430
r? @estebank
2026-01-29 22:34:08 +11:00
Stuart Cook
d49f50ff4a
Rollup merge of #151775 - calebzulawski:sync-from-portable-simd-2026-01-28, r=folkertdev
Portable SIMD subtree update

cc @folkertdev @programmerjake
2026-01-29 22:34:07 +11:00
yukang
4803644df9 Fix false positive in unused_parens caused by break 2026-01-29 17:21:26 +08:00
Yuki Okushi
4b22ee9fc5 Tweak E0599 to consolidate unsatisfied trait bound messages 2026-01-29 17:26:32 +09:00
Stuart Cook
3830f76b4a
Rollup merge of #151665 - arferreira:fix-rustdoc-contrast, r=GuillaumeGomez
Fix contrast ratio for `Since` element in rustdoc dark theme

Changed `--right-side-color` from `#808080` to `#ababab` in the dark theme.

<img width="742" height="784" alt="Screenshot 2026-01-25 at 8 04 29 PM" src="https://github.com/user-attachments/assets/38c5f0b9-2034-429f-87db-8a0ed8209b5d" />

Verified visually in dark theme, it's now more readable:

<img width="174" height="96" alt="Screenshot 2026-01-25 at 8 41 02 PM" src="https://github.com/user-attachments/assets/d0c30409-4374-48c4-ae9c-a0aec48e8957" />

Part of https://github.com/rust-lang/rust/issues/59845
Fixes rust-lang/rust#151422
2026-01-29 19:03:32 +11:00
Stuart Cook
f5822b672b
Rollup merge of #151559 - GuillaumeGomez:marker-hidden-deprecated-search, r=lolbinarycat
[rustdoc] Add a marker to tell users that there are hidden (deprecated) items in the search results

Someone on mastodon rightfully pointed out that having a visual indication that some search results were hidden would be a good idea if the "hide deprecated items" setting is enabled. In particular if no results are displayed.

It looks like this:

<img width="861" height="228" alt="Screenshot From 2026-01-24 00-26-33" src="https://github.com/user-attachments/assets/93aeef11-a550-47dc-9c78-219ea4fd822c" />

r? @lolbinarycat
2026-01-29 19:03:31 +11:00
Stuart Cook
9f0483e5f0
Rollup merge of #151596 - sgasho:150910_SimplifyCfg_passes_warn, r=nnethercote,saethlin
Fix -Zmir-enable-passes to detect unregistered enum names in declare_passes macro

related: https://github.com/rust-lang/rust/issues/150910

I fixed declare_passes macro to detect unregistered enum names

### UI Results
+nightly --> before: no warnings
+stage1 --> after: detect SimplifyCfg as an unknown pass

<img width="591" height="199" alt="スクリーンショット 2026-01-24 23 53 41" src="https://github.com/user-attachments/assets/ddabaa58-b4c6-4e80-a3c9-f40d866db273" />
2026-01-29 19:03:30 +11:00
Stuart Cook
9f551d31e4
Rollup merge of #150572 - heathdutton:issue-150174-asyncfn-diagnostic-v2, r=lcnr
Improve move error diagnostic for `AsyncFn` closures

When an async closure captures a variable by move but is constrained to `AsyncFn` or `AsyncFnMut`, the error message now explains that the closure kind is the issue and points to the trait bound, similar to the existing diagnostic for `Fn`/`FnMut` closures.

**Before:**
```
error[E0507]: cannot move out of `foos` which is behind a shared reference
  --> src/lib.rs:12:20
   |
11 | async fn foo(foos: &mut [&mut Foo]) -> Result<(), ()> {
   |              ---- move occurs because `foos` has type...
12 |     in_transaction(async || -> Result<(), ()> {
   |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^ `foos` is moved here
13 |         for foo in foos {
   |                    ---- variable moved due to use in coroutine
```

**After:**
```
error[E0507]: cannot move out of `y`, a captured variable in an `AsyncFn` closure
  --> src/lib.rs:9:10
   |
LL |     let y = vec![format!("World")];
   |         - captured outer variable
LL |     call(async || {
   |          ^^^^^^^^ captured by this `AsyncFn` closure
...
help: `AsyncFn` and `AsyncFnMut` closures require captured values to be able
      to be consumed multiple times, but `AsyncFnOnce` closures may consume
      them only once
  --> src/lib.rs:5:27
   |
LL | fn call<F>(_: F) where F: AsyncFn() {}
   |                           ^^^^^^^^^
```

Fixes rust-lang/rust#150174
2026-01-29 19:03:29 +11:00
Stuart Cook
dd43c8848d
Rollup merge of #150474 - reddevilmidzy:tidy-sub-dir, r=Zalathar
Tidy: detect ui tests subdirectory changes so `tests/ui/README.md` stays in sync

close: rust-lang/rust#150399

There's an issue where `tests/ui/README.md` isn't updated whenever the ui subdirectory changes.
I've added subdirectory change detection to tidy ~~added a new mention to `triage.toml` to notify `tests/ui/README.md` to also be updated~~.

r? @Urgau
2026-01-29 19:03:29 +11:00
Adwin White
b235cc22ac fix accidental type variable resolution in array coercion 2026-01-29 11:28:05 +08:00
sgasho
99591e6d42 Fix -Zmir-enable-passes to detect unregistered enum names 2026-01-29 09:01:05 +09:00
Caleb Zulawski
b71ff51277 Update std and tests to match std::simd API (remove LaneCount bound and rename to_int to to_simd) 2026-01-28 18:35:17 -05:00
bors
ba284f468c Auto merge of #151794 - JonathanBrouwer:rollup-rGbYGX2, r=JonathanBrouwer
Rollup of 12 pull requests

Successful merges:

 - rust-lang/rust#150491 (resolve: Mark items under exported ambiguous imports as exported)
 - rust-lang/rust#150720 (Do not suggest `derive` if there is already an impl)
 - rust-lang/rust#150968 (compiler-builtins: Remove the no-f16-f128 feature)
 - rust-lang/rust#151493 ([RFC] rustc_parse: improve the error diagnostic for "missing let in let chain")
 - rust-lang/rust#151660 (Bump `std`'s `backtrace`'s `rustc-demangle`)
 - rust-lang/rust#151696 (Borrowck: Simplify SCC annotation computation, placeholder rewriting)
 - rust-lang/rust#151704 (Implement `set_output_kind` for Emscripten linker)
 - rust-lang/rust#151706 (Remove Fuchsia from target OS list in unix.rs for sleep)
 - rust-lang/rust#151769 (fix undefined behavior in VecDeque::splice)
 - rust-lang/rust#151779 (stdarch subtree update)
 - rust-lang/rust#151449 ([rustdoc] Add regression test for rust-lang/rust#151411)
 - rust-lang/rust#151773 (clean up checks for constant promotion of integer division/remainder operations)
2026-01-28 21:40:46 +00:00
Jonathan Brouwer
0bf3f5d51c
Remove unused no_span option 2026-01-28 22:23:23 +01:00
Jonathan Brouwer
5d21a21695
Convert parse_nested_meta to parse_args_with for #[subdiagnostic] 2026-01-28 22:18:44 +01:00
Jonathan Brouwer
9e61014a8a
Convert parse_nested_meta to parse_args_with for #[diagnostic] 2026-01-28 22:18:37 +01:00
Jonathan Brouwer
775abf4f36
Rollup merge of #151449 - GuillaumeGomez:regression-test-for-151411, r=lolbinarycat
[rustdoc] Add regression test for #151411

Fixes rust-lang/rust#151411.

Seems like the ICE was already solved by https://github.com/rust-lang/rust/pull/151255. Well in any case, more regression tests won't hurt.

r? @lolbinarycat
2026-01-28 21:10:54 +01:00
Jonathan Brouwer
41caa6e22d
Rollup merge of #151493 - Unique-Usman:ua/missinglet, r=estebank
[RFC] rustc_parse: improve the error diagnostic for "missing let in let chain"
2026-01-28 21:10:50 +01:00
Jonathan Brouwer
3787595751
Rollup merge of #150720 - WhyNovaa:diagnostics-impl-fix, r=lcnr
Do not suggest `derive` if there is already an impl

This PR fixes an issue where the compiler would suggest adding `#[derive(Trait)]` even if the struct or enum already implements that trait manually.

Fixes [#146515](https://github.com/rust-lang/rust/issues/146515)
2026-01-28 21:10:49 +01:00
Jonathan Brouwer
8bdd8dc5e1
Rollup merge of #150491 - petrochenkov:ambigeffvis, r=yaahc
resolve: Mark items under exported ambiguous imports as exported

After https://github.com/rust-lang/rust/pull/147984 one of the imports in an ambiguous import set becomes accessible under a deny-by-default deprecation lint.

So if it points to something, that something needs to be marked as exported, so its MIR is encoded into metadata, its symbol is not lost from object files, etc.
The added test shows an example.
This fixes around 10-20 crater regressions found in https://github.com/rust-lang/rust/pull/149195#issuecomment-3641704823.

Unblocks https://github.com/rust-lang/rust/pull/149195.
2026-01-28 21:10:48 +01:00
Ed Page
52d4ef12a8 fix(parser): Disallow CR in frontmatter
T-lang came back on the stabilization PR asking for CR to be disallowed
to leave room for all stray CRs to be rejected in the future.
At that point, the test can remain but the implementation can be
removed.

If that plan does not go through, we'll need to re-evaluate
- whether this is more lint-like and should defer to the calling tool
  that is managing the frontmatter
- how much Rust should treat the frontmatter as Rust and apply the same
  grammar restrictions of "no stray CR" (like raw string literals)
2026-01-28 13:01:02 -06:00
Ed Page
fb995ef5b3 test(frontmatter): Show behavior for straw cr 2026-01-28 13:01:02 -06:00
bors
de6d33c033 Auto merge of #151550 - petrochenkov:packhyg2, r=nnethercote
resolve: Replace `Macros20NormalizedIdent` with `IdentKey`

This is a continuation of https://github.com/rust-lang/rust/pull/150741 and https://github.com/rust-lang/rust/pull/150982 based on the ideas from https://github.com/rust-lang/rust/pull/151491#issuecomment-3784421866.

Before this PR `Macros20NormalizedIdent` was used as a key in various "identifier -> its resolution" maps in `rustc_resolve`.
`Macros20NormalizedIdent` is a newtype around `Ident` in which `SyntaxContext` (packed inside `Span`) is guaranteed to be normalized using `normalize_to_macros_2_0`.
This type is also used in a number of functions looking up identifiers in those maps.
`Macros20NormalizedIdent` still contains span locations, which are useless and ignored during hash map lookups and comparisons due to `Ident`'s special `PartialEq` and `Hash` impls.

This PR replaces `Macros20NormalizedIdent` with a new type called `IdentKey`, which contains only a symbol and a normalized unpacked syntax context. (E.g. `IdentKey` == `Macros20NormalizedIdent` minus span locations.)
So we avoid keeping additional data and doing some syntax context packing/unpacking.

Along with `IdentKey` you can often see `orig_ident_span: Span` being passed around.
This is an unnormalized span of the original `Ident` from which `IdentKey` was obtained.
It is not used in map keys, but it is used in a number of other scenarios:
- diagnostics
- edition checks
- `allow_unstable` checks

This is because `normalize_to_macros_2_0` normalization is lossy and the normalized spans / syntax contexts no longer contain parts of macro backtraces, while the original span contains everything.
2026-01-28 18:31:51 +00:00
Heath Dutton🕴️
f5f2ca0dc6 Improve move error diagnostic for AsyncFn closures
When an async closure captures a variable by move but is constrained to
`AsyncFn` or `AsyncFnMut`, the error message now explains that the
closure kind is the issue and points to the trait bound, similar to the
existing diagnostic for `Fn`/`FnMut` closures.
2026-01-28 13:19:05 -05:00
bors
1e5065a4d9 Auto merge of #150945 - scottmcm:tweak-slice-partial-eq, r=Mark-Simulacrum
Tweak `SlicePartialEq` to allow MIR-inlining the `compare_bytes` call

rust-lang/rust#150265 disabled this because it was a net perf win, but let's see if we can tweak the structure of this to allow more inlining on this side while still not MIR-inlining the loop when it's not just `memcmp` and thus hopefully preserving the perf win.

This should also allow MIR-inlining the length check, which was previously blocked, and thus might allow some obvious non-matches to optimize away as well.
2026-01-28 14:31:41 +00:00
reddevilmidzy
500dc3c9c0 Reorder tests/ui/README.md 2026-01-28 21:25:51 +09:00
reddevilmidzy
7e6d3a2976 Add section to tests/ui/README.md 2026-01-28 21:25:51 +09:00
bors
a234ae6b65 Auto merge of #151778 - Zalathar:rollup-A0breU3, r=Zalathar
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#151239 (Support trait objects in type info reflection)
 - rust-lang/rust#150893 (offload: move (un)register lib into global_ctors)
 - rust-lang/rust#151013 (Add some clarifications and fixes for fmt syntax)
 - rust-lang/rust#151666 (compiler: Rename several types/traits for per-query vtables)
 - rust-lang/rust#151738 (Add `extern crate core` to diagnostic tests)
 - rust-lang/rust#151747 (Update `askama` version to `0.15.2`)
 - rust-lang/rust#151759 (Update `browser-ui-test` version to `0.23.3`)
 - rust-lang/rust#151763 (Add FileCheck annotations to simplify_match.rs)
 - rust-lang/rust#151766 (Fix `x fix`, again)
2026-01-28 11:21:46 +00:00
Usman Akinyemi
9ca8ed38eb rustc_parse: improve the error diagnostic for "missing let in let chain"
Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
2026-01-28 16:47:41 +05:30