Improve diagnostic for wrong borrow on binary operations
This PR improves the diagnostic for wrong borrow on binary operations by suggesting to reborrow on appropriate expressions.
```diff
+ = note: an implementation for `&Foo * &Foo` exist
+ help: consider reborrowing both sides
+ |
+ LL | let _ = &*ref_mut_foo * &*ref_mut_foo;
+ | ++ ++
```
Fixes https://github.com/rust-lang/rust/issues/109352
coverage: Replace `ExpressionOperandId` with enum `Operand`
*This is one step in my larger coverage refactoring ambitions described at <https://github.com/rust-lang/compiler-team/issues/645>.*
LLVM coverage has a concept of “mapping expressions” that allow a span's execution count to be computed as a simple arithmetic expression over other counters/expressions, instead of requiring a dedicated physical counter for every control-flow branch.
These expressions have an operator (`+` or `-`) and two operands. Operands are currently represented as `ExpressionOperandId`, which wraps a `u32` with the following semantics:
- 0 represents a special counter that always has a value of zero
- Values ascending from 1 represent counter IDs
- Values descending from `u32::MAX` represent the IDs of other expressions
---
This change replaces that whole `ExpressionOperandId` scheme with a simple enum that explicitly distinguishes between the three cases.
This lets us remove a lot of fiddly code for dealing with the different operand kinds:
- Previously it was only possible to distinguish between counter-ID operands and expression-ID operands by comparing the operand ID with the total number of counters in a function. This is unnecessary now that the enum distinguishes them explicitly.
- There's no need for expression IDs to descend from `u32::MAX` and then get translated into zero-based indices in certain places. Now that they ascend from zero, they can be used as indices directly.
- There's no need to reserve ID number 0 for the special zero operand, since it can just have its own variant in the enum, so counter IDs can count up from 0.
(Making counter IDs ascend from 0 also lets us fix an off-by-one error in the query for counting the total number of counters, which would cause LLVM to emit an extra unused counter for every instrumented function.)
---
This PR may be easiest to review as individual patches, since that breaks it up into clearly distinct parts:
- Replace a `u32` wrapper with an explicit enum, without changing the semantics of the underlying IDs being stored.
- Change the numbering scheme used by `Operand::Expression` to make expression IDs ascend from 0 (instead of descending from `u32::MAX`).
- Change the numbering scheme used by `Operand::Counter` to make counter IDs ascend from 0 (instead of ascending from 1).
Change default panic handler message format.
This changes the default panic hook's message format from:
```
thread '{thread}' panicked at '{message}', {location}
```
to
```
thread '{thread}' panicked at {location}:
{message}
```
This puts the message on its own line without surrounding quotes, making it easiser to read. For example:
Before:
```
thread 'main' panicked at 'env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`', src/main.rs:4:6
```
After:
```
thread 'main' panicked at src/main.rs:4:6:
env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`
```
---
See this PR by `@nyurik,` which does that for only multi-line messages (specifically because of `assert_eq`): https://github.com/rust-lang/rust/pull/111071
This is the change that does that for *all* panic messages.
[rustc_data_structures] Simplify SortedMap::insert.
It looks like current usage of `swap` is aimed at achieving what `std::mem::replace` does but more concisely and idiomatically.
Improve the rust style guide doc
- Make the levels of headings consistent in this whole document.
Before this change, the highest level of headings in some file is level 1, but in most of the files the that is level 2. Not consistent.
- Fix some headings
- Follow the markdown linter advices
- Remove redundant empty lines
- Surround each heading with empty lines
- Use the same symbol for different levels of unordered list entries
Directly link more target docs
Some platforms were not linked from platform-support.md
This fixes that, but errs towards extremely conservative, only directly linking platform docs if the docs actively mention the target, as otherwise I do not necessarily know if there was a reason for the omission.
bootstrap: use git merge-base for LLVM CI download logic
Fixes https://github.com/rust-lang/rust/issues/101907
I tested this with a local branch that has extra merge commits due to Miri, and it worked fine there. But I am sure there are tons of other situations I did not think of...
r? `@jyn514`
style-guide: Document style editions, start 2024 style edition
Link to a snapshot for the 2015/2018/2021 style edition.
This is a draft, because I'd like to wait for a few style guide fixes to merge
before snapshotting the 2015/2018/2021 style edition:
- https://github.com/rust-lang/rust/pull/113145
- https://github.com/rust-lang/rust/pull/113380
- https://github.com/rust-lang/rust/pull/113384
- https://github.com/rust-lang/rust/pull/113385
- https://github.com/rust-lang/rust/pull/113386
- https://github.com/rust-lang/rust/pull/113392
I'd like to wait for these for two reasons: to make it easier to see the
differences between the 2015/2018/2021 style edition and the 2024 style
edition (without the noise of guide-wide changes), and to minimize confusion so
that bugfixes to the style guide that we include in the previous edition don't
look like they're only part of the 2024 style edition.
I've used "Miscellaneous `rustfmt` bugfixes" as a starting point for the list
of 2024 changes, for now. We can update that when we add more 2024 changes.
The section added in this PR can then serve as a baseline for our drafts of
2024 style edition changes.
In the meantime, I'd like to get someone from `@rust-lang/style` to review and
approve the text here; I'll update it with a commit hash when the above PRs
have merged.
Some platforms were not linked from platform-support.md
This fixes that, but errs towards extremely conservative,
only directly linking platform docs if the docs actively
mention the target, as otherwise I do not necessarily
know if there was a reason for the omission.
Operand types are now tracked explicitly, so there is no need to reserve ID 0
for the special always-zero counter.
As part of the renumbering, this change fixes an off-by-one error in the way
counters were counted by the `coverageinfo` query. As a result, functions
should now have exactly the number of counters they actually need, instead of
always having an extra counter that is never used.
Operand types are now tracked explicitly, so there is no need for expression
IDs to avoid counter IDs by descending from `u32::MAX`. Instead they can just
count up from 0, and can be used directly as indices when necessary.
Because the three kinds of operand are now distinguished explicitly, we no
longer need fiddly code to disambiguate counter IDs and expression IDs based on
the total number of counters/expressions in a function.
This does increase the size of operands from 4 bytes to 8 bytes, but that
shouldn't be a big deal since they are mostly stored inside boxed structures,
and the current coverage code is not particularly size-optimized anyway.
The actual motivation here is to prevent `rustfmt` from suddenly reformatting
these enum variants onto a single line, when they become slightly shorter in
the future.
But there's no harm in adding some helpful documentation at the same time.
Update Clippy
r? `@Manishearth`
This is a bit delayed, because I thought it is a difficult conflict resolution and didn't have time for that over the weekend. Turns out, I just used the wrong merge base and it was actually easy... Don't do syncs in the middle of the night (even though I broke this rule with this PR again).
Detect trait upcasting through struct tail unsizing in new solver select
Oops, we were able to hide trait upcasting behind a parent unsize goal that evaluated to `Certainty::Yes`. Let's do rematching for `Certainty::Yes` unsize goals with `BuiltinImplSource::Misc` sources (corresponding to all of the other unsize rules) to make sure we end up selecting any nested goals which may be satisfied via `BuiltinImplSource::TraitUpcasting` or `::TupleUnsizing`.
r? ``@lcnr``
Update lexer emoji diagnostics to Unicode 15.0
This replaces the `unic-emoji-char` dep tree (which hasn't been updated for a while) with `unicode-properties` crate which contains Unicode 15.0 data.
Improves diagnostics for added emoji characters in recent years. (See tests).
cc #101840
cc ``@Manishearth``
Re-export core::ffi::FromBytesUntilNulError in std::ffi
Like the other CStr and CString error types, make a re-export for std::ffi::FromBytesUntilNulError.
This seems to have slipped through the cracks in the cstr_from_bytes_until_nul implementation and core_c_str migration.
Tracking Issue: #95027
Make `Debug` representations of `[Lazy, Once]*[Cell, Lock]` consistent with `Mutex` and `RwLock`
`Mutex` prints `<locked>` as a field value when its inner value cannot be accessed, but the lazy types print a fixed string like "`OnceCell(Uninit)`". This could cause confusion if the inner type is a unit type named `Uninit` and does not respect the pretty-printing flag. With this change, the format message is now "`OnceCell(<uninit>)`", consistent with `Mutex`.
Improve test case for experimental API remove_matches
## Add Test Cases for `remove_matches` Function
### Motivation
After reading the discussion in [this GitHub thread](https://github.com/rust-lang/rust/pull/71780), I'm trying to redesign the current API to use less memory when working with `String` and to make it simpler. I've discovered that some test cases are very helpful in ensuring that the new API behaves as intended. I'm still in the process of redesigning the current API, and these test cases have proven to be very useful.
### Testing
The current test has been tested with the command `./x test --stage 0 library/alloc`.
### Overview
This pull request adds several new test cases for the `remove_matches` function to make sure it works correctly in different situations. The `remove_matches` function is used to get rid of all instances of a specific pattern from a given text. These test cases thoroughly check how the function behaves in various scenarios.
### Test Cases
1. **Single Pattern Occurrence** (`test_single_pattern_occurrence`):
- Description: Tests the removal of a single pattern occurrence from the text.
- Input: Text: "abc", Pattern: 'b'
- Expected Output: "ac"
2. **Repeat Test Single Pattern Occurrence** (`repeat_test_single_pattern_occurrence`):
- Description: Repeats the previous test case to ensure consecutive removal of the same pattern.
- Input: Text: "ac", Pattern: 'b'
- Expected Output: "ac"
3. **Single Character Pattern** (`test_single_character_pattern`):
- Description: Tests the removal of a single character pattern.
- Input: Text: "abcb", Pattern: 'b'
- Expected Output: "ac"
4. **Pattern with Special Characters** (`test_pattern_with_special_characters`):
- Description: Tests the removal of a pattern containing special characters.
- Input: Text: "ศไทย中华Việt Nam; foobarศ", Pattern: 'ศ'
- Expected Output: "ไทย中华Việt Nam; foobar"
5. **Pattern Empty Text and Pattern** (`test_pattern_empty_text_and_pattern`):
- Description: Tests the removal of an empty pattern from an empty text.
- Input: Text: "", Pattern: ""
- Expected Output: ""
6. **Pattern Empty Text** (`test_pattern_empty_text`):
- Description: Tests the removal of a pattern from an empty text.
- Input: Text: "", Pattern: "something"
- Expected Output: ""
7. **Empty Pattern** (`test_empty_pattern`):
- Description: Tests the behavior of removing an empty pattern from the text.
- Input: Text: "Testing with empty pattern.", Pattern: ""
- Expected Output: "Testing with empty pattern."
8. **Multiple Consecutive Patterns 1** (`test_multiple_consecutive_patterns_1`):
- Description: Tests the removal of multiple consecutive occurrences of a pattern.
- Input: Text: "aaaaa", Pattern: 'a'
- Expected Output: ""
9. **Multiple Consecutive Patterns 2** (`test_multiple_consecutive_patterns_2`):
- Description: Tests the removal of a longer pattern that occurs consecutively.
- Input: Text: "Hello **world****today!**", Pattern: "**"
- Expected Output: "Hello worldtoday!"
10. **Case Insensitive Pattern** (`test_case_insensitive_pattern`):
- Description: Tests the removal of a case-insensitive pattern from the text.
- Input: Text: "CASE ** SeNsItIvE ** PaTtErN.", Pattern: "sEnSiTiVe"
- Expected Output: "CASE ** SeNsItIvE ** PaTtErN."
Fix ice tests when librustc-driver is linked dynamically
Running `dump-ice-to-disk`and `short-ice` tests on Linux targeting `x86_64-fortanix-unknown-sgx` platform results in:
```
jenkins@31cf43196355:~/workspace/rust-sgx-ci/Raoul/rust$ cat /home/jenkins/workspace/rust-sgx-ci/Raoul/rust/build/x86_64-unknown-linux-gnu/test/run-make/dump-ice-to-disk/dump-ice-to-disk/*
/home/jenkins/workspace/rust-sgx-ci/Raoul/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc: error while loading shared libraries: librustc_driver-fa98927b935b2881.so: cannot open shared object file: No such file or directory
/home/jenkins/workspace/rust-sgx-ci/Raoul/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc: error while loading shared libraries: librustc_driver-fa98927b935b2881.so: cannot open shared object file: No such file or directory
/home/jenkins/workspace/rust-sgx-ci/Raoul/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc: error while loading shared libraries: librustc_driver-fa98927b935b2881.so: cannot open shared object file: No such file or directory
/home/jenkins/workspace/rust-sgx-ci/Raoul/rust/build/x86_64-unknown-linux-gnu/stage1/bin/rustc: error while loading shared libraries: librustc_driver-fa98927b935b2881.so: cannot open shared object file: No such file or directory
```
Setting the LD_LIBRARY_PATH explicitly to `$(HOST_RPATH_DIR)` in these tests Makefiles resolves the issue. The `thumb-none-qemu` and `thumb-none-cortex-m` run-make tests do something similar.
cc: ```@jethrogb``` ```@vn971``` ```@mkaynov```
Update `.gitmodules` to use shallow submodule clones
This change makes submodule checkouts shallow by default. This significantly reduces the time needed to do a recursive checkout when `--shallow-submodules` is not specified, such as when `x` is not being used.