Commit graph

22240 commits

Author SHA1 Message Date
Stuart Cook
0a712d2b14
Rollup merge of #147115 - cezarbbb:stable_ssp, r=SparrowLii
More robust stack protector testing

I've added some tests related to the stack protector. These tests were originally in the LLVM stack protector test project.
These tests were written for the "Stabilize stack-protector" proposal, and therefore removed the "stack-protector=basic" test option, as this stack protector was considered ineffective in Rust.
For the proposal, see: rust-lang/rust#146369
For the discussion, see zulip: https://rust-lang.zulipchat.com/#narrow/channel/233931-t-compiler.2Fmajor-changes/topic/Proposal.20for.20Adapt.20Stack.20Protector.20for.20Ru.E2.80.A6.20compiler-team.23841

I have opened an issue to discuss the 'abi_mismatch' issue I encountered while writing tests for the coexistence of 'stack-protector' and 'safe-stack': https://github.com/rust-lang/rust/issues/149340

r? `@wesleywiser` (feel free to reassign)
cc `@nikic,` `@rcvalle,` `@davidtwco,` `@arielb1,` `@Darksonn,` `@Noratrieb,` `@SparrowLii`
2025-11-27 12:36:47 +11:00
Sasha Pourcelot
2ab2090937 Port the #![windows_subsystem] attribute to the new attribute system 2025-11-27 00:17:48 +01:00
Ed Page
70b6d77983 fix(parse): Limit frontmatter fences to 255 dashes
Like raw string literals.
2025-11-26 14:09:18 -06:00
Ed Page
67094fc00a test(frontmatter): Check handling of long code fences 2025-11-26 14:08:38 -06:00
bors
1be6b13be7 Auto merge of #149079 - zachs18:clone_from_ref, r=Mark-Simulacrum
Add `Box::clone_from_ref` and similar under `feature(clone_from_ref)`

Tracking issue: https://github.com/rust-lang/rust/issues/149075

Accepted ACP: https://github.com/rust-lang/libs-team/issues/483

This PR implements `clone_from_ref` (and `try_*` and `_*in` variants), to get a `Box<T>`, `Arc<T>`, or `Rc<T>` by cloning from a `&T` where `T: CloneToUninit`.

The "Implement..." commits replace some ad-hoc conversions with `clone_from_ref` variants, which can be split out to a separate PR if desired.

This PR will conflict with https://github.com/rust-lang/rust/pull/148769 due to usage of `Layout::dangling` (which that PR is renaming to `dangling_ptr`), so they should not be rolled up together, and the one which merges later will need to be amended.
2025-11-26 18:21:00 +00:00
reddevilmidzy
941a17a15a Relocate 5 tests from tests/ui/issues
Relocate issues/issue-51154.rs to closures/box-generic-closure.rs

Relocate issues/issue-51515.rs to
borrowck/assignment-to-immutable-ref.rs

Relocate issues/issue-53348.rs to mismatched_types/deref-string-assign.rs

Relocate issues/issue-52717.rs to
pattern/match-enum-struct-variant-field-missing.rs

Relocate issues/issue-53300.rs to
type/cannot-find-wrapper-with-impl-trait.rs
2025-11-27 00:39:52 +09:00
Romain Perier
b25336b010 Untruthful multiple different versions of a crate in the dependency graph
Currently, If `expected_def_id` and `another_trait_def_id` have their
crate imported as ExternCrateSource::Path the method
get_extern_crate_renamed_symbol() will return None for both, resulting
in a false positive. This fixes the issue by using a slitly different
approach, we use a predicate instead and do the comparison of the item
names only when both crates are imported as ExternCrateSource::Extern and
are direct dependencies of the LOCAL_CRATE, otherwise false is returned.
2025-11-26 15:59:55 +01:00
bjorn3
4627bff6e6 Show backtrace on allocation failures when possible
And if an allocation while printing the backtrace fails, don't try to
print another backtrace as that will never succeed.
2025-11-26 14:02:37 +00:00
Jamie Cunliffe
d9ed836e71 Fix issue with callsite inline attribute not being applied sometimes.
If the calling function had more target features enabled than the
callee than the attribute wasn't being applied as the arguments for
the check had been swapped round. Also includes target features that
are part of the global set as the warning was checking those but when
adding the attribute they were not checked.

Add a codegen-llvm test to check that the attribute is actually
applied as previously only the warning was being checked.
2025-11-26 13:31:26 +00:00
Stuart Cook
a57d7539cb
Rollup merge of #149317 - bjorn3:has_ffi_unwind_calls_inline_asm, r=petrochenkov
Handle inline asm in has_ffi_unwind_calls

This is required for the soundness of `options(may_unwind)`.

Extracted from https://github.com/rust-lang/rust/pull/149141.
2025-11-26 23:32:10 +11:00
Stuart Cook
aa98135ace
Rollup merge of #149307 - lapla-cogito:deny_const_auto_trait, r=fmease
Deny const auto traits

close rust-lang/rust#149285

The AST validation now detects and rejects const auto traits. Additionally, I updated an existing test that was using `const unsafe auto trait`.

r? fmease
2025-11-26 23:32:08 +11:00
Stuart Cook
2b150f2c65
Rollup merge of #147936 - Sa4dUs:offload-intrinsic, r=ZuseZ4
Offload intrinsic

This PR implements the minimal mechanisms required to run a small subset of arbitrary offload kernels without relying on hardcoded names or metadata.

- `offload(kernel, (..args))`: an intrinsic that generates the necessary host-side LLVM-IR code.
- `rustc_offload_kernel`: a builtin attribute that marks device kernels to be handled appropriately.

Example usage (pseudocode):
```rust
fn kernel(x: *mut [f64; 128]) {
    core::intrinsics::offload(kernel_1, (x,))
}

#[cfg(target_os = "linux")]
extern "C" {
    pub fn kernel_1(array_b: *mut [f64; 128]);
}

#[cfg(not(target_os = "linux"))]
#[rustc_offload_kernel]
extern "gpu-kernel" fn kernel_1(x: *mut [f64; 128]) {
    unsafe { (*x)[0] = 21.0 };
}
```
2025-11-26 23:32:03 +11:00
lcnr
8e08af1769 fix tooling 2025-11-26 11:09:03 +01:00
cezarbbb
be28e7fdd1 Add 'stack-protector' tests for Linux/Win32/Win64. 2025-11-26 17:04:37 +08:00
Oli Scherer
9218298caa Add a diagnostic attribute for special casing const bound errors for non-const impls 2025-11-26 07:40:47 +00:00
Asuka Minato
171c77e387 add test 2025-11-26 16:33:13 +09:00
bors
6840234806 Auto merge of #147799 - Enselic:slash-slash-at-debuginfo-tests, r=saethlin
compiletest: Use `//@` prefixes also for debuginfo test directives

So that when we later add support for revisions we can use the same syntax for revisions as elsewhere (for https://github.com/rust-lang/rust/pull/147426).

This also prevents people from making typos for commands since `src/tools/compiletest/src/directives/directive_names.rs` will catch such typos now.

Note that we add one FIXME for a non-trivial change for later:
```
// FIXME(#148097): Change `// cdb-checksimple_closure` to `//@ cdb-check:simple_closure`
```

### TODO
- [x] Triple-check that all tests still run and all directives are still applied. Done: https://github.com/rust-lang/rust/pull/147799#issuecomment-3478986910

### Zulip discussion

https://rust-lang.zulipchat.com/#narrow/channel/326414-t-infra.2Fbootstrap/topic/.2F.2F.40.20syntax.20for.20debuginfo.20tests/with/545015582
2025-11-26 06:51:20 +00:00
Asuka Minato
48bd321a71 fix 2025-11-26 07:09:42 +09:00
Marcelo Domínguez
5128ce10a0 Implement offload intrinsic 2025-11-25 20:04:27 +01:00
binarycat
93526103ea rustdoc: add regression test for #140968 2025-11-25 12:38:36 -06:00
bors
80d8f292d8 Auto merge of #149322 - matthiaskrgr:rollup-uf0hmx6, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#147736 (Stabilize `asm_cfg`)
 - rust-lang/rust#148652 (Cleanup and refactor FnCtxt::report_no_match_method_error)
 - rust-lang/rust#149167 (skip checking supertraits in object candidate for `NormalizesTo` goal)
 - rust-lang/rust#149210 (fix: Do not ICE on normalization failure of an extern static item)
 - rust-lang/rust#149268 (add implementation-internal namespace for globalasm)
 - rust-lang/rust#149274 (Fix invalid link generation for type alias methods)
 - rust-lang/rust#149302 (Fix comment wording in simplify_comparison_integral.rs)
 - rust-lang/rust#149305 (Simplify OnceCell Clone impl)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-11-25 17:52:25 +00:00
Matthias Krüger
d6966fa15a
Rollup merge of #149274 - GuillaumeGomez:tyalias-method-link, r=lolbinarycat
Fix invalid link generation for type alias methods

Fixes https://github.com/rust-lang/rust/issues/149205.

That one was quite the wild ride. First commit is the actual fix, the second commit is just a small name variable improvement while I was going through the code. Anyway, let's go through it:

 * We don't generate directly implementations in the HTML files for local impls (which I think is a mistake and should be changed, gonna do that as a follow-up) but instead generate a JS file for each type alias containing the HTML for these impls.
 * So in `write_shared.rs::TypeAliasPart::get`, when generating the JS file, we generate the impl into a `String` by calling `render_impl`. This method expects an `AssocItemLink` to help it generate the correct link to the item (I'm planning to also remove this enum because it's yet another way to generate anchors/hrefs).
 * Problem was: we call the `provided_trait_methods` method on the impl item... which is empty if not a trait impl. This becomes an issue when we arrive in `render::assoc_href_attr` because of this code:
     ```rust
            AssocItemLink::GotoSource(did, provided_methods) => {
                let item_type = match item_type {
                    ItemType::Method | ItemType::TyMethod => {
                        if provided_methods.contains(&name) {
                            ItemType::Method
                        } else {
                            ItemType::TyMethod
                        }
                    }
                    item_type => item_type,
                };
                // ...
            }
    ```

     Since `provided_methods` is always empty, it means all methods on type aliases will be `TyMethod`, generating `#tymethod.` URLs instead of `#method.`.
 * So generating `AssocItemLink::GoToSource` only on traits (when `provided_trait_methods` is supposed to return something) was the fix.
 * And finally, because it's (currently) generating implementations only through JS, it means we cannot test it in `tests/rustdoc` so I had to write the test in `tests/rustdoc-gui`. Once I change how we generate local implementations for type aliases, I'll move it to `tests/rustdoc`.

r? ```@lolbinarycat```
2025-11-25 17:51:17 +01:00
Matthias Krüger
50237b33d6
Rollup merge of #149268 - davidtwco:v0-mangling-global-asm-namespace, r=Kivooeo
add implementation-internal namespace for globalasm

Fixes rust-lang/rust#138261

Adds a namespace for `global_asm` with a lowercase letter which [is reserved for implementation-internal disambiguation](https://doc.rust-lang.org/rustc/symbol-mangling/v0.html#namespace:~:text=Lowercase%20letters%20are%20reserved%20for%20implementation%2Dinternal%20disambiguation%20categories%20(and%20demanglers%20should%20never%20show%20them)):

> Lowercase letters are reserved for implementation-internal disambiguation categories (and demanglers should never show them)

As a implementation-internal disambiguation category, the demangler implementations shouldn't need updated (i.e. if this were an uppercase letter, then our mangle-then-demangle checks would fail because the demangler would expect to have explicit handling). `'a'` is chosen arbitrarily, for **a**sm, but I can change it to something else if preferred.

`#[rustc_symbol_name]` only looks at top-level items, and would need a bunch of changes to be able to check the symbol for `foo::{constant}::{closure}` in the `global_asm` in this test, so for now the test just checks this compiles.

The alternative to this would be to prohibit declaration of items in the operand of a `global_asm`, which is a breaking change.
2025-11-25 17:51:16 +01:00
Matthias Krüger
2f566a88f4
Rollup merge of #149210 - ShoyuVanilla:issue-148161, r=jdonszelmann
fix: Do not ICE on normalization failure of an extern static item

Fixes https://github.com/rust-lang/rust/issues/148161
2025-11-25 17:51:16 +01:00
Matthias Krüger
53276ad027
Rollup merge of #149167 - adwinwhite:next-245, r=lcnr
skip checking supertraits in object candidate for `NormalizesTo` goal

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/245.

r? `@lcnr`
2025-11-25 17:51:15 +01:00
Matthias Krüger
04e4f95e7e
Rollup merge of #147736 - folkertdev:stabilize-asm-cfg, r=jdonszelmann
Stabilize `asm_cfg`

tracking issue: https://github.com/rust-lang/rust/issues/140364
closes https://github.com/rust-lang/rust/issues/140364

Reference PR:

- https://github.com/rust-lang/reference/pull/2063

# Request for Stabilization

## Summary

The `cfg_asm` feature allows `#[cfg(...)]` and `#[cfg_attr(...)]` on  the arguments of the assembly macros, for instance:

```rust
asm!( // or global_asm! or naked_asm!
    "nop",
    #[cfg(target_feature = "sse2")]
    "nop",
    // ...
    #[cfg(target_feature = "sse2")]
    a = const 123, // only used on sse2
);
```

## Semantics

Templates, operands, `options` and `clobber_abi` in the assembly macros (`asm!`, `naked_asm!` and `global_asm!`) can be annotated with `#[cfg(...)]` and `#[cfg_attr(...)]`. When the condition evaluates to true, the annotated argument has no effect, and is completely ignored when expanding the assembly macro.
## Documentation

reference PR: https://github.com/rust-lang/reference/pull/2063

## Tests

- [tests/ui/asm/cfg.rs](https://github.com/rust-lang/rust/blob/master/tests/ui/asm/cfg.rs) checks that `cfg`'d arguments where the condition evaluates to false have no effect
- [tests/ui/asm/cfg-parse-error.rs](https://github.com/rust-lang/rust/blob/master/tests/ui/asm/cfg.rs) checks the parsing rules (parsing effectively assumes that the cfg conditions are all true)

## History

- https://github.com/rust-lang/rust/issues/140279
- https://github.com/rust-lang/rust/pull/140367

# Resolved questions

**how are other attributes handled**

Other attributes are parsed,  but explicitly rejected.

# unresolved questions

**operand before template**

The current implementation expects at least one template string before any operands. In the example below, if the `cfg` condition evaluates to true, the assembly block is ill-formed. But even when it evaluates to `false` this block is rejected, because the parser still expects just a template (a template is parsed as an expression and then validated to ensure that it is or expands to a string literal).

Changing how this works is difficult.
```rust
// This is rejected because `a = out(reg) x` does not parse as an expresion.
asm!(
	#[cfg(false)]
	a = out(reg) x, //~ ERROR expected token: `,`
	"",
);
```

**lint on positional arguments?**

Adding a lint to warn on the definition or use of positional arguments being `cfg`'d out was discussed in https://github.com/rust-lang/rust/issues/140279#issuecomment-2832237372 and subsequent comments. Such a lint is not currently implemented, but that may not be a blocker based on the comments there.

r? `@traviscross` (I'm assuming you'll reassign as needed)
2025-11-25 17:51:13 +01:00
lapla
ae699c8e78
Avoid ICE when handling const auto traits in the next-gen solver 2025-11-26 01:28:40 +09:00
bjorn3
d3c580db21 Handle inline asm in has_ffi_unwind_calls
This is required for the soundness of options(may_unwind)
2025-11-25 16:01:02 +00:00
David Wood
8ed8f1892c
add implementation-internal namespace for globalasm 2025-11-25 13:56:43 +00:00
bors
0f6dae4afc Auto merge of #148122 - saethlin:deny-deref-nullptr, r=petrochenkov
Make deref_nullptr deny by default instead of warn

This lint was added 4 years ago in https://github.com/rust-lang/rust/pull/83948 and I cannot find any discussion on that PR or its issue about whether it should be warn or deny by default.

I think keeping this lint to warn was at one point in the past justifiable because of the old bindgen behavior of generating tests that do null pointer derefs. I've certainly heard that argument. I don't think it holds up now, so I think we should be more firm about code that is definitely UB.

We merged https://github.com/rust-lang/rust/pull/134424 which adds a runtime check for null pointer reads/writes, with very little fanfare. So now we know things like: This lint warns on 111 crates in crater, but 106 crates are encountering the runtime UB check. 65 crates hit both the lint and a runtime check. Of the 46 crates that only hit the lint, 25 look to me like machine-generated bindings, and all hits except 3a0eff4bd1/src/main.rs (L454) are trying to compute a field offset, and should use `offset_of!`.

Based on the contents of the crater runs for 1.91, I'd expect these crates to go from test-fail to build-fail as a result of this change:
```
gh/bernardjason/rust-invaders
gh/Leinnan/doppler
gh/Max-E/rust-gl-python-gtk
gh/nslebruh/rust-opengl-glfw
gh/nslebruh/rust_physics_gl_test
gh/oraoto/php-stacktrace
gh/playXE/jsrs
gh/Plecra/asm-w-ownership
gh/TateKennington/ROpenGL
gh/WillFarris/voxel-game
reg/ochre
```
Most of the crates where the lint fires already don't build for other reasons (note there are a lot of C bindings wrapper crates in the set).
2025-11-25 13:51:31 +00:00
lapla
3326fbd1f4
Check existing tests to only verify const auto traits parsing 2025-11-25 21:07:29 +09:00
lapla
231a3a241b
Deny const auto traits 2025-11-25 21:00:46 +09:00
bors
7934bbdf84 Auto merge of #149148 - davidtwco:v0-mangling-on-nightly-std, r=Kobzol
v0 mangling for std on nightly

Following rust-lang/rust#89917 and rust-lang/compiler-team#938, it doesn't make sense that `std` for these channels would have legacy mangling while the user's code would use `v0`.

r? `@Kobzol`
2025-11-25 10:25:47 +00:00
lcnr
feb13036ef remove support for type-of 2025-11-25 10:19:44 +01:00
bors
cdb4236e65 Auto merge of #149200 - yaahc:helper-compat-test, r=petrochenkov
Add test for derive helper compat collisions

Resolves https://github.com/rust-lang/reference/pull/2055#discussion_r2549423194

r? `@petrochenkov`
2025-11-25 05:53:58 +00:00
Martin Nordholts
5b57d02e9f compiletest: Use //@ prefixes also for debuginfo test directives
So that when we later add support for revisions we can use the same
syntax for revisions as elsewhere.

This also prevents people from making typos for commands since
`src/tools/compiletest/src/directives/directive_names.rs` will catch such
typos now.

Note that we one FIXME for a non-trivial change for later:
```
// FIXME(148097): Change `// cdb-checksimple_closure` to `//@ cdb-check:simple_closure`
```
2025-11-25 06:13:45 +01:00
Adwin White
525cdc75dc skip checking supertraits in assembly_object_bound_candidate for NormalizesTo goal 2025-11-25 11:36:16 +08:00
Ben Kimock
bef49a02ef Don't lint on derefs of null pointers to ZSTs 2025-11-24 21:45:28 -05:00
Ben Kimock
c0097978aa Make deref_nullptr deny by default instead of warn 2025-11-24 21:45:28 -05:00
Jane Losare-Lusby
7537b0bc06 Update tests/ui/proc-macro/helper-attr-compat-collision.rs
Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
2025-11-24 10:52:03 -08:00
Jane Losare-Lusby
30c2e26506 Add test for derive helper compat collisions 2025-11-24 10:52:03 -08:00
Matthias Krüger
738e87282e
Rollup merge of #149255 - reddevilmidzy:let-else, r=Kivooeo
Use `let...else` consistently in user-facing diagnostics

resolve: rust-lang/rust#148772

Standardize `let...else` terminology in user-facing diagnostics.

Goal: Consistently use `let...else` in all error/warning messages.

Internal technical names (`let-else`) in comments and documentation remain unchanged.

cc ``@carols10cents,`` ``@jieyouxu``
2025-11-24 19:10:46 +01:00
Matthias Krüger
ade1581dc7
Rollup merge of #149201 - chenyukang:fix-str-format, r=Kivooeo
Add suggest alternatives for Out-of-range \x escapes

Fixes rust-lang/rust#148917

seems add two notes seems better.

r? `@scottmcm`
2025-11-24 19:10:44 +01:00
Matthias Krüger
be49e00109
Rollup merge of #148234 - notriddle:doc-cci, r=GuillaumeGomez
rustdoc: make mergeable crate info more usable

Part of https://github.com/rust-lang/rust/issues/130676

Adds documentation and a feature change aimed at making this usable without breaking backwards compat.

cc ``@EtomicBomb``
2025-11-24 19:10:43 +01:00
Jamie Cunliffe
95b6747a9d Broken test to show alwaysinline attribute not being applied 2025-11-24 18:02:00 +00:00
Jana Dönszelmann
f20175293a
fixup warnings around the compiler 2025-11-24 17:14:26 +01:00
Guillaume Gomez
a21affabf8 Fix invalid link generation for type alias methods 2025-11-24 17:01:32 +01:00
Shoyu Vanilla
cf4668285f fix: Do not ICE on normalization failure of an extern static item 2025-11-24 23:50:49 +09:00
Folkert de Vries
06658ab84b
cmse: do not calculate the layout of a type with infer types 2025-11-24 13:26:24 +01:00
David Wood
62c5ea65dc
v0 mangling for std on nightly 2025-11-24 12:16:01 +00:00