Commit Graph

3073 Commits

Author SHA1 Message Date
David Wood
86ab2b60cd
hir_analysis: add {Meta,Pointee}Sized bounds
Opting-out of `Sized` with `?Sized` is now equivalent to adding a
`MetaSized` bound, and adding a `MetaSized` or `PointeeSized` bound
is equivalent to removing the default `Sized` bound - this commit
implements this change in `rustc_hir_analysis::hir_ty_lowering`.

`MetaSized` is also added as a supertrait of all traits, as this is
necessary to preserve backwards compatibility.

Unfortunately, non-global where clauses being preferred over item bounds
(where `PointeeSized` bounds would be proven) - which can result in
errors when a `PointeeSized` supertrait/bound/predicate is added to some
items. Rather than `PointeeSized` being a bound on everything, it can
be the absence of a bound on everything, as `?Sized` was.
2025-06-16 23:04:33 +00:00
David Wood
3b0e1c17d2
trait_sel: {Meta,Pointee}Sized on ?Sized types
Expand the automatic implementation of `MetaSized` and `PointeeSized` so
that it is also implemented on non-`Sized` types, just not `ty::Foreign`
(extern type).
2025-06-16 15:00:22 +00:00
bors
586ad391f5 Auto merge of #142455 - jdonszelmann:attempt-to-mitigate-delayed-lint-perf-problems, r=oli-obk
collect delayed lints in hir_crate_items

r? `@oli-obk`

Attempt to mitigate perf problems in rust-lang/rust#138164
2025-06-15 16:52:31 +00:00
bors
49a8ba0684 Auto merge of #142289 - fmease:maybe-perf-gen-args, r=compiler-errors
[perf] `GenericArgs`-related: Change asserts to debug asserts & use more slice interning over iterable interning

1. The 1st commit yields the following perf gains: [#142289 (comment)](https://github.com/rust-lang/rust/pull/142289#issuecomment-2964041303).
2. The 2nd commit might also have a minor positive perf impact, however that one wasn't tested in isolation.

For reference, the initial approach c7e6accd79 (results: https://github.com/rust-lang/rust/pull/142289#issuecomment-2961076587) had a lot more changes (apart from what's now contained in commit 1 and 2) which seemed to be perf irrelevant (cf. the partial countercheck in 6f82bf1cfe (results: https://github.com/rust-lang/rust/pull/142289#issuecomment-2968393647).
2025-06-14 19:42:04 +00:00
Matthias Krüger
fe54c3a5eb
Rollup merge of #142464 - RalfJung:variadic-fn-abi-error, r=workingjubilee
variadic functions: remove list of supported ABIs from error

I think this list is problematic for multiple reasons:
- It is bound to go out-of-date as it is in a very different place from where we actually define which functions support varagrs (`fn supports_varargs`).
- Many of the ABIs we list only work on some targets; it makes no sense to mention "aapcs" as a possible ABI when building for x86_64. (This led to a lot of confusion in https://github.com/rust-lang/rust/issues/110505 where the author thought they should use "cdecl" and then were promptly told that "cdecl" is not a legal ABI on their target.)
- Typically, when the programmer wrote `extern "foobar"`, it is because they need the "foobar" ABI. It is of little use to tell them that there are other ABIs with which varargs would work.

Cc ``@workingjubilee``
2025-06-14 11:27:11 +02:00
Matthias Krüger
ade745e214
Rollup merge of #140593 - m-ou-se:some-temp, r=Nadrieril
Temporary lifetime extension through tuple struct and tuple variant constructors

This makes temporary lifetime extension work for tuple struct and tuple variant constructors, such as `Some()`.

Before:
```rust
let a = &temp(); // Extended
let a = Some(&temp()); // Not extended :(
let a = Some { 0: &temp() }; // Extended
```

After:
```rust
let a = &temp(); // Extended
let a = Some(&temp()); // Extended
let a = Some { 0: &temp() }; // Extended
```

So, with this change, this works:

```rust
let a = Some(&String::from("hello")); // New: String lifetime now extended!

println!("{a:?}");
```

Until now, we did not extend through tuple struct/variant constructors (like `Some`), because they are function calls syntactically, and we do not want to extend the String lifetime in:

```rust
let a = some_function(&String::from("hello")); // String not extended!
```

However, it turns out to be very easy to distinguish between regular functions and constructors at the point where we do lifetime extension.

In practice, constructors nearly always use UpperCamelCase while regular functions use lower_snake_case, so it should still be easy to for a human programmer at the call site to see whether something qualifies for lifetime extension or not.

This needs a lang fcp.

---

More examples of what will work after this change:

```rust
let x = Person {
    name: "Ferris",
    job: Some(&Job { // `Job` now extended!
        title: "Chief Rustacean",
        organisation: "Acme Ltd.",
    }),
};

dbg!(x);
```

```rust
let file = if use_stdout {
    None
} else {
    Some(&File::create("asdf")?) // `File` now extended!
};

set_logger(file);
```

```rust
use std::path::Component;

let c = Component::Normal(&OsString::from(format!("test-{num}"))); // OsString now extended!

assert_eq!(path.components.first().unwrap(), c);
```
2025-06-14 11:27:09 +02:00
Jubilee
c3537c2f9e
Rollup merge of #142441 - compiler-errors:lazier-binder-value-folding, r=lcnr
Delay replacing escaping bound vars in `FindParamInClause`

By uplifting the `BoundVarReplacer`, which is used by (e.g.) normalization to replace escaping bound vars that are encountered when folding binders, we can use a similar strategy to delay the instantiation of a binder's contents in the `FindParamInClause` used by the new trait solver.

This should alleviate the recently added requirement that `Binder<T>: TypeVisitable` only if `T: TypeFoldable`, which was previously required b/c we were calling `enter_forall` so that we could structurally normalize aliases that we found within the predicates of a param-env clause.

r? lcnr
2025-06-13 20:59:19 -07:00
Michael Goulet
b138202002 TypeVisiting binders no longer requires TypeFolding its interior 2025-06-13 17:54:45 +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
Ralf Jung
963fdbc852 variadic functions: remove list of supported ABIs from error 2025-06-13 18:10:06 +02:00
Jana Dönszelmann
6f5a717a6c
collect delayed lints in hir_crate_items 2025-06-13 14:03:01 +02:00
Mara Bos
e71a93b5c2 Add comment. 2025-06-13 09:20:55 +02:00
Mara Bos
99929fa9e6 Implement temporary lifetime extension for tuple ctors. 2025-06-13 09:04:12 +02:00
Matthias Krüger
7c3b2e5254
Rollup merge of #140770 - folkertdev:custom-abi, r=tgross35
add `extern "custom"` functions

tracking issue: rust-lang/rust#140829
previous discussion: https://github.com/rust-lang/rust/issues/140566

In short, an `extern "custom"` function is a function with a custom ABI, that rust does not know about. Therefore, such functions can only be defined with `#[unsafe(naked)]` and `naked_asm!`, or via an `extern "C" { /* ... */ }` block. These functions cannot be called using normal rust syntax: calling them can only be done from inline assembly.

The motivation is low-level scenarios where a custom calling convention is used. Currently, we often pick `extern "C"`, but that is a lie because the function does not actually respect the C calling convention.

At the moment `"custom"` seems to be the name with the most support. That name is not final, but we need to pick something to actually implement this.

r? `@traviscross`
cc `@tgross35`

try-job: x86_64-apple-2
2025-06-13 05:19:14 +02:00
Matthias Krüger
86e9995e7a
Rollup merge of #142410 - RalfJung:align_of, r=WaffleLapkin,workingjubilee
intrinsics: rename min_align_of to align_of

Now that `pref_align_of` is gone (https://github.com/rust-lang/rust/pull/141803), we can give the intrinsic backing `align_of` its proper name.

r? `@workingjubilee` or `@bjorn3`
2025-06-13 05:16:59 +02:00
León Orell Valerian Liehr
3a31f62421
Use more slicing and slice interning over iterable interning 2025-06-13 01:16:01 +02:00
bors
bb3a3c530c Auto merge of #142438 - matthiaskrgr:rollup-u1jdnhz, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#134536 (Lint on fn pointers comparisons in external macros)
 - rust-lang/rust#141069 (Suggest mut when possbile for temporary value dropped while borrowed)
 - rust-lang/rust#141934 (resolve: Tweak `private_macro_use` lint to be compatible with upcoming macro prelude changes)
 - rust-lang/rust#142034 (Detect method not being present that is present in other tuple types)
 - rust-lang/rust#142402 (chore(doctest): Remove redundant blank lines)
 - rust-lang/rust#142406 (Note when enum variants shadow an associated function)
 - rust-lang/rust#142407 (Remove bootstrap adhoc group)
 - rust-lang/rust#142408 (Add myself (WaffleLapkin) to review rotation)
 - rust-lang/rust#142418 (Remove lower_arg_ty as all callers were passing `None`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-12 23:05:49 +00:00
Folkert de Vries
5f73ce2b7e
add extern "custom" functions 2025-06-12 20:27:10 +02:00
Ralf Jung
62418f4c56 intrinsics: rename min_align_of to align_of 2025-06-12 17:50:25 +02:00
Oli Scherer
488ebeecbe Remove lower_arg_ty as all callers were passing None 2025-06-12 15:04:09 +00:00
Jana Dönszelmann
6072207a11
introduce new lint infra
lint on duplicates during attribute parsing
To do this we stuff them in the diagnostic context to be emitted after
hir is constructed
2025-06-12 09:56:47 +02:00
bors
bdb04d6c4f Auto merge of #141763 - lcnr:fixme-gamer, r=BoxyUwU
`FIXME(-Znext-solver)` triage

r? `@BoxyUwU`
2025-06-11 11:47:05 +00:00
Jubilee
8808a9c17f
hir_analysis: Elaborate on lint strategy for unsupported ABIs
Co-authored-by: Ralf Jung <post@ralfj.de>
2025-06-09 23:48:33 -07:00
Jubilee Young
580a9555d5 compiler: Fix reusing same lint on fn ptrs with newly-deprecated ABIs 2025-06-09 15:38:38 -07:00
bors
b6685d748f Auto merge of #141435 - RalfJung:unsupported_calling_conventions, r=workingjubilee
Add (back) `unsupported_calling_conventions` lint to reject more invalid calling conventions

This adds back the `unsupported_calling_conventions` lint that was removed in https://github.com/rust-lang/rust/pull/129935, in order to start the process of dealing with https://github.com/rust-lang/rust/issues/137018. Specifically, we are going for the plan laid out [here](https://github.com/rust-lang/rust/issues/137018#issuecomment-2672118326):
- thiscall, stdcall, fastcall, cdecl should only be accepted on x86-32
- vectorcall should only be accepted on x86-32 and x86-64

The difference to the status quo is that:
- We stop accepting stdcall, fastcall on targets that are windows && non-x86-32 (we already don't accept these on targets that are non-windows && non-x86-32)
- We stop accepting cdecl on targets that are non-x86-32
- (There is no difference for thiscall, this was already a hard error on non-x86-32)
- We stop accepting vectorcall on targets that are windows && non-x86-*

Vectorcall is an unstable ABI so we can just make this a hard error immediately. The others are stable, so we emit the `unsupported_calling_conventions` forward-compat lint. I set up the lint to show up in dependencies via cargo's future-compat report immediately, but we could also make it show up just for the local crate first if that is preferred.

try-job: i686-msvc-1
try-job: x86_64-msvc-1
try-job: test-various
2025-06-09 05:21:49 +00:00
bors
6ccd447603 Auto merge of #141700 - RalfJung:atomic-intrinsics-part2, r=bjorn3
Atomic intrinsics : use const generic ordering, part 2

This completes what got started in https://github.com/rust-lang/rust/pull/141507 by using a const generic for the ordering for all intrinsics. It is based on that PR; only the last commit is new.

Blocked on:
- https://github.com/rust-lang/rust/pull/141507
- https://github.com/rust-lang/rust/pull/141687
- https://github.com/rust-lang/stdarch/pull/1811
- https://github.com/rust-lang/rust/pull/141964

r? `@bjorn3`
2025-06-08 20:17:28 +00:00
Ralf Jung
fab11f619d add specific help messages for stdcall and cdecl 2025-06-08 07:34:41 +02:00
Ralf Jung
873122c006 add (back) unsupported_calling_conventions lint to reject more invalid calling conventions 2025-06-08 07:34:41 +02:00
bors
0b65d0db5f Auto merge of #142074 - oli-obk:its-finally-gone, r=petrochenkov
Remove CollectItemTypesVisitor

I always felt like we were very unnecessarily walking the HIR, let's see if perf agrees

There is lots to ~~improve~~ consolidate further here, as we still have 3 item wfchecks:

* check_item (matching on the hir::ItemKind)
    * actually doing trait solver based checks (by using HIR spans)
* lower_item (matching on the hir::ItemKind after loading it again??)
    * just ensure_ok-ing a bunch of queries
* check_item_type (matching on DefKind)
    * some type based checks, mostly ensure_ok-ing a bunch of queries

fixes rust-lang/rust#121429
2025-06-08 02:04:41 +00:00
bors
cdd545be1b Auto merge of #141950 - oli-obk:big-body-owner-loop, r=compiler-errors
Move coroutine_by_move_body_def_id into the big check_crate body owner loop

This avoids starting a parallel loop in sequence and instead runs all the queries for a specific DefId together.
2025-06-07 20:06:23 +00:00
Ralf Jung
2a3a6150d4 move all intrinsic typeck logic into the one big match 2025-06-07 21:45:58 +02:00
Ralf Jung
8808c9d34b intrinsics: use const generic to set atomic ordering 2025-06-07 21:45:58 +02:00
Guillaume Gomez
3a6f1b0375
Rollup merge of #142103 - scottmcm:fieldidx-in-interp, r=oli-obk
Update `InterpCx::project_field` to take `FieldIdx`

As suggested by Ralf in https://github.com/rust-lang/rust/pull/142005#discussion_r2125839015
2025-06-06 23:53:18 +02:00
Guillaume Gomez
4ce2db5b31
Rollup merge of #142043 - estebank:const-suggestion, r=wesleywiser
Verbose suggestion to make param `const`

```
error[E0747]: type provided when a constant was expected
  --> $DIR/invalid-const-arguments.rs:10:19
   |
LL | impl<N> Foo for B<N> {}
   |                   ^
   |
help: consider changing this type parameter to a const parameter
   |
LL - impl<N> Foo for B<N> {}
LL + impl<const N: u8> Foo for B<N> {}
   |
```

Part of rust-lang/rust#141973.
2025-06-06 23:53:17 +02:00
Scott McMurray
8bce2255e8 Update InterpCx::project_field to take FieldIdx
As suggested by Ralf in 142005.
2025-06-05 19:15:56 -07:00
Oli Scherer
fd3da4bebd Replace some Option<Span> with Span and use DUMMY_SP instead of None 2025-06-05 14:14:59 +00:00
Oli Scherer
fa282f4928 Remove CollectItemTypesVisitor 2025-06-05 13:37:34 +00:00
Oli Scherer
c83bd8b5f3 wfcheck closures 2025-06-05 13:37:34 +00:00
Oli Scherer
9949ea73c1 Move generic arg checks from the hir item types visitor to ty wfcheck 2025-06-05 13:37:34 +00:00
Oli Scherer
bfe4c5f78c Move opaque type checks from the hir item types visitor onto the wfcheck of the opaqe type itself 2025-06-05 10:30:09 +00:00
Esteban Küber
35cb28b7cf Verbose suggestion to make param const
```
error[E0747]: type provided when a constant was expected
  --> $DIR/invalid-const-arguments.rs:10:19
   |
LL | impl<N> Foo for B<N> {}
   |                   ^
   |
help: consider changing this type parameter to a const parameter
   |
LL - impl<N> Foo for B<N> {}
LL + impl<const N: u8> Foo for B<N> {}
   |
```
2025-06-04 21:23:11 +00:00
Oli Scherer
82ed50c294 Run wfcheck in one big loop instead of per module 2025-06-03 15:16:51 +00:00
lcnr
7dac755be8 FIXME(-Znext-solver) triage
Co-authored-by: Michael Goulet <michael@errs.io>
2025-06-03 14:23:56 +02:00
Oli Scherer
8a0fdbd407 Move coroutine_by_move_body_def_id into the big check_crate body owner loop 2025-06-03 08:06:24 +00:00
bors
f0999ffdc4 Auto merge of #139118 - scottmcm:slice-get-unchecked-intrinsic, r=workingjubilee
`slice.get(i)` should use a slice projection in MIR, like `slice[i]` does

`slice[i]` is built-in magic, so ends up being quite different from `slice.get(i)` in MIR, even though they're both doing nearly identical operations -- checking the length of the slice then getting a ref/ptr to the element if it's in-bounds.

This PR adds a `slice_get_unchecked` intrinsic for `impl SliceIndex for usize` to use to fix that, so it no longer needs to do a bunch of lines of pointer math and instead just gets the obvious single statement.  (This is *not* used for the range versions, since `slice[i..]` and `slice[..k]` can't use the mir Slice projection as they're using fenceposts, not indices.)

I originally tried to do this with some kind of GVN pattern, but realized that I'm pretty sure it's not legal to optimize `BinOp::Offset` to `PlaceElem::Index` without an extremely complicated condition.  Basically, the problem is that the `Index` projection on a dereferenced slice pointer *cares about the metadata*, since it's UB to `PlaceElem::Index` outside the range described by the metadata.  But then you cast the fat pointer to a thin pointer then offset it, that *ignores* the slice length metadata, so it's possible to write things that are legal with `Offset` but would be UB if translated in the obvious way to `Index`.  Checking (or even determining) the necessary conditions for that would be complicated and error-prone, whereas this intrinsic-based approach is quite straight-forward.

Zero backend changes, because it just lowers to MIR, so it's already supported naturally by CTFE/Miri/cg_llvm/cg_clif.
2025-05-31 21:38:21 +00:00
Matthias Krüger
387170c74b
Rollup merge of #141740 - nnethercote:hir-ItemKind-field-order, r=fee1-dead
Hir item kind field order

A follow-up to rust-lang/rust#141675.

r? `@fee1-dead`
2025-05-31 18:51:48 +02:00
Scott McMurray
4668124cc7 slice.get(i) should use a slice projection in MIR, like slice[i] does 2025-05-30 12:04:41 -07:00
Matthias Krüger
ad2d91ce11
Rollup merge of #141507 - RalfJung:atomic-intrinsics, r=bjorn3
atomic_load intrinsic: use const generic parameter for ordering

We have a gazillion intrinsics for the atomics because we encode the ordering into the intrinsic name rather than making it a parameter. This is particularly bad for those operations that take two orderings. Let's fix that!

This PR only converts `load`, to see if there's any feedback that would fundamentally change the strategy we pursue for the const generic intrinsics.

The first two commits are preparation and could be a separate PR if you prefer.

`@BoxyUwU` -- I hope this is a use of const generics that is unlikely to explode? All we need is a const generic of enum type. We could funnel it through an integer if we had to but an enum is obviously nicer...

`@bjorn3` it seems like the cranelift backend entirely ignores the ordering?
2025-05-30 07:01:30 +02:00
Nicholas Nethercote
f8887aa5af Reorder fields in hir::ItemKind variants.
Specifically `TyAlias`, `Enum`, `Struct`, `Union`. So the fields match
the textual order in the source code.

The interesting part of the change is in
`compiler/rustc_hir/src/hir.rs`. The rest is extremely mechanical
refactoring.
2025-05-30 02:23:20 +10:00
bors
8afd71079a Auto merge of #141717 - jhpratt:rollup-neu8nzl, r=jhpratt
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#138285 (Stabilize `repr128`)
 - rust-lang/rust#139994 (add `CStr::display`)
 - rust-lang/rust#141571 (coretests: extend and simplify float tests)
 - rust-lang/rust#141656 (CI: Add cargo tests to aarch64-apple-darwin)

Failed merges:

 - rust-lang/rust#141430 (remove `visit_clobber` and move `DummyAstNode` to `rustc_expand`)
 - rust-lang/rust#141636 (avoid some usages of `&mut P<T>` in AST visitors)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-29 08:53:27 +00:00