Commit Graph

280098 Commits

Author SHA1 Message Date
Celina G. Val
804cce47d9 Refactor contract builtin macro + error handling
Instead of parsing the different components of a function signature,
eagerly look for either the `where` keyword or the function body.

- Also address feedback to use `From` instead of `TryFrom` in cranelift
  contract and ubcheck codegen.
2025-02-03 13:55:15 -08:00
Felix S. Klock II
6a6c6b891b Separate contract feature gates for the internal machinery
The extended syntax for function signature that includes contract clauses
should never be user exposed versus the interface we want to ship
externally eventually.
2025-02-03 13:55:15 -08:00
Felix S. Klock II
b279ff9dcf demonstrate how to capture state at precondition time and feed into postcondition predicate. 2025-02-03 13:55:15 -08:00
Felix S. Klock II
ae7eff0be5 Desugars contract into the internal AST extensions
Check ensures on early return due to Try / Yeet

Expand these two expressions to include a call to contract checking
2025-02-03 13:54:32 -08:00
Celina G. Val
38eff16d0a Express contracts as part of function header and lower it to the contract lang items
includes post-developed commit: do not suggest internal-only keywords as corrections to parse failures.

includes post-developed commit: removed tabs that creeped in into rustfmt tool source code.

includes post-developed commit, placating rustfmt self dogfooding.

includes post-developed commit: add backquotes to prevent markdown checking from trying to treat an attr as a markdown hyperlink/

includes post-developed commit: fix lowering to keep contracts from being erroneously inherited by nested bodies (like closures).

Rebase Conflicts:
 - compiler/rustc_parse/src/parser/diagnostics.rs
 - compiler/rustc_parse/src/parser/item.rs
 - compiler/rustc_span/src/hygiene.rs

Remove contracts keywords from diagnostic messages
2025-02-03 12:54:00 -08:00
Felix S. Klock II
777def87d5 contracts: added lang items that act as hooks for rustc-injected code to invoke.
see test for an example of the kind of injected code that is anticipated here.
2025-02-03 12:54:00 -08:00
Felix S. Klock II
bcb8565f30 Contracts core intrinsics.
These are hooks to:

  1. control whether contract checks are run
  2. allow 3rd party tools to intercept and reintepret the results of running contracts.
2025-02-03 12:53:57 -08:00
bors
534d79adf9 Auto merge of #136481 - jieyouxu:rollup-w0lnnqb, r=jieyouxu
Rollup of 8 pull requests

Successful merges:

 - #136356 (Docs for f16 and f128: correct a typo and add details)
 - #136404 (Remove a footgun-y feature / relic of the past from the compiletest DSL)
 - #136432 (LTA: Actually check where-clauses for well-formedness at the def site)
 - #136438 (miri: improve error when offset_from preconditions are violated)
 - #136441 ([`compiletest`-related cleanups 1/7] Cleanup `is_rustdoc` logic and remove a useless path join in rustdoc-json runtest logic)
 - #136455 (Remove some `Clone` bounds and derives.)
 - #136464 (Remove hook calling via `TyCtxtAt`.)
 - #136467 (override default config profile on tarballs)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-03 16:42:25 +00:00
bors
f2c4ccd852 Auto merge of #136352 - lqd:ensure-stacks, r=compiler-errors
Add a couple of missing `ensure_sufficient_stacks`

r? `@saethlin` I hope you didn't spend time on this already.

(I couldn't sleep, opened `check_tail_calls`, there was a single call where it could happen, might as well fix it)

This PR adds a couple of missing `ensure_sufficient_stack`s:
- one in `check_tail_calls` that prevented the #135709 backport on some targets.
- after that was fixed, the test still didn't pass starting at 4MB, so I also added one in `check_unsafety` and that made it pass.

I didn't add an `rmake` test purposefully limiting the min stack size on `issue-74564-if-expr-stack-overflow.rs`, but we could if we wanted to.

On `apple-aarch64-darwin`, this is enough to make `RUST_MIN_STACK=$((1024*1024*3)) ./x test tests/ui --test-args tests/ui/issues/issue-74564-if-expr-stack-overflow.rs` pass for me locally, and it does stack overflow otherwise.
2025-02-03 13:56:04 +00:00
许杰友 Jieyou Xu (Joe)
f65c6afcec
Rollup merge of #136467 - onur-ozkan:override-default-profile-on-tarballs, r=jieyouxu
override default config profile on tarballs

This is the same logic used in the Python script 613bdd4997/src/bootstrap/bootstrap.py (L1273-L1274)
2025-02-03 19:13:30 +08:00
许杰友 Jieyou Xu (Joe)
5bd0f32378
Rollup merge of #136464 - nnethercote:rm-TyCtxtAt-for-hooks, r=oli-obk
Remove hook calling via `TyCtxtAt`.

All hooks receive a `TyCtxtAt` argument.

Currently hooks can be called through `TyCtxtAt` or `TyCtxt`. In the latter case, a `TyCtxtAt` is constructed with a dummy span and passed to the hook.

However, in practice hooks are never called through `TyCtxtAt`, and always receive a dummy span. (I confirmed this via code inspection, and double-checked it by temporarily making the `TyCtxtAt` code path panic and running all the tests.)

This commit removes all the `TyCtxtAt` machinery for hooks. All hooks now receive `TyCtxt` instead of `TyCtxtAt`. There are two existing hooks that use `TyCtxtAt::span`: `const_caller_location_provider` and `try_destructure_mir_constant_for_user_output`. For both hooks the span is always a dummy span, probably unintentionally. This dummy span use is now explicit. If a non-dummy span is needed for these two hooks it would be easy to add it as an extra argument because hooks are less constrained than queries.

r? `@oli-obk`
2025-02-03 19:13:29 +08:00
许杰友 Jieyou Xu (Joe)
40d1cb406d
Rollup merge of #136455 - nnethercote:less-Clone, r=compiler-errors
Remove some `Clone` bounds and derives.

r? `@cjgillot`
2025-02-03 19:13:28 +08:00
许杰友 Jieyou Xu (Joe)
bdc6b4def5
Rollup merge of #136441 - jieyouxu:cleanup-is-rustdoc, r=compiler-errors
[`compiletest`-related cleanups 1/7] Cleanup `is_rustdoc` logic and remove a useless path join in rustdoc-json runtest logic

Reference for overall changes: https://github.com/rust-lang/rust/pull/136437
Part **1** of **7** of the *`compiletest`-related cleanups* PR series.

### Summary

- Don't match on path when we already have test suite names.
- Remove a useless path join.

r? bootstrap (or compiler)
2025-02-03 19:13:28 +08:00
许杰友 Jieyou Xu (Joe)
43764db758
Rollup merge of #136438 - RalfJung:offset_from_ub_errors, r=oli-obk
miri: improve error when offset_from preconditions are violated

Fixes https://github.com/rust-lang/miri/issues/4143
2025-02-03 19:13:27 +08:00
许杰友 Jieyou Xu (Joe)
1df7b30926
Rollup merge of #136432 - fmease:lta-fix-def-site-checks, r=compiler-errors
LTA: Actually check where-clauses for well-formedness at the def site

All of the added tests used to wrongfully pass.

r? oli-obk or types/compiler or reassign
2025-02-03 19:13:27 +08:00
许杰友 Jieyou Xu (Joe)
ca23707787
Rollup merge of #136404 - fmease:rm-compiletest-relic-of-the-past, r=Noratrieb,jieyouxu
Remove a footgun-y feature / relic of the past from the compiletest DSL

The compiletest DSL still features a historical remnant from the time when its directives were merely prefixed with `//` instead of `//`@`` when unknown directive names weren't rejected since they could just as well be part of prose:

As an "optimization", it stops looking for directives once it stumbles upon a line which starts with either `fn` or `mod`. This is super footgun-y as it obviously leads to any seeming compiletest directives below `fn` and `mod` items getting completely ignored.

See #136403 for a practical example. As well the assembly test updated in this PR.

~~Blocked on #136403.~~ (merged)
2025-02-03 19:13:26 +08:00
许杰友 Jieyou Xu (Joe)
7be7f3b50e
Rollup merge of #136356 - pthariensflame:patch-1, r=tgross35
Docs for f16 and f128: correct a typo and add details

CC: #116909; corrects and expands #124750.
2025-02-03 19:13:26 +08:00
bors
a5db378dc1 Auto merge of #136413 - EnzymeAD:fix-autodiff-comptime-regression, r=oli-obk
fix autodiff compile time regression

Tries to fix the regression from https://github.com/rust-lang/rust/pull/133429

Tracking:

- https://github.com/rust-lang/rust/issues/124509
2025-02-03 11:10:56 +00:00
bors
7daf4cf911 Auto merge of #133138 - azhogin:azhogin/target-modifiers, r=davidtwco,saethlin
Target modifiers (special marked options) are recorded in metainfo

Target modifiers (special marked options) are recorded in metainfo and compared to be equal in different linked crates.

PR for this RFC: https://github.com/rust-lang/rfcs/pull/3716

Option may be marked as `TARGET_MODIFIER`, example: `regparm: Option<u32> = (None, parse_opt_number, [TRACKED TARGET_MODIFIER]`.
If an TARGET_MODIFIER-marked option has non-default value, it will be recorded in crate metainfo as a `Vec<TargetModifier>`:
```
pub struct TargetModifier {
    pub opt: OptionsTargetModifiers,
    pub value_name: String,
}
```

OptionsTargetModifiers is a macro-generated enum.

Option value code (for comparison) is generated using `Debug` trait.

Error example:
```
error: mixing `-Zregparm` will cause an ABI mismatch in crate `incompatible_regparm`
  --> $DIR/incompatible_regparm.rs:10:1
   |
LL | #![crate_type = "lib"]
   | ^
   |
   = help: the `-Zregparm` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely
   = note: `-Zregparm=1` in this crate is incompatible with `-Zregparm=2` in dependency `wrong_regparm`
   = help: set `-Zregparm=2` in this crate or `-Zregparm=1` in `wrong_regparm`
   = help: if you are sure this will not cause problems, use `-Cunsafe-allow-abi-mismatch=regparm` to silence this error

error: aborting due to 1 previous error
```

`-Cunsafe-allow-abi-mismatch=regparm,reg-struct-return` to disable list of flags.
2025-02-03 07:16:57 +00:00
onur-ozkan
8c5e6a20d0 override default config profile on tarballs
This is the same logic used in the Python script 613bdd4997/src/bootstrap/bootstrap.py (L1273-L1274)

Signed-off-by: onur-ozkan <work@onurozkan.dev>
2025-02-03 06:53:58 +00:00
Nicholas Nethercote
e661514bda Remove hook calling via TyCtxtAt.
All hooks receive a `TyCtxtAt` argument.

Currently hooks can be called through `TyCtxtAt` or `TyCtxt`. In the
latter case, a `TyCtxtAt` is constructed with a dummy span and passed to
the hook.

However, in practice hooks are never called through `TyCtxtAt`, and
always receive a dummy span. (I confirmed this via code inspection, and
double-checked it by temporarily making the `TyCtxtAt` code path panic
and running all the tests.)

This commit removes all the `TyCtxtAt` machinery for hooks. All hooks
now receive `TyCtxt` instead of `TyCtxtAt`. There are two existing hooks
that use `TyCtxtAt::span`: `const_caller_location_provider` and
`try_destructure_mir_constant_for_user_output`. For both hooks the span
is always a dummy span, probably unintentionally. This dummy span use is
now explicit. If a non-dummy span is needed for these two hooks it would
be easy to add it as an extra argument because hooks are less
constrained than queries.
2025-02-03 17:02:33 +11:00
León Orell Valerian Liehr
f88f0a8c0e
Remove a footgun-y feature / relic of the past from the compiletest DSL 2025-02-03 05:45:18 +01:00
Laine Taffin Altman
baa1cdde29
Docs for f16 and f128: correct a typo and add details 2025-02-02 19:48:57 -08:00
León Orell Valerian Liehr
c371363650
LTA: Check where-clauses for well-formedness at the def site 2025-02-03 03:43:14 +01:00
bors
613bdd4997 Auto merge of #136454 - matthiaskrgr:rollup-ewejzmp, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #136145 (Test validity of pattern types)
 - #136339 (CompileTest: Add Directives to Ignore `arm-unknown-*` Targets)
 - #136403 (Fix malformed error annotations in a UI test)
 - #136414 (Shorten error message for callable with wrong return type)
 - #136425 (Move `rustc_middle::infer::unify_key`)
 - #136426 (Explain why we retroactively change a static initializer to have a different type)
 - #136445 (Couple of cleanups to DiagCtxt and EarlyDiagCtxt)
 - #136452 (Miri subtree update)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-02 23:15:58 +00:00
Nicholas Nethercote
f0b6d660c9 Derive Clone on fewer THIR types.
Some of these were never necessary, and some were facilitated by the
previous commit.
2025-02-03 10:12:40 +11:00
Nicholas Nethercote
17e4aec449 TypeVisitable doesn't require Clone.
`TypeFoldable` does, because it involves the production of new values.
But `TypeVisitable` only involves the visiting of values.
2025-02-03 10:12:40 +11:00
Matthias Krüger
a8055f944f
Rollup merge of #136452 - RalfJung:miri-sync, r=RalfJung
Miri subtree update

r? `@ghost`

Unblocks https://github.com/rust-lang/rust/pull/122408 from the Miri side
2025-02-02 23:06:58 +01:00
Matthias Krüger
f1bdf3ba4a
Rollup merge of #136445 - bjorn3:diag_ctxt_cleanup, r=oli-obk
Couple of cleanups to DiagCtxt and EarlyDiagCtxt
2025-02-02 23:06:57 +01:00
Matthias Krüger
f5ae630f10
Rollup merge of #136426 - oli-obk:push-nkpuulwurykn, r=compiler-errors
Explain why we retroactively change a static initializer to have a different type

I keep getting confused about it and in turn confused `@GuillaumeGomez` while trying to explain it badly
2025-02-02 23:06:57 +01:00
Matthias Krüger
0429945476
Rollup merge of #136425 - nnethercote:mv-rustc_middle-infer, r=lcnr
Move `rustc_middle::infer::unify_key`

`rustc_infer` is a much better place for it.

r? `@lcnr`
2025-02-02 23:06:56 +01:00
Matthias Krüger
dc4d38740e
Rollup merge of #136414 - estebank:expected-return-type, r=oli-obk
Shorten error message for callable with wrong return type

```
error: expected `{closure@...}` to return `Ret`, but it returns `Other`
```
instead of
```
error: expected `{closure@...}` to be a closure that returns `Ret`, but it returns `Other`
```
2025-02-02 23:06:55 +01:00
Matthias Krüger
5ab356fde8
Rollup merge of #136403 - fmease:fix-a-ui-test, r=oli-obk
Fix malformed error annotations in a UI test

The compiletest DSL still features a historical remnant from the time when its directives were merely prefixed with `//` instead of `//`@`` when unknown directive names weren't rejected since they could just as well be part of prose:

As an "optimization", it stops looking for directives once it stumbles upon a line which starts with either `fn` or `mod`. This allowed a malformed error annotation of the form `//`@[…]~^^^`` to go undetected & unexercised (as it's placed below `fn main() {`).

Obviously a character other than ``@`` would've mangled the error annotation, too (but it might've caught the reviewer's eye). I specifically found this file because I ran `rg '^(fn|mod)[\s\S]*?//`@'` tests/ui --multiline -trust` to check how footgun-y that "special feature" of compiletest is.
2025-02-02 23:06:55 +01:00
Matthias Krüger
4d3a4ee9e8
Rollup merge of #136339 - veera-sivarajan:ignore-arm-unknown-headers, r=jieyouxu
CompileTest: Add Directives to Ignore `arm-unknown-*` Targets

In  #134626, I want to ignore `arm-unknown-*` targets because the LLVM IR for those looks very different compared to other targets: https://rust.godbolt.org/z/ssYMhdv4x.

I can use `ignore-arm` but, I think, it would exclude large number of Apple devices.

So this PR adds a few directives to ignore `arm-unknown-*` targets specifically.
2025-02-02 23:06:54 +01:00
Matthias Krüger
f56e4b343b
Rollup merge of #136145 - oli-obk:push-wxvpklmkppqz, r=RalfJung
Test validity of pattern types

r? `@RalfJung`

pulled out of  #136006 so we don't have to rely on libcore types excercising this code path

There's nothing to fix. `rustc_layout_scalar_valid_range_start` structs just failed their validation on their value instead of their fields' value, causing a diff where moving to pattern types adds an additional `.0` field access to the validation error
2025-02-02 23:06:54 +01:00
Ralf Jung
df9a3f2647 update lockfile 2025-02-02 21:23:11 +01:00
Ralf Jung
3262fab0a8
Merge pull request #4142 from joboet/apple-futex
shim Apple's futex primitives
2025-02-02 19:55:06 +00:00
Oli Scherer
7e4ccc2f12 Maintain a list of types permitted per pattern 2025-02-02 19:30:53 +00:00
Oli Scherer
ded0836c18 Check the base type of pattern types for validity first 2025-02-02 19:30:53 +00:00
joboet
2d6c9b4c79
shim Apple's futex primitives
This is necessary to unblock rust-lang/rust#122408. The documentation for these is available [here](https://developer.apple.com/documentation/os/os_sync_wait_on_address?language=objc).

Because the futex wait operations (`os_sync_wait_on_address` et al.) return the number of remaining waiters after returning, this required some changes to the common futex infrastructure, which I've changed to take a callback instead of precalculating the return values.
2025-02-02 20:28:50 +01:00
Oli Scherer
2f2b32b84e Test validity of pattern types 2025-02-02 19:28:22 +00:00
Ralf Jung
60e1c0cb03
Merge pull request #4172 from RalfJung/miri_get_backtrace
miri_get_backtrace: stop supporting the v0 protocol
2025-02-02 19:14:20 +00:00
Ralf Jung
6b656cc0c7
Merge pull request #4174 from RalfJung/read-write-callback
files: make read/write take callback to store result
2025-02-02 19:13:49 +00:00
bors
4a43094662 Auto merge of #136448 - matthiaskrgr:rollup-pdim5di, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #134272 (Remove rustc_encodable_decodable feature)
 - #136283 (Update encode_utf16 to mention it is native endian)
 - #136394 (Clean up MonoItem::instantiation_mode)
 - #136402 (diagnostics: fix borrowck suggestions for if/while let conditionals)
 - #136415 (Highlight clarifying information in "expected/found" error)
 - #136422 (Convert two `rustc_middle::lint` functions to `Span` methods.)
 - #136434 (rustc_allowed_through_unstable_modules: require deprecation message)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-02 19:13:36 +00:00
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
198384c8cc
Rollup merge of #136283 - hkBst:patch-31, r=workingjubilee
Update encode_utf16 to mention it is native endian

Fixes #83102
2025-02-02 18:05:22 +01:00