684 Commits

Author SHA1 Message Date
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
Ralf Jung
b9b29c4379 repr(transparent): do not consider repr(C) types to be 1-ZST 2025-10-27 19:25:14 +01:00
Waffle Lapkin
08b4323bad remove useless #![deny]s 2025-10-19 19:48:21 +02:00
Waffle Lapkin
82b0cd8bee deny never type lints by default 2025-10-17 11:46:25 +02:00
dianne
ec99e3eca2 clarify wording of match ergonomics diagnostics 2025-10-08 02:12:24 -07:00
Mark Rousskov
201f299ef6 Apply cfg(bootstrap) replacement 2025-09-26 19:09:23 -04: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
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
León Orell Valerian Liehr
27a180a31a Move more early buffered lints to dyn lint diagnostics (3/N) 2025-09-14 12:38:12 +02:00
León Orell Valerian Liehr
379b181fe6 Remove a dead early lint
Dropped in favor a hard error in RUST-127907.
2025-09-14 12:38:11 +02:00
León Orell Valerian Liehr
31c0d96cb6 Move more early buffered lints to dyn lint diagnostics (2/N) 2025-09-14 12:38:11 +02:00
León Orell Valerian Liehr
2e816736ef Move more early buffered lints to dyn lint diagnostics (1/N) 2025-09-14 12:38:11 +02:00
Stuart Cook
f90cc353b8 Rollup merge of #145932 - JamieCunliffe:target-feature-inlining, r=jackh726
Allow `inline(always)` with a target feature behind a unstable feature `target_feature_inline_always`.

Rather than adding the inline always attribute to the function definition, we add it to the callsite. We can then check that the target features match and that the call would be safe to inline. If the function isn't inlined due to a mismatch, we emit a warning informing the user that the function can't be inlined due to the target feature mismatch.

See tracking issue rust-lang/rust#145574
2025-09-04 10:01:55 +10:00
Jakub Beránek
9de09ac101 Fix stage 1 compiler tests 2025-08-30 15:28:41 +02:00
James Barford-Evans
bcfc9b5073 inline at the callsite & warn when target features mismatch
Co-authored-by: Jamie Cunliffe <Jamie.Cunliffe@arm.com>
2025-08-27 14:45:01 +01:00
Josh Triplett
52fadd8f96 Migrate BuiltinLintDiag::HiddenUnicodeCodepoints to use LintDiagnostic directly 2025-08-22 03:01:35 -07:00
Josh Triplett
863387ca6a Remove unused BuiltinLintDiag variant InnerAttributeUnstable
This variant doesn't appear to have ever been used.

There's a matching message in `rustc_resolve`, that used to have a FIXME
for porting it to the new diagnostic infrastructure, but that message is
using `feature_err`, which doesn't use buffered lints. Thus, even when
that does get ported, it won't use `BuiltinLintDiag`.
2025-08-22 02:14:21 -07:00
Josh Triplett
690a5782f8 Migrate BuiltinLintDiag::MissingAbi to use LintDiagnostic directly 2025-08-22 02:01:01 -07:00
Josh Triplett
b5c714cfc1 Migrate BuiltinLintDiag::UnexpectedBuiltinCfg to use LintDiagnostic directly 2025-08-22 02:01:01 -07:00
Josh Triplett
c99320156d Refactor lint buffering to avoid requiring a giant enum
Lint buffering currently relies on a giant enum `BuiltinLintDiag`
containing all the lints that might potentially get buffered. In
addition to being an unwieldy enum in a central crate, this also makes
`rustc_lint_defs` a build bottleneck: it depends on various types from
various crates (with a steady pressure to add more), and many crates
depend on it.

Having all of these variants in a separate crate also prevents detecting
when a variant becomes unused, which we can do with a dedicated type
defined and used in the same crate.

Refactor this to use a dyn trait, to allow using `LintDiagnostic` types
directly.

This requires boxing, but all of this is already on the slow path
(emitting an error).

Because the existing `BuiltinLintDiag` requires some additional types in
order to decorate some variants, which are only available later in
`rustc_lint`, use an enum `DecorateDiagCompat` to handle both the `dyn
LintDiagnostic` case and the `BuiltinLintDiag` case.
2025-08-22 01:59:56 -07:00
Josh Triplett
f0c8f7062b rustc_lint_defs: Eliminate the dependency on rustc_hir for Namespace
`rustc_lint_defs` uses `rustc_hir` solely for the `Namespace` type,
which it only needs the static description from. Use the static
description directly, to eliminate the dependency on `rustc_hir`.

This reduces a long dependency chain:
- Many things depend on `rustc_errors`
- `rustc_errors` depends on `rustc_lint_defs`
- `rustc_lint_defs` depended on `rustc_hir` prior to this commit
- `rustc_hir` depends on `rustc_target`
2025-08-20 15:04:00 -07:00
Josh Triplett
6cb9dd563c rustc_lint_defs: Use DefPathHash from rustc_span rather than rustc_hir 2025-08-20 15:04:00 -07:00
Josh Triplett
f3c8b7ad40 Split rustc_hir_id out of rustc_hir
Some crates depend on `rustc_hir` but only want `HirId` and similar id
types. `rustc_hir` is a heavy dependency, since it pulls in
`rustc_target`. Split these types out into their own crate
`rustc_hir_id`.

This allows `rustc_errors` to drop its direct dependency on `rustc_hir`.

(`rustc_errors` still depends on `rustc_hir` indirectly through
`rustc_lint_defs`; a subsequent commit will fix that.)
2025-08-20 15:01:13 -07:00
Josh Triplett
b65fab6299 Move IntoDiagArg earlier in the dependency chains
`rustc_errors` depends on numerous crates, solely to implement its
`IntoDiagArg` trait on types from those crates. Many crates depend on
`rustc_errors`, and it's on the critical path.

We can't swap things around to make all of those crates depend on
`rustc_errors` instead, because `rustc_errors` would end up in
dependency cycles.

Instead, move `IntoDiagArg` into `rustc_error_messages`, which has far
fewer dependencies, and then have most of these crates depend on
`rustc_error_messages`.

This allows `rustc_errors` to drop dependencies on several crates,
including the large `rustc_target`.

(This doesn't fully reduce dependency chains yet, as `rustc_errors`
still depends on `rustc_hir` which depends on `rustc_target`. That will
get fixed in a subsequent commit.)
2025-08-20 15:01:13 -07:00
Bastian Kersting
95bdb34494 Remove the no_sanitize attribute in favor of sanitize
This removes the #[no_sanitize] attribute, which was behind an unstable
feature named no_sanitize. Instead, we introduce the sanitize attribute
which is more powerful and allows to be extended in the future (instead
of just focusing on turning sanitizers off).

This also makes sanitize(kernel_address = ..) attribute work with
-Zsanitize=address

To do it the same as how clang disables address sanitizer, we now
disable ASAN on sanitize(kernel_address = "off") and KASAN on
sanitize(address = "off").

The same was added to clang in https://reviews.llvm.org/D44981.
2025-08-18 08:45:28 +00:00
Stuart Cook
44eb7a167c Rollup merge of #144865 - WaffleLapkin:track-tail, r=lqd
Fix tail calls to `#[track_caller]` functions

We want `#[track_caller]` to be semver independent, i.e. it should not be a breaking change to add or remove it. Since it changes ABI of a function (adding an additional argument) we have to be careful to preserve this property when adding tail calls.

The only way to achieve this that I can see is:
- we forbid tail calls in functions which are marked with `#[track_caller]` (already implemented)
- tail-calling a `#[track_caller]` marked function downgrades the tail-call to a normal call (or equivalently tail-calls the shim made by fn def to fn ptr cast) (this pr)

Ideally the downgrade would be performed by a MIR pass, but that requires post mono MIR opts (cc ```@saethlin,``` rust-lang/rust#131650). For now I've changed code in cg_ssa to accomodate this behaviour (+ added a hack to mono collector so that the shim is actually generated)

Additionally I added a lint, although I don't think it's strictly necessary.

Alternative to rust-lang/rust#144762 (and thus closes rust-lang/rust#144762)
Fixes https://github.com/rust-lang/rust/issues/144755
2025-08-15 16:16:31 +10:00
Jakub Beránek
c2bc9265f0 Rollup merge of #145274 - compiler-errors:unused-must-use, r=fmease
Remove unused `#[must_use]`

Self-explanatory

Fixes https://github.com/rust-lang/rust/issues/145257
2025-08-13 07:03:49 +02:00
Waffle Lapkin
85d1c89e0f fix tail calls to #[track_caller] functions 2025-08-13 02:26:52 +02:00
Michael Goulet
2c0409c7e8 Remove unused must_use 2025-08-12 19:54:57 +00:00
Esteban Küber
625143bac3 Add link to docs on malformed attributes 2025-08-11 16:00:49 +00:00
Jonathan Brouwer
b2b4bd41fa Start reporting future breakage for ILL_FORMED_ATTRIBUTE_INPUT in dependencies
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-08-10 10:48:08 +02:00
Stuart Cook
238e3bf9e9 Rollup merge of #144369 - joshtriplett:mbe-expr-semi-deny-by-default, r=petrochenkov
Upgrade semicolon_in_expressions_from_macros from warn to deny

This is already warn-by-default, and a future compatibility warning (FCW) that warns in dependencies. Upgrade it to deny-by-default, as the next step towards hard error.

Per https://github.com/rust-lang/rust/issues/79813#issuecomment-3109105631
2025-08-07 20:49:43 +10:00
Vadim Petrochenkov
33cb4190a2 Mark all deprecation lints in name resolution as deny-by-default and report-in-deps 2025-08-05 15:28:49 +03:00
Ralf Jung
0cc4be268e add unsupported_calling_conventions to lint list 2025-08-01 09:47:47 +02:00
León Orell Valerian Liehr
940376f1b1 Rollup merge of #144014 - dianne:edition-guide-links, r=estebank
don't link to the nightly version of the Edition Guide in stable lints

As reported in rust-lang/rust#143557 for `rust_2024_incompatible_pat`, most future-Edition-incompatibility lints link to the nightly version of the Edition Guide; the lints were written before their respective Editions (and their guides) stabilized. But now that Rusts 2021 and 2024 are stable, these lints are emitted on stable versions of the compiler, where it makes more sense to present users with links that don't say "nightly" in them.

This does not change the link for `rust_2024_incompatible_pat`. That's handled in rust-lang/rust#144006.
2025-07-24 15:08:21 +02:00
Josh Triplett
288a565451 Upgrade semicolon_in_expressions_from_macros from warn to deny
This is already warn-by-default, and a future compatibility warning
(FCW) that warns in dependencies. Upgrade it to deny-by-default, as the
next step towards hard error.
2025-07-23 09:14:12 -07:00
dianne
41e6f767b6 future-incompat lints: don't link to the nightly edition-guide version 2025-07-16 01:44:02 -07:00
David Mládek
8b868fa534 Implement resolver warnings about reexporting private dependencies 2025-07-15 15:44:25 +02:00
bors
b1d2f2c64c Auto merge of #140717 - mejrs:diagnostic_lints, r=oli-obk
Split up the `unknown_or_malformed_diagnostic_attributes` lint

This splits up the lint into the following lint group:
- `unknown_diagnostic_attributes` - triggers if the attribute is unknown to the current compiler
- `misplaced_diagnostic_attributes` - triggers if the attribute exists but it is not placed on the item kind it's meant for
- `malformed_diagnostic_attributes` - triggers if the attribute's syntax or options are invalid
- `malformed_diagnostic_format_literals` - triggers if the format string literal is invalid, for example if it has unpaired curly braces or invalid parameters
- this pr doesn't create it, but future lints for things like deprecations can also go here.

This PR does not start emitting lints in places that previously did not.

## Motivation

I want to have finer control over what `unknown_or_malformed_diagnostic_attributes` does

I have a project with fairly low msrv that is/will have a lower msrv than future diagnostic attributes. So lints will be emitted when I or others compile it on a lower msrv.

At this time, there are two options to silence these lints:

-  `#[allow(unknown_or_malformed_diagnostic_attributes)]` - this risks diagnostic regressions if I (or others) mess up using the attribute, or if the attribute's syntax ever changes.
- write a build script to detect the compiler version and emit cfgs, and then conditionally enable the attribute:
    ```rust
    #[cfg_attr(rust_version_99, diagnostic::new_attr_in_rust_99(thing = ..))]`
    struct Foo;
    ```
    or conditionally `allow`  the lint:
    ```rust
   // lib.rs
   #![cfg_attr(not(current_rust), allow(unknown_or_malformed_diagnostic_attributes))]
   ```

I like to avoid using build scripts if I can, so the following works much better for me. That is what this PR will let me do in the future:
```rust
    #[allow(unknown_diagnostic_attribute, reason = "attribute came out in rust 1.99 but msrv is 1.70")]
    #[diagnostic::new_attr_in_rust_99(thing = ..)]`
    struct Foo;
2025-07-13 01:11:56 +00:00
mejrs
a7bf5c4fa2 Split up the unknown_or_malformed_diagnostic_attributes lint 2025-07-11 01:24:24 +02:00
Trevor Gross
6bcc39c7fe Rollup merge of #143011 - LorrensP-2158466:warn-ambiguity-into-error, r=petrochenkov
Make lint `ambiguous_glob_imports` deny-by-default and report-in-deps

This pr aims to finish the second part of rust-lang/rust#114095. It converts the `ambiguous_glob_imports` lint from a warning to an error.

Currently, only the lint definition and the related tests are changed, a crater run should provide us with information on whether we should go for this.
2025-07-10 03:23:53 -04:00
klensy
c76d032f01 setup CI and tidy to use typos for spellchecking and fix few typos 2025-07-03 10:51:06 +03:00
Folkert de Vries
1dfc8406dc make tidy-alphabetical use a natural sort 2025-06-25 22:52:38 +02:00
LorrensP-2158466
9624046977 deny AMBIGUOUS_GLOB_IMPORTS; tests fail in this commit 2025-06-25 15:40:18 +02:00
Jubilee Young
b34c52043f compiler: Remove unsupported_fn_ptr_calling_conventions lint 2025-06-23 09:39:59 -07:00
León Orell Valerian Liehr
8b35ae3a22 Rollup merge of #141937 - WaffleLapkin:never-report-in-deps, r=oli-obk,traviscross
Report never type lints in dependencies

This PR marks never type lints (`never_type_fallback_flowing_into_unsafe` & `dependency_on_unit_never_type_fallback`) to be included in cargo's reports / to be emitted when they happen in dependencies.

This PR is based on rust-lang/rust#141936
r? oli-obk
2025-06-15 23:51:55 +02:00
bjorn3
3e944fa391 Remove all support for wasm's legacy ABI 2025-06-14 09:57:06 +00:00
bors
8da623945f Auto merge of #142443 - matthiaskrgr:rollup-l1l6d0v, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#128425 (Make `missing_fragment_specifier` an unconditional error)
 - rust-lang/rust#135927 (retpoline and retpoline-external-thunk flags (target modifiers) to enable retpoline-related target features)
 - rust-lang/rust#140770 (add `extern "custom"` functions)
 - rust-lang/rust#142176 (tests: Split dont-shuffle-bswaps along opt-levels and arches)
 - rust-lang/rust#142248 (Add supported asm types for LoongArch32)
 - rust-lang/rust#142267 (assert more in release in `rustc_ast_lowering`)
 - rust-lang/rust#142274 (Update the stdarch submodule)
 - rust-lang/rust#142276 (Update dependencies in `library/Cargo.lock`)
 - rust-lang/rust#142308 (Upgrade `object`, `addr2line`, and `unwinding` in the standard library)

Failed merges:

 - rust-lang/rust#140920 (Extract some shared code from codegen backend target feature handling)

r? `@ghost`
`@rustbot` modify labels: rollup

try-job: aarch64-apple
try-job: x86_64-msvc-1
try-job: x86_64-gnu
try-job: dist-i586-gnu-i586-i686-musl
try-job: test-various
2025-06-13 17:44:15 +00:00
Trevor Gross
841f7ce69a Make missing_fragment_specifier an unconditional error
This was attempted in [1] then reverted in [2] because of fallout.
Recently, this was made an edition-dependent error in [3].

Make missing fragment specifiers an unconditional error again.

[1]: https://github.com/rust-lang/rust/pull/75516
[2]: https://github.com/rust-lang/rust/pull/80210
[3]: https://github.com/rust-lang/rust/pull/128006
2025-06-12 07:57:12 +00:00
Jubilee Young
86493f75a5 compiler: Avoid reporting unsupported_calling_conventions in deps 2025-06-11 09:55:41 -07:00