Commit graph

43374 commits

Author SHA1 Message Date
Matthias Krüger
961bf7ffa6
Rollup merge of #136434 - RalfJung:rustc_allowed_through_unstable_modules-deprecation-required, r=compiler-errors
rustc_allowed_through_unstable_modules: require deprecation message

This changes the `#[rustc_allowed_through_unstable_modules]` attribute so that a deprecation message (ideally directing people towards the stable path) is required.
2025-02-02 18:05:25 +01:00
Matthias Krüger
5bc5827636
Rollup merge of #136422 - nnethercote:convert-lint-functions, r=Noratrieb
Convert two `rustc_middle::lint` functions to `Span` methods.

`rustc_middle` is a huge crate and it's always good to move stuff out of it. There are lots of similar methods already on `Span`, so these two functions, `in_external_macro` and `is_from_async_await`, fit right in. The diff is big because `in_external_macro` is used a lot by clippy lints.

r? ``@Noratrieb``
2025-02-02 18:05:24 +01:00
Matthias Krüger
7e3d872bc0
Rollup merge of #136415 - estebank:highlight-clarification, r=compiler-errors
Highlight clarifying information in "expected/found" error

When the expected and found types have the same textual representation, we add clarifying in parentheses. We now visually highlight it in the output.

Detect a corner case where the clarifying information would be the same for both types and skip it, as it doesn't add anything useful.

![Screenshot of the rustc highlighted output on the terminal](https://github.com/user-attachments/assets/aa4b9433-5332-4941-b2c2-1a43e5cadff7)
2025-02-02 18:05:24 +01:00
Matthias Krüger
e066208255
Rollup merge of #136402 - notriddle:notriddle/let-expr-detector, r=compiler-errors
diagnostics: fix borrowck suggestions for if/while let conditionals

This code detects the case where one of the borrows is inside the let init expr while the other end is not. If that happens, we don't want to suggest adding a semicolon, because it won't work.

Fixes #133941
2025-02-02 18:05:23 +01:00
Matthias Krüger
453c32d614
Rollup merge of #136394 - saethlin:clean-up-instantiation-mode, r=compiler-errors
Clean up MonoItem::instantiation_mode

More progress on cleaning up and documenting instantiation mode selection.

This should have no behavior changes at all, it just rearranges the code inside `MonoItem::instantiation_mode` to a more logical flow and I've tried to explain every choice the implementation is making.
2025-02-02 18:05:23 +01:00
Matthias Krüger
48aede0773
Rollup merge of #134272 - RalfJung:destabilize-rustc_encodable_decodable, r=oli-obk
Remove rustc_encodable_decodable feature

This has been shown in future-compat reports since Rust 1.79 (https://github.com/rust-lang/rust/pull/116016), released June 2024. Let's see if crater still finds any issues.

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

Cc ``@rust-lang/libs-api``
2025-02-02 18:05:22 +01:00
Ralf Jung
3320e91575 rustc_allowed_through_unstable_modules: require deprecation message 2025-02-02 12:36:12 +01:00
Matthias Krüger
44def58274
Rollup merge of #136412 - estebank:fn-ptr-cast-suggestion, r=jieyouxu
Tweak fn pointer suggestion span

Use a more targeted span when suggesting casting an `fn` item to an `fn` pointer.

```
error[E0308]: cannot coerce functions which must be inlined to function pointers
  --> $DIR/cast.rs:10:33
   |
LL |     let _: fn(isize) -> usize = callee;
   |            ------------------   ^^^^^^ cannot coerce functions which must be inlined to function pointers
   |            |
   |            expected due to this
   |
   = note: expected fn pointer `fn(_) -> _`
                 found fn item `fn(_) -> _ {callee}`
   = note: fn items are distinct from fn pointers
help: consider casting to a fn pointer
   |
LL |     let _: fn(isize) -> usize = callee as fn(isize) -> usize;
   |                                        +++++++++++++++++++++
```
```
error[E0308]: mismatched types
  --> $DIR/fn-pointer-mismatch.rs:42:30
   |
LL |     let d: &fn(u32) -> u32 = foo;
   |            ---------------   ^^^ expected `&fn(u32) -> u32`, found fn item
   |            |
   |            expected due to this
   |
   = note: expected reference `&fn(_) -> _`
                found fn item `fn(_) -> _ {foo}`
help: consider using a reference
   |
LL |     let d: &fn(u32) -> u32 = &foo;
   |                              +
```
Previously we'd point at the whole expression for replacement, instead of marking what was being added.

We could also modify the suggestions for `&(name as fn())`, but for that we require storing more accurate spans than we have now.
2025-02-02 12:31:58 +01:00
Matthias Krüger
3559a48b8e
Rollup merge of #136368 - estebank:listify, r=fee1-dead
Make comma separated lists of anything easier to make for errors

Provide a new function `listify`, meant to be used in cases similar to `pluralize!`. When you have a slice of arbitrary elements that need to be presented to the user, `listify` allows you to turn that into a list of comma separated strings.

This reduces a lot of redundant logic that happens often in diagnostics.
2025-02-02 12:31:57 +01:00
Matthias Krüger
ce5db2f9f1
Rollup merge of #136358 - clubby789:opt-none-noinline, r=saethlin
`#[optimize(none)]` implies `#[inline(never)]`

Fixes #136329
2025-02-02 12:31:57 +01:00
Matthias Krüger
39efaa09d6
Rollup merge of #136328 - estebank:long-ty-path, r=jieyouxu,lqd
Rework "long type names" printing logic

Make it so more type-system types can be printed in a shortened version (like `Predicate`s).

Centralize printing the information about the "full type name path".

Make the "long type path" for the file where long types are written part of `Diag`, so that it becomes easier to keep track of it, and ensure it will always will be printed out last in the diagnostic by making its addition to the output implicit.

Tweak the shortening of types in "expected/found" labels.

Remove dead file `note.rs`.
2025-02-02 12:31:56 +01:00
Matthias Krüger
58a5f891f9
Rollup merge of #136279 - Zalathar:ensure-ok, r=oli-obk
Rename `tcx.ensure()` to `tcx.ensure_ok()`, and improve the associated docs

This is all based on my archaeology for https://rust-lang.zulipchat.com/#narrow/channel/182449-t-compiler.2Fhelp/topic/.60TyCtxtEnsure.60.

The main renamings are:
- `tcx.ensure()` → `tcx.ensure_ok()`
- `tcx.ensure_with_value()` → `tcx.ensure_done()`
- Query modifier `ensure_forwards_result_if_red` → `return_result_from_ensure_ok`

Hopefully these new names are a better fit for the *actual* function and purpose of these query call modes.
2025-02-02 12:31:55 +01:00
Nicholas Nethercote
06090e89d3 Convert two rustc_middle::lint functions to Span methods.
`rustc_middle` is a huge crate and it's always good to move stuff out of
it. There are lots of similar methods already on `Span`, so these two
functions, `in_external_macro` and `is_from_async_await`, fit right in.
The diff is big because `in_external_macro` is used a lot by clippy
lints.
2025-02-02 13:57:34 +11:00
Esteban Küber
c75e601543 Highlight clarifying information in "expected/found" error
When the expected and found types have the same textual representation, we add clarifying in parentheses. We now visually highlight it in the output.

Detect a corner case where the clarifying information would be the same for both types and skip it, as it doesn't add anything useful.
2025-02-02 02:39:43 +00:00
Esteban Küber
028a920c53 Tweak fn pointer suggestion span
Use a more targeted span when suggesting casting an `fn` item to an `fn` pointer.

```
error[E0308]: cannot coerce functions which must be inlined to function pointers
  --> $DIR/cast.rs:10:33
   |
LL |     let _: fn(isize) -> usize = callee;
   |            ------------------   ^^^^^^ cannot coerce functions which must be inlined to function pointers
   |            |
   |            expected due to this
   |
   = note: expected fn pointer `fn(_) -> _`
                 found fn item `fn(_) -> _ {callee}`
   = note: fn items are distinct from fn pointers
help: consider casting to a fn pointer
   |
LL |     let _: fn(isize) -> usize = callee as fn(isize) -> usize;
   |                                        +++++++++++++++++++++
```
```
error[E0308]: mismatched types
  --> $DIR/fn-pointer-mismatch.rs:42:30
   |
LL |     let d: &fn(u32) -> u32 = foo;
   |            ---------------   ^^^ expected `&fn(u32) -> u32`, found fn item
   |            |
   |            expected due to this
   |
   = note: expected reference `&fn(_) -> _`
                found fn item `fn(_) -> _ {foo}`
help: consider using a reference
   |
LL |     let d: &fn(u32) -> u32 = &foo;
   |                              +
```
Previously we'd point at the whole expression for replacement, instead of marking what was being added.

We could also modify the suggestions for `&(name as fn())`, but for that we require storing more accurate spans than we have now.
2025-02-02 00:46:02 +00:00
Michael Howell
ecb2d5c43d diagnostics: fix borrowck suggestions for if/while let conditionals
This code detects the case where one of the borrows is inside the
let init expr while the other end is not. If that happens, we don't
want to suggest adding a semicolon, because it won't work.
2025-02-01 14:39:43 -07:00
Ben Kimock
eea88f5dcb Clean up MonoItem::instantiation_mode 2025-02-01 12:57:04 -05:00
Matthias Krüger
2a82ebdcb7
Rollup merge of #136374 - saethlin:enzyme-linkage, r=oli-obk
Add link attribute for Enzyme's LLVMRust FFI

Since https://github.com/rust-lang/rust/pull/133429 landed, the compiler doesn't build with `-Zcross-crate-inline-threshold=always`. I don't expect anyone else to test or fix issues with that goofy configuration, so I'm fixing it.

This PR adds a link attribute just like https://github.com/rust-lang/rust/pull/118142 for all the new LLVMRust functions. They were actually added in https://github.com/rust-lang/rust/pull/130060 but weren't used until just now.
2025-02-01 16:41:05 +01:00
Matthias Krüger
2fd3007cbc
Rollup merge of #130514 - compiler-errors:unsafe-binders, r=oli-obk
Implement MIR lowering for unsafe binders

This is the final bit of the unsafe binders puzzle. It implements MIR, CTFE, and codegen for unsafe binders, and enforces that (for now) they are `Copy`. Later on, I'll introduce a new trait that relaxes this requirement to being "is `Copy` or `ManuallyDrop<T>`" which more closely models how we treat union fields.

Namely, wrapping unsafe binders is now `Rvalue::WrapUnsafeBinder`, which acts much like an `Rvalue::Aggregate`. Unwrapping unsafe binders are implemented as a MIR projection `ProjectionElem::UnwrapUnsafeBinder`, which acts much like `ProjectionElem::Field`.

Tracking:
- https://github.com/rust-lang/rust/issues/130516
2025-02-01 16:41:03 +01:00
Ben Kimock
ce7cb312fa Add link attribute for Enzyme's FFI 2025-01-31 21:11:23 -05:00
Zalathar
3ae0239f85 Mark the tcx-ensure wrapper types with #[must_use] 2025-02-01 12:42:41 +11:00
Zalathar
3581512fb8 Use an explicit type when discarding the result of tcx.ensure_ok() 2025-02-01 12:42:41 +11:00
Zalathar
fef46f4e07 Rename ensure_forwards_result_if_red to return_result_from_ensure_ok 2025-02-01 12:42:41 +11:00
Zalathar
9e4f10db65 Rename tcx.ensure_with_value() to tcx.ensure_done() 2025-02-01 12:42:39 +11:00
Zalathar
24cdaa146a Rename tcx.ensure() to tcx.ensure_ok() 2025-02-01 12:38:54 +11:00
Matthias Krüger
1935bbfd18
Rollup merge of #136348 - RalfJung:miri-float-min-max, r=oli-obk
miri: make float min/max non-deterministic

This makes Miri match the documentation that landed in https://github.com/rust-lang/rust/pull/136296.

r? ``@oli-obk``
2025-02-01 01:19:22 +01:00
Matthias Krüger
47e6684e53
Rollup merge of #136314 - compiler-errors:const-deref-adj, r=fee1-dead
Use proper type when applying deref adjustment in const

When applying a deref adjustment to some type `Wrap<T>` which derefs to `T`, we were checking that `T: ~const Deref`, not `Wrap<T>: ~const Deref` like we should have been.

r? project-const-traits

Fixes #136273
Fixes #135210 -- I just deleted the test since the regression test is uninteresting
2025-02-01 01:19:21 +01:00
Matthias Krüger
3c4b9122ec
Rollup merge of #135900 - compiler-errors:derive-wf, r=lcnr
Manually walk into WF obligations in `BestObligation` proof tree visitor

When we encounter a `WellFormed` obligation in the `BestObligation` proof tree visitor, ignore the proof tree and call `wf::unnormalized_obligations` to derive well-formed obligations with the correct cause codes. This is to avoid having to replicate the somewhat delicate logic that `wf.rs` does to set up its obligation causes... Don't see a better way to do this.

vibes?? r? lcnr
2025-02-01 01:19:19 +01:00
Matthias Krüger
2460b280db
Rollup merge of #135840 - vayunbiyani:omit_intrinsic_unused_param_warning, r=oli-obk
omit unused args warnings for intrinsics without body

potential fix for https://github.com/rust-lang/rust/issues/135598
2025-02-01 01:19:19 +01:00
Esteban Küber
0751e9036a Rework "long type names" printing logic
Make it so more type-system types can be printed in a shortened version (like `Predicate`s).

Centralize printing the information about the "full type name path".

Make the "long type path" for the file where long types are written part of `Diag`, so that it becomes easier to keep track of it, and ensure it will always will be printed out last in the diagnostic by making its addition to the output implicit.

Tweak the shortening of types in "expected/found" labels.

Remove dead file `note.rs`.
2025-01-31 20:39:01 +00:00
Esteban Küber
8e9422f94e Make comma separated lists of anything easier to make for errors
Provide a new function `listify`, meant to be used in cases similar to `pluralize!`. When you have a slice of arbitrary elements that need to be presented to the user, `listify` allows you to turn that into a list of comma separated strings.

This reduces a lot of redundant logic that happens often in diagnostics.
2025-01-31 20:36:44 +00:00
bors
854f22563c Auto merge of #136350 - matthiaskrgr:rollup-6eqfyvh, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #134531 ([rustdoc] Add `--extract-doctests` command-line flag)
 - #135860 (Compiler: Finalize dyn compatibility renaming)
 - #135992 (Improve documentation when adding a new target)
 - #136194 (Support clobber_abi in BPF inline assembly)
 - #136325 (Delay a bug when indexing unsized slices)
 - #136326 (Replace our `LLVMRustDIBuilderRef` with LLVM-C's `LLVMDIBuilderRef`)
 - #136330 (Remove unnecessary hooks)
 - #136336 (Overhaul `rustc_middle::util`)
 - #136341 (Remove myself from vacation)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-31 20:16:46 +00:00
Michael Goulet
304b3cfcb2 Manually walk into WF obligations in BestObligation proof tree visitor 2025-01-31 18:21:58 +00:00
Michael Goulet
d8b176f683 Move fulfillment error derivation into new module 2025-01-31 18:16:02 +00:00
clubby789
2c35bd0499 #[optimize(none)] implies #[inline(never)] 2025-01-31 17:51:49 +00:00
Michael Goulet
442b9a9387 Validation 2025-01-31 17:40:28 +00:00
Michael Goulet
b63341e892 Enforce unsafe binders must be Copy (for now) 2025-01-31 17:40:28 +00:00
Michael Goulet
fc1a9186dc Implement MIR, CTFE, and codegen for unsafe binders 2025-01-31 17:19:53 +00:00
bors
aa4cfd0809 Auto merge of #134424 - 1c3t3a:null-checks, r=saethlin
Insert null checks for pointer dereferences when debug assertions are enabled

Similar to how the alignment is already checked, this adds a check
for null pointer dereferences in debug mode. It is implemented similarly
to the alignment check as a `MirPass`.

This inserts checks in the same places as the `CheckAlignment` pass and additionally
also inserts checks for `Borrows`, so code like
```rust
let ptr: *const u32 = std::ptr::null();
let val: &u32 = unsafe { &*ptr };
```
will have a check inserted on dereference. This is done because null references
are UB. The alignment check doesn't cover these places, because in `&(*ptr).field`,
the exact requirement is that the final reference must be aligned. This is something to
consider further enhancements of the alignment check.

For now this is implemented as a separate `MirPass`, to make it easy to disable
this check if necessary.

This is related to a 2025H1 project goal for better UB checks in debug
mode: https://github.com/rust-lang/rust-project-goals/pull/177.

r? `@saethlin`
2025-01-31 15:56:53 +00:00
Matthias Krüger
95f746d2ef
Rollup merge of #136336 - nnethercote:overhaul-rustc_middle-util, r=jieyouxu
Overhaul `rustc_middle::util`

It's an odd module with some odd stuff in it.

r? `@Noratrieb`
2025-01-31 12:28:20 +01:00
Matthias Krüger
417aa6c1f6
Rollup merge of #136330 - nnethercote:rm-unnecessary-hooks, r=oli-obk
Remove unnecessary hooks

Some hooks can be downgraded to vanilla functions.

r? `@oli-obk`
2025-01-31 12:28:19 +01:00
Matthias Krüger
a5a005febe
Rollup merge of #136326 - Zalathar:llvm-di-builder-ref, r=nikic
Replace our `LLVMRustDIBuilderRef` with LLVM-C's `LLVMDIBuilderRef`

Inspired by trying to split #134009 into smaller steps that are easier to review individually.

This makes it possible to start incrementally replacing our debuginfo bindings with the ones in the LLVM-C API, all of which operate on `LLVMDIBuilderRef`.

There should be no change to compiler behaviour.
2025-01-31 12:28:18 +01:00
Matthias Krüger
f1daf9e2c4
Rollup merge of #136325 - compiler-errors:indirectly, r=RalfJung
Delay a bug when indexing unsized slices

Fixes #136298

r? RalfJung or reassign
2025-01-31 12:28:18 +01:00
Matthias Krüger
12a7f06e3c
Rollup merge of #136194 - taiki-e:bpf-clobber-abi, r=amanieu
Support clobber_abi in BPF inline assembly

This supports [`clobber_abi`](https://doc.rust-lang.org/nightly/reference/inline-assembly.html#abi-clobbers) which is one of the requirements of stabilization mentioned in the tracking Issue for `asm_experimental_arch` (#93335).

Refs: [Section 1.1 "Registers and calling convention" in BPF ABI Recommended Conventions and Guidelines v1.0](https://github.com/torvalds/linux/blob/v6.13/Documentation/bpf/standardization/abi.rst#11registers-and-calling-convention)
> R0 - R5 are scratch registers and BPF programs needs to spill/fill them if necessary across calls.

cc `@alessandrod` `@dave-tucker` `@tamird` `@vadorovsky` (target maintainers mentioned in platform support document which will be added by https://github.com/rust-lang/rust/pull/135107)

r? `@Amanieu`

`@rustbot` label +O-eBPF +A-inline-assembly
2025-01-31 12:28:17 +01:00
Matthias Krüger
308ea7120b
Rollup merge of #135860 - fmease:compiler-mv-obj-save-dyn-compat-ii, r=jieyouxu
Compiler: Finalize dyn compatibility renaming

Update the Reference link to use the new URL fragment from https://github.com/rust-lang/reference/pull/1666 (this change has finally hit stable). Fixes a FIXME.

Follow-up to #130826.
Part of #130852.

~~Blocking it on #133372.~~ (merged)

r? ghost
2025-01-31 12:28:15 +01:00
Bastian Kersting
b151b513ba Insert null checks for pointer dereferences when debug assertions are enabled
Similar to how the alignment is already checked, this adds a check
for null pointer dereferences in debug mode. It is implemented similarly
to the alignment check as a MirPass.

This is related to a 2025H1 project goal for better UB checks in debug
mode: https://github.com/rust-lang/rust-project-goals/pull/177.
2025-01-31 11:13:34 +00:00
Ralf Jung
d98270b07a miri: make float min/max non-deterministic 2025-01-31 11:56:02 +01:00
bors
7f36543a48 Auto merge of #136332 - jhpratt:rollup-aa69d0e, r=jhpratt
Rollup of 9 pull requests

Successful merges:

 - #132156 (When encountering unexpected closure return type, point at return type/expression)
 - #133429 (Autodiff Upstreaming - rustc_codegen_ssa, rustc_middle)
 - #136281 (`rustc_hir_analysis` cleanups)
 - #136297 (Fix a typo in profile-guided-optimization.md)
 - #136300 (atomic: extend compare_and_swap migration docs)
 - #136310 (normalize `*.long-type.txt` paths for compare-mode tests)
 - #136312 (Disable `overflow_delimited_expr` in edition 2024)
 - #136313 (Filter out RPITITs when suggesting unconstrained assoc type on too many generics)
 - #136323 (Fix a typo in conventions.md)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-31 09:42:28 +00:00
bors
25a16572a3 Auto merge of #136331 - jhpratt:rollup-curo1f4, r=jhpratt
Rollup of 8 pull requests

Successful merges:

 - #135414 (Stabilize `const_black_box`)
 - #136150 (ci: use windows 2025 for i686-mingw)
 - #136258 (rustdoc: rename `issue-\d+.rs` tests to have meaningful names (part 11))
 - #136270 (Remove `NamedVarMap`.)
 - #136278 (add constraint graph to polonius MIR dump)
 - #136287 (LLVM changed the nocapture attribute to captures(none))
 - #136291 (some test suite cleanups)
 - #136296 (float::min/max: mention the non-determinism around signed 0)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-31 06:55:04 +00:00
Jacob Pratt
e6285b8ff1
Rollup merge of #136313 - compiler-errors:too-many-args, r=lqd
Filter out RPITITs when suggesting unconstrained assoc type on too many generics

Fixes #136233
2025-01-31 00:26:34 -05:00