Skip to content

Commit c435af0

Browse files
committed
Auto merge of rust-lang#114318 - matthiaskrgr:rollup-c7gcw18, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#111081 (impl SliceIndex<str> for (Bound<usize>, Bound<usize>)) - rust-lang#113394 (style-guide: Document style editions, start 2024 style edition) - rust-lang#113588 (bootstrap: use git merge-base for LLVM CI download logic) - rust-lang#113743 (Directly link more target docs) - rust-lang#114262 (Improve the rust style guide doc) - rust-lang#114309 (Update books) - rust-lang#114313 ([rustc_data_structures] Simplify SortedMap::insert.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 866710c + a902550 commit c435af0

File tree

20 files changed

+259
-186
lines changed

20 files changed

+259
-186
lines changed

compiler/rustc_data_structures/src/sorted_map.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,11 @@ impl<K: Ord, V> SortedMap<K, V> {
4949
}
5050

5151
#[inline]
52-
pub fn insert(&mut self, key: K, mut value: V) -> Option<V> {
52+
pub fn insert(&mut self, key: K, value: V) -> Option<V> {
5353
match self.lookup_index_for(&key) {
5454
Ok(index) => {
5555
let slot = unsafe { self.data.get_unchecked_mut(index) };
56-
mem::swap(&mut slot.1, &mut value);
57-
Some(value)
56+
Some(mem::replace(&mut slot.1, value))
5857
}
5958
Err(index) => {
6059
self.data.insert(index, (key, value));

library/core/src/slice/index.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ where
727727
}
728728

729729
/// Convert pair of `ops::Bound`s into `ops::Range` without performing any bounds checking and (in debug) overflow checking
730-
fn into_range_unchecked(
730+
pub(crate) fn into_range_unchecked(
731731
len: usize,
732732
(start, end): (ops::Bound<usize>, ops::Bound<usize>),
733733
) -> ops::Range<usize> {
@@ -747,7 +747,7 @@ fn into_range_unchecked(
747747

748748
/// Convert pair of `ops::Bound`s into `ops::Range`.
749749
/// Returns `None` on overflowing indices.
750-
fn into_range(
750+
pub(crate) fn into_range(
751751
len: usize,
752752
(start, end): (ops::Bound<usize>, ops::Bound<usize>),
753753
) -> Option<ops::Range<usize>> {
@@ -772,7 +772,7 @@ fn into_range(
772772

773773
/// Convert pair of `ops::Bound`s into `ops::Range`.
774774
/// Panics on overflowing indices.
775-
fn into_slice_range(
775+
pub(crate) fn into_slice_range(
776776
len: usize,
777777
(start, end): (ops::Bound<usize>, ops::Bound<usize>),
778778
) -> ops::Range<usize> {

library/core/src/slice/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub mod sort;
3838

3939
mod ascii;
4040
mod cmp;
41-
mod index;
41+
pub(crate) mod index;
4242
mod iter;
4343
mod raw;
4444
mod rotate;

library/core/src/str/traits.rs

+52
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,58 @@ unsafe impl SliceIndex<str> for ops::Range<usize> {
252252
}
253253
}
254254

255+
/// Implements substring slicing for arbitrary bounds.
256+
///
257+
/// Returns a slice of the given string bounded by the byte indices
258+
/// provided by each bound.
259+
///
260+
/// This operation is *O*(1).
261+
///
262+
/// # Panics
263+
///
264+
/// Panics if `begin` or `end` (if it exists and once adjusted for
265+
/// inclusion/exclusion) does not point to the starting byte offset of
266+
/// a character (as defined by `is_char_boundary`), if `begin > end`, or if
267+
/// `end > len`.
268+
#[stable(feature = "slice_index_str_with_ops_bound_pair", since = "CURRENT_RUSTC_VERSION")]
269+
unsafe impl SliceIndex<str> for (ops::Bound<usize>, ops::Bound<usize>) {
270+
type Output = str;
271+
272+
#[inline]
273+
fn get(self, slice: &str) -> Option<&str> {
274+
crate::slice::index::into_range(slice.len(), self)?.get(slice)
275+
}
276+
277+
#[inline]
278+
fn get_mut(self, slice: &mut str) -> Option<&mut str> {
279+
crate::slice::index::into_range(slice.len(), self)?.get_mut(slice)
280+
}
281+
282+
#[inline]
283+
unsafe fn get_unchecked(self, slice: *const str) -> *const str {
284+
let len = (slice as *const [u8]).len();
285+
// SAFETY: the caller has to uphold the safety contract for `get_unchecked`.
286+
unsafe { crate::slice::index::into_range_unchecked(len, self).get_unchecked(slice) }
287+
}
288+
289+
#[inline]
290+
unsafe fn get_unchecked_mut(self, slice: *mut str) -> *mut str {
291+
let len = (slice as *mut [u8]).len();
292+
// SAFETY: the caller has to uphold the safety contract for `get_unchecked_mut`.
293+
unsafe { crate::slice::index::into_range_unchecked(len, self).get_unchecked_mut(slice) }
294+
}
295+
296+
#[inline]
297+
fn index(self, slice: &str) -> &str {
298+
crate::slice::index::into_slice_range(slice.len(), self).index(slice)
299+
}
300+
301+
#[inline]
302+
fn index_mut(self, slice: &mut str) -> &mut str {
303+
crate::slice::index::into_slice_range(slice.len(), self).index_mut(slice)
304+
}
305+
}
306+
255307
/// Implements substring slicing with syntax `&self[.. end]` or `&mut
256308
/// self[.. end]`.
257309
///

src/bootstrap/llvm.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use crate::util::{self, exe, output, t, up_to_date};
2424
use crate::{CLang, GitRepo, Kind};
2525

2626
use build_helper::ci::CiEnv;
27+
use build_helper::git::get_git_merge_base;
2728

2829
#[derive(Clone)]
2930
pub struct LlvmResult {
@@ -128,13 +129,19 @@ pub fn prebuilt_llvm_config(
128129
/// This retrieves the LLVM sha we *want* to use, according to git history.
129130
pub(crate) fn detect_llvm_sha(config: &Config, is_git: bool) -> String {
130131
let llvm_sha = if is_git {
132+
// We proceed in 2 steps. First we get the closest commit that is actually upstream. Then we
133+
// walk back further to the last bors merge commit that actually changed LLVM. The first
134+
// step will fail on CI because only the `auto` branch exists; we just fall back to `HEAD`
135+
// in that case.
136+
let closest_upstream =
137+
get_git_merge_base(Some(&config.src)).unwrap_or_else(|_| "HEAD".into());
131138
let mut rev_list = config.git();
132139
rev_list.args(&[
133140
PathBuf::from("rev-list"),
134141
format!("--author={}", config.stage0_metadata.config.git_merge_commit_email).into(),
135142
"-n1".into(),
136143
"--first-parent".into(),
137-
"HEAD".into(),
144+
closest_upstream.into(),
138145
"--".into(),
139146
config.src.join("src/llvm-project"),
140147
config.src.join("src/bootstrap/download-ci-llvm-stamp"),

src/doc/rustc/src/platform-support.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ target | notes
101101
`x86_64-unknown-freebsd` | 64-bit FreeBSD
102102
`x86_64-unknown-illumos` | illumos
103103
`x86_64-unknown-linux-musl` | 64-bit Linux with MUSL
104-
`x86_64-unknown-netbsd` | NetBSD/amd64
104+
[`x86_64-unknown-netbsd`](platform-support/netbsd.md) | NetBSD/amd64
105105

106106
## Tier 2
107107

@@ -128,7 +128,7 @@ target | std | notes
128128
`aarch64-apple-ios` | ✓ | ARM64 iOS
129129
[`aarch64-apple-ios-sim`](platform-support/aarch64-apple-ios-sim.md) | ✓ | Apple iOS Simulator on ARM64
130130
`aarch64-fuchsia` | ✓ | Alias for `aarch64-unknown-fuchsia`
131-
`aarch64-unknown-fuchsia` | ✓ | ARM64 Fuchsia
131+
[`aarch64-unknown-fuchsia`](platform-support/fuchsia.md) | ✓ | ARM64 Fuchsia
132132
[`aarch64-linux-android`](platform-support/android.md) | ✓ | ARM64 Android
133133
`aarch64-unknown-none-softfloat` | * | Bare ARM64, softfloat
134134
`aarch64-unknown-none` | * | Bare ARM64, hardfloat
@@ -159,7 +159,7 @@ target | std | notes
159159
`mips64-unknown-linux-muslabi64` | ✓ | MIPS64 Linux, n64 ABI, MUSL
160160
`mips64el-unknown-linux-muslabi64` | ✓ | MIPS64 (LE) Linux, n64 ABI, MUSL
161161
`mipsel-unknown-linux-musl` | ✓ | MIPS (LE) Linux with MUSL
162-
`nvptx64-nvidia-cuda` | * | --emit=asm generates PTX code that [runs on NVIDIA GPUs]
162+
[`nvptx64-nvidia-cuda`](platform-support/nvptx64-nvidia-cuda.md) | * | --emit=asm generates PTX code that [runs on NVIDIA GPUs]
163163
`riscv32i-unknown-none-elf` | * | Bare RISC-V (RV32I ISA)
164164
`riscv32imac-unknown-none-elf` | * | Bare RISC-V (RV32IMAC ISA)
165165
`riscv32imc-unknown-none-elf` | * | Bare RISC-V (RV32IMC ISA)
@@ -183,7 +183,7 @@ target | std | notes
183183
`x86_64-apple-ios` | ✓ | 64-bit x86 iOS
184184
[`x86_64-fortanix-unknown-sgx`](platform-support/x86_64-fortanix-unknown-sgx.md) | ✓ | [Fortanix ABI] for 64-bit Intel SGX
185185
`x86_64-fuchsia` | ✓ | Alias for `x86_64-unknown-fuchsia`
186-
`x86_64-unknown-fuchsia` | ✓ | 64-bit Fuchsia
186+
[`x86_64-unknown-fuchsia`](platform-support/fuchsia.md) | ✓ | 64-bit x86 Fuchsia
187187
[`x86_64-linux-android`](platform-support/android.md) | ✓ | 64-bit x86 Android
188188
`x86_64-pc-solaris` | ✓ | 64-bit Solaris 10/11, illumos
189189
`x86_64-unknown-linux-gnux32` | ✓ | 64-bit Linux (x32 ABI) (kernel 4.15, glibc 2.27)
@@ -337,6 +337,6 @@ target | std | host | notes
337337
`x86_64-uwp-windows-gnu` | ✓ | |
338338
`x86_64-uwp-windows-msvc` | ✓ | |
339339
`x86_64-wrs-vxworks` | ? | |
340-
`x86_64h-apple-darwin` | ✓ | ✓ | macOS with late-gen Intel (at least Haswell)
340+
[`x86_64h-apple-darwin`](platform-support/x86_64h-apple-darwin.md) | ✓ | ✓ | macOS with late-gen Intel (at least Haswell)
341341

342342
[runs on NVIDIA GPUs]: https://github.com/japaric-archived/nvptx#targets

src/doc/style-guide/src/README.md

+6-4
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ options.
3636

3737
### Indentation and line width
3838

39-
* Use spaces, not tabs.
40-
* Each level of indentation must be 4 spaces (that is, all indentation
39+
- Use spaces, not tabs.
40+
- Each level of indentation must be 4 spaces (that is, all indentation
4141
outside of string literals and comments must be a multiple of 4).
42-
* The maximum width for a line is 100 characters.
42+
- The maximum width for a line is 100 characters.
4343

4444
#### Block indent
4545

@@ -100,10 +100,12 @@ fn baz() {}
100100
```
101101

102102
### [Module-level items](items.md)
103+
103104
### [Statements](statements.md)
105+
104106
### [Expressions](expressions.md)
105-
### [Types](types.md)
106107

108+
### [Types](types.md)
107109

108110
### Comments
109111

src/doc/style-guide/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
- [Other style advice](advice.md)
1010
- [`Cargo.toml` conventions](cargo.md)
1111
- [Guiding principles and rationale](principles.md)
12+
- [Rust style editions](editions.md)
1213
- [Nightly-only syntax](nightly.md)

src/doc/style-guide/src/advice.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,16 @@ if y {
1818

1919
## Names
2020

21-
* Types shall be `UpperCamelCase`,
22-
* Enum variants shall be `UpperCamelCase`,
23-
* Struct fields shall be `snake_case`,
24-
* Function and method names shall be `snake_case`,
25-
* Local variables shall be `snake_case`,
26-
* Macro names shall be `snake_case`,
27-
* Constants (`const`s and immutable `static`s) shall be `SCREAMING_SNAKE_CASE`.
28-
* When a name is forbidden because it is a reserved word (such as `crate`),
29-
either use a raw identifier (`r#crate`) or use a trailing underscore
30-
(`crate_`). Don't misspell the word (`krate`).
21+
- Types shall be `UpperCamelCase`,
22+
- Enum variants shall be `UpperCamelCase`,
23+
- Struct fields shall be `snake_case`,
24+
- Function and method names shall be `snake_case`,
25+
- Local variables shall be `snake_case`,
26+
- Macro names shall be `snake_case`,
27+
- Constants (`const`s and immutable `static`s) shall be `SCREAMING_SNAKE_CASE`.
28+
- When a name is forbidden because it is a reserved word (such as `crate`),
29+
either use a raw identifier (`r#crate`) or use a trailing underscore
30+
(`crate_`). Don't misspell the word (`krate`).
3131

3232
### Modules
3333

src/doc/style-guide/src/editions.md

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Rust style editions
2+
3+
The default Rust style evolves over time, as Rust does. However, to avoid
4+
breaking established code style, and CI jobs checking code style, changes to
5+
the default Rust style only appear in *style editions*.
6+
7+
Code written in a given
8+
[Rust edition](https://doc.rust-lang.org/edition-guide/)
9+
uses the corresponding Rust style edition by default. To make it easier to
10+
migrate code style separately from the semantic changes between Rust editions,
11+
formatting tools such as `rustfmt` allow updating the style edition separately
12+
from the Rust edition.
13+
14+
The current version of the style guide describes the latest Rust style edition.
15+
Each distinct past style will have a corresponding archived version of the
16+
style guide.
17+
18+
Note that archived versions of the style guide do not document formatting for
19+
newer Rust constructs that did not exist at the time that version of the style
20+
guide was archived. However, each style edition will still format all
21+
constructs valid in that Rust edition, with the style of newer constructs
22+
coming from the first subsequent style edition providing formatting rules for
23+
that construct (without any of the systematic/global changes from that style
24+
edition).
25+
26+
Not all Rust editions have corresponding changes to the Rust style. For
27+
instance, Rust 2015, Rust 2018, and Rust 2021 all use the same style edition.
28+
29+
## Rust 2024 style edition
30+
31+
This style guide describes the Rust 2024 style edition. The Rust 2024 style
32+
edition is currently nightly-only and may change before the release of Rust
33+
2024.
34+
35+
For a full history of changes in the Rust 2024 style edition, see the git
36+
history of the style guide. Notable changes in the Rust 2024 style edition
37+
include:
38+
39+
- Miscellaneous `rustfmt` bugfixes.
40+
41+
## Rust 2015/2018/2021 style edition
42+
43+
The archived version of the style guide at
44+
<https://github.com/rust-lang/rust/tree/37343f4a4d4ed7ad0891cb79e8eb25acf43fb821/src/doc/style-guide/src>
45+
describes the style edition corresponding to Rust 2015, Rust 2018, and Rust
46+
2021.

0 commit comments

Comments
 (0)