Commit graph

45845 commits

Author SHA1 Message Date
bors
7d7de5bf3c Auto merge of #139088 - spastorino:ergonomic-ref-counting-2, r=nikomatsakis
Ergonomic ref counting: optimize away clones when possible

This PR build on top of https://github.com/rust-lang/rust/pull/134797. It optimizes codegen of ergonomic ref-counting when the type being `use`d is only known to be copy after monomorphization. We avoid codening a clone and generate bitwise copy instead.

RFC: https://github.com/rust-lang/rfcs/pull/3680
Tracking issue: https://github.com/rust-lang/rust/issues/132290
Project goal: https://github.com/rust-lang/rust-project-goals/issues/107

r? `@nikomatsakis`

This PR could better sit on top of https://github.com/rust-lang/rust/pull/131650 but as it did not land yet I've decided to just do minimal changes. It may be the case that doing what I'm doing regress the performance and we may need to go the full route of https://github.com/rust-lang/rust/pull/131650.
cc `@saethlin` in this regard.
2025-04-10 09:08:23 +00:00
Oli Scherer
f80b12129e Avoid some more duplication 2025-04-10 08:19:12 +00:00
Oli Scherer
673012faf7 Some performance shenanigans 2025-04-10 07:19:38 +00:00
Nicholas Nethercote
9bb1008e1d Avoid empty identifiers for delegate params and args.
Instead use `argN`. The empty identifiers could flow to
`Liveness::should_warn`, where they would trigger a bounds error.

Fixes #139512.
2025-04-10 14:46:53 +10:00
bors
9d28fe3976 Auto merge of #139000 - compiler-errors:rigid-missing-item, r=lcnr
Rigidly project missing item due to guaranteed impossible sized predicate

This is a somewhat involved change, but it amounts to treating missing impl items due to guaranteed impossible where clauses (dyn/str/slice sized, cc #135480) as *rigid projections* rather than projecting to an error term, since that was preventing either reporting a proper error (in an empty param env) *or* successfully type checking the code (in the presence of trivially false where clauses).

Fixes https://github.com/rust-lang/rust/issues/138970

r? `@lcnr` `@oli-obk`
2025-04-10 04:03:59 +00:00
bors
6813f955a6 Auto merge of #139279 - BoxyUwU:bump-boostrap, r=jieyouxu
Bump boostrap compiler to new beta

try-job: `*msvc*`
2025-04-10 00:43:25 +00:00
Nicholas Nethercote
663a317c20 Address review comments. 2025-04-10 09:39:21 +10:00
Nicholas Nethercote
1b3fc585cb Rename some name variables as ident.
It bugs me when variables of type `Ident` are called `name`. It leads to
silly things like `name.name`. `Ident` variables should be called
`ident`, and `name` should be used for variables of type `Symbol`.

This commit improves things by by doing `s/name/ident/` on a bunch of
`Ident` variables. Not all of them, but a decent chunk.
2025-04-10 09:30:55 +10:00
Michael Goulet
6cd724bb43 Make unnormalizable item ambiguous in coherence 2025-04-09 20:31:58 +00:00
Michael Goulet
830aeb6102 Use a query rather than recomputing the tail repeatedly 2025-04-09 20:26:58 +00:00
Michael Goulet
ccdfd310be Mark GAT WC as GoalSource::AliasWellFormed so that we recurse into them in error reporting 2025-04-09 20:26:57 +00:00
Michael Goulet
27836e1e57 Rigidly project missing item due to guaranteed impossible sized predicate 2025-04-09 20:26:57 +00:00
Matthias Krüger
7aab307541
Rollup merge of #139575 - timesince:master, r=wesleywiser
Remove redundant words

Remove redundant words
2025-04-09 20:23:13 +02:00
Matthias Krüger
e962e52725
Rollup merge of #139551 - jogru0:121672, r=oli-obk
report call site of inlined scopes for large assignment lints

Addressed issue: #121672
Tracking issue: #83518

r? `@oli-obk`

I tried to follow your comment about what to do [here](https://github.com/rust-lang/rust/issues/121672#issuecomment-1972783675). However, I'm totally unfamiliar with the code so far (this is my first contribution touching compiler code), so I apologize in advance if I did something stupid 😅

In particular, I'm not sure I use the _correct_ source scope to look for inline data, as there is a whole `IndexVec` of them. My changes definitely did something, as can be seen by the added ui test. However, the result is not as anticipated in the issue:
```
LL |     let cell = std::cell::UnsafeCell::new(data);
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ value moved from here
```
instead of
```
LL |     let cell = std::cell::UnsafeCell::new(data);
   |                                           ^^^^ value moved from here
```
raising my suspicion that maybe I got the wrong source scope.
2025-04-09 20:23:12 +02:00
Matthias Krüger
584cd13924
Rollup merge of #139513 - compiler-errors:higher-ranked-proj, r=lcnr
Report higher-ranked trait error when higher-ranked projection goal fails in new solver

~~See HACK comment inline. Not actually sure if it should be marked as a *HACK*, b/c~~ it's kinda a legitimate case we want to care about unless we're going to make the proof tree visitor *smarter* about the leak check than the actual trait solver itself.

Encountered this while battling with `NiceRegionError`s in the old solver b/c I wondered what this code ended up giving us in the *new* solver as a comparison:
```rust
trait Foo {}

impl<T: FnOnce(&())> Foo for T {}

fn baz<T: Foo>() {}

fn main() {
    baz::<fn(&'static ())>();
}
```

On master it's pretty bad:
```
error[E0271]: type mismatch resolving `<fn(&()) as FnOnce<(&(),)>>::Output == ()`
 --> <source>:8:11
  |
8 |     baz::<fn(&'static ())>();
  |           ^^^^^^^^^^^^^^^ types differ
  |
note: required for `fn(&'static ())` to implement `Foo`
 --> <source>:3:22
  |
3 | impl<T: FnOnce(&())> Foo for T {}
  |         -----------  ^^^     ^
  |         |
  |         unsatisfied trait bound introduced here
```

After this PR it's much better:
```
error[E0277]: the trait bound `fn(&'static ()): Foo` is not satisfied
 --> /home/mgx/test.rs:8:11
  |
8 |     baz::<fn(&'static ())>();
  |           ^^^^^^^^^^^^^^^ the trait `for<'a> FnOnce(&'a ())` is not implemented for `fn(&'static ())`
  |
  = note: expected a closure with arguments `(&'static (),)`
             found a closure with arguments `(&(),)`
note: required for `fn(&'static ())` to implement `Foo`
 --> /home/mgx/test.rs:3:22
  |
3 | impl<T: FnOnce(&())> Foo for T {}
  |         -----------  ^^^     ^
  |         |
  |         unsatisfied trait bound introduced here
note: required by a bound in `baz`
 --> /home/mgx/test.rs:5:11
  |
5 | fn baz<T: Foo>() {}
  |           ^^^ required by this bound in `baz`
```

r? lcnr
2025-04-09 20:23:11 +02:00
Michael Goulet
f6faaee372 Report higher-ranked trait error when higher-ranked projection goal fails in new solver 2025-04-09 17:53:32 +00:00
Oli Scherer
3528a65dd7 Deduplicate target type setting in unify_and callbacks 2025-04-09 13:17:38 +00:00
Oli Scherer
34258d62cd Add a dedicated function for the common unify_and(identity) case 2025-04-09 13:00:33 +00:00
Oli Scherer
804b6c9636 Rename unify to unify_raw 2025-04-09 12:57:58 +00:00
Oli Scherer
697768a664 Simplify some unify_and calls 2025-04-09 12:55:07 +00:00
Matthias Krüger
db7e32c074
Rollup merge of #139468 - compiler-errors:has_stashed_diagnostic, r=oli-obk
Don't call `Span::with_parent` on the good path in `has_stashed_diagnostic`

More unnecessary incurred span tracking avoided by not calling `span.with_parent(None)`. This is useless on its own but makes it much easier to fix other "span tracking on the good path" issues in the future.

r? oli-obk
2025-04-09 14:52:38 +02:00
Matthias Krüger
7494bd9a4f
Rollup merge of #139364 - Kohei316:feat/doc-hidden-suggestion, r=nnethercote
Make the compiler suggest actual paths instead of visible paths if the visible paths are through any doc hidden path.

close #127011
Currently, when emitting a diagnostic about a valid trait, the compiler suggestes using visible paths of the trait even if they are through a doc hidden path. This PR updates the compiler to suggest actual paths in these cases.
2025-04-09 14:52:37 +02:00
Oli Scherer
f20efc4c61 Handle UnsafePointer coercions in one place 2025-04-09 12:45:54 +00:00
Boxy
c93005ee65 update cfgs 2025-04-09 12:29:59 +01:00
Boxy
a6c2ec04b4 replace version placeholder 2025-04-09 12:29:59 +01:00
timesince
069fd02588
Remove redundant words 2025-04-09 18:46:50 +08:00
David Wood
72d17bfebb
re-use sized fast path
There's an existing fast path for the `type_op_prove_predicate`
predicate, checking for trivially `Sized` types, which can be re-used
when evaluating obligations within queries. This should improve
performance, particularly in anticipation of new sizedness traits being
added which can take advantage of this.
2025-04-09 10:42:26 +00:00
bors
f06e5c1e35 Auto merge of #139327 - cjgillot:gvn-place, r=oli-obk
Allow GVN to produce places and not just locals.

That may be too big of a hammer, as we may introduce new deref projections (possible UB footgun + probably not good for perf).

The second commit opts out of introducing projections that don't have a stable offset, which is probably what we want. Hence no new Deref and no new Index projections.

Fixes https://github.com/rust-lang/rust/issues/138936
cc `@scottmcm` `@dianqk`
2025-04-09 08:50:33 +00:00
Oli Scherer
b2aa9d0620 Remove some dead or leftover code related to rustc-intrinsic abi removal 2025-04-09 07:57:13 +00:00
Romain Perier
8b6ff4a378 Suggest the use of impl Trait in function parameter only
Currently in case of a Trait object in closure parameter, the compiler
suggests either to use a reference, which is correct or to use an
`impl Trait` which is not. Do not emit this suggestion when the parameter
is part of a closure.
2025-04-09 08:56:04 +02:00
bors
97c966bb40 Auto merge of #139552 - matthiaskrgr:rollup-b194mk8, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #139494 (Restrict some queries by def-kind more)
 - #139496 (Revert r-a changes of rust-lang/rust#139455)
 - #139506 (add missing word in doc comment (part 2))
 - #139515 (Improve presentation of closure signature mismatch from `Fn` trait goal)
 - #139520 (compiletest maintenance: sort deps and drop dep on `anyhow`)
 - #139523 (Rustc dev guide subtree update)
 - #139526 (Fix deprecation note for std::intrinsics)
 - #139528 (compiletest: Remove the `--logfile` flag)
 - #139541 (Instantiate higher-ranked transmute goal w/ placeholders before emitting sub-obligations)
 - #139547 (Update library tracking issue template to set S-tracking-unimplemented)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-09 05:39:18 +00:00
Nicholas Nethercote
7ae5c7f32d Avoid an empty trait name in impl blocks.
`resolve_ident_in_lexical_scope` checks for an empty name. Why is this
necessary? Because `parse_item_impl` can produce an `impl` block with an
empty trait name in some cases. This is pretty gross and very
non-obvious.

This commit avoids the use of the empty trait name. In one case the
trait name is instead pulled from `TyKind::ImplTrait`, which prevents
the output for `tests/ui/impl-trait/extra-impl-in-trait-impl.rs` from
changing. In the other case we just fail the parse and don't try to
recover. I think losing error recovery in this obscure case is worth
the code cleanup.

This change affects `tests/ui/parser/impl-parsing.rs`, which is split in
two, and the obsolete `..` syntax cases are removed (they are tested
elsewhere).
2025-04-09 15:01:14 +10:00
Nicholas Nethercote
f419b18d16 Return early on an error path in parse_item_impl.
Currently the code continues, using an empty path, but it doesn't need
to.
2025-04-09 15:00:30 +10:00
Manuel Drehwald
f151ceadfe emit a better error message for using the macro incorrectly 2025-04-08 21:54:34 -04:00
bors
de5b8a4c77 Auto merge of #139536 - matthiaskrgr:rollup-j6goald, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #139476 (rm `RegionInferenceContext::var_infos`)
 - #139485 (compiletest: Stricter parsing for diagnostic kinds)
 - #139491 (Update books)
 - #139500 (document panic behavior of Vec::resize and Vec::resize_with)
 - #139501 (Fix stack overflow in exhaustiveness due to recursive HIR opaque hidden types)
 - #139504 (add missing word in doc comment)
 - #139509 (clean: remove Deref<Target=RegionKind> impl for Region and use `.kind()`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-08 22:51:10 +00:00
Jane Losare-Lusby
6f55015835 fix "still mutable" ice while metrics are enabled 2025-04-08 15:00:37 -07:00
Nadrieril
f458151b7a Remove redundant assignment 2025-04-08 23:33:53 +02:00
Nadrieril
6588018fb4 Return a type from check_pat_inner 2025-04-08 23:33:53 +02:00
Nadrieril
38adb9931c Reorganize check_pat_inner 2025-04-08 23:33:52 +02:00
Nadrieril
19950b52c7 Turn the peeling loop into a recursive call 2025-04-08 23:26:48 +02:00
Nadrieril
9f57903e9c Insert adjustments incrementally 2025-04-08 23:26:48 +02:00
Nadrieril
a0d9c87266 Inline calc_default_binding_mode 2025-04-08 23:26:48 +02:00
Matthias Krüger
8a64ba5c3f
Rollup merge of #139541 - compiler-errors:transmute, r=lcnr
Instantiate higher-ranked transmute goal w/ placeholders before emitting sub-obligations

This avoids an ICE where we weren't keeping track of bound variables correctly in the `Freeze` obligations we emit for transmute goals. We could use `rebind` instead on that goal, but I think it's better just to instantiate the binder.

Fixes #139538

r? `@lcnr` or reassign
2025-04-08 21:26:02 +02:00
Matthias Krüger
b41e2bd807
Rollup merge of #139515 - compiler-errors:sig-mismatch, r=lcnr
Improve presentation of closure signature mismatch from `Fn` trait goal

Flip the order of "expected" and "found" since that wasn't correct.

Don't present the arguments as a tuple, since it leaves a trailing comma. Instead, just use `fn(arg, arg)`.

Finally, be better with binders since we were just skipping binders.

r? oli-obk or reassign
2025-04-08 21:25:59 +02:00
Matthias Krüger
894f471d1e
Rollup merge of #139494 - compiler-errors:restrict-queries, r=oli-obk
Restrict some queries by def-kind more

Random cleanup. I prefer things to assert more so as to catch bugs :)

r? oli-obk
2025-04-08 21:25:57 +02:00
Jonathan Gruner
6d71fc15d8 for large assignment lint, use the correct span for checking for duplicate lints 2025-04-08 21:22:20 +02:00
Jonathan Gruner
df6254f7a2 report call site of inlined scopes for large assignment lints 2025-04-08 20:49:50 +02:00
Celina G. Val
3feac59b79 Fix unreachable expression warning
Invert the order that we pass the arguments to the
`contract_check_ensures` function to avoid the warning when the tail
of the function is unreachable.

Note that the call itself is also unreachable, but we have already
handled that case by ignoring unreachable call for contract calls.
2025-04-08 10:46:31 -07:00
Michael Goulet
68692b7fbb Instantiate higher-ranked transmute goal 2025-04-08 17:00:29 +00:00
Matthias Krüger
1cbf8b56af
Rollup merge of #139509 - xizheyin:issue-139359, r=lcnr
clean: remove Deref<Target=RegionKind> impl for Region and use `.kind()`

Closes #139359

r? `@lcnr`
2025-04-08 18:05:34 +02:00