3031 Commits

Author SHA1 Message Date
Matthias Krüger
149ad71e05 Rollup merge of #144291 - oli-obk:const_trait_alias, r=fee1-dead
Constify trait aliases

Allow `const trait Foo = Bar + [const] Baz;` trait alias declarations. Their rules are the same as with super traits of const traits. So `[const] Baz` or `const Baz` is only required for `[const] Foo` or `const Foo` bounds respectively.

tracking issue rust-lang/rust#41517 (part of the general trait alias feature gate, but I can split it out into a separate const trait alias feature gate. I just assumed that const traits would stabilize before trait aliases, and we'd want to stabilize trait aliases together with const trait aliases at the same time)

r? ``@compiler-errors`` ``@fee1-dead``
2025-10-31 02:39:14 +01:00
bors
6906167e01 Auto merge of #148193 - camsteffen:remove-qpath-langitem, r=cjgillot
Remove `QPath::LangItem`

Closes rust-lang/rust#115178.

r? cjgillot
2025-10-30 10:04:21 +00:00
bors
907705abea Auto merge of #148208 - camsteffen:assign-desugar-span, r=wesleywiser
Remove unused `AssignDesugar` span
2025-10-29 01:59:52 +00:00
Cameron Steffen
a45c6dd2c0 Remove AssignDesugar span 2025-10-28 11:18:58 -05:00
Oli Scherer
3ca752f979 Trait aliases are rare large ast nodes, box them 2025-10-28 11:11:56 +00:00
Stuart Cook
ef8003bbb9 Rollup merge of #147185 - RalfJung:repr-c-not-zst, r=petrochenkov
repr(transparent): do not consider repr(C) types to be 1-ZST

Context: https://github.com/rust-lang/unsafe-code-guidelines/issues/552

This experiments with a [suggestion](https://github.com/rust-lang/rfcs/pull/3845#discussion_r2388463698) by ```@RustyYato``` to stop considering repr(C) types as 1-ZST for the purpose of repr(transparent). If we go with https://github.com/rust-lang/rfcs/pull/3845 (or another approach for fixing repr(C)), they will anyway not be ZST on all targets any more, so this removes a portability hazard. Furthermore, zero-sized repr(C) structs [may have to be treated](https://github.com/rust-lang/unsafe-code-guidelines/issues/552#issuecomment-3250657813) as non-ZST for the win64 ABI (at least that's what gcc/clang do), so allowing them to be ignored in repr(transparent) types is not entirely coherent.

Turns out we already have an FCW for repr(transparent), namely https://github.com/rust-lang/rust/issues/78586. This extends that lint to also check for repr(C).
2025-10-28 20:39:32 +11:00
Cameron Steffen
ead5e120a5 Remove QPath::LangItem 2025-10-27 21:19:38 -05:00
Cameron Steffen
e289f27329 Remove QPath::LangItem from for loops 2025-10-27 20:35:55 -05:00
Ralf Jung
b9b29c4379 repr(transparent): do not consider repr(C) types to be 1-ZST 2025-10-27 19:25:14 +01:00
bors
23fced0fcc Auto merge of #146069 - camsteffen:range-desugar-span, r=SparrowLii
Mark desugared range expression spans with DesugaringKind::RangeExpr

This is a prerequisite to removing `QPath::LangItem` (rust-lang/rust#115178) because otherwise there would be no way to detect a range expression in the HIR.

There are some non-obvious Clippy changes so a Clippy team review would be good.
2025-10-27 02:50:35 +00:00
bors
4d94478977 Auto merge of #147826 - Muscraft:update-typos, r=Noratrieb
Update typos

I saw that `typos` was a few versions out of date and figured it would be a good idea to update it. Upgrading to `1.38.1` adds the [July](https://github.com/crate-ci/typos/issues/1331), [August](https://github.com/crate-ci/typos/issues/1345), and [September](https://github.com/crate-ci/typos/issues/1370) dictionary updates. As part of this change, I also sorted the configuration file.
2025-10-22 13:11:47 +00:00
Cameron Steffen
3bdf45f7db Mark range expr with desugaring 2025-10-21 10:04:34 -05:00
Oli Scherer
ad4bd083f3 Add not-null pointer patterns to pattern types 2025-10-21 11:22:51 +00:00
Scott Schafer
12f6b9697f chore: Update typos to 1.38.1 2025-10-20 12:20:15 -06:00
Stuart Cook
061f854d07 Rollup merge of #147382 - joshtriplett:unused-must-use-ignore-result-unit-uninhabited, r=fmease
unused_must_use: Don't warn on `Result<(), Uninhabited>` or `ControlFlow<Uninhabited, ()>`

This suppresses warnings on things like `Result<(), !>`, which helps simplify code using the common pattern of having an `Error` associated type: code will only have to check the error if there is a possibility of error.

This will, for instance, help with future refactorings of `write!` in the standard library.

As this is a user-visible change to lint behavior, it'll require a lang FCP.

---

My proposal, here, is that we handle this simple case to make common patterns more usable. This does not rule out the possibility of adding more cases in the future, including general trait-based cases. However, I don't think we should make this common case wait on the more general cases. In particular, this solution does not close any doors on replacing this special case with a general case.

This would unblock some planned work in the standard library to make `write!` more usable for infallible cases (e.g. writing into a `Vec` or `String`).
2025-10-20 16:12:54 +11:00
Matthias Krüger
8f11852e78 Rollup merge of #138679 - Shunpoco:issue-125323, r=oli-obk
Issue-125323: ICE non-ADT in struct pattern when long time constant evaluation is in for loop

This PR fixes #125323

## Context
According to the issue, the ICE happens since #121206.
In the PR, some error methods were reorganized. For example, has_errors() was renamed to has_errors_exclude_lint_errors(). However, some codes which used the original has_errors() were not switched to has_errors_exclude_lint_errors(). I finally found that report_error() in writeback.rs causes this ICE. Currently the method uses tainted_by_errors() to get guar (ErrorGuaranteed), but originally it used dcx().has_errors() but it wasn't changed to has_errors_exclude_lint_errors() when changes in #121206 were merged. I don't think I fully understand how an error is propagated, but I suppose that the error from long time constant evaluation is unexpectedly propagated other parts (in this ICE, for loop), then cause the non-ADT in struct pattern ICE.

## Change
- Fix report_error() in writeback.rs: use dcx().has_errors_exclude_lint_errors() instead of tainted_by_errors() to prevent error propagation from constant evaluation.
- Add test for the ICE
- Modify some tests to align the change: Due to this fix, E0282 error happens (or not happen anymore) in some tests.

## NOTE
The 4th commit aims to revert the fix in #123516 because I confirmed that the ICE solved by the PR doesn't happen if I modify report_error(). I think the root cause of that ICE is the same as #125323 . But I can discard this commit since we can fix #125323 without it.
2025-10-18 23:54:43 +02:00
Matthias Krüger
32d21cb0b2 Rollup merge of #146509 - RalfJung:res-opt-layout-guarantees, r=traviscross
Result/Option layout guarantee clarifications

- It seems worth spelling out that this guarantee allows particular transmutes.
- After the `Result` section was written, the `Option` section it referenced gained *more* guarantees, saying that `None` is represented as `[0u8; N]`. Those guarantees were not meant to apply to `Result`. Make the `Result` section more self-contained to make this more clear.
- "Type has no fields" is unclear since there is no general definition of what the fields of some arbitrary type are. Replace that by a more accurate description of the actual check implemented [here](e379c77586/compiler/rustc_lint/src/types.rs (L828-L838)).

r? `@traviscross`
2025-10-18 15:09:02 +02:00
bors
32892a37b4 Auto merge of #146913 - camsteffen:refactor-lint-syntax, r=fee1-dead
mismatched_lifetime_syntax lint refactors and optimizations

I found several opportunities to return early so I'm hoping those will have a perf improvement. Otherwise, it's various refactors for simplicity.
2025-10-18 03:18:09 +00:00
Ralf Jung
781432e355 clarify 'no fields' 2025-10-17 23:18:14 +00:00
Shunpoco
8e59e3ba33 treat an error taint from const eval lint in late_lint and check_mod_deathness
error from const eval lint causes ICE at check_pat in late_lint, because the function expects the typeck result isn't tainted by error but it is.
To avoid the ICE, check_pat returns earlier if the typeck_result is tainted.

check_mod_deathness also has an issue from the same reason. visit_body for making live symbols expects the typeck result has no error.
So this commit adds a check in visit_nested_body to avoid the ICE.
However, if visit_nested_body just returns without doing anything, all codes with the error are marked as dead, because live_symbols is empty.
To avoid this side effect, visit_nested_body and other visit_* functions in MarkSymbolVistior should return appropriate error.
If a function returns ControlFlow::Break, live_symbols_and_ignore_derived_traits returns earlier with error,
then check_mod_deathness, the caller of the function returns earlier without pushing everything into dead_codes.
2025-10-17 18:20:21 +01:00
Cameron Steffen
9b2c9a8c5b Refactor default_could_be_derived 2025-10-17 08:36:34 -05:00
Matthias Krüger
c607de5508 Rollup merge of #147676 - jdonszelmann:span-is-doc-comment, r=GuillaumeGomez
Return spans out of `is_doc_comment` to reduce reliance on `.span()` on attributes

r? `@GuillaumeGomez`
2025-10-15 23:41:03 +02:00
bors
28d0a4a205 Auto merge of #143548 - Diggsey:db-limit-extern-crate-usage, r=oli-obk
Restrict sysroot crate imports to those defined in this repo.

It's common to import dependencies from the sysroot via `extern crate` rather than use an explicit cargo dependency, when it's necessary to use the same dependency version as used by rustc itself. However, this is dangerous for crates.io crates, since rustc may not pull in the dependency on some targets, or may pull in multiple versions. In both cases, the `extern crate` fails to resolve.

To address this, re-export all such dependencies from the appropriate `rustc_*` crates, and use this alias from crates which would otherwise need to use `extern crate`.

See https://github.com/rust-lang/rust/pull/143492 for an example of the kind of issue that can occur.
2025-10-15 13:32:03 +00:00
Diggory Blake
c6a952159f Restrict sysroot crate imports to those defined in this repo.
It's common to import dependencies from the sysroot via `extern crate`
rather than use an explicit cargo dependency, when it's necessary to use
the same dependency version as used by rustc itself. However, this is
dangerous for crates.io crates, since rustc may not pull in the
dependency on some targets, or may pull in multiple versions. In both
cases, the `extern crate` fails to resolve.

To address this, re-export all such dependencies from the appropriate
`rustc_*` crates, and use this alias from crates which would otherwise
need to use `extern crate`.
2025-10-15 13:17:25 +01:00
Matthias Krüger
783307c4c3 Rollup merge of #147677 - jdonszelmann:fewer-span-exceptions, r=WaffleLapkin
Fewer exceptions in `span()` on parsed attributes

r? ``@JonathanBrouwer``
2025-10-14 19:47:33 +02:00
Jana Dönszelmann
7a368c8abb Use span from parsed attribute 2025-10-14 16:17:36 +02:00
Jana Dönszelmann
3941b42993 return spans out of is_doc_comment to reduce reliance on .span() on attrs 2025-10-14 15:36:09 +02:00
yukang
d658bcfdfe Suppress unused_parens for labeled break 2025-10-14 12:32:51 +08:00
Josh Triplett
7aa7ecc982 Factor out a helper function to check if a type is uninhabited 2025-10-10 13:13:49 -07:00
Josh Triplett
39f59bf6a2 unused_must_use: Suppress warnings for ControlFlow<Uninhabited, ()> too 2025-10-10 13:09:49 -07:00
Josh Triplett
6f89cecf37 unused_must_use: Don't warn on Result<(), Uninhabited>
This suppresses warnings on things like `Result<(), !>`, which helps
simplify code using the common pattern of having an `Error` associated
type: code will only have to check the error if there is a possibility
of error.
2025-10-10 13:09:46 -07:00
Stuart Cook
9ace0de26b Rollup merge of #147489 - chenyukang:yukang-prefer-repeat-n, r=Kivooeo,oli-obk
Prefer to use repeat_n over repeat().take()

More from https://github.com/rust-lang/rust/pull/147464, but batch processed with `ast-grep` to find and replace.

second commit add notes for library: affaf532f9

r? ``@RalfJung``
2025-10-09 18:43:26 +11:00
yukang
1654cce210 prefer to use repeat_n over repeat and take 2025-10-09 01:24:55 +08:00
Boxy Uwu
8e9b0c4ca9 rename select_where_possible and select_all_or_error 2025-10-07 23:02:23 +01:00
bors
4fa824bb78 Auto merge of #147375 - folkertdev:power-align-union, r=RalfJung
ignore power alignment rule on unions

fixes https://github.com/rust-lang/rust/issues/147348

The power alignment rule only applies to the non-first field of a struct, and so should not apply to unions at all.

The current code also does not consider enums (whose fields might be, morally, structs). Given that C does not actually have ADTs like this it's probably fine from a compatibility perspective, but I'll leave that to the powerpc folks.

cc `@daltenty` `@gilamn5tr`
r? compiler
2025-10-05 22:14:55 +00:00
Josh Triplett
2997070be1 unused_must_use: Factor out a variable for the parent module DefId
This simplifies the initial conditional, and will allow reusing the
variable in subsequent checks.
2025-10-05 10:23:44 -07:00
bors
981353ca16 Auto merge of #147345 - Kivooeo:tidy-flt-fix, r=Kobzol
Tidy: revert `flt` to `ftl`

As was explained here https://github.com/rust-lang/rust/pull/147191#issuecomment-3353801210, this reverting this change because `flt` is incorrect format

Also maybe there is existed PR for that? I didn't found one

Follow up https://github.com/rust-lang/rust/pull/147191

cc `@GuillaumeGomez`
2025-10-05 15:55:18 +00:00
Folkert de Vries
5a0ea3bfba power align: ignore repr(C) unions and enums 2025-10-05 14:18:17 +02:00
Cameron Steffen
f0eea4cc4f LifetimeSyntax little things 2025-10-04 13:41:49 -05:00
Cameron Steffen
ba5a42b48b LifetimeSyntax tweak data structure 2025-10-04 13:41:49 -05:00
Cameron Steffen
c915c989f6 Eagerly evaluate lifetime syntax category 2025-10-04 13:41:49 -05:00
Cameron Steffen
775b893b5c Use ty reference 2025-10-04 13:40:44 -05:00
Kivooeo
67bc030833 change flt back to ftl 2025-10-04 18:18:58 +00:00
Deadbeef
a5c9030271 Extract common logic for iterating over features
Two places doing the same thing is enough to motivate me to extract this to a method :)
2025-10-02 21:43:14 +00:00
Jonathan Brouwer
6abcadc235 Port #[macro_export] to the new attribute parsing infrastructure
Co-authored-by: Anne Stijns <anstijns@gmail.com>
2025-09-21 10:42:47 -04:00
Stuart Cook
540fd20ba6 Rollup merge of #146664 - fmease:clean-up-dyn, r=jdonszelmann
Clean up `ty::Dynamic`

1. As a follow-up to PR rust-lang/rust#143036, remove `DynKind` entirely.
2. Inside HIR ty lowering, consolidate modules `dyn_compatibility` and `lint` into `dyn_trait`
   * `dyn_compatibility` wasn't about dyn compatibility itself, it's about lowering trait object types
   * `lint` contained dyn-Trait-specific diagnostics+lints only
2025-09-18 11:48:51 +10:00
León Orell Valerian Liehr
26f3337d4e Remove DynKind 2025-09-17 04:46:46 +02:00
bors
a9d0a6f155 Auto merge of #138271 - mu001999-contrib:fix-138234, r=jackh726
Keep space if arg does not follow punctuation when lint unused parens

Fixes rust-lang/rust#138234

If the arg follows punctuation, still pass `left_pos` with `None` and no space will be added, else then pass `left_pos` with `Some(arg.span.lo())`, so that we can add the space as expected.

And `emit_unused_delims` can make sure no more space will be added if the expr follows space.

---

Edited:

Directly use the `value_span` to check whether the expr removed parens will follow identifier or be followed by identifier.
2025-09-16 18:43:49 +00:00
Mu001999
9991ec282f Keep space if expr follows identifier when lint unused parens 2025-09-16 11:31:59 +00:00
León Orell Valerian Liehr
ec7ad59789 Move more early buffered lints to dyn lint diagnostics (4/N) 2025-09-14 12:38:12 +02:00