Commit Graph

47859 Commits

Author SHA1 Message Date
Matthias Krüger
f7168af76f Rollup merge of #140707 - compiler-errors:range-pat-struct-norm, r=lcnr
Structurally normalize in range pattern checking in HIR typeck

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/200

r? lcnr
2025-05-08 20:22:18 +02:00
Matthias Krüger
a054be7434 Rollup merge of #140684 - compiler-errors:unnecessary-assoc, r=lcnr
Only include `dyn Trait<Assoc = ...>` associated type bounds for `Self: Sized` associated types if they are provided

Since #136458, we began filtering out associated types with `Self: Sized` bounds when constructing the list of associated type bounds to put into our `dyn Trait` types. For example, given:

```rust
trait Trait {
    type Assoc where Self: Sized;
}
```

After #136458, even if a user writes `dyn Trait<Assoc = ()>`, the lowered ty would have an empty projection list, and thus be equivalent to `dyn Trait`. However, this has the side effect of no longer constraining any types in the RHS of `Assoc = ...`, not implying any WF implied bounds, and not requiring that they hold when unsizing.

After this PR, we include these bounds, but (still) do not require that they are provided. If the are not provided, they are skipped from the projections list.

This results in `dyn Trait` types that have differing numbers of projection bounds. This will lead to re-introducing type mismatches e.g. between `dyn Trait` and `dyn Trait<Assoc = ()>`. However, this is expected and doesn't suffer from any of the deduplication unsoundness from before #136458.

We may want to begin to ignore thse bounds in the future by bumping `unused_associated_type_bounds` to an FCW. I don't want to tangle that up into the fix that was originally intended in #136458, so I'm doing a "fix-forward" in this PR and deferring thinking about this for the future.

Fixes #140645

r? lcnr
2025-05-08 20:22:16 +02:00
Matthias Krüger
6914d83de9 Rollup merge of #140095 - nnethercote:rm-word_or_empty, r=jdonszelmann
Eliminate `word_and_empty` methods.

To remove the last remaining `Ident::empty` uses.

r? `@jdonszelmann`
2025-05-08 20:22:09 +02:00
Michael Goulet
292ecd5242 Remove some unnecessary erases 2025-05-08 16:20:57 +00:00
bendn
3b4c4938c5 add signed integers to unnecessary_lints to ensure feature parity with clippy 2025-05-08 23:16:49 +07:00
Michael Goulet
9af6ee50ed Structurally resolve in check_ref_cast and calc_adjust_mode 2025-05-08 15:00:17 +00:00
lcnr
01854845bc refactor probe_and_consider_param_env_candidate 2025-05-08 14:51:41 +00:00
lcnr
31ebe11f61 normalization: avoid incompletely constraining GAT args 2025-05-08 14:38:47 +00:00
xizheyin
88c1796384 Use span before macro expansion in lint for-loops-over-falibles
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-08 21:17:33 +08:00
Matthias Krüger
54f1da4486 Rollup merge of #140758 - dpaoliello:armhazard, r=jieyouxu
[win][arm64] Disable MSVC Linker 'Arm Hazard' warning

While trying to get the aarch64-msvc build working correctly (#140136), I observed the following test failure:

From <https://github.com/rust-lang/rust/pull/140136#issuecomment-2848179657>

```
  = note: main.main.d17f5fbe6225cf88-cgu.0.rcgu.o : fatal error LNK1322: cannot avoid potential ARM hazard (Cortex-A53 MPCore processor bug #843419) in section 0x57; please consider using compiler option /Gy if it was not used
```

This is warning of a code sequence that triggers a bug in Cortex-A53 processors: <https://developer.arm.com/documentation/epm048406/latest>

However, since Windows 10 isn't supported on the Cortex-A53, this warning is not required, so it can be suppressed using the undocumented `/arm64hazardfree` flag.
2025-05-08 13:55:45 +02:00
Matthias Krüger
4ed13189ec Rollup merge of #140736 - xizheyin:issue-140166, r=petrochenkov
trait selection: check `&` before suggest remove deref

FIxes #140166

r? compiler
2025-05-08 13:55:44 +02:00
Nicholas Nethercote
d22461c9b7 Remove associated type InvocationCollectorNode::AttrsTy
It's always equal to `ast::AttrVec`, so just use that directly.
2025-05-08 19:59:48 +10:00
Matthias Krüger
34feb216e6 Rollup merge of #140769 - Zoxc:fix-140731, r=oli-obk
Add `DefPathData::OpaqueLifetime` to avoid conflicts for remapped opaque lifetimes

This adds `DefPathData::OpaqueLifetime` to ensure the def paths for remapped opaque lifetimes remain unique.

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

r? ``@oli-obk``
2025-05-08 08:14:20 +02:00
Matthias Krüger
74b79aee60 Rollup merge of #140711 - compiler-errors:combine-maybes, r=lcnr
Do not discard constraints on overflow if there was candidate ambiguity

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/201.

There's a pretty chunky justification in the test.

r? lcnr
2025-05-08 08:14:18 +02:00
Matthias Krüger
aace48811b Rollup merge of #140641 - lcnr:opaque-type-storage-entries, r=compiler-errors
detect additional uses of opaques after writeback

Based on #140607. It's a lot harder to encounter in practice than I though 😅 😁 I've still added it with the expectation that somebody will encounter it at some point.

Also modifies the `EvalCtxt` to use the same impl to detect newly added opaque types.

r? ``@compiler-errors``
2025-05-08 08:14:18 +02:00
Matthias Krüger
a810f8ac89 Rollup merge of #140523 - compiler-errors:late-early-mismatch, r=jackh726
Better error message for late/early lifetime param mismatch

Rework the way we report early-/late-bound lifetime param mismatches to equate the trait and impl signatures using region variables, so that we can detect when a late-bound param is present in the signature in place of an early-bound param, or vice versa.

The diagnostic is a bit more technical, but it's more obviously clear to see what the problem is, even if it's not great at explaining how to fix it. I think this could be improved further, but I still think it's much better than what exists today.

Note to reviewer(s): I'd appreciate if we didn't bikeshed *too* much about this verbiage, b/c I hope it's clear that the old message sucked a lot. I'm happy to file bugs for interested new contributors to improve the messaging further.

Edit(fmease): Fixes https://github.com/rust-lang/rust/issues/33624.
2025-05-08 08:14:16 +02:00
Matthias Krüger
8a3ab85e7d Rollup merge of #140260 - compiler-errors:only-global-post-norm, r=lcnr
Only prefer param-env candidates if they remain non-global after norm

Introduce `CandidateSource::GlobalParamEnv`, and dynamically compute the `CandidateSource` based on whether the predicate contains params *post-normalization*.

This code needs some cleanup and documentation. I'm just putting this up for review.

cc https://github.com/rust-lang/trait-system-refactor-initiative/issues/179

r? lcnr
2025-05-08 08:14:16 +02:00
bors
7e552b46af Auto merge of #140106 - dianne:deref-pat-usefulness, r=Nadrieril
allow deref patterns to participate in exhaustiveness analysis

Per [this proposal](https://hackmd.io/4qDDMcvyQ-GDB089IPcHGg#Exhaustiveness), this PR allows deref patterns to participate in exhaustiveness analysis. Currently all deref patterns enforce `DerefPure` bounds on their scrutinees, so this assumes all patterns it's analyzing are well-behaved. This also doesn't support [mixed exhaustiveness](https://hackmd.io/4qDDMcvyQ-GDB089IPcHGg#Mixed-exhaustiveness), and instead emits an error if deref patterns are used together with normal constructors. I think mixed exhaustiveness would be nice to have (especially if we eventually want to support arbitrary `Deref` impls[^1]), but it'd require more work to get reasonable diagnostics[^2].

Tracking issue for deref patterns: #87121

r? `@Nadrieril`

[^1]: Regardless of whether we support limited exhaustiveness checking for untrusted `Deref` or always require other arms to be exhaustive, I think it'd be useful to allow mixed matching for user-defined smart pointers. And it'd be strange if it worked there but not for `Cow`.

[^2]: I think listing out witnesses of non-exhaustiveness can be confusing when they're not necessarily disjoint, and when you only need to cover some of them, so we'd probably want special formatting and/or explanatory subdiagnostics. And if it's implemented similarly to unions, we'd probably also want some way of merging witnesses; the way witnesses for unions can appear duplicated is pretty unfortunate. I'm not sure yet how the diagnostics should look, especially for deeply nested patterns.
2025-05-08 02:16:45 +00:00
bors
ae3e8c6191 Auto merge of #140751 - GuillaumeGomez:rollup-eahw4ta, r=GuillaumeGomez
Rollup of 8 pull requests

Successful merges:

 - #140234 (Separate dataflow analysis and results)
 - #140614 (Correct warning message in restricted visibility)
 - #140671 (Parser: Recover error from named params while parse_path)
 - #140700 (Don't crash on error codes passed to `--explain` which exceed our internal limit of 9999 )
 - #140706 ([rustdoc] Ensure that temporary doctest folder is correctly removed even if doctests failed)
 - #140734 (Fix regression from #140393 for espidf / horizon / nuttx / vita)
 - #140741 (add armv5te-unknown-linux-gnueabi target maintainer)
 - #140745 (run-make-support: set rustc dylib path for cargo wrapper)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-07 23:03:25 +00:00
John Kåre Alsaker
5913e55dfc Add DefPathData::OpaqueLifetime to avoid conflicts for remapped opaque lifetimes 2025-05-07 22:17:29 +02:00
bors
e9f8103f93 Auto merge of #140590 - lcnr:closure-in-dead-code, r=compiler-errors
borrowck nested items in dead code

fixes https://github.com/rust-lang/rust/issues/140583

r? `@compiler-errors`
2025-05-07 19:49:36 +00:00
Daniel Paoliello
75ca6c621e [win][arm64] Disable MSVC Linker 'Arm Hazard' warning 2025-05-07 12:02:14 -07:00
Michael Goulet
f03d246db9 Better error message for late/early lifetime param mismatch 2025-05-07 18:12:54 +00:00
lcnr
e7979eab89 detect additional uses of opaques after writeback 2025-05-07 17:59:51 +00:00
lcnr
fc0ef54fd9 opaque_type_storage to InferCtxtLike 2025-05-07 17:58:20 +00:00
Daniel Paoliello
6dabf7ea3a [Arm64EC] Only decorate functions with # 2025-05-07 10:36:12 -07:00
Michael Goulet
3799d8427a Review 2025-05-07 17:29:12 +00:00
Michael Goulet
b27d630f89 Point out region bound mismatches in check_region_bounds_on_impl_item 2025-05-07 17:13:39 +00:00
Michael Goulet
a910329c67 Use MaybeCause::or to allow constraints from overflows if they are combined with ambiguity 2025-05-07 17:12:15 +00:00
Kivooeo
3cd065d3d3 macro expansion issue 2025-05-07 21:51:41 +05:00
Michael Goulet
fd37906477 Only include associated type bounds for Self:Sized associated types if they are provided 2025-05-07 16:36:55 +00:00
Michael Goulet
df47958894 Remove manual WF hack 2025-05-07 16:29:59 +00:00
Michael Goulet
8a21d1b495 Review 2025-05-07 16:29:49 +00:00
Guillaume Gomez
7d372aec2f Rollup merge of #140700 - Kivooeo:new-fix-six, r=davidtwco,fmease
Don't crash on error codes passed to `--explain` which exceed our internal limit of 9999

removed panic in case where we do `--explain > 9999` and added check for it

now error looks like this instead of ICE
```
$ rustc.exe --explain E10000
error: E10000 is not a valid error code
```
fixes #140647
r? `@fmease`
2025-05-07 18:19:06 +02:00
Guillaume Gomez
32325e1dec Rollup merge of #140671 - xizheyin:issue-140169, r=petrochenkov
Parser: Recover error from named params while parse_path

Fixes #140169

I added test to the first commit and the second added the code and changes to test.

r? `@petrochenkov`
2025-05-07 18:19:06 +02:00
Guillaume Gomez
f7a9c672f0 Rollup merge of #140614 - yuk1ty:fix-invalid-module-name-visibility, r=davidtwco
Correct warning message in restricted visibility

Fixes #131220
2025-05-07 18:19:05 +02:00
Guillaume Gomez
82c99c41c0 Rollup merge of #140234 - nnethercote:separate-Analysis-and-Results, r=davidtwco
Separate dataflow analysis and results

`Analysis` gets put into `Results` with `EntryStates`, by `iterate_to_fixpoint`. This has two problems:
- `Results` is passed various places where only `Analysis` is needed.
- `EntryStates` is passed around mutably everywhere even though it is immutable.

This commit mostly separates `Analysis` from `Results` and fixes these two problems.

r? `@davidtwco`
2025-05-07 18:19:04 +02:00
Michael Goulet
1f774d74b3 Only prefer param-env candidates if they remain non-global after norm 2025-05-07 16:00:21 +00:00
Michael Goulet
df13f7c1fa Require T: TypeFoldable in Binder<T> visit 2025-05-07 16:00:21 +00:00
xizheyin
bd88f3e3e3 Check & before suggest remove deref when trait_selection
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-07 23:23:25 +08:00
xizheyin
b922da3586 Use parse_param_general when parsing (T, U)->R in parse_path_segment
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>

Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
2025-05-07 22:56:14 +08:00
dianne
30a0ac66db delay introducing pattern bindings into scope
This splits introduction of bindings into scope
(`apply_pattern_bindings`) apart from manipulation of the pattern's
binding map (`fresh_binding`). By delaying the latter, we can keep
bindings from appearing in-scope in guards.

Since `fresh_binding` is now specifically for manipulating a pattern's
bindings map, this commit also inlines a use of `fresh_binding` that was
only adding to the innermost rib.
2025-05-07 06:47:16 -07:00
bors
3ef8e64ce9 Auto merge of #139758 - Zoxc:thread-local-graph, r=oli-obk
Use thread local dep graph encoding

This adds thread local encoding of dep graph nodes. Each thread has a `MemEncoder` that gets flushed to the global `FileEncoder` when it exceeds 64 kB. Each thread also has a local cache of dep indices. This means there can now be empty gaps in `SerializedDepGraph`.

Indices are marked green and also allocated by the new atomic operation `DepNodeColorMap::try_mark_green` as the encoder lock is removed.
2025-05-07 12:39:54 +00:00
bors
db0e836148 Auto merge of #140735 - GuillaumeGomez:rollup-dlhbxsg, r=GuillaumeGomez
Rollup of 4 pull requests

Successful merges:

 - #139518 (Stabilize precise capture syntax in style guide)
 - #140398 (Fix backtrace for cygwin)
 - #140719 (fix typo in autorefs lint doc example)
 - #140724 (Update `compiler-builtins` to 0.1.158)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-07 09:31:15 +00:00
Guillaume Gomez
763209e422 Rollup merge of #140719 - wyfo:patch-1, r=lcnr
fix typo in autorefs lint doc example

The documentation is talking about other way using only raw pointers, but the example was use `std::slice::from_raw_parts_mut` which also create a reference. `std::ptr::slice_from_raw_parts_mut` should be used instead, and it also highlights the benefit of raw pointer manipulation compared to dereference, as the function doesn't need to be unsafe anymore.

Moreover, [`unsafe_op_in_unsafe_fn`](https://doc.rust-lang.org/edition-guide/rust-2024/unsafe-op-in-unsafe-fn.html) warning has been enabled since Edition 2024, so I've updated the examples to use unsafe blocks.
2025-05-07 10:50:49 +02:00
dianne
3007433e2c add a type alias for the pattern bindings stack
I'll be modifying it in future commits, so I think it's cleanest to
abstract it out. Possibly a newtype would be ideal, but for now this is
least disruptive.
2025-05-07 00:52:58 -07:00
bors
f76c7367c6 Auto merge of #137995 - hkBst:parse_format_reuse_unescape, r=nnethercote
Remove duplicate impl of string unescape from parse_format

r? `@nnethercote`
2025-05-07 06:18:39 +00:00
Nicholas Nethercote
603766cd72 Avoid some unwraps.
By using `@` patterns more.

Also, use `Symbol` more in a couple of errors to avoid some unnecessary
conversions to strings. This even removes a lifetime.
2025-05-07 12:56:44 +10:00
Nicholas Nethercote
d81472f266 Eliminate word_or_empty methods.
To get rid of the `Ident::empty` uses.

This requires introducing `PathParser::word_sym`, as an alternative to
`PathParser::word`.
2025-05-07 12:56:41 +10:00
dianne
fb261a179d error early when mixing deref patterns with normal constructors
Without adding proper support for mixed exhaustiveness, mixing deref
patterns with normal constructors would either violate
`ConstructorSet::split`'s invariant 4 or 7. We'd either be ignoring rows
with normal constructors or we'd have problems in unspecialization from
non-disjoint constructors. Checking mixed exhaustivenss similarly to how
unions are currently checked should work, but the diagnostics for unions
are confusing. Since mixing deref patterns with normal constructors is
pretty niche (currently it only makes sense for `Cow`), emitting an
error lets us avoid committing to supporting mixed exhaustiveness
without a good answer for the diagnostics.
2025-05-06 18:53:55 -07:00