Skip to content

Commit

Permalink
Auto merge of rust-lang#114318 - matthiaskrgr:rollup-c7gcw18, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

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
  • Loading branch information
bors committed Aug 1, 2023
2 parents 866710c + a902550 commit c435af0
Show file tree
Hide file tree
Showing 20 changed files with 259 additions and 186 deletions.
5 changes: 2 additions & 3 deletions compiler/rustc_data_structures/src/sorted_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,11 @@ impl<K: Ord, V> SortedMap<K, V> {
}

#[inline]
pub fn insert(&mut self, key: K, mut value: V) -> Option<V> {
pub fn insert(&mut self, key: K, value: V) -> Option<V> {
match self.lookup_index_for(&key) {
Ok(index) => {
let slot = unsafe { self.data.get_unchecked_mut(index) };
mem::swap(&mut slot.1, &mut value);
Some(value)
Some(mem::replace(&mut slot.1, value))
}
Err(index) => {
self.data.insert(index, (key, value));
Expand Down
6 changes: 3 additions & 3 deletions library/core/src/slice/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ where
}

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

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

/// Convert pair of `ops::Bound`s into `ops::Range`.
/// Panics on overflowing indices.
fn into_slice_range(
pub(crate) fn into_slice_range(
len: usize,
(start, end): (ops::Bound<usize>, ops::Bound<usize>),
) -> ops::Range<usize> {
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub mod sort;

mod ascii;
mod cmp;
mod index;
pub(crate) mod index;
mod iter;
mod raw;
mod rotate;
Expand Down
52 changes: 52 additions & 0 deletions library/core/src/str/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,58 @@ unsafe impl SliceIndex<str> for ops::Range<usize> {
}
}

/// Implements substring slicing for arbitrary bounds.
///
/// Returns a slice of the given string bounded by the byte indices
/// provided by each bound.
///
/// This operation is *O*(1).
///
/// # Panics
///
/// Panics if `begin` or `end` (if it exists and once adjusted for
/// inclusion/exclusion) does not point to the starting byte offset of
/// a character (as defined by `is_char_boundary`), if `begin > end`, or if
/// `end > len`.
#[stable(feature = "slice_index_str_with_ops_bound_pair", since = "CURRENT_RUSTC_VERSION")]
unsafe impl SliceIndex<str> for (ops::Bound<usize>, ops::Bound<usize>) {
type Output = str;

#[inline]
fn get(self, slice: &str) -> Option<&str> {
crate::slice::index::into_range(slice.len(), self)?.get(slice)
}

#[inline]
fn get_mut(self, slice: &mut str) -> Option<&mut str> {
crate::slice::index::into_range(slice.len(), self)?.get_mut(slice)
}

#[inline]
unsafe fn get_unchecked(self, slice: *const str) -> *const str {
let len = (slice as *const [u8]).len();
// SAFETY: the caller has to uphold the safety contract for `get_unchecked`.
unsafe { crate::slice::index::into_range_unchecked(len, self).get_unchecked(slice) }
}

#[inline]
unsafe fn get_unchecked_mut(self, slice: *mut str) -> *mut str {
let len = (slice as *mut [u8]).len();
// SAFETY: the caller has to uphold the safety contract for `get_unchecked_mut`.
unsafe { crate::slice::index::into_range_unchecked(len, self).get_unchecked_mut(slice) }
}

#[inline]
fn index(self, slice: &str) -> &str {
crate::slice::index::into_slice_range(slice.len(), self).index(slice)
}

#[inline]
fn index_mut(self, slice: &mut str) -> &mut str {
crate::slice::index::into_slice_range(slice.len(), self).index_mut(slice)
}
}

/// Implements substring slicing with syntax `&self[.. end]` or `&mut
/// self[.. end]`.
///
Expand Down
9 changes: 8 additions & 1 deletion src/bootstrap/llvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::util::{self, exe, output, t, up_to_date};
use crate::{CLang, GitRepo, Kind};

use build_helper::ci::CiEnv;
use build_helper::git::get_git_merge_base;

#[derive(Clone)]
pub struct LlvmResult {
Expand Down Expand Up @@ -128,13 +129,19 @@ pub fn prebuilt_llvm_config(
/// This retrieves the LLVM sha we *want* to use, according to git history.
pub(crate) fn detect_llvm_sha(config: &Config, is_git: bool) -> String {
let llvm_sha = if is_git {
// We proceed in 2 steps. First we get the closest commit that is actually upstream. Then we
// walk back further to the last bors merge commit that actually changed LLVM. The first
// step will fail on CI because only the `auto` branch exists; we just fall back to `HEAD`
// in that case.
let closest_upstream =
get_git_merge_base(Some(&config.src)).unwrap_or_else(|_| "HEAD".into());
let mut rev_list = config.git();
rev_list.args(&[
PathBuf::from("rev-list"),
format!("--author={}", config.stage0_metadata.config.git_merge_commit_email).into(),
"-n1".into(),
"--first-parent".into(),
"HEAD".into(),
closest_upstream.into(),
"--".into(),
config.src.join("src/llvm-project"),
config.src.join("src/bootstrap/download-ci-llvm-stamp"),
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rust-by-example
10 changes: 5 additions & 5 deletions src/doc/rustc/src/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ target | notes
`x86_64-unknown-freebsd` | 64-bit FreeBSD
`x86_64-unknown-illumos` | illumos
`x86_64-unknown-linux-musl` | 64-bit Linux with MUSL
`x86_64-unknown-netbsd` | NetBSD/amd64
[`x86_64-unknown-netbsd`](platform-support/netbsd.md) | NetBSD/amd64

## Tier 2

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

[runs on NVIDIA GPUs]: https://github.com/japaric-archived/nvptx#targets
10 changes: 6 additions & 4 deletions src/doc/style-guide/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ options.

### Indentation and line width

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

#### Block indent

Expand Down Expand Up @@ -100,10 +100,12 @@ fn baz() {}
```

### [Module-level items](items.md)

### [Statements](statements.md)

### [Expressions](expressions.md)
### [Types](types.md)

### [Types](types.md)

### Comments

Expand Down
1 change: 1 addition & 0 deletions src/doc/style-guide/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
- [Other style advice](advice.md)
- [`Cargo.toml` conventions](cargo.md)
- [Guiding principles and rationale](principles.md)
- [Rust style editions](editions.md)
- [Nightly-only syntax](nightly.md)
20 changes: 10 additions & 10 deletions src/doc/style-guide/src/advice.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ if y {

## Names

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

### Modules

Expand Down
46 changes: 46 additions & 0 deletions src/doc/style-guide/src/editions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Rust style editions

The default Rust style evolves over time, as Rust does. However, to avoid
breaking established code style, and CI jobs checking code style, changes to
the default Rust style only appear in *style editions*.

Code written in a given
[Rust edition](https://doc.rust-lang.org/edition-guide/)
uses the corresponding Rust style edition by default. To make it easier to
migrate code style separately from the semantic changes between Rust editions,
formatting tools such as `rustfmt` allow updating the style edition separately
from the Rust edition.

The current version of the style guide describes the latest Rust style edition.
Each distinct past style will have a corresponding archived version of the
style guide.

Note that archived versions of the style guide do not document formatting for
newer Rust constructs that did not exist at the time that version of the style
guide was archived. However, each style edition will still format all
constructs valid in that Rust edition, with the style of newer constructs
coming from the first subsequent style edition providing formatting rules for
that construct (without any of the systematic/global changes from that style
edition).

Not all Rust editions have corresponding changes to the Rust style. For
instance, Rust 2015, Rust 2018, and Rust 2021 all use the same style edition.

## Rust 2024 style edition

This style guide describes the Rust 2024 style edition. The Rust 2024 style
edition is currently nightly-only and may change before the release of Rust
2024.

For a full history of changes in the Rust 2024 style edition, see the git
history of the style guide. Notable changes in the Rust 2024 style edition
include:

- Miscellaneous `rustfmt` bugfixes.

## Rust 2015/2018/2021 style edition

The archived version of the style guide at
<https://github.com/rust-lang/rust/tree/37343f4a4d4ed7ad0891cb79e8eb25acf43fb821/src/doc/style-guide/src>
describes the style edition corresponding to Rust 2015, Rust 2018, and Rust
2021.
Loading

0 comments on commit c435af0

Please sign in to comment.