remove UnevaluatedConstKind::def_id
this is some of the const side of https://github.com/rust-lang/rust/issues/152245
not quite a _full_ removal, there's still some spicy things such as `UnevaluatedConstKind::def_span` remaining that won't quite work for new non-DefID `UnevaluatedConstKind` cases, but IMO this is the bulk of the work, and feature-specific things can deal with their quirks in their own PRs when they know their own use cases.
r? @BoxyUwU
self-reminder: file an issue on what to do about rustc_public's handling of the raw DefIds in rustc_public AliasTy/AliasConst
Suggest comma multiple
Following from rust-lang/rust#157545
If there are multiple missing comma's, suggest fixing all of them in one step to avoid error cascade.
For example:
```
error: attribute items not separated with `,`
|
LL | name = "name"
| ^ help: try adding `,` here
```
followed by
```
error: attribute items not separated with `,`
|
LL | kind = "static"
| ^ help: try adding `,` here
```
after adding the comma.
Now this becomes one error:
```
error: attribute items not separated with `,`
--> $DIR/attr-missing-comma.rs:10:18
|
LL | name = "name"
| ^
|
help: try adding `,` here
|
LL | name = "name",
| +
help: try adding `,` here
|
LL | kind = "static",
| +
```
Use `mul nuw nsw` in `intrinsics::copy`
Essentially the same as rust-lang/rust#157560, just for `copy` instead of `copy_nonoverlapping`.
> Yeah, in fact both copy and copy_nonoverlapping could use this since we know the result must be at most isize::MAX else it cannot be inbounds.
> ~ https://github.com/rust-lang/rust/pull/157560#issuecomment-4642072687
r? saethlin
Use alternate means of detecting enums in `is_udt`
This fixes a small regression from https://github.com/rust-lang/rust/pull/155336
Flat enums are excluded from `is_udt` since LLDB natively handles them correctly. The previous logic (`SBType.IsScopedEnumerationType()`) behaved correctly for non-msvc targets, but for some reason on msvc enums don't count as scoped enumerations?
The new logic checks the type returned by `SBType.GetEnumerationIntegerType()`. If the queried type isn't an enum, the returned type is invalid. This behaves correctly on both msvc and non-msvc targets, and its behavior doesn't conflict with sum-type enums.
As always, testing on msvc isn't really possible atm. That should change soon though =)
---
try-job: aarch64-apple
perf: use `get_unchecked` for `TwoWaySearcher`
## What is this PR?
*This is related to rust-lang/rust#27721.*
This PR is a proposal for a performance improvement in `std::pattern`.
Profiling of [https://github.com/quickwit-oss/quickwit](https://github.com/quickwit-oss/quickwit) in production shows that `TwoWaySearcher::next` is one of the most CPU-time-consuming functions, so I thought I would give it a look.
I read the [contribution guide](https://std-dev-guide.rust-lang.org/development/perf-benchmarking.html) and this seems to be a fitting proposal.
It seems like `TwoWaySearcher::next` and `TwoWaySearcher::next_back` could be made faster by using `get_unchecked` in the inner loop comparisons instead of regular indexing, which is safe in the conditions where it would be done (indices are within bounds by construction).
I added some `SAFETY` comments in the code to explain why this is safe, as I believe is customary in those cases (and according to [this page as well](https://std-dev-guide.rust-lang.org/policy/safety-comments.html)).
### Benchmarks
I ran the existing bencharmks before/after the changes (only on my laptop, I can run them in other places if that's necessary).
```
./x.py bench library/coretests -- pattern::
```
We seem to be getting a ~7.5-12% performance improvement at a very low cost, which sounds worthwhile to me.
But this is the first time I'm proposing a change in Rust, so I'm looking forward to feedback on this.
```
BEFORE CHANGES
pattern::ends_with_char 3398.91ns/iter +/- 526.28
pattern::ends_with_str 3545.04ns/iter +/- 1108.76
pattern::starts_with_char 3348.31ns/iter +/- 352.38
pattern::starts_with_str 3710.59ns/iter +/- 435.57
AFTER CHANGES
pattern::ends_with_char 3125.99ns/iter +/- 567.09 (-8.03%)
pattern::ends_with_str 3106.43ns/iter +/- 258.33 (-12.38%)
pattern::starts_with_char 3094.55ns/iter +/- 595.42 (-7.59%)
pattern::starts_with_str 3365.75ns/iter +/- 268.88 (-9.29%)
```
System info for the benchmarks run
<details>
```
Based on commit 8317fef204
rustc 1.96.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: aarch64-apple-darwin
release: 1.96.0-dev
LLVM version: 22.1.2
Apple M4 Max
16
64 GB
ProductName: macOS
ProductVersion: 26.3
BuildVersion: 25D125
(this was run on AC and without any heavy load from other apps or whatnot)
```
</details>
In `copy_nonoverlapping`, use `mul nuw nsw` to compute the byte size
Seems like we might as well? Adding these flags means the optimizer can tell the limited range on the count of items -- like how we use these flags (rust-lang/rust#136575) when calculating `size_of_val` for a slice.
Today we use a wrapping multiplication, which mean that `copy_nonoverlapping::<u32>(src, dst, 0x40000000_00000001)` appears like 4 bytes -- a perfectly reasonable size! -- once it gets to the `memcpy` call.
If I'm understanding <https://doc.rust-lang.org/std/ptr/fn.copy_nonoverlapping.html#safety> properly, this is just exploiting existing UB, since `src` and `dst` must each be inside an allocation, and those allocations can be at most `isize::MAX` bytes. (Plus, fundamentally, to be non-overlapping there's not enough space in the address space to be bigger than `isize::MAX`.)
cc @RalfJung to make sure this is ok, as requested last he found out I was newly exploiting some UB in codegen 🙃
r? codegen
Suggest using comma to separate valid attribute list items
If the parser encounters a missing comma in an attribute arg list and the next item is valid, suggest adding the comma.
For example:
```
error: attribute items not separated with `,`
--> $DIR/expected-comma-found-token.rs:7:26
|
LL | message="the message"
| ^ help: try adding `,` here
```
Improve documentation of `align_of` and `Alignment`.
* The documentation for `align_of_val()` and `Alignment::of_val()` did not explain its use in interacting with `dyn` types, and even contained the false statement that “Every reference to a value of the type `T` must be a multiple of this number”. This change removes that statement from everything except `align_of()`, and adds a mention of, and example code for, getting the alignment of a `dyn` value.
* The documentation for `align_of_val_raw()` did not explain how it relates to other functions in the family. Now it does.
* Added a caveat that the alignment of `i32` is not always 4, despite the examples asserting this.
@rustbot label A-docs
Silence llbc's output by default to prevent rustc's linker output warning
https://github.com/rust-lang/rust/pull/153968 recently made visible that the llvm-bitcode-linker (llbc) always emits messages to stdout even when linking successfully. Additionally, these messages use ANSI escape sequences for coloring, which don't get rendered correctly.
This patch fixes both.
- It silences llbc's output by default and adds a verbosity command line argument to it (`-v` for verbose and `-vv` for very verbose, which can be added by using rustc's `-Clink-arg=` argument).
- It also removes the ANSI escape sequences and makes the output more linker-like (by removing timestamps, tracing-level, tracing-target).
cc: @kjetilkjeka
@rustbot label +L-linker_messages +O-NVPTX
Clarify MaybeUninit::zeroed padding docs
Closesrust-lang/rust#111608.
This clarifies that padding bytes in `MaybeUninit::zeroed()` are not guaranteed to remain zeroed when the `MaybeUninit<T>` value is returned, matching the existing `mem::zeroed` documentation that padding is not necessarily zeroed.
Verification:
- `git diff --check`
- `./x fmt --check`
- `./x test tidy`
- `./x test library/core --doc`
triagebot: Update messages to direct changes to appropriate repositories
Follow-up https://github.com/rust-lang/rust/pull/154465
Regularize messages that reference repository-specific changes, directing contributors to the appropriate repositories.
Document equivalence of `highest_one` and `ilog2` methods on integers
Add notes to the primitive integer and `NonZero` types clarifying the equivalence between `highest_one` and the `ilog2`/`checked_ilog2` methods for non-negative values.
Tracking issue: rust-lang/rust#145203
riscv: promote d, e, and f target_features to CfgStableToggleUnstable
Reference PR:
- https://github.com/rust-lang/reference/pull/2274
This PR is a continuation of rust-lang/rust#155962
It uses the new `CfgStableToggleUnstable` stability level for the `"d"`, `"e"`, and `"f"` `target_features` of RISC-V. This way, it will be possible to add conditional code blocks depending on whether the target architecture has FPU, for instance.
The PR is related to rust-lang/rust#150257
r? @RalfJung
macros: report unbound metavariables directly
Fixesrust-lang/rust#95943.
When a macro expansion contains an unbound `$ident`, report it as a missing macro parameter instead of keeping the generic fragment parser error as the primary diagnostic.
This keeps the existing typo suggestions and available-metavariable notes.
LineWriter: cap write_vectored newline scan to avoid quadratic write_all_vectored
This also adds some test coverage to confirm LineWriter behaves as expected under some edge cases.
Syntactically reject equality predicates
### Background (History)
Equality predicates have been *syntactically* valid since PR rust-lang/rust#39158 / nightly-2017-02-02 / 1.16 (released 2017-03-16, 9 years ago), both forms that is: `$ty = $ty` *and* `$ty == $ty`. They're not registered as an unstable feature despite having a tracking issue (rust-lang/rust#20041). Naturally, they don't have a feature gate. Of course, we reject them post-expansion, so they are still semantically invalid.
Parser scaffolding for `$ident = $ty` was added in RUST-19391 (2014) which was then generalized to `$ty = $ty` in RUST-20002 (2014) and extended to additionally cover `$ty == $ty` in RUST-39158 (2017). As mentioned, the last PR also made them grammatical.
RUST-87471 (2021) attempted to start impl'ing typeck'ing but it was closed due to concerns: https://github.com/rust-lang/rust/pull/87471#issuecomment-889831233 (already back in 2017 there were concerns: https://github.com/rust-lang/rust/pull/39158/changes#r97811244).
In 2022, T-lang discussed this feature during a meeting and raised concerns: https://github.com/rust-lang/rust/issues/20041#issuecomment-1062456506. However, they were inclined to accept a restricted form, namely `T::AssocTy = $ty` (`T` is a (self) ty param or a self ty alias) and `<$ty as Trait>::AssocTy = $ty` since that's trivial to support in HIR ty lowering (this is still accurate).
### Change
This renders equality predicates `$ty = $ty` and `$ty == $ty` syntactically invalid again. On stable, they're merely semantically invalid. This is motivated by the fact that
1. their syntax isn't even decided upon
1. should it be `=` or `==`?
2. should the LHS be syntactically restricted to (possibly qualified) paths (i.e., *TypePath | QualifiedPathInType*), only semantically or not at all?
* "syntactically" could indeed make sense since we might want to generalize types to so-called *terms* here (i.e., *Type | GenericArgsConst*) for [mGCA](https://github.com/rust-lang/rust/issues/132980) but we can't generalize `$ty = $ty` to `$term = $term` due to ambiguities [^1] that would require backtracking whereas `$typepath = $term` wouldn't have that problem
2. we might (decide to) never impl this feature
* after all, implementation concerns were raised as early as 9 years ago which are still relevant today even with the next-gen trait solver on the horizon
3. the compiler + tools contain a bunch of code for dealing with these predicates
* like lowering, name resolution, rustfmt and Clippy
* that's entirely useless since they get unconditionally rejected anyway
* this code doesn't need to exist (for now)
I've merely upgraded the semantic hard error to a syntactic hard error, I've intentionally not introduced an unstable feature under which equality predicates become legal.
That's because a hard error is easier to push through procedurally, it's an important first step (we can always turn it into a feature gate error later on) and since this potential feature isn't backed by any official lang experiment.
I don't consider T-lang's message https://github.com/rust-lang/rust/issues/20041#issuecomment-1062456506 from 2022 to be sufficient because it doesn't answer questions like (1.i), (1.ii) or whether code like `T: Trait<A>, <T as Trait<B>>::AssocTy = Ty` (`A` ≠ `B`) or `T: Trait<'r>, for<'a> <T as Trait<'a>>::AssocTy = Ty` should be legal (which would be more powerful / could lead to typechecking issues, idk) or not assuming we're going with the restricted form ofc (we would need input from T-types).
### Lang nomination
https://github.com/rust-lang/rust/pull/153513#issuecomment-4069728773
[^1]: Code like `fn f() -> i32 where { 0 }` is intentionally legal today but if we had `$term = $term` the `{ 0 }` could then also be the start of an equality predicate like `{ 0 } = 0`.
Cleanup and optimize `render_impls`
- take ownership of the `Vec<&Impl>` instead of copying into another alloc
- reuse `ImplString` to do natural sort ordering
- lazy formatting
Somewhat of a follow-up to rust-lang/rust#157233 and rust-lang/rust#157179 (cc @nnethercote - thanks!)
This kinda undoes f7c8bc2b13 but IMHO it makes more sense to be explicit about negative impl ordering, and also seems kinda wasteful to "render" the negativity into a string and rely on however ASCII decided to order characters. I can also undo this part, I think this PR is still a positive change even without it.
r? @GuillaumeGomez
LLM disclosure:
I used LLM for reviewing my changes and making sure some assumptions I was making were correct (i.e. that `render_impls` will not render anything IFF the list of traits passed to it is empty)
Add infallible primitive type lookups to template arg resolver
Fixes a regression that seem to come from LLDB 22 where looking up primitive types by name on MSVC no longer works. Container types use type name lookups to resolve generics, so it causes container types (e.g. `Vec<i32>`) to fail to create their child values.
Before:
```
(lldb) v vec_v
(alloc::vec::Vec<i32,alloc::alloc::Global>) vec_v = size=5 {}
(lldb) v vec_v[0]
error: <user expression 0>:1:6: array index 0 is not valid for "(Vec<i32,alloc::alloc::Global>) vec_v"
1 | vec_v[0]
| ^
```
After:
```
(lldb) v vec_v
(alloc::vec::Vec<i32,alloc::alloc::Global>) vec_v = size=5 {
[0] = 10
[1] = 20
[2] = 30
[3] = 40
[4] = 50
}
(lldb) v vec_v[0]
(long) vec_v[0] = 10
```
This patch maps the type name to its `eBasicType` equivalent (i.e. the LLDB enum for primitive types) and looks up the type based on that. AFAIK, `eBasicType` lookups are 100% infallible. Even if the primitive type somehow isn't in the debug info, `TypeSystemClang` will invent the appropriate `SBType` object for it.
This isn't a major blocker for the test suite rework, but it does prevent me from blessing tests with container types on MSVC unless I downgrade to LLDB 21.
r? @jieyouxu, @Kobzol
Manually unroll loop in `str::floor_char_boundary`
This commit manually unrolls the while loops to at most three iterations, exploiting the UTF-8 invariant that a character is at most four bytes long.
Benefits:
- Prevents LLVM from generating unbounded unrolled code when `index` is statically known - e.g., `s.floor_char_boundary(20)` previously could emit up to 20 repeated loop bodies.
- Eliminates the check at `index - 3`: the UTF-8 invariant guarantees that if `index - 2` is not a character boundary, `index - 3` must be, so the third iteration needs no conditional.
- Allows out-of-order CPUs to issue all three byte loads in parallel, since their offsets are statically known.
This commit will closerust-lang/rust#149466 with simpler code. The optimizer appears to be able to eliminate bound checks and panic paths.
Further optimize `SliceIndex<str>` impl for `Range<usize>`
We can shave a further 2 `icmp`s by inlining `is_char_boundary` and rearranging the checks.
Follow up to https://github.com/rust-lang/rust/pull/145024
Resolver: Batched Import Resolution
*[View all comments](https://triagebot.infra.rust-lang.org/gh-comments/rust-lang/rust/pull/145108)*
Transforms the current algorithm for resolving imports to a batched algorithm. Every import in the `indeterminate_imports` set is resolved in isolation. This is the only real difference from the current algorithm.
r? petrochenkov