Commit Graph

19780 Commits

Author SHA1 Message Date
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
Alona Enraght-Moony
aeb70c710a rustdoc-json: Remove newlines from attributes 2025-05-07 18:45:58 +00:00
Michael Goulet
f03d246db9 Better error message for late/early lifetime param mismatch 2025-05-07 18:12:54 +00:00
Daniel Paoliello
742aaf9b69 [arm64] Pointer auth test should link with C static library statically 2025-05-07 10:52:18 -07:00
Daniel Paoliello
3286d4aad7 [win][arm64] Disable various DebugInfo tests that don't work on Arm64 Windows 2025-05-07 10:49:54 -07: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
Guillaume Gomez
83e3d0e17b Rollup merge of #140706 - GuillaumeGomez:fix-missing-temp-dir-cleanup, r=notriddle
[rustdoc] Ensure that temporary doctest folder is correctly removed even if doctests failed

Fixes #139899.

The bug was due to the fact that if any doctest fails for any reason, we call `exit` (or it's called inside `libtest` if not edition 2024), meaning that `TempDir`'s destructor isn't called, and therefore the temporary folder isn't cleaned up.

Took me a while to figure out how to reproduce but finally I was able to reproduce the bug with:

`````rust
#![doc(test(attr(deny(warnings))))]

//! ```
//! let a = 12;
//! ```
`````

And then I ensured that panicking doctests were cleaned up as well:

`````rust
//! ```
//! panic!();
//! ```
`````

And finally I checked if it was fixed for merged doctests too (`--edition 2024`).

To make this work, I needed to add a new public function in `libtest` too which would call a function once all tests have been run.

So only issue is: I have absolutely no idea how we can add a regression test for this fix. If anyone has an idea...

r? `@notriddle`
2025-05-07 18:19:07 +02: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
Michael Goulet
1f774d74b3 Only prefer param-env candidates if they remain non-global after norm 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
Guillaume Gomez
442ae63257 Add regression test for #139899 2025-05-07 16:08:54 +02:00
xizheyin
f46806fb14 Add ui test suggest-remove-deref-issue-140166
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-07 17:32:59 +08: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
dianne
cf43bba1e5 add exhaustiveness/usefulness tests for deref patterns 2025-05-06 18:53:55 -07:00
dianne
b41d8bde00 let deref patterns participate in usefulness/exhaustiveness
This does not yet handle the case of mixed deref patterns with normal
constructors; it'll ICE in `Constructor::is_covered_by`. That'll be
fixed in a later commit.
2025-05-06 18:53:55 -07:00
Jacob Pratt
3d8ef7afca Rollup merge of #140713 - compiler-errors:check_ref_cast, r=lcnr
Structurally resolve in `check_ref_cast` in new solver

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

r? lcnr
2025-05-07 00:29:25 +00:00
Jacob Pratt
8984d650e1 Rollup merge of #140709 - notriddle:rm-unportable-markdown, r=GuillaumeGomez
rustdoc: remove unportable markdown lint and old parser

Follow up https://github.com/rust-lang/rust/pull/127127
2025-05-07 00:29:25 +00:00
Jacob Pratt
bda326f40c Rollup merge of #140607 - lcnr:opaque-type-storage, r=compiler-errors
support duplicate entries in the opaque_type_storage

Necessary for the new solver as we may unify keys when eagerly resolving for canonical queries. See the relevant comment when instantiating query responses:
```rust
            // We eagerly resolve inference variables when computing the query response.
            // This can cause previously distinct opaque type keys to now be structurally equal.
            //
            // To handle this, we store any duplicate entries in a separate list to check them
            // at the end of typeck/borrowck. We could alternatively eagerly equate the hidden
            // types here. However, doing so is difficult as it may result in nested goals and
            // any errors may make it harder to track the control flow for diagnostics.
            if let Some(prev) = prev {
                self.delegate.add_duplicate_opaque_type(key, prev, self.origin_span);
            }
```

This will be far more relevant with #140497.

r? `@compiler-errors`
2025-05-07 00:29:23 +00:00
Jacob Pratt
4a8dbe0537 Rollup merge of #139534 - madhav-madhusoodanan:apx-target-feature-addition, r=workingjubilee
Added support for `apxf` target feature
2025-05-07 00:29:21 +00:00
Jacob Pratt
60a4b939a3 Rollup merge of #134273 - RalfJung:de-stabilize-bench, r=ibraheemdev,traviscross
de-stabilize bench attribute

This has been soft-unstable since forever (https://github.com/rust-lang/rust/pull/64066), and shown in future-compat reports since Rust 1.77 (https://github.com/rust-lang/rust/pull/116274).

The feature covering `bench` itself is tracked in https://github.com/rust-lang/rust/issues/50297, which has been closed despite still having active feature gates referencing it.

Cc `@rust-lang/libs-api`
2025-05-07 00:29:20 +00:00
Michael Goulet
636a138cda Structurally resolve in check_ref_cast 2025-05-06 19:30:55 +00:00
Kivooeo
3c1c0726ad added error handle for error code > 9999 2025-05-06 23:02:47 +05:00
Madhav Madhusoodanan
c32dc2dbda Added apxf target feature test 2025-05-06 23:28:28 +05:30
Michael Howell
e648e5b710 rustdoc: remove unportable markdown lint and old parser
Follow up https://github.com/rust-lang/rust/pull/127127
2025-05-06 10:33:04 -07:00
Guillaume Gomez
3b82d4640a Rollup merge of #139966 - Zalathar:span-merge, r=oli-obk
coverage: Only merge adjacent coverage spans

For a long time, coverage instrumentation has automatically “merged” spans with the same control-flow into a smaller number of larger spans, even when the spans being merged are not overlapping or adjacent. This causes any source text between the original spans to be included in the merged span, which is then associated with an execution count when shown in coverage reports.

That approach causes a number of problems:
- The intervening source text can contain all sorts of things that shouldn't really be marked as executable code (e.g. nested items, parts of macro invocations, long comments). In some cases we have complicated workarounds (e.g. bucketing to avoid merging spans across nested items), but in other cases there isn't much we can do.
- Merging can have aesthetically weird effects, such as including unbalanced parentheses, because the merging process doesn't really understand what it's doing at a source code level.
- It generally leads to an accumulation of piled-on heuristics and special cases that give decent-looking results, but are fiendishly difficult to modify or replace.

Therefore, this PR aims to abolish the merging of non-adjacent coverage spans.

The big tradeoff here is that the resulting coverage metadata (embedded in the instrumented binary) tends to become larger, because the overall number of distinct spans has increased. That's unfortunate, but I see it as the inevitable cost of cleaning up the messes and inaccuracies that were caused by the old approach. And the resulting spans do tend to be more accurate to the program's actual control-flow.

---

The `.coverage` snapshot changes give an indication of how this PR will affect user-visible coverage reports. In many cases the changes to reporting are minor or even nonexistent, despite substantial changes to the metadata (as indicated by `.cov-map` snapshots).

---

try-job: aarch64-gnu
2025-05-06 19:27:39 +02:00
León Orell Valerian Liehr
8c37c8c3e6 Preserve generic args in suggestions for ambiguous associated items
Most notably, this preserves the `(..)` of ambiguous RTN paths.
2025-05-06 17:04:03 +02:00
León Orell Valerian Liehr
9e1832998d Factor out resolve_type_relative_path
IMPORTANT: This leads to a tiny diagnostic regression that will be fixed in the next commit!
2025-05-06 17:00:01 +02:00
lcnr
431f02d531 support duplicates in the opaque_types_storage 2025-05-06 14:59:09 +00:00
bors
1a95cc6f9d Auto merge of #140702 - GuillaumeGomez:rollup-rpyxs20, r=GuillaumeGomez
Rollup of 4 pull requests

Successful merges:

 - #140135 (Unify sidebar buttons to use the same image)
 - #140632 (add a test for issue rust-lang/rust#81317)
 - #140658 (`deref_patterns`: let string and byte string literal patterns peel references and smart pointers before matching)
 - #140681 (Don't ignore compiler stderr in `lib-defaults.rs`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-06 13:42:09 +00:00
Guillaume Gomez
9d05497ff6 Rollup merge of #140681 - jieyouxu:test_helpers, r=petrochenkov
Don't ignore compiler stderr in `lib-defaults.rs`

Closes #54222.

- Don't ignore compiler stderr.
- Document test intent.
- Move under `tests/ui/link-native-libs/` instead.

This was previously discussed on https://web.archive.org/web/20181028094402/https://botbot.me/mozilla/rust-tools/2017-02-21/?page=1.

try-job: armhf-gnu
try-job: test-various
try-job: x86_64-msvc-1
try-job: i686-msvc-1
try-job: x86_64-mingw-1
try-job: aarch64-apple
try-job: x86_64-apple-1
2025-05-06 14:50:47 +02:00
Guillaume Gomez
ebd12fcc5e Rollup merge of #140658 - dianne:lit-deref-pats-p2, r=oli-obk
`deref_patterns`: let string and byte string literal patterns peel references and smart pointers before matching

This follows up on #140028. Together, they allow using string and byte string literal patterns to match on smart pointers when `deref_patterns` is enabled. In particular, string literals can now match on `String`, subsuming the functionality of the `string_deref_patterns` feature.

More generally, this works by letting literals peel references (and smart pointers) before matching, similar to most other patterns, providing an answer to #44849. Though it's only partially implemented at this point: this doesn't yet let named const patterns peel before matching. The peeling logic is general enough to support named consts, but the typing rules for named const patterns would need adjustments to feel consistent (e.g. arrays would need rules to be usable as slices, and `const STR: &'static str` wouldn't be able to match on a `String` unless a rule was added to let it be used where a `str` is expected, similar to what #140028 did for literals).

This also allows string and byte string patterns to match on mutable references, following up on https://github.com/rust-lang/rust/pull/140028#discussion_r2053927512. Rather than forward the mutability of the scrutinee to literal patterns, I've opted to peel `&mut`s from the scrutinee. From a design point of view, this makes the behavior consistent with what would be expected from deref coercions using the methodology in the next paragraph. From a diagnostics point of view, this avoids labeling string and byte string patterns as "mutable references", which I think could be confusing. See [`byte-string-type-errors.rs`](https://github.com/rust-lang/rust/compare/master...dianne:rust:lit-deref-pats-p2?expand=1#diff-4a0dd9b164b67c706751f3c0b5762ddab08bcef05a91972beb0190c6c1cd3706) for how the diagnostics look.

At a high level, the peeling logic implemented here tries to mimic how deref coercions work for expressions: we peel references (and smart pointers) from the scrutinee until the pattern can match against it, and no more. This is primarily tested by [`const-pats-do-not-mislead-inference.rs`](https://github.com/rust-lang/rust/compare/master...dianne:rust:lit-deref-pats-p2?expand=1#diff-19afc05b8aae9a30fe4a3a8c0bc2ab2c56b58755a45cdf5c12be0d5e83c4739d). To illustrate the connection, I wasn't sure if this made sense to include in the test file, but I've translated those tests to make sure they give the same inference results as deref coercions: [(playground)](https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=1869744cb9cdfed71a686990aadf9fe1). In each case, a reference to the scrutinee is coerced to have the type of the pattern (under a reference).

Tracking issue for deref patterns: #87121

r? `@oli-obk`
cc `@Nadrieril`
2025-05-06 14:50:46 +02:00
Guillaume Gomez
3501842edb Rollup merge of #140632 - Skgland:test-for-issue-81317, r=oli-obk
add a test for issue rust-lang/rust#81317

closes rust-lang/rust#81317
2025-05-06 14:50:46 +02:00
Guillaume Gomez
a92ba60d0f Rollup merge of #140135 - GuillaumeGomez:sidebars-image, r=rustdoc
Unify sidebar buttons to use the same image

Part of https://github.com/rust-lang/rust/issues/139832.

The source sidebar looks like this with the new image:

![image](https://github.com/user-attachments/assets/df4fee52-fb71-4794-91b7-3afc6d2aab70)

You can test it [here](https://rustdoc.crud.net/imperio/sidebar-images/src/foo/foo.rs.html).

r? `@notriddle`
2025-05-06 14:50:45 +02:00
Zalathar
4d5a1acebf coverage: Only merge adjacent coverage spans
This also removes some manipulation of the function signature span that only
made sense in the context of merging non-adjacent spans.
2025-05-06 20:42:25 +10:00
bors
f5d3fe273b Auto merge of #140561 - compiler-errors:gather-fewer-locals, r=lcnr
Do not gather local all together at the beginning of typeck

r? lcnr
2025-05-06 10:27:27 +00:00
Jieyou Xu
cbaa73beca tests: don't ignore compiler stderr in lib-defaults.rs
And also:

- Document test intent.
- Move under `link-native-libs/` instead.
2025-05-06 16:49:25 +08:00
Stuart Cook
f14b4e6924 Rollup merge of #140678 - compiler-errors:dont-ice-on-infer-in-upvar, r=lcnr
Be a bit more relaxed about not yet constrained infer vars in closure upvar analysis

See the writeup in `tests/ui/closures/opaque-upvar.rs`.

TL;DR is that this has to do with the fact that the recursive revealing uses, which have not yet been constrained from the defining use by the time that closure upvar inference is performed, remain as infer vars during upvar analysis. We don't really care, though, since anywhere we structurally match on a type in upvar analysis, we already call `structurally_resolve_type` right before `.kind()`, which would emit a true ambiguity error.

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

r? lcnr
2025-05-06 16:28:43 +10:00