Commit Graph

2136 Commits

Author SHA1 Message Date
Esteban Küber
857918e9bc review comments
Replace tuple with struct and remove unnecessary early return.
2025-01-11 01:23:37 +00:00
Esteban Küber
919f672c3d Avoid unnecessary note when type has escaping bounds 2025-01-11 01:10:29 +00:00
Esteban Küber
91425d0ef8 Avoid duplicated note 2025-01-11 01:10:29 +00:00
Esteban Küber
05c39438e2 Account for for<'a> types when checking for non-structural type in constant as pattern
When we encounter a constant in a pattern, we check if it is non-structural. If so, we check if the type implements `PartialEq`, but for types with escaping bound vars the check would be incorrect as is, so we break early. This is ok because these types would be filtered anyways.

Fix #134764.
2025-01-11 01:10:29 +00:00
David Wood
cc9a9ecccb
mir_build: check annotated functions w/out callers 2025-01-10 18:37:57 +00:00
Oli Scherer
8505904dcc Remove the now-useless Result from lit_to_const 2025-01-09 08:48:46 +00:00
Oli Scherer
07fcead073 Always take the Ok path in lit_to_const and produce error constants instead 2025-01-09 08:48:00 +00:00
Oli Scherer
787af97bab Use error constant instead of explicit error handling 2025-01-09 08:48:00 +00:00
Oli Scherer
7833cf7a47 Make lit_to_mir_constant infallible 2025-01-09 08:48:00 +00:00
bors
e26ff2f908 Auto merge of #135260 - matthiaskrgr:rollup-8irqs72, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #134228 (Exhaustively handle expressions in patterns)
 - #135194 (triagebot: mark tidy changes with a more specific `A-tidy` label)
 - #135222 (Ensure that we don't try to access fields on a non-struct pattern type)
 - #135250 (A couple simple borrowck cleanups)
 - #135252 (Fix release notes link)
 - #135253 (Revert #131365)

Failed merges:

 - #135195 (Make `lit_to_mir_constant` and `lit_to_const` infallible)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-08 21:31:51 +00:00
Ding Xiang Fei
045271cccc run borrowck tests on BIDs and emit tail-expr-drop-order lints for
potential violations
2025-01-08 15:58:09 +00:00
Oli Scherer
4a8773a3af Rename PatKind::Lit to Expr 2025-01-08 07:34:59 +00:00
Oli Scherer
c9365dd09f Exhaustively handle expressions in patterns 2025-01-08 07:33:46 +00:00
Matthias Krüger
a20d0d5a5c
Rollup merge of #134989 - max-niederman:guard-patterns-hir, r=oli-obk
Lower Guard Patterns to HIR.

Implements lowering of [guard patterns](https://rust-lang.github.io/rfcs/3637-guard-patterns.html) (see the [tracking issue](#129967)) to HIR.
2025-01-07 21:39:40 +01:00
Jubilee
7cf3b96a83
Rollup merge of #135046 - RalfJung:rustc_box_intrinsic, r=compiler-errors
turn rustc_box into an intrinsic

I am not entirely sure why this was made a special magic attribute, but an intrinsic seems like a more natural way to add magic expressions to the language.
2025-01-04 07:57:33 -08:00
bors
fd127a3a84 Auto merge of #135031 - RalfJung:intrinsics-without-body, r=oli-obk
rustc_intrinsic: support functions without body

We synthesize a HIR body `loop {}` but such bodyless intrinsics.

Most of the diff is due to turning `ItemKind::Fn` into a brace (named-field) enum variant, because it carries a `bool`-typed field now. This is to remember whether the function has a body. MIR building panics to avoid ever translating the fake `loop {}` body, and the intrinsic logic uses the lack of a body to implicitly mark that intrinsic as must-be-overridden.

I first tried actually having no body rather than generating the fake body, but there's a *lot* of code that assumes that all function items have HIR and MIR, so this didn't work very well. Then I noticed that even `rustc_intrinsic_must_be_overridden` intrinsics have MIR generated (they are filled with an `Unreachable` terminator) so I guess I am not the first to discover this. ;)

r? `@oli-obk`
2025-01-04 12:50:38 +00:00
Ralf Jung
3cd3649c6c rustc_intrinsic: support functions without body; they are implicitly marked as must-be-overridden 2025-01-04 11:41:51 +01:00
Ralf Jung
b806dccdc4 const-in-pattern: test that the PartialEq impl does not need to be const 2025-01-03 16:08:29 +01:00
Ralf Jung
ac9cb908ac turn rustc_box into an intrinsic 2025-01-03 12:01:31 +01:00
Max Niederman
b579c36224 add guard patterns to HIR and implement lowering 2024-12-31 17:21:29 -08:00
chloefeal
e1b65be417
Fix typos
Signed-off-by: chloefeal <188809157+chloefeal@users.noreply.github.com>
2024-12-27 21:35:57 +08:00
Scott McMurray
5ba54c9e31 Delete Rvalue::Len
Everything's moved to `PtrMetadata` instead.
2024-12-22 06:12:39 -08:00
Michael Goulet
42d1a4c48b Handle DropKind::ForLint in coroutines correctly 2024-12-20 18:18:06 +00:00
bors
11663cd3bf Auto merge of #134486 - compiler-errors:drop-for-lint, r=nikomatsakis
Make sure we handle `backwards_incompatible_lint` drops appropriately in drop elaboration

In #131326, a new kind of scheduled drop (`drop_kind: DropKind::Value` + `backwards_incompatible_lint: true`) was added so that we could insert a new kind of no-op MIR statement (`backward incompatible drop`) for linting purposes.

These drops were intended to have *no side-effects*, but drop elaboration code forgot to handle these drops specially and they were handled otherwise as normal drops in most of the code. This ends up being **unsound** since we insert more than one drop call for some values, which means that `Drop::drop` could be called more than once.

This PR fixes this by splitting out the `DropKind::ForLint` and adjusting the code. I'm not totally certain if all of the places I've adjusted are either reachable or correct, but I'm pretty certain that it's *more* correct than it was previously.

cc `@dingxiangfei2009`
r? nikomatsakis

Fixes #134482
2024-12-19 15:58:08 +00:00
Niko Matsakis
6564403641 pacify merciless fmt 2024-12-19 14:32:25 +00:00
Niko Matsakis
b535061060 explain how build_scope_drops works 2024-12-19 13:53:35 +00:00
Michael Goulet
e5e0387cdb Rename Scope.id to Scope.local_id, remove trivial accessor 2024-12-19 02:31:58 +00:00
Michael Goulet
1f352acd34 Use TypingEnv from MIR builder 2024-12-19 02:31:52 +00:00
Michael Goulet
5e079011ea Separate DropKind::ForLint 2024-12-18 21:58:39 +00:00
许杰友 Jieyou Xu (Joe)
7e4f45a377
Rollup merge of #134399 - spastorino:invert-if-condition, r=jieyouxu
Do not do if ! else, use unnegated cond and swap the branches instead

I'm tidying up my ergonomic ref counting PR and I'm going to make some small, simple and unrelated changes outside that PR, so the main PR sticks more straight to the point.
2024-12-18 22:56:55 +08:00
许杰友 Jieyou Xu (Joe)
f3faaf524c
Rollup merge of #134394 - dianne:clarify-pat-2024-migration, r=compiler-errors
Clarify the match ergonomics 2024 migration lint's output

This makes a few changes:
- Rather than using the whole pattern as a span for the lint, this collects spans for each problematic default binding mode reset and labels them with why they're problems.
- The lint's suggestions are now verbose-styled, so that it's clear what's being suggested vs. what's problematic.
- The wording is now less technical, and the hard error version of this diagnostic now links to the same reference material as the lint (currently an unwritten page of the edition guide).

I'm not totally confident in the wording or formatting, so I'd appreciate feedback on that in particular. I tried to draw a connection with word choice between the labels and the suggestion, but it might be imprecise, unclear, or cluttered. If so, it might be worth making the labels more terse and adding notes that explain them, but that's harder to read in a way too.

cc ```@Nadrieril``` ```@Jules-Bertholet```

Closes #133854. For reference, the error from that issue becomes:
```
error: pattern uses features incompatible with edition 2024
  --> $DIR/remove-me.rs:6:25
   |
LL |     map.iter().filter(|(&(_x, _y), &_c)| false);
   |                         ^          ^ cannot implicitly match against multiple layers of reference
   |                         |
   |                         cannot implicitly match against multiple layers of reference
   |
help: make the implied reference pattern explicit
   |
LL |     map.iter().filter(|&(&(_x, _y), &_c)| false);
   |                        +
```
2024-12-18 22:56:54 +08:00
DianQK
93aea1d0fe
mir: require is_cleanup when creating BasicBlockData 2024-12-18 20:43:54 +08:00
Santiago Pastorino
3218476c12 Do not do if ! else, use unnegated cond and swap the branches instead 2024-12-18 18:57:33 +08:00
Nicholas Nethercote
2620eb42d7 Re-export more rustc_span::symbol things from rustc_span.
`rustc_span::symbol` defines some things that are re-exported from
`rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some
closely related things such as `Ident` and `kw`. So you can do `use
rustc_span::{Symbol, sym}` but you have to do `use
rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good
reason.

This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`,
and changes many `rustc_span::symbol::` qualifiers in `compiler/` to
`rustc_span::`. This is a 200+ net line of code reduction, mostly
because many files with two `use rustc_span` items can be reduced to
one.
2024-12-18 13:38:53 +11:00
dianne
28c6d0b55b Add the edition guide link from the match 2024 migration lint to the error as well 2024-12-17 15:21:28 -08:00
dianne
77e9051e22 Improve the pattern migration 2024 migration lint's message 2024-12-17 13:46:00 -08:00
dianne
a676872e0f Clarify the match ergonomics 2024 migration lint's output 2024-12-17 13:38:21 -08:00
Jacob Pratt
0956be6aa5
Rollup merge of #134400 - spastorino:fix-some-comments, r=compiler-errors
Fix some comments related to upvars handling

I'm tidying up my ergonomic ref counting PR and I'm going to make some small, simple and unrelated changes outside that PR, so the main PR sticks more straight to the point.
2024-12-17 05:37:19 -05:00
Zalathar
c58219b786 Explain why build was renamed to builder 2024-12-17 11:41:11 +11:00
Zalathar
bccbe70991 Rename rustc_mir_build::build to builder 2024-12-17 11:41:11 +11:00
Santiago Pastorino
62d5aaa8d4
Adjust upvar.rs file path 2024-12-16 17:05:28 -03:00
Matthias Krüger
7c301ecdf5
Rollup merge of #134371 - scottmcm:fix-134352, r=oli-obk
Check for array lengths that aren't actually `usize`

I wish typeck wouldn't give us `ty::Array`s that have this problem in the first place, but we can check for it.

Fixes #134352
cc ``@matthiaskrgr``
2024-12-16 20:00:26 +01:00
Matthias Krüger
d03e3c8612
Rollup merge of #134197 - Enselic:mirror, r=lcnr
rustc_mir_build: Clarify that 'mirrored' does not mean 'flipped' or 'reversed'

My intuition for 'mirrored' is that it means 'flipped' or 'reversed'. Clarify that that is not what is meant to 'mirror' the THIR from the HIR.
2024-12-16 20:00:13 +01:00
Matthias Krüger
050e0cc6eb
Rollup merge of #134314 - compiler-errors:default-struct-value-const, r=estebank
Make sure to use normalized ty for unevaluated const in default struct value

This cleans up the way that we construct the `mir::Const::Unevaluated` for default struct values. We were previously using `from_unevaluated`, which doesn't normalize the type, and is really only used for inline assembly. Other codepaths (such as `ExprKind::NamedConst`) use the type from the body.

Also, let's stop using `literal_operand`, which also is really not meant for calls other than for literal comparisons in pattern lowering.

Also move all of the tests to a separate subdirectory so they don't need to have the same prefix on all the test files.

Fixes #134298
r? estebank or reassign
2024-12-16 08:03:32 +01:00
Scott McMurray
43a79a0f4b Check for array lengths that aren't actually usize 2024-12-15 22:18:09 -08:00
Jonathan Dönszelmann
d50c0a5480
Add hir::Attribute 2024-12-15 19:18:46 +01:00
Stuart Cook
d48af09ffd
Rollup merge of #134285 - oli-obk:push-vwrqsqlwnuxo, r=Urgau
Add some convenience helper methods on `hir::Safety`

Makes a lot of call sites simpler and should make any refactorings needed for https://github.com/rust-lang/rust/pull/134090#issuecomment-2541332415 simpler, as fewer sites have to be touched in case we end up storing some information in the variants of `hir::Safety`
2024-12-15 20:01:38 +11:00
bors
b57d93d8b9 Auto merge of #133734 - scottmcm:lower-indexing-to-ptrmetadata, r=davidtwco,RalfJung
Bounds-check with PtrMetadata instead of Len in MIR

Rather than emitting `Len(*_n)` in array index bounds checks, emit `PtrMetadata(copy _n)` instead -- with some asterisks for arrays and `&mut` that need it to be done slightly differently.

We're getting pretty close to removing `Len` entirely, actually.  I think just one more PR after this (for slice drop shims).

r? mir
2024-12-14 22:43:39 +00:00
Oli Scherer
8a4e5d7444 Add some convenience helper methods on hir::Safety 2024-12-14 20:31:07 +00:00
Michael Goulet
f870761cd8 Make sure to use normalized ty for unevaluated const for default struct value 2024-12-14 18:05:19 +00:00