1966 Commits

Author SHA1 Message Date
Stuart Cook
633cc0cc6c
Rollup merge of #142681 - 1c3t3a:sanitize-off-on, r=rcvalle
Remove the `#[no_sanitize]` attribute in favor of `#[sanitize(xyz = "on|off")]`

This came up during the sanitizer stabilization (rust-lang/rust#123617). Instead of a `#[no_sanitize(xyz)]` attribute, we would like to have a `#[sanitize(xyz = "on|off")]` attribute, which is more powerful and allows to be extended in the future (instead
of just focusing on turning sanitizers off). The implementation is done according to what was [discussed on Zulip](https://rust-lang.zulipchat.com/#narrow/channel/343119-project-exploit-mitigations/topic/Stabilize.20the.20.60no_sanitize.60.20attribute/with/495377292)).

The new attribute also works on modules, traits and impl items and thus enables usage as the following:
```rust
#[sanitize(address = "off")]
mod foo {
    fn unsanitized(..) {}

    #[sanitize(address = "on")]
    fn sanitized(..) {}
}

trait MyTrait {
  #[sanitize(address = "off")]
  fn unsanitized_default(..) {}
}

#[sanitize(thread = "off")]
impl MyTrait for () {
    ...
}
```

r? ```@rcvalle```
2025-08-19 14:18:16 +10: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
Bastian Kersting
3ef065bf87 Implement the #[sanitize(..)] attribute
This change implements the #[sanitize(..)] attribute, which opts to
replace the currently unstable #[no_sanitize]. Essentially the new
attribute works similar as #[no_sanitize], just with more flexible
options regarding where it is applied. E.g. it is possible to turn
a certain sanitizer either on or off:
`#[sanitize(address = "on|off")]`

This attribute now also applies to more places, e.g. it is possible
to turn off a sanitizer for an entire module or impl block:
```rust
\#[sanitize(address = "off")]
mod foo {
    fn unsanitized(..) {}

    #[sanitize(address = "on")]
    fn sanitized(..) {}
}

\#[sanitize(thread = "off")]
impl MyTrait for () {
    ...
}
```

This attribute is enabled behind the unstable `sanitize` feature.
2025-08-18 08:30:00 +00:00
Sasha Pourcelot
51bccdd1ab Port #[custom_mir(..)] to the new attribute system 2025-08-15 11:19:29 +02:00
Jonathan Brouwer
5245c39972
Remove the old target checking logic 2025-08-14 18:18:42 +02:00
Jonathan Brouwer
106731f714
Improved Target type
- Added a few more variants which are needed for various attributes
- Previously a trait method with default block had the same target representation as a method in a `impl trait for` block, this has been changed (See `MethodKind`)
- Added `plural_name` for more precision on the form of the name
2025-08-14 18:11:47 +02:00
Guillaume Gomez
44d3217c20
Rollup merge of #145323 - scrabsha:push-pqwvmznzzmpr, r=jdonszelmann
Port the `#[linkage]` attribute to the new attribute system

r? `@jdonszelmann`
2025-08-14 11:39:39 +02:00
Guillaume Gomez
ad21c6d898
Rollup merge of #145266 - camsteffen:reduce-queries, r=petrochenkov
Reduce some queries around associated items
2025-08-14 11:39:38 +02:00
Sasha Pourcelot
d435197afc Port the #[linkage] attribute to the new attribute system 2025-08-13 21:01:37 +02:00
Cameron Steffen
d4eb0947f1 Cleanup assoc parent utils 2025-08-13 09:33:09 -05: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
Michael Goulet
2c0409c7e8 Remove unused must_use 2025-08-12 19:54:57 +00:00
bors
8e62bfd311 Auto merge of #144678 - jdonszelmann:no-mangle-extern, r=bjorn3
Make no_mangle on foreign items explicit instead of implicit

for a followup PR I'm working on I need some foreign items to mangle. I could add a new attribute: `no_no_mangle` or something silly like that but by explicitly putting `no_mangle` in the codegen fn attrs of foreign items we can default it to `no_mangle` and then easily remove it when we don't want it.

I guess you'd know about this r? `@bjorn3.` Shouldn't be too hard to review :)

Builds on rust-lang/rust#144655 which should merge first.
2025-08-12 16:20:24 +00:00
Stuart Cook
42af95b18e
Rollup merge of #145251 - tiif:support_trait, r=BoxyUwU
Support using #[unstable_feature_bound] on trait

This is needed to unblock https://github.com/rust-lang/rust/pull/145095

r? ```````@BoxyUwU```````
2025-08-12 20:37:55 +10:00
Stuart Cook
55cb4b294c
Rollup merge of #145214 - notJoon:fix/enable-self-assignment, r=petrochenkov
fix: re-enable self-assignment

## Description

Re-enables the self-assignment detection that was previously disabled due to unrelated regressions. The fix detects useless assignments like `x = x` and `foo.field = foo.field`.

## History

The original regressions (rust-lang/rust#81626, rust-lang/rust#81658) were specifically about false positives in write-only field detection, not self-assignment detection. Belows are brief history for the rule that I understand.

- Self-assignment detection was originally implemented in rust-lang/rust#87129 to address rust-lang/rust#75356
- The implementation was disabled alongside the revert of rust-lang/rust#81473's "write-only fields" detection
- rust-lang/rust#81473 was reverted via rust-lang/rust#86212 and rust-lang/rust#83171 due to false positives in write-only field detection (rust-lang/rust#81626, rust-lang/rust#81658)
- The self-assignment detection feature got removed, even though it wasn't the reason for the problems

This PR only re-enables the self-assignment checks, which are orthogonal to the problematic write-only field analysis.

## Changes
- Removed `#[allow(dead_code)]` from `compiler/rustc_passes/src/dead.rs` file
    - `handle_assign` and
    - `check_for_self_assign`
- Added `ExprKind::Assign` handling in `visit_expr` to call both methods
- Updated test expectations in `tests/ui/lint/dead-code/self-assign.rs`
2025-08-12 20:37:52 +10:00
Stuart Cook
9fd7702305
Rollup merge of #145155 - scrabsha:push-tkvwkolzooyq, r=jdonszelmann
Port `#[allow_internal_unsafe]` to the new attribute system (attempt 2)

This is a slightly modified version of ae1487aa9922de7642c448cc0908584026699e1c, which caused a performance regression (reverted in https://github.com/rust-lang/rust/pull/145086#issue-3303428759). The diff between this PR and the previous one can be seen in 027a1def.

r? ```````@jdonszelmann``````` 💖
2025-08-12 20:37:51 +10:00
Jana Dönszelmann
7aa8707639
make no_mangle explicit on foreign items 2025-08-12 12:07:14 +02:00
Cameron Steffen
bf266dc834 Propagate TraitImplHeader to hir 2025-08-11 17:05:42 -05:00
tiif
bcf87e4172 Update error message 2025-08-11 13:28:23 +00:00
tiif
d523b9f325 Support using #[unstable_feature_bound] on trait 2025-08-11 13:28:19 +00:00
Sasha Pourcelot
6603fe1caa Port #[allow_internal_unsafe] to the new attribute system (attempt 2) 2025-08-11 15:01:52 +02:00
Lee ByeongJun
ba350ff911 fix: re-enable self-assignment 2025-08-10 22:50:14 +09:00
bors
8712e45675 Auto merge of #144873 - cjgillot:implications, r=lqd
Implement `stability_implications` without a visitor.

Since https://github.com/rust-lang/rust/pull/143845, the `Annotator` visitor was a no-op when the crate is not staged_api. This PR avoids using a visitor altogether, making `stability_implications` truly a no-op in most cases.
2025-08-10 05:44:53 +00:00
Deadbeef
ad1113f87e remove P 2025-08-09 15:47:01 +08:00
Jana Dönszelmann
866bc26475
Revert "Port #[allow_internal_unsafe] to the new attribute system"
This reverts commit 4f7a6ace9e2f2192af7b5d32f4b1664189e0e143.
2025-08-08 11:54:20 +02:00
Trevor Gross
8f519761a5
Rollup merge of #144857 - scrabsha:push-pwtyrnmqkrtr, r=jdonszelmann
Port `#[allow_internal_unsafe]` to the new attribute system

Related to https://github.com/rust-lang/rust/issues/131229#issue-2565886367.

r? ````@jdonszelmann````
2025-08-07 19:36:35 -05:00
Sasha Pourcelot
4f7a6ace9e Port #[allow_internal_unsafe] to the new attribute system 2025-08-07 15:47:21 +02:00
Stuart Cook
995ca3e532
Rollup merge of #143808 - JonathanBrouwer:should_panic_parser, r=jdonszelmann
Port `#[should_panic]` to the new attribute parsing infrastructure

Ports `#[should_panic]` to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971351163

r? ```@jdonszelmann```
2025-08-07 20:49:40 +10:00
Jonathan Brouwer
f7ad4065fe
Port #[should_panic] to the new attribute parsing infrastructure
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-08-06 21:37:51 +02:00
Guillaume Gomez
96a41c5aba
Rollup merge of #144794 - scrabsha:push-noqrrttovmwy, r=jdonszelmann
Port `#[coroutine]` to the new attribute system

Related to https://github.com/rust-lang/rust/issues/131229#issue-2565886367.

r? `````@jdonszelmann`````
2025-08-06 21:29:27 +02:00
bors
ec7c026125 Auto merge of #144863 - cjgillot:live-or-dead, r=Urgau
Simplify dead code lint

This PR scratches a few itches I had when looking at that code.

The perf improvement comes from keeping the `scanned` set through several marking phases. This pretty much divides by 2 the number of HIR traversals.
2025-08-05 18:10:21 +00:00
Camille GILLOT
d0da6ca110 Update doc-comment. 2025-08-04 23:02:27 +00:00
Camille GILLOT
e0a89c4b14 Simplify maybe_record_as_seed. 2025-08-04 23:00:45 +00:00
Sasha Pourcelot
904e2af3a9 Port #[coroutine] to the new attribute system
Related to https://github.com/rust-lang/rust/issues/131229#issue-2565886367.
2025-08-04 18:37:40 +02:00
Camille GILLOT
36f2045a93 Implement stability_implications without a visitor. 2025-08-03 22:05:37 +00:00
Camille GILLOT
effc509b40 Simplify lint emission. 2025-08-03 02:48:58 +00:00
Camille GILLOT
377728a404 Keep scanned set across calls to mark_live_symbols. 2025-08-03 02:09:55 +00:00
Camille GILLOT
f601717c5b Use less HIR when seeding work list. 2025-08-03 02:04:58 +00:00
Camille GILLOT
6c39b30f80 Simplify handling of unsolved items. 2025-08-03 02:04:26 +00:00
Camille GILLOT
99ee62305a Remove struct_constructors. 2025-08-03 01:44:20 +00:00
Camille GILLOT
aba0b65707 Use DefKind in should_explore. 2025-08-02 22:42:54 +00:00
Camille GILLOT
bc177055f7 Do not record derived impl def-id for dead code. 2025-08-02 19:19:17 +00:00
bjorn3
ae2f8d9216 Remove the omit_gdb_pretty_printer_section attribute
Disabling loading of pretty printers in the debugger itself is more
reliable. Before this commit the .gdb_debug_scripts section couldn't be
included in dylibs or rlibs as otherwise there is no way to disable the
section anymore without recompiling the entire standard library.
2025-08-01 20:04:59 +00:00
Jana Dönszelmann
e1d3ad89c7
remove rustc_attr_data_structures 2025-07-31 14:19:27 +02:00
Cameron Steffen
b43164cef6 Rename impl_of_method -> impl_of_assoc 2025-07-28 09:54:53 -05:00
Cameron Steffen
172af038a7 Rename trait_of_item -> trait_of_assoc 2025-07-28 09:53:50 -05:00
bors
d242a8bd5a Auto merge of #144469 - Kivooeo:chains-cleanup, r=SparrowLii
Some `let chains` clean-up

Not sure if this kind of clean-up is welcoming because of size, but I decided to try out one

r? compiler
2025-07-28 05:25:23 +00:00
Kivooeo
b8eb046e6e use let chains in mir, resolve, target 2025-07-28 06:10:36 +05:00
Jonathan Brouwer
c4e7cb806c
Implement check_attr 2025-07-26 20:25:39 +02:00
León Orell Valerian Liehr
404f904f76
Rollup merge of #143374 - cjgillot:bare-extern-crate-map, r=petrochenkov
Unquerify extern_mod_stmt_cnum.

Based on https://github.com/rust-lang/rust/pull/143247
r? `````@ghost````` for perf
2025-07-24 15:08:19 +02:00