Commit graph

3073 commits

Author SHA1 Message Date
Urgau
249d399caa Don't lint on interior mutable const item coming from derefs
(cherry picked from commit 2581c2571c)
2026-01-08 16:09:05 -08:00
bors
3e2dbcdd3a Auto merge of #149646 - matthiaskrgr:rollup-jbfeow8, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#147224 (Emscripten: Turn wasm-eh on by default)
 - rust-lang/rust#149405 (Recover on misspelled item keyword)
 - rust-lang/rust#149443 (Tidying up UI tests [6/N])
 - rust-lang/rust#149524 (Move attribute safety checking to attribute parsing)
 - rust-lang/rust#149593 (powf, powi: point out SNaN non-determinism)
 - rust-lang/rust#149605 (Use branch name instead of HEAD when unshallowing)
 - rust-lang/rust#149612 (Apply the `bors` environment also to the `outcome` job)
 - rust-lang/rust#149623 (Don't require a normal tool build of clippy/rustfmt when running their test steps)
 - rust-lang/rust#149627 (Point to the item that is incorrectly annotated with `#[diagnostic::on_const]`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-12-04 22:04:03 +00:00
Matthias Krüger
5c9a4eed87
Rollup merge of #149544 - reddevilmidzy:where, r=fmease
Only apply `no_mangle_const_items`'s suggestion to plain const items

resolve: rust-lang/rust#149511
2025-12-04 09:22:11 +01:00
reddevilmidzy
2951d72219 Simplify and robustly compute suggestion span using
`vis_span.to(ident.span.shrink_to_lo())`
2025-12-04 11:01:40 +09:00
reddevilmidzy
6ce0f0ff91 Only apply no_mangle_const_items's suggestion to plain const items 2025-12-04 11:01:10 +09:00
Jonathan Brouwer
884fb5aef2
Move attribute safety checking to rustc_attr_parsing 2025-12-03 17:00:06 +01:00
León Orell Valerian Liehr
109e5e5999
Move early buffered lint ambigous-glob-imports to a dyn lint diagnostic 2025-12-01 16:31:53 +01:00
León Orell Valerian Liehr
3ad6359f54
Move more early buffered lints to dyn lint diagnostics (6/N) 2025-11-30 17:59:42 +01:00
León Orell Valerian Liehr
74d12e8598
Move more early buffered lints to dyn lint diagnostics (5/N) 2025-11-30 17:54:38 +01:00
Matthias Krüger
d67a12dfff
Rollup merge of #148256 - lcnr:orphan-check, r=spastorino,WaffleLapkin
remove support for `typeof`

see https://github.com/rust-lang/compiler-team/issues/940 closes https://github.com/rust-lang/rust/issues/148700

This also enables checks for invariants previously broken by `typeof` again.

r? types
2025-11-27 15:59:11 +01:00
lcnr
feb13036ef remove support for type-of 2025-11-25 10:19:44 +01:00
Ben Kimock
4752322343 Add a little cfg_attr(bootstrap) to make the doctest work on stage1 2025-11-24 21:50:02 -05: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
Urgau
dc2a61eccd Add const_item_interior_mutations lint 2025-11-22 14:48:40 +01:00
Matthias Krüger
2cc5bf7b6a
Rollup merge of #147421 - Kivooeo:ice-fix51621, r=chenyukang
Add check if span is from macro expansion

The same thing I did in https://github.com/rust-lang/rust/pull/147416, actually the same bug but in another place, I'm not really sure how this method is good for fixing such ICEs, but, it does work and not conflicting with any existing tests, so I guess, it's fine

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

r? compiler
2025-11-19 09:48:06 +01:00
Camille Gillot
72444372ae Replace OffsetOf by an actual sum. 2025-11-18 00:10:03 +00:00
Kivooeo
47384f79fa add check for when span is from macro expansion 2025-11-12 13:19:52 +00:00
Stuart Cook
60b2068eed
Rollup merge of #148770 - folkertdev:naked-c-variadic, r=workingjubilee
implement `feature(c_variadic_naked_functions)`

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

[#t-lang > C-variadic naked functions](https://rust-lang.zulipchat.com/#narrow/channel/213817-t-lang/topic/C-variadic.20naked.20functions/with/554593886)

This feature allows naked c-variadic function definitions with any ABI that is supported for foreign c-variadic functions.

```rust
#![feature(c_variadic, c_variadic_naked_functions)]

#[unsafe(naked)]
unsafe extern "win64" fn variadic_win64(_: u32, _: ...) -> u32 {
    core::arch::naked_asm!(
        r#"
        push    rax
        mov     qword ptr [rsp + 40], r9
        mov     qword ptr [rsp + 24], rdx
        mov     qword ptr [rsp + 32], r8
        lea     rax, [rsp + 40]
        mov     qword ptr [rsp], rax
        lea     eax, [rdx + rcx]
        add     eax, r8d
        pop     rcx
        ret
    "#,
    )
}
```

r? ````@workingjubilee````
2025-11-12 12:26:40 +11:00
Tamir Duberstein
fcf6809b05
rustc_target: introduce Os
Improve type safety by using an enum rather than strings.
2025-11-11 18:55:40 -05:00
Stuart Cook
16944b814b
Rollup merge of #148667 - hkBst:clippy-fix-14, r=Kivooeo
a few small clippy fixes
2025-11-11 21:09:42 +11:00
Stuart Cook
5b9211c5b3
Rollup merge of #141470 - GuillaumeGomez:function_casts_as_integer, r=urgau
Add new `function_casts_as_integer` lint

The `function_casts_as_integer` lint detects cases where users cast a function pointer into an integer.

*warn-by-default*

### Example

```rust
fn foo() {}
let x = foo as usize;
```

```
warning: casting a function into an integer implicitly
  --> $DIR/function_casts_as_integer.rs:9:17
   |
LL |     let x = foo as usize;
   |                 ^^^^^^^^
   |
help: add `fn() as usize`
   |
LL |     let x = foo as fn() as usize;
   |                 +++++++
```

### Explanation

You should never cast a function directly into an integer but go through a cast as `fn` first to make it obvious what's going on. It also allows to prevent confusion with (associated) constants.

Related to https://github.com/rust-lang/rust/issues/81686 and https://stackoverflow.com/questions/68701177/whats-the-meaning-of-casting-a-rust-enum-variant-to-a-numeric-data-type

r? ````@urgau````
2025-11-11 21:09:32 +11:00
Guillaume Gomez
66b4e93ba8 Add instructions on what to do in case casts other than to integers is ever working for function pointers 2025-11-10 20:44:33 +01:00
Guillaume Gomez
f22600e9a0 Fix typos 2025-11-10 16:38:28 +01:00
Guillaume Gomez
0a2c473ae7 Convert function_cast_as_integer lint suggestion to plain *const () cast 2025-11-10 16:38:28 +01:00
Guillaume Gomez
a23b8c48a5 Add new function_casts_as_integer lint 2025-11-10 16:38:27 +01:00
Frank King
5ef48ed448 Implement &pin patterns and ref pin bindings 2025-11-10 09:57:08 +08:00
Folkert de Vries
568c6ed8c9
propagate function attributes in ast visitor 2025-11-09 14:35:11 +01:00
Stuart Cook
b0c4434a7f
Rollup merge of #148601 - GrigorenkoPV:invalid_atomic_ordering, r=Kivooeo
`invalid_atomic_ordering`: also lint `update` & `try_update`

Split from rust-lang/rust#148590

Tracking issue for `update` and `try_update`: rust-lang/rust#135894
2025-11-09 13:22:30 +11:00
bors
72b21e1a64 Auto merge of #139558 - camelid:mgca-const-items, r=oli-obk,BoxyUwU
mgca: Add ConstArg representation for const items

tracking issue: rust-lang/rust#132980
fixes rust-lang/rust#131046
fixes rust-lang/rust#134641

As part of implementing `min_generic_const_args`, we need to distinguish const items that can be used in the type system, such as in associated const equality projections, from const items containing arbitrary const code, which must be kept out of the type system. Specifically, all "type consts" must be either concrete (no generics) or generic with a trivial expression like `N` or a path to another type const item.

To syntactically distinguish these cases, we require, for now at least, that users annotate all type consts with the `#[type_const]` attribute. Then, we validate that the const's right-hand side is indeed eligible to be a type const and represent it differently in the HIR.

We accomplish this representation using a new `ConstItemRhs` enum in the HIR, and a similar but simpler enum in the AST. When `#[type_const]` is **not** applied to a const (e.g. on stable), we represent const item right-hand sides (rhs's) as HIR bodies, like before. However, when the attribute is applied, we instead lower to a `hir::ConstArg`. This syntactically distinguishes between trivial const args (paths) and arbitrary expressions, which are represented using `AnonConst`s. Then in `generics_of`, we can take advantage of the existing machinery to bar the `AnonConst` rhs's from using parent generics.
2025-11-08 22:31:33 +00:00
Noah Lev
66267da3e9 Use "rhs" terminology instead of "body" 2025-11-08 13:50:48 -05:00
Marijn Schouten
244eef6d2b a few small clippy fixes 2025-11-07 19:57:52 +00:00
Pavel Grigorenko
bd23d55f29 invalid_atomic_ordering: also lint update & try_update 2025-11-07 16:17:10 +03:00
Stuart Cook
12deb2f513
Rollup merge of #143037 - androm3da:bcain/hexagon_regspan_label, r=Amanieu
Make named asm_labels lint not trigger on hexagon register spans

Fixes https://github.com/rust-lang/rust/issues/143021
2025-11-06 14:07:15 +11:00
Brian Cain
71e599b91a Make named asm_labels lint not trigger on hexagon register spans 2025-11-05 16:24:30 -06:00
bjorn3
973c7527b4 Unify the configuration of the compiler docs
Previously it was rather inconsistent which crates got the rust logo and
which didn't and setting html_root_url was forgotten in many cases.
2025-11-05 11:25:27 +00:00
Ralf Jung
8b96fbecb6 FCW for repr(C) enums whose discriminant values do not fit into a c_int 2025-11-04 11:44:55 +01:00
Matthias Krüger
e62b652e6e
Rollup merge of #148348 - hkBst:dangling-ptr-lint-1, r=Urgau
dangling ptr lint cleanup

This cleans up the dangling_pointers_from_locals lint.
2025-11-02 15:56:50 +01:00
Noah Lev
0515aa5a3e mgca: Add ConstArg representation for const items 2025-11-01 14:59:10 -04:00
Marijn Schouten
0bd6a03edf dangling ptr lint cleanup 2025-11-01 15:15:05 +00:00
Matthias Krüger
dc9060688a
Rollup merge of #139751 - frank-king:feature/pin-project, r=Nadrieril,traviscross
Implement pin-project in pattern matching for `&pin mut|const T`

This PR implements part of rust-lang/rust#130494. It supports pin-project in pattern matching for `&pin mut|const T`.

~Pin-projection by field access (i.e. `&pin mut|const place.field`) is not fully supported yet since pinned-borrow is not ready (rust-lang/rust#135731).~

CC ``````@traviscross``````
2025-11-01 08:25:44 +01:00
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
Frank King
26f35ae269 Implement pattern matching for &pin mut|const T 2025-10-30 07:56:16 +08: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