Commit graph

2335 commits

Author SHA1 Message Date
Zalathar
7de67a16c5 Flatten the option check in lower_pattern_range_endpoint 2025-02-03 12:51:58 +11: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
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
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
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
Michael Goulet
fc1a9186dc Implement MIR, CTFE, and codegen for unsafe binders 2025-01-31 17:19:53 +00:00
Rémy Rakic
94562ee1ea ensure sufficient stack in unsafety check 2025-01-31 12:24:16 +00:00
Rémy Rakic
2c778c1e4c ensure sufficient stack in tail call check 2025-01-31 12:24:16 +00: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
Nicholas Nethercote
1d2cb611f7 Remove the mir_build hook.
It was downgraded from a query in #122721 but it can just be a vanilla
function because it's not called in `rustc_middle`.
2025-01-31 15:15:01 +11:00
Nicholas Nethercote
4b025ca083 Remove the thir_{tree,flat} hooks.
They were downgraded from queries in #123995 but they can just be
vanilla functions because they are not called in `rustc_middle`.
2025-01-31 15:13:51 +11:00
Lukas Markeffsky
ca3ff832e3 add comments 2025-01-30 18:13:16 +01:00
Lukas Markeffsky
10fc0b159e introduce ty::Value
Co-authored-by: FedericoBruzzone <federico.bruzzone.i@gmail.com>
2025-01-30 17:47:44 +01:00
Oli Scherer
0cd51863ff Avoid calling the layout_of query in lit_to_const 2025-01-30 15:37:49 +00:00
Oli Scherer
a7ce15d361 Don't allow negative unsigned literals 2025-01-30 14:33:58 +00:00
bors
ae5de6c759 Auto merge of #134248 - oli-obk:patkind-path-removal, r=BoxyUwU
Merge `PatKind::Path` into `PatKind::Expr`

Follow-up to #134228

We always had a duplication where `Path`s could be represented as `PatKind::Path` or `PatKind::Lit(ExprKind::Path)`. We had to handle both everywhere, and still do after #134228, so I'm removing it now.
2025-01-29 19:16:29 +00:00
Oli Scherer
f47ad71059 Eliminate PatKind::Path 2025-01-29 15:45:13 +00:00
León Orell Valerian Liehr
8d183d2b86
Rollup merge of #136121 - oli-obk:push-zzvxlynmnqpp, r=estebank
Deduplicate operand creation between scalars, non-scalars and string patterns

just something that felt duplicated and would make pattern type handling a bit more roundabout.
2025-01-29 06:03:20 +01:00
Matthias Krüger
21ddd7ab89
Rollup merge of #135748 - compiler-errors:len-2, r=RalfJung,oli-obk
Lower index bounds checking to `PtrMetadata`, this time with the right fake borrow semantics 😸

Change `Rvalue::RawRef` to take a `RawRefKind` instead of just a `Mutability`. Then introduce `RawRefKind::FakeForPtrMetadata` and use that for lowering index bounds checking to a `PtrMetadata`. This new `RawRefKind::FakeForPtrMetadata` acts like a shallow fake borrow in borrowck, which mimics the semantics of the old `Rvalue::Len` operation we're replacing.

We can then use this `RawRefKind` instead of using a span desugaring hack in CTFE.

cc ``@scottmcm`` ``@RalfJung``
2025-01-28 14:23:22 +01:00
Oli Scherer
d62f885a8e Edit the inputs to const == val check instead of duplicating logic 2025-01-28 08:55:54 +00:00
Michael Goulet
eeecb56b73 Represent the raw pointer for a array length check as a new kind of fake borrow 2025-01-28 00:00:33 +00:00
Michael Goulet
057313b7a6 Reapply "Auto merge of #133734 - scottmcm:lower-indexing-to-ptrmetadata, r=davidtwco,RalfJung"
This reverts commit 122a55bb44.
2025-01-27 23:42:47 +00:00
Oli Scherer
e1e2e17d20 Use an operand instead of a place that is always turned into an operand 2025-01-27 10:36:30 +00:00
Oli Scherer
a9213c27ad Deduplicate operand creation between scalars, non-scalars and string patterns 2025-01-27 10:24:05 +00:00
Michael Goulet
ac1c6c50f4 Use identifiers in diagnostics more often 2025-01-27 01:23:34 +00:00
Matthias Krüger
2080d66a15
Rollup merge of #136018 - estebank:long-moved-type, r=jieyouxu
Use short ty string for move errors

```
error[E0382]: use of moved value: `x`
  --> bay.rs:14:14
   |
12 | fn foo(x: D) {
   |        - move occurs because `x` has type `(((..., ..., ..., ...), ..., ..., ...), ..., ..., ...)`, which does not implement the `Copy` trait
13 |     let _a = x;
   |              - value moved here
14 |     let _b = x; //~ ERROR use of moved value
   |              ^ value used here after move
   |
   = note: the full type name has been written to 'bay.long-type-14349227078439097973.txt'
   = note: consider using `--verbose` to print the full type name to the console
help: consider cloning the value if the performance cost is acceptable
   |
13 |     let _a = x.clone();
   |               ++++++++
```

Address 4th case in #135919.
2025-01-25 08:03:37 +01:00
Esteban Küber
91b759354c Use short ty string for move errors
```
error[E0382]: use of moved value: `x`
  --> bay.rs:14:14
   |
12 | fn foo(x: D) {
   |        - move occurs because `x` has type `(((..., ..., ..., ...), ..., ..., ...), ..., ..., ...)`, which does not implement the `Copy` trait
13 |     let _a = x;
   |              - value moved here
14 |     let _b = x; //~ ERROR use of moved value
   |              ^ value used here after move
   |
   = note: the full type name has been written to 'bay.long-type-14349227078439097973.txt'
   = note: consider using `--verbose` to print the full type name to the console
help: consider cloning the value if the performance cost is acceptable
   |
13 |     let _a = x.clone();
   |               ++++++++
```
2025-01-24 18:12:56 +00:00
Waffle Lapkin
af2ce8b702
don't drop types with no drop glue when tailcalling
this is required as otherwise drops of `&mut` refs count as a usage of a
'two-phase temporary' causing an ICE.
2025-01-24 06:45:19 +01:00
Matthias Krüger
f875983035
Rollup merge of #135409 - Shunpoco:issue-133117-ICE-never-false-edge-start-block, r=Nadrieril
Fix ICE-133117: multiple never-pattern arm doesn't have false_edge_start_block

Fixes #133117 , and close fixes #133063 , fixes #130779

In order to fix ICE-133117, at first I needed to tackle to ICE-133063 (this fixed 130779 as well).

### ICE-133063 and ICE-130779
This ICE is caused by those steps:
1. An arm has or-pattern, and all of the sub-candidates are never-pattern
2. In that case, all sub-candidates are removed in remove_never_subcandidates(). So the arm (candidate) has no sub-candidate.
3. In the current implementation, if there is no sub-candidate, the function assigns `pre_binding_block` into the candidate ([here](https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/builder/matches/mod.rs#L2002-L2004)). However, otherwise_block should be assigned to the candidate as well, because the otherwise_block is unwrapped in multiple place (like in lower_match_tree()). As a result, it causes the panic.

I simply added the same block as pre_binding_block into otherwise_block, but I'm wondering if there is a better block to assign to otherwise_block (is it ok to assign the same block into pre_binding and otherwise?)

### ICE-133117
This is caused by those steps:
1. There are two arms, both are or-pattern and each has one match-pair (in the test code, both are `(!|!)`), and the second arm has a guard.
2. In match_candidate() for the first arm, it expands the second arm’s sub-candidates as well ([here](https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/builder/matches/mod.rs#L1800-L1805)). As a result, the root candidate of the second arm is not evaluated/modified in match_candidate(). So a false_edge_start_block is not assigned to the candidate.
3. merge_trivial_subcandidates() is called against the candidate for the second arm. It just returns immediately because the candidate has a guard. So a flase_edge_start_block is not assigned to the candidate also in this function.
4. remove_never_subcandidates() is called against the candidate. Since all sub-candidates are never-pattern. they are removed.
5. In lower_match_tree(), since there is no sub-candidate for the candidate, the candidate itself is evaluated in visit_leave_rev ([here](https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/builder/matches/mod.rs#L1532)). Because the candidate has no false_edge_start_block, it causes the panic.

So I modified the order of if blocks in merge_trivial_subcandidates() to assign a false_edge_start_block if the candidate doesn't have.
2025-01-22 20:37:24 +01:00
Shunpoco
7275bdf6ec modify comment
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
2025-01-22 02:42:11 +00:00
Shunpoco
481ed2d931 address review: modify matches/mod.rs
The candidate shouldn't have false_edge_start_block if it has sub candidates.
In remove_never_subcandidates(), the false_edge_start_block from the first sub candidte is assigned to a value and the value is later used if all sub candidates are removed and candidate doesn't have false_edge_start_block.
In merge_trivial_subcandidates, I leave the if block which assign a false_edge_start_block into the candidate as before I put this commit since compile panics.

Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
2025-01-22 01:55:58 +00:00
Rémy Rakic
9bad0daef6 add fixme in typoed const pattern lint 2025-01-21 16:18:34 +00:00
bors
b5741a36a8 Auto merge of #135754 - jieyouxu:rollup-j4q1hpr, r=jieyouxu
Rollup of 7 pull requests

Successful merges:

 - #135542 (Add the concrete syntax for precise capturing to 1.82 release notes.)
 - #135700 (Emit single privacy error for struct literal with multiple private fields and add test for `default_field_values` privacy)
 - #135722 (make it possible to use ci-rustc on tarball sources)
 - #135729 (Add debug assertions to compiler profile)
 - #135736 (rustdoc: Fix flaky doctest test)
 - #135738 (Replace usages of `map_or(bool, ...)` with `is_{some_and|none_or|ok_and}`)
 - #135747 (Rename FileName::QuoteExpansion to CfgSpec)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-01-20 10:35:43 +00:00
许杰友 Jieyou Xu (Joe)
3f2f695d68
Rollup merge of #135310 - estebank:issue-135289, r=Nadrieril
Always force non-trimming of path in `unreachable_patterns` lint

Creating a "trimmed DefID path" when no error is being emitted is an ICE (on purpose). If we create a trimmed path for a lint that is then silenced before being emitted causes a known ICE. This side-steps the issue by always using `with_no_trimmed_path!`.

This was verified to fix https://github.com/quinn-rs/quinn/, but couldn't write a repro case for the test suite.

Fix #135289.
2025-01-20 12:38:31 +08:00
Yotam Ofek
264fa0fc54 Run clippy --fix for unnecessary_map_or lint 2025-01-19 19:15:00 +00:00
bors
c62b732724 Auto merge of #135709 - lqd:bring-back-len, r=compiler-errors
Temporarily bring back `Rvalue::Len`

r? `@compiler-errors` as requested in https://github.com/rust-lang/rust/issues/135671#issuecomment-2599580364

> However, in the mean time, I'd rather we not crunch trying to find and more importantly validate the soundness of a solution 🤔

Agreed. To fix the IMO P-critical #135671 for which we somehow didn't have test coverage, this PR temporarily reverts:
- https://github.com/rust-lang/rust/pull/133734
- its bugfix https://github.com/rust-lang/rust/pull/134371
- https://github.com/rust-lang/rust/pull/134330

cc `@scottmcm`

I added the few samples from that issue as a test, but we can add more in the future, in particular it seems `@steffahn` [will work on that](https://github.com/rust-lang/rust/issues/135671#issuecomment-2599714354).

Fixes #135671. And if we want to land this, it should also be nominated for beta backport.
2025-01-19 06:09:51 +00:00
Rémy Rakic
122a55bb44 Revert "Auto merge of #133734 - scottmcm:lower-indexing-to-ptrmetadata, r=davidtwco,RalfJung"
This reverts commit b57d93d8b9, reversing
changes made to 0aeaa5eb22.
2025-01-18 22:09:35 +00:00
Rémy Rakic
0bb4880581 Revert "Rollup merge of #134371 - scottmcm:fix-134352, r=oli-obk"
This reverts commit 7c301ecdf5, reversing
changes made to dffaad8332.
2025-01-18 22:09:34 +00:00
Rémy Rakic
ca1c17c88d Revert "Auto merge of #134330 - scottmcm:no-more-rvalue-len, r=matthewjasper"
This reverts commit e108481f74, reversing
changes made to 303e8bd768.
2025-01-18 22:09:34 +00:00
Michael Goulet
b08f3d5bdb Consolidate ad-hoc MIR lints into real pass-manager-based MIR lints 2025-01-18 21:25:47 +00:00
Luca Versari
8fee6a7739 Coerce safe-to-call target_feature functions to fn pointers. 2025-01-16 10:54:33 +01:00
Oli Scherer
767d4fe64e Avoid notes that only make sense for unsafe functions 2025-01-15 08:58:17 +00:00
Oli Scherer
56178ddc90 Treat safe target_feature functions as unsafe by default 2025-01-15 08:58:17 +00:00
Oli Scherer
a907c56a77 Add hir::HeaderSafety to make follow up commits simpler 2025-01-14 10:54:11 +00:00
Shunpoco
8a57fa634c Fix ICE-133117
If all subcandidates have never-pattern, we should assign false_edge_start_block to the parent candidate
if it doesn't have. merge_trivial_subcandidates does so, but if the candidate has guard it returns before the assignment.

Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
2025-01-12 14:45:09 +00:00
Shunpoco
3a83422c13 Fix ICE-133063
If all subcandidates have never-pattern, the parent candidate should have otherwise_block
because some methods expect the candidate has the block.

Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
2025-01-12 14:45:09 +00:00
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