281859 Commits

Author SHA1 Message Date
bors
f04bbc60f8 Auto merge of #136771 - scottmcm:poke-slice-iter-next, r=joboet
Simplify `slice::Iter::next` enough that it inlines

Inspired by this zulip conversation: <https://rust-lang.zulipchat.com/#narrow/channel/189540-t-compiler.2Fwg-mir-opt/topic/Feedback.20on.20a.20MIR.20optimization.20idea/near/498579990>

~~Draft for now because it needs #136735 to get the codegen tests to pass.~~
2025-02-20 18:20:40 +00:00
bors
28b83ee596 Auto merge of #137123 - Zalathar:user-type-span, r=oli-obk
Don't store a redundant span in user-type projections

While experimenting with some larger changes, I noticed that storing this span here is unnecessary, because it is also present in the corresponding `CanonicalUserTypeAnnotation` and can be retrieved via the annotation's ID.
2025-02-20 12:19:14 +00:00
Zalathar
8bb574fdd3 Don't store a redundant span in user-type projections
This span is already present in the corresponding
`CanonicalUserTypeAnnotation`, and can be retrieved via the annotation's ID.
2025-02-20 20:37:17 +11:00
Zalathar
a64efc72d0 Avoid a useless clone of UserTypeProjection 2025-02-20 20:31:06 +11:00
Zalathar
bf3bb5fd37 Flatten the check for ref/non-ref bindings 2025-02-20 20:31:06 +11:00
Zalathar
849b0920b1 Partly flatten the user-type loop in TypeVerifier::visit_local_decl 2025-02-20 20:31:06 +11:00
bors
c62239aeb3 Auto merge of #137058 - scottmcm:trunc-unchecked, r=nikic
Emit `trunc nuw` for unchecked shifts and `to_immediate_scalar`

- For shifts this shrinks the IR by no longer needing an `assume` while still providing the UB information
- Having this on the `i8`→`i1` truncations will hopefully help with some places that have to load `i8`s or pass those in LLVM structs without range information
2025-02-20 09:05:22 +00:00
bors
eeb9035117 Auto merge of #137023 - Kobzol:bump-sccache, r=marcoieni
Bump sccache in CI to 0.9.1

We haven't updated the used sccache version for years, it has accrued a bunch of fixes and features in the meantime. It now supports the `--show-adv-stats` flag, which gives a more detailed summary of the results of caching. And it can also cache Rust code, which could be useful in the future (https://github.com/rust-lang/rust/pull/136942 - although now there are no large wins).

It also supports caching PGO now, but since the PGO profiles are always different, it won't make any real difference.

https://github.com/rust-lang/rust/pull/133076 previously tried to update the version to 0.3 (CC `@klensy)`

r? `@marcoieni`
2025-02-20 05:59:04 +00:00
bors
6d3c050de8 Auto merge of #137295 - matthiaskrgr:rollup-tdu3t39, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #135296 (interpret: adjust vtable validity check for higher-ranked types)
 - #137106 (Add customized compare for Link in rustdoc)
 - #137253 (Restrict `bevy_ecs` `ParamSet` hack)
 - #137262 (Make fewer crates depend on `rustc_ast_ir`)
 - #137263 (Register `USAGE_OF_TYPE_IR_INHERENT`, remove inherent usages)
 - #137266 (MIR visitor tweaks)
 - #137269 (Pattern Migration 2024: properly label `&` patterns whose subpatterns are from macro expansions)
 - #137277 (stabilize `inherent_str_constructors`)
 - #137281 (Tweak "expected ident" parse error to avoid talking about doc comments)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-20 02:39:28 +00:00
Matthias Krüger
ed45c1187f
Rollup merge of #137281 - estebank:doc-comment-syntax-error, r=compiler-errors
Tweak "expected ident" parse error to avoid talking about doc comments

When encountering a doc comment without an identifier after, we'd unconditionally state "this doc comment doesn't document anything", swallowing the *actual* error which is that the thing *after* the doc comment wasn't expected. Added a check that the found token is something that "conceptually" closes the previous item before emitting that error, otherwise just complain about the missing identifier.

In both of the following cases, the syntax error follows a doc comment:
```
error: expected identifier, found keyword `Self`
  --> $DIR/doc-before-bad-variant.rs:4:5
   |
LL | enum TestEnum {
   |      -------- while parsing this enum
...
LL |     Self,
   |     ^^^^ expected identifier, found keyword
   |
   = help: enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }`
```
```
error: expected identifier, found `<`
  --> $DIR/doc-before-syntax-error.rs:2:1
   |
LL | <>
   | ^ expected identifier
```

Fix #71982.
2025-02-20 00:55:16 +01:00
Matthias Krüger
be73ea82ce
Rollup merge of #137277 - m4rch3n1ng:stabilize-inherent-str-constructors, r=tgross35
stabilize `inherent_str_constructors`

fcp done in https://github.com/rust-lang/rust/issues/131114#issuecomment-2668859969.

tracking issue: #131114
closes: #131114
2025-02-20 00:55:16 +01:00
Matthias Krüger
704a024688
Rollup merge of #137269 - dianne:fix-ref-pat-label-span, r=davidtwco
Pattern Migration 2024: properly label `&` patterns whose subpatterns are from macro expansions

See the failing test output in the first commit for an example of what this going wrong looks like. The error/lint diagnostic tries to point to just the `&` or `&mut` of reference patterns when labeling the causes, to make the output clearer (#134394). The trimming there wasn't quite right though: it used the interior of the reference pattern as a cutoff and extended backwards to find where to trim the pattern's span, but this breaks if the `&` and the interior are from different sources. This PR instead trims by starting at the start of the pattern and ending at the final character of the `&` (or `&mut`, `ref`, `ref mut`, or `mut`, depending on what the error/lint is labeling); that way, there's no opportunity for failure from mixing sources.

I'm not 100% happy with this approach, but I'm also not sure what the best practices are as far as hacky `SourceMap` munching goes, so please let me know if something else would be preferred.

Since `SourceMap::span_through_char` can't change the syntax context of the span, I've also removed a call to `Span::with_ctxt` (we care about the edition of the span in question since this is a hard error in Rust 2024). If we want to be extra safe in case that changes, I can re-add it or track error hardness separately in the `rust_2024_migration_desugared_pats` table.
2025-02-20 00:55:15 +01:00
Matthias Krüger
10ba57516f
Rollup merge of #137266 - nnethercote:mir-visitor-tweaks, r=compiler-errors
MIR visitor tweaks

Some minor improvements I found while looking at this code.

r? `@tmandry`
2025-02-20 00:55:14 +01:00
Matthias Krüger
4981994588
Rollup merge of #137263 - compiler-errors:inherentless, r=lcnr
Register `USAGE_OF_TYPE_IR_INHERENT`, remove inherent usages

I implemented a lint to discourage the usage of `rustc_type_ir::inherent` but never actually enabled it. People started using `rustc_type_ir::inherent` methods through globs, lol.

r? fmease or reassign as you please
2025-02-20 00:55:14 +01:00
Matthias Krüger
80e861c142
Rollup merge of #137262 - compiler-errors:ast-ir-begone, r=lcnr
Make fewer crates depend on `rustc_ast_ir`

I think it simplifies the crate graph and also exposes people less to confusion if downstream crates don't interact with `rustc_ast_ir` directly and instead just use its functionality reexported through more familiar paths.

r? oli-obk since you introduced ast-ir
2025-02-20 00:55:13 +01:00
Matthias Krüger
4f84ba1a20
Rollup merge of #137253 - compiler-errors:bevy-hack, r=jackh726
Restrict `bevy_ecs` `ParamSet` hack

This limits the bevy WF hack to only apply to ADTs named `ParamSet` that come from crates named `bevy_ecs`, and references to the latter.

Previously, we were applying it to all ADTs that contained the substring `"ParamSet"`. This could show up anywhere in the ADT name, and it could come from any crate. It's a bit concerning since other code could theoretically begin to rely on this behavior too (though I don't expect it to)

This simplifies the logic a bit and turns it into a visitor.

r? `@jackh726`
2025-02-20 00:55:13 +01:00
Matthias Krüger
8ccfd06e46
Rollup merge of #137106 - chenyukang:yukang-fix-sidebar-sort, r=notriddle
Add customized compare for Link in rustdoc

Maybe some other types in sidebar need to be sorted in this way, maybe add this crate `natord` is ok?

r?  clubby789

Fixes #137098
2025-02-20 00:55:12 +01:00
Matthias Krüger
6055793062
Rollup merge of #135296 - lukas-code:dyn-leak-check, r=compiler-errors
interpret: adjust vtable validity check for higher-ranked types

## What

Transmuting between trait objects where a generic argument or associated type only differs in bound regions (not bound at or above the trait object's binder) is now UB. For example

* transmuting between `&dyn Trait<for<'a> fn(&'a u8)>` and `&dyn Trait<fn(&'static u8)>` is UB.
* transmuting between `&dyn Trait<Assoc = for<'a> fn(&'a u8)>` and `&dyn Trait<Assoc = fn(&'static u8)>` is UB.
* transmuting between `&dyn Trait<for<'a> fn(&'a u8) -> (&'a u8, &'static u8)>` and `&dyn Trait<for<'a> fn(&'a u8) -> (&'static u8, &'a u8)>` is UB.

Transmuting between subtypes (in either direction) is still allowed, which means that bound regions that are bound at or above the trait object's binder can still be changed:

* transmuting between `&dyn for<'a> Trait<fn(&'a u8)>` and `&dyn for Trait<fn(&'static u8)>` is fine.
* transmuting between `&dyn for<'a> Trait<dyn Trait<fn(&'a u8)>>` and `&dyn for Trait<dyn Trait<fn(&'static u8)>>` is fine.

## Why

Very similar to https://github.com/rust-lang/rust/issues/120217 and https://github.com/rust-lang/rust/issues/120222, changing a trait object's generic argument to a type that only differs in bound regions can still affect the vtable layout and lead to segfaults at runtime (for an example see `src/tools/miri/tests/fail/validity/dyn-transmute-inner-binder.rs`).

Since we already already require that the trait object predicates must be equal modulo bound regions, it is only natural to extend this check to also require type equality considering bound regions.

However, it also makes sense to allow transmutes between a type and a subtype thereof. For example `&dyn for<'a> Trait<&'a u8>` is a subtype of `&dyn Trait<&'static ()>` and they are guaranteed to have the same vtable, so it makes sense to allow this transmute. So that's why bound lifetimes that are bound to the trait object itself are treated as free lifetime for the purpose of this check.

Note that codegen already relies on the property that subtyping cannot change the the vtable and this is asserted here (note the leak check): 251206c27b/compiler/rustc_codegen_ssa/src/base.rs (L106-L153)

Furthermore, we allow some pointer-to-pointer casts like `*const dyn for<'a> Trait<&'a u8>` to `*const Wrapper<dyn Trait<&'static u8>>` that instantiate the trait object binder and are currently lowered to a single pointer-to-pointer cast in MIR (`CastKind::PtrToPtr`) and *not* an unsizing coercion (`CastKind::PointerCoercion(Unsize)`), so the current MIR lowering of these would be UB if we didn't allow subtyping transmutes.

---

fixes https://github.com/rust-lang/rust/issues/135230
cc `@rust-lang/opsem`
r? `@compiler-errors` for the implementation
2025-02-20 00:55:11 +01:00
bors
4e1356b959 Auto merge of #137290 - matthiaskrgr:rollup-a7xdbi4, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #120580 (Add `MAX_LEN_UTF8` and `MAX_LEN_UTF16` Constants)
 - #132268 (Impl TryFrom<Vec<u8>> for String)
 - #136093 (Match Ergonomics 2024: update old-edition behavior of feature gates)
 - #136344 (Suggest replacing `.` with `::` in more error diagnostics.)
 - #136690 (Use more explicit and reliable ptr select in sort impls)
 - #136815 (CI: Stop /msys64/bin from being prepended to PATH in msys2 shell)
 - #136923 (Lint `#[must_use]` attributes applied to methods in trait impls)
 - #137155 (Organize `OsString`/`OsStr` shims)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-19 23:29:37 +00:00
Matthias Krüger
3964bb131b
Rollup merge of #137155 - thaliaarchi:wtf8-organize, r=ChrisDenton
Organize `OsString`/`OsStr` shims

Synchronize the `bytes.rs` and `wtf8.rs` shims for `OsString`/`OsStr` so they're easier to diff between each other. This is mostly ordering items the same between the two. I tried to minimize moves and went for the average locations between the files.

With them in the same order, it is clear that `FromInner<_>` is not implemented for `bytes::Buf` and `Clone::clone_from` is not implemented for `wtf8::Buf`, but they are for the other. Fix that.

I added #[inline] to all inherent methods of the `OsString`/`OsStr` shims, because it seemed that was already the rough pattern. `bytes.rs` has more inlining than `wtf8.rs`, so I added the corresponding ones to `wtf8.rs`. Then, the common missing ones have no discernible pattern to me. They're not divided by non-allocating/allocating. Perhaps the pattern is that UTF-8 validation isn't inlined? Since these types are merely the inner values in `OsStr`/`OsString`, I put inline on all methods and let those public types dictate inlining. I have not inspected codegen or run benchmarks.

Also, touch up some (private) documentation comments.

r? ``````@ChrisDenton``````
2025-02-19 21:16:12 +01:00
Matthias Krüger
c29cc600fd
Rollup merge of #136923 - samueltardieu:push-vxxqvqwspssv, r=davidtwco
Lint `#[must_use]` attributes applied to methods in trait impls

The `#[must_use]` attribute has no effect when applied to methods in trait implementations. This PR adds it to the unused `#[must_use]` lint, and cleans the extra attributes in portable-simd and Clippy.
2025-02-19 21:16:11 +01:00
Matthias Krüger
40379e299c
Rollup merge of #136815 - ChrisDenton:fix-mingw-ci, r=Kobzol
CI: Stop /msys64/bin from being prepended to PATH in msys2 shell

We used to do this along time ago but we stopped doing it when we started installing msys2 manually. 4fd3cf96a1/src/ci/scripts/install-msys2.sh (L11-L13)

Fixes #136795

try-job: dist-i686-mingw
2025-02-19 21:16:11 +01:00
Matthias Krüger
59d2b102b4
Rollup merge of #136690 - Voultapher:use-more-explicit-and-reliable-ptr-select, r=thomcc
Use more explicit and reliable ptr select in sort impls

Using `if ...` with the intent to avoid branches can be surprising to readers and carries the risk of turning into jumps/branches generated by some future compiler version, breaking crucial optimizations.

This commit replaces their usage with the explicit and IR annotated `bool::select_unpredictable`.
2025-02-19 21:16:09 +01:00
Matthias Krüger
82279108e1
Rollup merge of #136344 - zachs18:dot_notation_more_defkinds_3, r=davidtwco
Suggest replacing `.` with `::` in more error diagnostics.

First commit makes the existing "help: use the path separator to refer to an item" also work when the base is a type alias, not just a trait/module/struct.

The existing unconditional `DefKind::Mod | DefKind::Trait` match arm is changed to a conditional `DefKind::Mod | DefKind::Trait | DefKind::TyAlias` arm that only matches if the `path_sep` suggestion-adding closure succeeds, so as not to stop the later `DefKind::TyAlias`-specific suggestions if the path-sep suggestion does not apply. This shouldn't change behavior for `Mod` or `Trait` (due to the default arm's `return false` etc).

This commit also updates `tests/ui/resolve/issue-22692.rs` to reflect this, and also renames it to something more meaningful.

This commit also makes the `bad_struct_syntax_suggestion` closure take `err` as a parameter instead of capturing it, since otherwise caused borrowing errors due to the change to using `path_sep` in a pattern guard.

<details> <summary> Type alias diagnostic example </summary>

```rust
type S = String;

fn main() {
    let _ = S.new;
}
```

```diff
 error[E0423]: expected value, found type alias `S`
  --> diag7.rs:4:13
   |
 4 |     let _ = S.new;
   |             ^
   |
-  = note: can't use a type alias as a constructor
+  help: use the path separator to refer to an item
+  |
+4 |     let _ = S::new;
+  |              ~~
```

</details>

Second commit adds some cases for `enum`s, where if there is a field/method expression where the field/method has the name of a unit/tuple variant, we assume the user intended to create that variant[^1] and suggest replacing the `.` from the field/method suggestion with a `::` path separator. If no such variant is found (or if the error is not a field/method expression), we give the existing suggestion that suggests adding `::TupleVariant(/* fields */)` after the enum.

<details> <summary> Enum diagnostic example </summary>

```rust
enum Foo {
    A(u32),
    B,
    C { x: u32 },
}

fn main() {
    let _ = Foo.A(42); // changed
    let _ = Foo.B;     // changed
    let _ = Foo.D(42); // no change
    let _ = Foo.D;     // no change
    let _ = Foo(42);   // no change
}
```

```diff
 error[E0423]: expected value, found enum `Foo`
  --> diag8.rs:8:13
   |
 8 |     let _ = Foo.A(42); // changed
   |             ^^^
   |
 note: the enum is defined here
  --> diag8.rs:1:1
   |
 1 | / enum Foo {
 2 | |     A(u32),
 3 | |     B,
 4 | |     C { x: u32 },
 5 | | }
   | |_^
-help: you might have meant to use the following enum variant
-  |
-8 |     let _ = Foo::B.A(42); // changed
-  |             ~~~~~~
-help: alternatively, the following enum variant is available
+help: use the path separator to refer to a variant
   |
-8 |     let _ = (Foo::A(/* fields */)).A(42); // changed
-  |             ~~~~~~~~~~~~~~~~~~~~~~
+8 |     let _ = Foo::A(42); // changed
+  |                ~~

 error[E0423]: expected value, found enum `Foo`
  --> diag8.rs:9:13
   |
 9 |     let _ = Foo.B;     // changed
   |             ^^^
   |
 note: the enum is defined here
  --> diag8.rs:1:1
   |
 1 | / enum Foo {
 2 | |     A(u32),
 3 | |     B,
 4 | |     C { x: u32 },
 5 | | }
   | |_^
-help: you might have meant to use the following enum variant
-  |
-9 |     let _ = Foo::B.B;     // changed
-  |             ~~~~~~
-help: alternatively, the following enum variant is available
+help: use the path separator to refer to a variant
   |
-9 |     let _ = (Foo::A(/* fields */)).B;     // changed
-  |             ~~~~~~~~~~~~~~~~~~~~~~
+9 |     let _ = Foo::B;     // changed
+  |                ~~

 error[E0423]: expected value, found enum `Foo`
   --> diag8.rs:10:13
    |
 10 |     let _ = Foo.D(42); // no change
    |             ^^^
    |
 note: the enum is defined here
   --> diag8.rs:1:1
    |
 1  | / enum Foo {
 2  | |     A(u32),
 3  | |     B,
 4  | |     C { x: u32 },
 5  | | }
    | |_^
 help: you might have meant to use the following enum variant
    |
 10 |     let _ = Foo::B.D(42); // no change
    |             ~~~~~~
 help: alternatively, the following enum variant is available
    |
 10 |     let _ = (Foo::A(/* fields */)).D(42); // no change
    |             ~~~~~~~~~~~~~~~~~~~~~~

 error[E0423]: expected value, found enum `Foo`
   --> diag8.rs:11:13
    |
 11 |     let _ = Foo.D;     // no change
    |             ^^^
    |
 note: the enum is defined here
   --> diag8.rs:1:1
    |
 1  | / enum Foo {
 2  | |     A(u32),
 3  | |     B,
 4  | |     C { x: u32 },
 5  | | }
    | |_^
 help: you might have meant to use the following enum variant
    |
 11 |     let _ = Foo::B.D;     // no change
    |             ~~~~~~
 help: alternatively, the following enum variant is available
    |
 11 |     let _ = (Foo::A(/* fields */)).D;     // no change
    |             ~~~~~~~~~~~~~~~~~~~~~~

 error[E0423]: expected function, tuple struct or tuple variant, found enum `Foo`
   --> diag8.rs:12:13
    |
 12 |     let _ = Foo(42);   // no change
    |             ^^^ help: try to construct one of the enum's variants: `Foo::A`
    |
    = help: you might have meant to construct the enum's non-tuple variant
 note: the enum is defined here
   --> diag8.rs:1:1
    |
 1  | / enum Foo {
 2  | |     A(u32),
 3  | |     B,
 4  | |     C { x: u32 },
 5  | | }
    | |_^

 error: aborting due to 5 previous errors
```

</details>

[^1]: or if it's a field expression and a tuple variant, that they meant to refer the variant constructor.
2025-02-19 21:16:07 +01:00
Matthias Krüger
659838ebfd
Rollup merge of #136093 - dianne:match-2024-for-edition-2021, r=Nadrieril
Match Ergonomics 2024: update old-edition behavior of feature gates

This updates the behavior of the feature gates `ref_pat_eat_one_layer_2024_structural` and `ref_pat_eat_one_layer_2024` in Editions 2021 and earlier to correspond to the left and right typing rules compared [here](https://nadrieril.github.io/typing-rust-patterns/?opts1=AQEBAQIBAQEBAAAAAAAAAAAAAAAAAAA%3D&style=UserVisible&compare=true&opts2=AQEBAQIBAQABAAAAAQEBAAEBAAABAAA%3D&mode=rules), respectively. Compared to the `stable_rust` rules:
- they both allow reference patterns to match a lone inherited ref,
- they both allow `&` patterns to eat `&mut` reference types (and lone `&mut` inherited refs) as if they're shared,
- they both allow `&mut` patterns to eat `&` reference types when there's a `&mut` inherited reference to also eat,
- and the left ruleset has RFC 3627's Rule 3: after encountering a shared reference type in the scrutinee, the default binding mode will be treated as by-shared-ref when it would otherwise be by-mutable-ref.

I think there's already tests for all of those typing rules, so I've added revisions to use the existing tests with the new rulesets. Additionally, I've added a few tests to make sure we handle mixed-edition patterns appropriately, and I've added references to the unstable book.

Relevant tracking issue: #123076

r? ``@ghost``
2025-02-19 21:16:04 +01:00
Matthias Krüger
7b7b1d4ee9
Rollup merge of #132268 - elichai:string_try_from_vec, r=Amanieu
Impl TryFrom<Vec<u8>> for String

I think this is useful enough to have :)
As a general question, is there any policy around adding "missing" trait implementations? (like adding `AsRef<T> for T` for std types), I mostly stumble upon them when using a lot of "impl Trait in argument position" like (`foo: impl Into<String>`)
2025-02-19 21:16:02 +01:00
Matthias Krüger
84e9f29007
Rollup merge of #120580 - HTGAzureX1212:HTGAzureX1212/issue-45795, r=m-ou-se
Add `MAX_LEN_UTF8` and `MAX_LEN_UTF16` Constants

This pull request adds the `MAX_LEN_UTF8` and `MAX_LEN_UTF16` constants as per #45795, gated behind the `char_max_len` feature.

The constants are currently applied in the `alloc`, `core` and `std` libraries.
2025-02-19 21:16:01 +01:00
bors
f280acf4c7 Auto merge of #137284 - matthiaskrgr:rollup-deuhk46, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #127793 (Added project-specific Zed IDE settings)
 - #134995 (Stabilize const_slice_flatten)
 - #136301 (Improve instant docs)
 - #136347 (Add a bullet point to `std::fs::copy`)
 - #136794 (Stabilize file_lock)
 - #137094 (x86_win64 ABI: do not use xmm0 with softfloat ABI)
 - #137227 (docs(dev): Update the feature-gate instructions)
 - #137232 (Don't mention `FromResidual` on bad `?`)
 - #137251 (coverage: Get hole spans from nested items without fully visiting them)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-19 20:14:30 +00:00
Scott McMurray
6f9cfd694d Rework OperandRef::extract_field to stop calling to_immediate_scalar on things which are already immediates
That means it stops trying to truncate things that are already `i1`s.
2025-02-19 12:03:40 -08:00
Scott McMurray
642a705f71 PR feedback 2025-02-19 11:36:52 -08:00
Scott McMurray
511bf307f0 Emit trunc nuw for unchecked shifts and to_immediate_scalar
- For shifts this shrinks the IR by no longer needing an `assume` while still providing the UB information
- Having this on the `i8`→`i1` truncations will hopefully help with some places that have to load `i8`s or pass those in LLVM structs without range information
2025-02-19 11:36:52 -08:00
may
b24f77507f
stabilize inherent_str_constructors 2025-02-19 19:24:49 +01:00
dianne
2be26f0fe8 add clarifying comments to chars used for label-trimming 2025-02-19 10:01:13 -08:00
Matthias Krüger
3fc6dfd5ed
Rollup merge of #137251 - Zalathar:holes-visitor, r=jieyouxu
coverage: Get hole spans from nested items without fully visiting them

This is a small simplification to the code that collects the spans of nested items within a function, so that those spans can be treated as “holes” to be avoided by the current function's coverage mappings.

The old code was using `nested_filter::All` to ensure that the visitor would see nested items. But we don't need the actual items themselves; we just need their spans, which we can obtain via a custom implementation of `visit_nested_item`.

This avoids the more expansive queries required by `nested_filter::All`.
2025-02-19 18:52:10 +01:00
Matthias Krüger
dd60b6ca27
Rollup merge of #137232 - estebank:from-residual-note, r=petrochenkov
Don't mention `FromResidual` on bad `?`

Unless `try_trait_v2` is enabled, don't mention that `FromResidual` isn't implemented for a specific type when the implicit `From` conversion of a `?` fails. For the end user on stable, `?` might as well be a compiler intrinsic, so we remove that note to avoid further confusion and allowing other parts of the error to be more prominent.

```
error[E0277]: `?` couldn't convert the error to `u8`
  --> $DIR/bad-interconversion.rs:4:20
   |
LL | fn result_to_result() -> Result<u64, u8> {
   |                          --------------- expected `u8` because of this
LL |     Ok(Err(123_i32)?)
   |        ------------^ the trait `From<i32>` is not implemented for `u8`
   |        |
   |        this can't be annotated with `?` because it has type `Result<_, i32>`
   |
   = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
   = help: the following other types implement trait `From<T>`:
             `u8` implements `From<Char>`
             `u8` implements `From<bool>`
```
2025-02-19 18:52:08 +01:00
Matthias Krüger
fa10786e18
Rollup merge of #137227 - epage:features_untracked, r=compiler-errors
docs(dev): Update the feature-gate instructions

`features_untracked` was removed in #114723

features are now functions as of  #132027
2025-02-19 18:52:08 +01:00
Matthias Krüger
d8debbdd68
Rollup merge of #137094 - RalfJung:softfloat-means-no-simd, r=tgross35
x86_win64 ABI: do not use xmm0 with softfloat ABI

This adjusts https://github.com/rust-lang/rust/pull/134290 to not apply the new logic to targets marked as "softfloat". That fixes most instances of the issue brought up [here](https://github.com/rust-lang/rust/issues/116558#issuecomment-2661027437).

r? `@tgross35`
2025-02-19 18:52:07 +01:00
Matthias Krüger
ce72b8d91e
Rollup merge of #136794 - cberner:stabilize, r=joshtriplett
Stabilize file_lock

Closes #130994
2025-02-19 18:52:06 +01:00
Matthias Krüger
e6406ad4dd
Rollup merge of #136347 - allevo:patch-1, r=Amanieu
Add a bullet point to `std::fs::copy`

I needed to copy a file but I got the following error:
```
Os { code: 2, kind: NotFound, message: "No such file or directory" }
```
After read the documentation, I though the error was generated by the `from` parameter, forgetting the `to` part. Anyway, I got the error because the parent folder of `to` didn't exist.
Even if the documentation explicitly saying `but is not limited to just these cases`, I would like to add this case because I spent 3 hours around it.

This PR just wants to put a mention about it.
2025-02-19 18:52:05 +01:00
Matthias Krüger
2c1e1bd2cb
Rollup merge of #136301 - hkBst:patch-33, r=thomcc
Improve instant docs

This should be enough to close #79881.
2025-02-19 18:52:04 +01:00
Matthias Krüger
2c380a4661
Rollup merge of #134995 - DaniPopes:stable-const_slice_flatten, r=Amanieu
Stabilize const_slice_flatten

Const-stabilizes `slice::as_flattened{,_mut}`:
```rust
// core::slice
impl<T, const N: usize> [[T; N]] {
    pub const fn as_flattened(&self) -> &[T];
    pub const fn as_flattened_mut(&mut self) -> &mut [T];
}
```

Tracking issue: https://github.com/rust-lang/rust/issues/95629

Requires separate FCP, as per https://github.com/rust-lang/rust/issues/95629#issuecomment-2566546257.

Closes https://github.com/rust-lang/rust/issues/95629.

`````@rustbot````` modify labels: +T-libs-api

Happy new year!
2025-02-19 18:52:03 +01:00
Matthias Krüger
be36bd288f
Rollup merge of #127793 - ChaiTRex:zed_support, r=Kobzol
Added project-specific Zed IDE settings

This repository currently has project-specific VS Code IDE settings in `.vscode` and `compiler/rustc_codegen_cranelift/.vscode`. Now there are equivalent project-specific Zed IDE settings alongside those.

This fixes `rust-analyzer` not being able to properly handle this project.

Note that:

1. The contents of `src/tools/rust-analyzer/.vscode` could not be translated to Zed, as they aren't basic IDE settings.
2. One of the VS Code settings in `.vscode` has no corresponding setting in Zed, and so this has been noted like this:

    ```json
      "_settings_only_in_vs_code_not_yet_in_zed": {
        "git.detectSubmodulesLimit": 20
      },
    ```
2025-02-19 18:52:03 +01:00
dianne
452c14e7c2 re-add explicit with_ctxt and tweak comments 2025-02-19 09:48:06 -08:00
Esteban Küber
a090e76dab Tweak "expected ident" parse error to avoid talking about doc comments
When encountering a doc comment without an identifier after, we'd unconditionally state "this doc comment doesn't document anything", swallowing the *actual* error which is that the thing *after* the doc comment wasn't expected. Added a check that the found token is something that "conceptually" closes the previous item before emitting that error, otherwise just complain about the missing identifier.

In both of the following cases, the syntax error follows a doc comment:
```
error: expected identifier, found keyword `Self`
  --> $DIR/doc-before-bad-variant.rs:4:5
   |
LL | enum TestEnum {
   |      -------- while parsing this enum
...
LL |     Self,
   |     ^^^^ expected identifier, found keyword
   |
   = help: enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }`
```
```
error: expected identifier, found `<`
  --> $DIR/doc-before-syntax-error.rs:2:1
   |
LL | <>
   | ^ expected identifier
```

Fix #71982.
2025-02-19 17:26:13 +00:00
dianne
51a2ee3252 don't get trapped inside of expansions when trimming labels 2025-02-19 01:43:38 -08:00
dianne
ef6df3b713 add a failing test 2025-02-19 00:56:45 -08:00
Nicholas Nethercote
5bb37ce764 Improve formatting within make_mir_visitor macro body.
rustfmt doesn't touch it because it's a macro body, but it's large
enough that the misformatting is annoying. This commit improves it. The
most common problems fixed:

- Unnecessary multi-line patterns reduced to one line.
- Multi-line function headers adjusted so the parameter indentation
  doesn't depend on the length of the function name. (This is Rust code,
  not C.)
- `|` used at the start of lines, not the end.
- More consistent formatting of empty function bodies.
- Overly long lines are broken.
2025-02-19 19:42:19 +11:00
Nicholas Nethercote
311e8d3e5d Remove MirVisitable.
The `MirVisitable` trait is just a complicated way to visit either a
statement or a terminator. (And its impl for `Terminator` is unused.) It
has a single use.

This commit removes it, replacing it with an if/else, which is shorter
and simpler.
2025-02-19 19:42:17 +11:00
Nicholas Nethercote
cee430b2ce Add super_local method to the MIR visitors.
`visit_local` is the only method that doesn't call a corresponding
`super_local` method. This is valid, because `super_local` would be
empty. But it's inconsistent with every other case; we have multiple
other empty `super` methods: `super_span`, `super_ty`, etc.

This commit adds an empty `super_local` and makes `visit_local` call it.
2025-02-19 19:41:50 +11:00
Tommaso Allevi
3ad847779e
Update library/std/src/fs.rs
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
2025-02-19 09:17:18 +01:00