Commit Graph

18385 Commits

Author SHA1 Message Date
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
Stuart Cook
d36e719fbc Rollup merge of #140673 - GuillaumeGomez:clean-rustdoc-tests, r=notriddle
Clean rustdoc tests folder

We were starting to have way too many tests in the `tests/rustdoc/` folder so I moved some of them in sub-folders. We now have less than 300 tests at the "top level" so I guess it's good enough for now.

So this PR just moves tests in sub-folders and that's pretty much it. 😃

r? ``@notriddle``
2025-05-06 16:28:42 +10:00
Stuart Cook
42156bde4d Rollup merge of #140251 - Zalathar:coverage-dump-path, r=clubby789
coverage-dump: Resolve global file IDs to filenames

The coverage-dump tool, used by coverage tests, currently includes “global file ID” numbers in its dump output.

This PR adds support for parsing coverage filename information from LLVM assembly `.ll` files, and resolving those file IDs to the corresponding filename, for inclusion in dump output.

This makes dump output more informative, especially for test cases involving multiple files, and will be important for testing expansion region support in the future.

---

The bootstrap changes don't necessarily have to land at the same time (e.g. they could be deferred to after the stage0 redesign if requested), but I would prefer to land them now if possible.
2025-05-06 16:28:40 +10:00
Stuart Cook
627873a078 Rollup merge of #140035 - fee1-dead-contrib:push-oszwkkvmpkks, r=jieyouxu,wesleywiser
Implement RFC 3503: frontmatters

Tracking issue: #136889

Supercedes #137193. This implements [RFC 3503](https://github.com/rust-lang/rfcs/blob/master/text/3503-frontmatter.md).

This might break rust-analyzer. Will look into how to fix that.

Suggestions welcome for how to improve diagnostics.
2025-05-06 16:28:39 +10:00
Stuart Cook
5ca0053c79 Rollup merge of #139764 - dtolnay:extractif, r=Amanieu
Consistent trait bounds for ExtractIf Debug impls

Closes #137654. Refer to that issue for a table of the **4** different impl signatures we previously had in the standard library for Debug impls of various ExtractIf iterator types.

The one we are standardizing on is the one so far only used by `alloc::collections::linked_list::ExtractIf`, which is _no_ `F: Debug` bound, _no_ `F: FnMut` bound, only `T: Debug` bound.

This PR applies the following signature changes:

```diff
/* alloc::collections::btree_map */

    pub struct ExtractIf<'a, K, V, F, A = Global>
    where
-       F: 'a + FnMut(&K, &mut V) -> bool,
        Allocator + Clone,

    impl Debug for ExtractIf<'a, K, V, F,
+       A,
    >
    where
        K: Debug,
        V: Debug,
-       F: FnMut(&K, &mut V) -> bool,
+       A: Allocator + Clone,
```

```diff
/* alloc::collections::btree_set */

    pub struct ExtractIf<'a, T, F, A = Global>
    where
-       T: 'a,
-       F: 'a + FnMut(&T) -> bool,
        Allocator + Clone,

    impl Debug for ExtractIf<'a, T, F, A>
    where
        T: Debug,
-       F: FnMut(&T) -> bool,
        A: Allocator + Clone,
```

```diff
/* alloc::collections::linked_list */

    impl Debug for ExtractIf<'a, T, F,
+       A,
    >
    where
        T: Debug,
+       A: Allocator,
```

```diff
/* alloc::vec */

    impl Debug for ExtractIf<'a, T, F, A>
    where
        T: Debug,
-       F: Debug,
        A: Allocator,
-       A: Debug,
```

```diff
/* std::collections::hash_map */

    pub struct ExtractIf<'a, K, V, F>
    where
-       F: FnMut(&K, &mut V) -> bool,

    impl Debug for ExtractIf<'a, K, V, F>
    where
+       K: Debug,
+       V: Debug,
-       F: FnMut(&K, &mut V) -> bool,
```

```diff
/* std::collections::hash_set */

    pub struct ExtractIf<'a, T, F>
    where
-       F: FnMut(&T) -> bool,

    impl Debug for ExtractIf<'a, T, F>
    where
+       T: Debug,
-       F: FnMut(&T) -> bool,
```

I have made the following changes to bring these types into better alignment with one another.

- Delete `F: Debug` bounds. These are especially problematic because Rust closures do not come with a Debug impl, rendering the impl useless.

- Delete `A: Debug` bounds. Allocator parameters are unstable for now, but in the future this would become an API commitment that we do not debug-print a representation of the allocator when printing an iterator.

- Delete `F: FnMut` bounds. Requires `hashbrown` PR: https://github.com/rust-lang/hashbrown/pull/616. **API commitment:** we commit to not doing RefCell voodoo inside ExtractIf to have some way for its Debug impl (which takes &amp;self) to call a FnMut closure, if this is even possible.

- Add `T: Debug` bounds (or `K`/`V`), even on Debug impls that do not currently make use of them, but might in the future. **Breaking change.** Must backport into Rust 1.87 (current beta) or do a de-stabilization PR in beta to delay those types by one release.

- Render using `debug_struct` + `finish_non_exhaustive`, instead of `debug_tuple`.

- Do not render the _entire_ underlying collection.

- Show a "peek" field indicating the current position of the iterator.
2025-05-06 16:28:38 +10:00
Stuart Cook
01cbc86218 Rollup merge of #139550 - Urgau:rmeta-remap-path-scope, r=nnethercote
Fix `-Zremap-path-scope` rmeta handling

This PR fixes the conditional remapping (`-Zremap-path-scope`) of rmeta file paths ~~by using the `debuginfo` scope~~ by conditionally embedding the local path in addition to the remapped path.

Fixes https://github.com/rust-lang/rust/issues/139217
2025-05-06 16:28:38 +10:00
David Tolnay
c35914383a Consistent trait bounds for ExtractIf Debug impls 2025-05-05 19:46:46 -07:00
Zalathar
c53a76743c coverage-dump: Dump filenames instead of global file IDs (and bless) 2025-05-06 11:58:58 +10:00
Guillaume Gomez
bdbf1c631a Rollup merge of #140672 - compiler-errors:deeply-normalize, r=lcnr
Deeply normalize in the new solver in WF

We need to deeply normalize types we check for well-formedness, since we only collect implied bounds from normalized signature types.

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

r? lcnr
2025-05-05 21:32:35 +02:00
Guillaume Gomez
0d7067d7b2 Rollup merge of #140661 - Darksonn:fixedx18-tm, r=wesleywiser
Make `-Zfixed-x18` into a target modifier

As part of #136966, the `-Zfixed-x18` flag should be turned into a target modifier. This is a blocker to stabilization of the flag. The flag was originally added in #124655 and the MCP for its addition is [MCP#748](https://github.com/rust-lang/compiler-team/issues/748).

On some aarch64 targets, the x18 register is used as a temporary caller-saved register by default. When the `-Zfixed-x18` flag is passed, this is turned off so that the compiler doesn't use the x18 register. This allows end-users to use the x18 register for other purposes. For example, by accessing it with inline asm you can use the register as a very efficient thread-local variable. Another common use-case is to store the stack pointer needed by the shadow-call-stack sanitizer. There are also some aarch64 targets where not using x18 is the default – in those cases the flag is a no-op.

Note that this flag does not *on its own* cause an ABI mismatch. What actually causes an ABI mismatch is when you have different compilation units that *disagree* on what it should be used for. But having a CU that uses it and another CU that doesn't normally isn't enough to trigger an ABI problem. However, we still consider the flag to be a target modifier in all cases, since it is assumed that you are passing the flag because you intend to assign some other meaning to the register. Rejecting all flag mismatches even if not all are unsound is consistent with [RFC#3716](https://rust-lang.github.io/rfcs/3716-target-modifiers.html). See the headings "not all mismatches are unsound" and "cases that are not caught" for additional discussion of this.

On aarch64 targets where `-Zfixed-x18` is not a no-op, it is an error to pass `-Zsanitizer=shadow-call-stack` without also passing `-Zfixed-x18`.
2025-05-05 21:32:34 +02:00
Guillaume Gomez
1e90557ae8 Rollup merge of #140374 - compiler-errors:global_asm-bug, r=lcnr
Resolve instance for SymFn in global/naked asm

`Instance::expect_resolve` ensures that we're actually going from trait item -> impl item.

Fixes #140373
2025-05-05 21:32:32 +02:00
Guillaume Gomez
ab7623e93c Rollup merge of #140115 - dianqk:gvn-matchbr, r=oli-obk
mir-opt: execute MatchBranchSimplification after GVN

This can provide more opportunities for MatchBranchSimplification.

Currently, rustc does not optimize the following code into a single statement at mir-opt, and this PR fixes the first case.

```rust
pub fn match1(c: bool, v1: i32, v2: i32) -> i32 {
    if c { v1 - v2 } else { v1 - v2 }
}

pub fn match2(c: bool, v1: i32) -> i32 {
    if c { v1 - 1 } else { v1 - 1 }
}
```

https://rust.godbolt.org/z/Y8xPMjrfM

r? mir-opt
2025-05-05 21:32:30 +02:00
Skgland
fb8784585e fix tidy and bless test 2025-05-05 21:09:31 +02:00
Michael Goulet
c0dfa44c48 Be a bit more relaxed about not yet constrained infer vars in closure upvar analysis 2025-05-05 19:06:45 +00:00
Skgland
7fc84ac964 expand comment 2025-05-05 20:40:44 +02:00
Urgau
6a7996e303 Take into-account -Zremap-path-scope when embedding filenames 2025-05-05 19:45:34 +02:00
Michael Goulet
12d3021ef0 Deeply normalize in the new solver in WF 2025-05-05 15:52:38 +00:00
Guillaume Gomez
27e39c3ac6 Created tests/rustdoc/async subfolder to limit number of files at the top level 2025-05-05 17:49:12 +02:00
Guillaume Gomez
e14e19a67d Created tests/rustdoc/extern subfolder to limit number of files at the top level 2025-05-05 17:49:12 +02:00
Guillaume Gomez
e245c3bc6b Move primitive rustdoc tests into the primitive sub folder 2025-05-05 17:47:18 +02:00
Guillaume Gomez
4b6bc73507 Created tests/rustdoc/enum subfolder to limit number of files at the top level 2025-05-05 17:47:18 +02:00
Guillaume Gomez
fa2b9227a1 Created tests/rustdoc/assoc subfolder to limit number of files at the top level 2025-05-05 17:47:18 +02:00
Guillaume Gomez
b84f4cc39e Created tests/rustdoc/impl subfolder to limit number of files at the top level 2025-05-05 17:47:18 +02:00
Guillaume Gomez
be71d8b24f Created tests/rustdoc/doc-cfg subfolder to limit number of files at the top level 2025-05-05 17:47:18 +02:00
Guillaume Gomez
d1f4a0bcb6 Created tests/rustdoc/macro subfolder to limit number of files at the top level 2025-05-05 17:47:18 +02:00
Guillaume Gomez
eee6c97535 Created tests/rustdoc/private subfolder to limit number of files at the top level 2025-05-05 17:47:18 +02:00
Guillaume Gomez
a00b39961a Move intra-doc tests into the expected subfolder 2025-05-05 17:47:18 +02:00
Guillaume Gomez
9db7de5915 Created tests/rustdoc/jump-to-def subfolder to limit number of files at the top level 2025-05-05 17:47:18 +02:00
Guillaume Gomez
ff971d001d Created tests/rustdoc/auto subfolder to limit number of files at the top level 2025-05-05 17:47:18 +02:00
Guillaume Gomez
b374996ab8 Created tests/rustdoc/anchors subfolder to limit number of files at the top level 2025-05-05 17:47:18 +02:00
Guillaume Gomez
099f730dcf Created tests/rustdoc/source-code-pages subfolder to limit number of files at the top level 2025-05-05 17:47:17 +02:00
Guillaume Gomez
b796179f98 Created tests/rustdoc/reexports subfolder to limit number of files at the top level 2025-05-05 17:47:17 +02:00
Deadbeef
662182637e Implement RFC 3503: frontmatters
Supercedes #137193
2025-05-05 23:10:08 +08:00
xizheyin
896cf8029c Add ui test fn-trait-use-named-params
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-05-05 22:56:03 +08:00
Michael Goulet
45598de704 Do not gather local all together at the beginning of typeck 2025-05-05 14:27:09 +00:00
Michael Goulet
833c212b81 Rename Instance::new to Instance::new_raw and add a note that it is raw 2025-05-05 13:17:35 +00:00
Michael Goulet
3a1ee645ca Resolve instance for SymFn in global/naked asm 2025-05-05 13:17:35 +00:00
Alice Ryhl
4b58c5034a Make -Zfixed-x18 into a target modifier 2025-05-05 12:42:27 +00:00
bors
243c5a35e1 Auto merge of #140453 - Zoxc:next-disambiguator, r=oli-obk
Remove global `next_disambiguator` state and handle it with a `DisambiguatorState` type

This removes `Definitions.next_disambiguator` as it doesn't guarantee deterministic def paths when `create_def` is called in parallel. Instead a new `DisambiguatorState` type is passed as a mutable reference to `create_def` to help create unique def paths. `create_def` calls with distinct  `DisambiguatorState` instances must ensure that that the def paths are unique without its help.

Anon associated types did rely on this global state for uniqueness and are changed to use (method they're defined in + their position in the method return type) as the `DefPathData` to ensure uniqueness. This also means that the method they're defined in appears in error messages, which is nicer.

`DefPathData::NestedStatic` is added to use for nested data inside statics instead of reusing `DefPathData::AnonConst` to avoid conflicts with those.

cc `@oli-obk`
2025-05-05 11:50:43 +00:00
dianne
17bb4bbc86 always peel &mut, to allow matching on &mut str 2025-05-05 04:29:33 -07:00