Commit graph

394 commits

Author SHA1 Message Date
Matthew Jasper
ac45a67297 Use delayed bug for normalization errors in drop elaboration
Normalization can fail from errors from other items so use a delayed
bug instead of checking the body.
2025-04-11 16:31:28 +00:00
bors
71b68da1bd Auto merge of #139578 - ferrocene:pa-compiletest-edition, r=jieyouxu
Fix breakage when running compiletest with `--test-args=--edition=2015`

Compiletest has an `--edition` flag to change the default edition tests are run with. Unfortunately no test suite successfully executes when that flag is passed. If the edition is set to something greater than 2015 the breakage is expected, since the test suite currently supports only edition 2015 (Ferrous Systems will open an MCP about fixing that soonish). Surprisingly, the test suite is also broken if `--edition=2015` is passed to compiletest. This PR focuses on fixing the latter.

This PR fixes the two categories of failures happening when `--edition=2015` is passed:

* Some edition-specific tests set their edition through `//@ compile-flags` instead of `//@ edition`. Compiletest doesn't parse the compile flags, so it would see no `//@ edition` and add another `--edition` flag, leading to a rustc error.
* Compiletest would add the edition after `//@ compile-flags`, while some tests depend on flags passed to `//@ compile-flags` being the last flags in the rustc invocation.

Note that for the first category, I opted to manually go and replace all `//@ compile-flags` setting an edition with an explicit `//@ edition`. We could've changed compiletest to instead check whether an edition was set in `//@ compile-flags`, but I thought it was better to enforce a consistent way to set the edition in tests.

I also added the edition to the stamp, so that changing `--edition` results in tests being re-executed.

r? `@jieyouxu`
2025-04-11 10:53:45 +00:00
Pietro Albini
cd371b90e2
replace //@ compile-flags: --edition with //@ edition 2025-04-10 09:56:37 +02:00
Santiago Pastorino
d6ad9e6191
Remove crash test that do not ICE anymore 2025-04-07 16:53:12 -03:00
Stuart Cook
66ccc4fe28
Rollup merge of #139341 - nnethercote:fix-137874, r=petrochenkov
Apply `Recovery::Forbidden` when reparsing pasted macro fragments.

Fixes #137874.

The changes to the output of `tests/ui/associated-consts/issue-93835.rs`
partly undo the changes seen when `NtTy` was removed in #133436, which
is good.

r? ``@petrochenkov``
2025-04-05 13:18:17 +11:00
Nicholas Nethercote
b9e13cb539 Apply Recovery::Forbidden when reparsing pasted macro fragments.
Fixes #137874.

Removes `tests/crashes/137874.rs`; the new test is simpler (defines its
own macro) but tests the same thing.

The changes to the output of `tests/ui/associated-consts/issue-93835.rs`
partly undo the changes seen when `NtTy` was removed in #133436, which
is good.
2025-04-04 13:24:26 +11:00
lcnr
509a144eed add TypingMode::Borrowck 2025-04-03 11:13:10 +02:00
Stuart Cook
bae53a7c3c
Rollup merge of #135295 - eyraudh:master, r=compiler-errors
Check empty SIMD vector in inline asm

fixes [#134334](https://github.com/rust-lang/rust/issues/134334)
2025-04-02 13:10:36 +11:00
Michael Goulet
e2d5033bce Feed HIR for by-move coroutine body def, since the inliner tries to read its attrs 2025-03-31 21:10:56 +00:00
Hadrien Eyraud
6948343b9f fix: Check empty SIMD vector in inline asm 2025-03-23 19:41:39 +01:00
bors
db687889a5 Auto merge of #138719 - lcnr:concrete_opaque_types-closures, r=oli-obk
merge opaque types defined in nested bodies

A small step towards https://github.com/rust-lang/types-team/issues/129

r? `@oli-obk`
2025-03-22 06:55:52 +00:00
Michael Goulet
220851cc75 Do not rely on type_var_origin in OrphanCheckErr::NonLocalInputType 2025-03-20 02:17:14 +00:00
lcnr
cfc78cec79 merge opaque types of nested bodies 2025-03-19 17:52:53 +01:00
Michael Goulet
93b31d9b21 Remove existing AFIDT implementation 2025-03-18 17:35:26 +00:00
dianne
36ff87e90e EUV: fix place of deref pattern's interior's scrutinee
The place previously used here was that of the temporary holding the
reference returned by `Deref::deref` or `DerefMut::deref_mut`. However,
since the inner pattern of `deref!(inner)` expects the deref-target type
itself, this would ICE when that type was inspected (e.g. by the EUV
case for slice patterns). This adds a deref projection to fix that.

Since current in-tree consumers of EUV (upvar inference and clippy)
don't care about Rvalues, the place could be simplified to
`self.cat_rvalue(pat.hir_id, self.pat_ty_adjusted(subpat)?)` to save
some cycles. I personally find EUV to be a bit fragile, so I've opted
for pedantic correctness. Maybe a `HACK` comment would suffice though?
2025-03-13 01:01:26 -07:00
bors
c625102320 Auto merge of #138366 - matthiaskrgr:rollup-cn16m7q, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #137715 (Allow int literals for pattern types with int base types)
 - #138002 (Disable CFI for weakly linked syscalls)
 - #138051 (Add support for downloading GCC from CI)
 - #138231 (Prevent ICE in autodiff validation by emitting user-friendly errors)
 - #138245 (stabilize `ci_rustc_if_unchanged_logic` test for local environments)
 - #138256 (Do not feed anon const a type that references generics that it does not have)
 - #138284 (Do not write user type annotation for const param value path)
 - #138296 (Remove `AdtFlags::IS_ANONYMOUS` and `Copy`/`Clone` condition for anonymous ADT)
 - #138352 (miri native_calls: ensure we actually expose *mutable* provenance to the memory FFI can access)
 - #138354 (remove redundant `body`  arguments)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-03-11 21:17:18 +00:00
Matthias Krüger
16ff824133
Rollup merge of #138284 - compiler-errors:const-param-ty-annotation, r=BoxyUwU
Do not write user type annotation for const param value path

As I noted in the code comment, `DefKind::ConstParam` isn't actually *generic* over its own args, we just use the identity args from the body when lowering the value path so we have something to plug into the `EarlyBinder` we get back from `type_of` for the const param. So skip over it in `write_user_type_annotation_from_args`.

Somewhat unrelated, but I left an explanation for a somewhat mysterious quirk in the THIR lowering of user type annotations for patterns having to do with ctors and their `type_of` not actually being the type of the pattern node it's ascribing.

Fixes #138048

r? ``@BoxyUwU``
2025-03-11 19:35:32 +01:00
Matthias Krüger
4ff58c9103
Rollup merge of #138256 - compiler-errors:anon-const-ty, r=BoxyUwU
Do not feed anon const a type that references generics that it does not have

Fixes #137865

See the comment I left in the code. We could alternatively give these anon consts the generics from the parent, but that would be moving in a GCE-esque direction that we may not want. Open to tweaks here.

r? BoxyUwU
2025-03-11 19:35:31 +01:00
bors
6650252439 Auto merge of #128440 - oli-obk:defines, r=lcnr
Add `#[define_opaques]` attribute and require it for all type-alias-impl-trait sites that register a hidden type

Instead of relying on the signature of items to decide whether they are constraining an opaque type, the opaque types that the item constrains must be explicitly listed.

A previous version of this PR used an actual attribute, but had to keep the resolved `DefId`s in a side table.

Now we just lower to fields in the AST that have no surface syntax, instead a builtin attribute macro fills in those fields where applicable.

Note that for convenience referencing opaque types in associated types from associated methods on the same impl will not require an attribute. If that causes problems `#[defines()]` can be used to overwrite the default of searching for opaques in the signature.

One wart of this design is that closures and static items do not have generics. So since I stored the opaques in the generics of functions, consts and methods, I would need to add a custom field to closures and statics to track this information. During a T-types discussion we decided to just not do this for now.

fixes #131298
2025-03-11 18:13:31 +00:00
Oli Scherer
cb4751d4b8 Implement #[define_opaque] attribute for functions. 2025-03-11 12:05:02 +00:00
Matthias Krüger
0d6311931b
Rollup merge of #138278 - Bryanskiy:delegation-ice-1, r=petrochenkov
Delegation: fix ICE with invalid `MethodCall` generation

`ExprKind::MethodCall` is now generated instead of `ExprKind::Call` if
- the resolved function has a `&self` argument
- the resolved function is an associated item <- was missed before

Fixes https://github.com/rust-lang/rust/issues/128190
Fixes https://github.com/rust-lang/rust/issues/128119
Fixes https://github.com/rust-lang/rust/issues/127916

r? `@petrochenkov`
2025-03-10 15:57:14 +01:00
Bryanskiy
61122d1829 Delegation: fix ICE with invalid MethodCall generation 2025-03-10 17:08:29 +03:00
Michael Goulet
ed6dfddfeb Do not feed anon const a type that references generics that it does not have 2025-03-09 20:03:13 +00:00
Michael Goulet
8ab05adc37 Do not write user type annotation for const param value path 2025-03-09 19:50:50 +00:00
Matthias Krüger
088b125853 crashes: couple more tests 2025-03-08 20:13:07 +01:00
Nicholas Nethercote
af92a33dee Make synthetic RPITIT assoc ty name handling more rigorous.
Currently it relies on special treatment of `kw::Empty`, which is really
easy to get wrong. This commit makes the special case clearer in the
type system by using `Option`. It's a bit clumsy, but the synthetic name
handling itself is a bit clumsy; better to make it explicit than sneak
it in.

Fixes #133426.
2025-03-07 20:59:45 +11:00
许杰友 Jieyou Xu (Joe)
fe4c0850fe
Rollup merge of #138028 - workingjubilee:is-rustic-abi, r=compiler-errors
compiler: add `ExternAbi::is_rustic_abi`

Various parts of the compiler were hand-rolling this extremely simple check that is nonetheless easy to get wrong as the compiler evolves over time. Discourage them from being so "original" again by replacing it with a single implementation on the type that represents these ABIs. This simplifies a surprising amount of code as a result.

Also fixes #132981, an ICE that emerged due to other checks being made stricter.
2025-03-05 21:46:46 +08:00
Jubilee Young
8a689878ce compiler: use is_rustic_abi in ty_utils
expands some conditionals to include different "rustic" ABIs, so that we
actually handle passing args through all "rustic" ABIs
2025-03-04 19:57:51 -08:00
Michael Goulet
9d3d5a7fbb Check signature WF when lowering MIR body 2025-03-03 23:09:42 +00:00
Gary Guo
395b0fb4d9 Bless tests 2025-02-26 19:27:19 +00:00
Jacob Pratt
d41520052e
Rollup merge of #137458 - compiler-errors:render-fn, r=fmease
Fix missing self subst when rendering `impl Fn*<T>` with no output type

r? `@fmease` or reassign

Fixes #133597
cc #137456
2025-02-23 02:44:20 -05:00
Michael Goulet
431b9aa38f Fix missing self subst when rendering Fn* trait with no output type 2025-02-23 04:46:51 +00:00
Matthias Krüger
4115f51d15
Rollup merge of #137180 - compiler-errors:sym-regions, r=oli-obk
Give `global_asm` a fake body to store typeck results, represent `sym fn` as a hir expr to fix `sym fn` operands with lifetimes

There are a few intertwined problems with `sym fn` operands in both inline and global asm macros.

Specifically, unlike other anon consts, they may evaluate to a type with free regions in them without actually having an item-level type annotation to give them a "proper" type. This is in contrast to named constants, which always have an item-level type annotation, or unnamed constants which are constrained by their position (e.g. a const arg in a turbofish, or a const array length).

Today, we infer the type of the operand by looking at the HIR typeck results; however, those results are region-erased, so during borrowck we ICE since we don't expect to encounter erased regions. We can't just fill this type with something like `'static`, since we may want to use real (free) regions:

```rust
fn foo<'a>() {
  asm!("/* ... */", sym bar::<&'a ()>);
}
```

The first idea may be to represent `sym fn` operands using *inline* consts instead of anon consts. This makes sense, since inline consts can reference regions from the parent body (like the `'a` in the example above). However, this introduces a problem with `global_asm!`, which doesn't *have* a parent body; inline consts *must* be associated with a parent body since they are not a body owner of their own. In #116087, I attempted to fix this by using two separate `sym` operands for global and inline asm. However, this led to a lot of confusion and also some unattractive code duplication.

In this PR, I adjust the lowering of `global_asm!` so that it's lowered in a "fake" HIR body. This body contains a single expression which is `ExprKind::InlineAsm`; we don't *use* this HIR body, but it's used in typeck and borrowck so that we can properly infer and validate the the lifetimes of `sym fn` operands.

I then adjust the lowering of `sym fn` to instead be represented with a HIR expression. This is both because it's no longer necessary to represent this operand as an anon const, since it's *just* a path expression, and also more importantly to sidestep yet another ICE (https://github.com/rust-lang/rust/issues/137179), which has to do with the existing code breaking an invariant of def-id creation and anon consts. Specifically, we are not allowed to synthesize a def-id for an anon const when that anon const contains expressions with def-ids whose parent is *not* that anon const. This is somewhat related to https://github.com/rust-lang/rust/pull/130443#issuecomment-2445678945, which is also a place in the compiler where synthesizing anon consts leads to def-id parenting issue.

As a side-effect, this consolidates the type checking for inline and global asm, so it allows us to simplify `InlineAsmCtxt` a bit. It also allows us to delete a bit of hacky code from anon const `type_of` which was there to detect `sym fn` operands specifically. This also could be generalized to support `const` asm operands with types with lifetimes in them. Since we specifically reject these consts today, I'm not going to change the representation of those consts (but they'd just be turned into inline consts).

r? oli-obk -- mostly b/c you're patient and also understand the breadth of the code that this touches, please reassign if you don't want to review this.

Fixes #111709
Fixes #96304
Fixes #137179
2025-02-23 00:16:19 +01:00
Michael Goulet
6ba39f7dc7 Make a fake body to store typeck results for global_asm 2025-02-22 00:12:07 +00:00
Michael Goulet
72bd174c43 Do not deduplicate list of associated types provided by dyn principal 2025-02-21 19:32:45 +00:00
Scott McMurray
6f9cfd694d Rework OperandRef::extract_field to stop calling to_immediate_scalar on things which are already immediates
That means it stops trying to truncate things that are already `i1`s.
2025-02-19 12:03:40 -08:00
Matthew Jasper
87e5969572 Update tests for dropck normalization errors
Takes crash tests from #135039, #103899, #91985 and #105299 and turns them into ui tests
2025-02-17 11:33:07 +00:00
lcnr
059288ed44 adjust derive_error 2025-02-13 23:49:09 +01:00
Matthias Krüger
fb52da3808 crashes: more tests 2025-02-09 10:40:18 +01:00
Matthias Krüger
cbd44d7998
Rollup merge of #134367 - WaffleLapkin:trait_upcasting_as_a_treat, r=compiler-errors
Stabilize `feature(trait_upcasting)`

This feature was "done" for a while now, I think it's finally time to stabilize it! Stabilization report: https://github.com/rust-lang/rust/pull/134367#issuecomment-2545839841.
cc reference PR: https://github.com/rust-lang/reference/pull/1622.

Closes #65991 (tracking issue), closes #89460 (the lint is no longer future incompat).

r? compiler-errors
2025-02-07 18:26:25 +01:00
Matthias Krüger
1c794b908b
Rollup merge of #135973 - WaffleLapkin:tail-track-caller-fix, r=compiler-errors
fix tail call checks wrt `#[track_caller]`

Only check the caller + disallow caller having the attribute.

fixes #134336

r? `@compiler-errors`

<sub>apparently there were no tests for `#[track_caller]` before... ooops</sub>
2025-02-07 12:01:56 +01:00
Waffle Lapkin
e9d5d1113f
remove feature(trait_upcasting) from tests and bless them 2025-02-06 23:44:23 +01:00
Matthias Krüger
4b7e55ada3
Rollup merge of #133925 - folkertdev:improve-repr-warnings, r=compiler-errors
disallow `repr()` on invalid items

fixes https://github.com/rust-lang/rust/issues/129606
fixes https://github.com/rust-lang/rust/issues/132391

Disallows `repr()` (so a repr with no arguments) on items where that won't ever make sense.

Also this generates an error when `repr` is used on a trait method and the `fn_align` feature is not enabled. Looks like that was missed here:

https://github.com/rust-lang/rust/pull/110313/files

Which first accepts the align attribute on trait methods.

r? `@compiler-errors`

cc `@jdonszelmann` who claimed https://github.com/rust-lang/rust/issues/132391 and generally has been working on attributes
2025-02-06 21:56:24 +01:00
Waffle Lapkin
992e3b4f03
fix tail call checks wrt #[track_caller]
only check the caller + disallow caller having the attr.
2025-02-06 21:06:51 +01:00
Matthias Krüger
5da750001d
Rollup merge of #136520 - compiler-errors:redundant-layout-assert, r=lcnr
Remove unnecessary layout assertions for object-safe receivers

The soundness of `DispatchFromDyn` relies on the fact that, like all other built-in marker-like layout traits (e.g. `Sized`, `CoerceUnsized`), the guarantees that they enforce in *generic* code via traits will result in assumptions that we can rely on in codegen.

Specifically, `DispatchFromDyn` ensures that we end up with a receiver that is a valid pointer type, and its implementation validity recursively ensures that the ABI of that pointer type upholds the `Scalar` or `ScalarPair` representation for sized and unsized pointees, respectively.

The check that this layout guarantee holds for arbitrary, possibly generic receiver types that also may exist in possibly impossible-to-instantiate where clauses is overkill IMO, and leads to several ICEs due to the fact that computing layouts before monomorphization is going to be fallible at best.

This PR removes the check altogether, since it just exists as a sanity check from very long ago, 6f2a161b1b.

Fixes #125810
Fixes #90110

This PR is an alternative to #136195. cc `@adetaylor.` I didn't realize in that PR that the layout checks that were being modified were simply *sanity checks*, rather than being actually necessary for soundness.
2025-02-04 18:49:41 +01:00
Matthias Krüger
29e1dddd83
Rollup merge of #136497 - Jarcho:fn_ctxt, r=compiler-errors
Report generic mismatches when calling bodyless trait functions

Don't know if there's an open issue for this. Just happened to notice this when working in that area.

The awkward extra spans added to the diagnostics of some tests (e.g. `trait-with-missing-associated-type-restriction`) is consistent with what happens for normal functions. Should probably be removed since that span doesn't seem to note anything useful.

First and third commit are both cleanups removing some unnecessary work. Second commit has the actual fix.

fixes #135124
2025-02-04 18:49:40 +01:00
Matthias Krüger
a8ecb79d19
Rollup merge of #136274 - compiler-errors:sized-wf, r=lcnr
Check Sizedness of return type in WF

Still need to clean this up a bit. This should fix https://github.com/rust-lang/trait-system-refactor-initiative/issues/150.

r? lcnr
2025-02-04 18:49:37 +01:00
Jacob Pratt
2a8a1911da
Rollup merge of #134777 - saethlin:enable-more-tests-on-windows, r=Noratrieb
Enable more tests on Windows

As part of the discussion of https://github.com/rust-lang/compiler-team/issues/822 on Zulip, it was mentioned that problems with the i686-pc-windows-gnu target may have resulted in tests being disabled on Windows.

So in this PR, I've ripped out all our `//@ ignore-windows` directives, then re-added all the ones that are definitely required based on the outcome of try-builds, and in some cases I've improved the justification or tightened the directives to `//@ ignore-msvc` or ignoring specific targets.
2025-02-04 05:36:50 -05:00
Jason Newcomb
8b1c28fdd0 Fix ICE when function argument mismatches. 2025-02-03 20:55:22 -05:00
Michael Goulet
0b26dc0b51 Remove unnecessary layout assertions for object-safe receivers 2025-02-04 01:50:31 +00:00