Skip to content

Commit 51abac5

Browse files
authored
Merge branch 'rust-lang:master' into update-rustc-dev-guide-book
2 parents acedffe + a2d7c81 commit 51abac5

File tree

685 files changed

+12604
-5194
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

685 files changed

+12604
-5194
lines changed

.github/workflows/ci.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# and also on pushes to special branches (auto, try).
33
#
44
# The actual definition of the executed jobs is calculated by a Python
5-
# script located at src/ci/github-actions/calculate-job-matrix.py, which
5+
# script located at src/ci/github-actions/ci.py, which
66
# uses job definition data from src/ci/github-actions/jobs.yml.
77
# You should primarily modify the `jobs.yml` file if you want to modify
88
# what jobs are executed in CI.
@@ -56,18 +56,18 @@ jobs:
5656
- name: Calculate the CI job matrix
5757
env:
5858
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
59-
run: python3 src/ci/github-actions/calculate-job-matrix.py >> $GITHUB_OUTPUT
59+
run: python3 src/ci/github-actions/ci.py calculate-job-matrix >> $GITHUB_OUTPUT
6060
id: jobs
6161
job:
62-
name: ${{ matrix.name }}
62+
name: ${{ matrix.full_name }}
6363
needs: [ calculate_matrix ]
6464
runs-on: "${{ matrix.os }}"
6565
defaults:
6666
run:
6767
shell: ${{ contains(matrix.os, 'windows') && 'msys2 {0}' || 'bash' }}
6868
timeout-minutes: 360
6969
env:
70-
CI_JOB_NAME: ${{ matrix.image }}
70+
CI_JOB_NAME: ${{ matrix.name }}
7171
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
7272
# commit of PR sha or commit sha. `GITHUB_SHA` is not accurate for PRs.
7373
HEAD_SHA: ${{ github.event.pull_request.head.sha || github.sha }}
@@ -233,7 +233,7 @@ jobs:
233233
env:
234234
DATADOG_SITE: datadoghq.com
235235
DATADOG_API_KEY: ${{ secrets.DATADOG_API_KEY }}
236-
DD_GITHUB_JOB_NAME: ${{ matrix.name }}
236+
DD_GITHUB_JOB_NAME: ${{ matrix.full_name }}
237237
run: |
238238
cd src/ci
239239
npm ci

Cargo.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
541541

542542
[[package]]
543543
name = "clippy"
544-
version = "0.1.85"
544+
version = "0.1.86"
545545
dependencies = [
546546
"anstream",
547547
"cargo_metadata 0.18.1",
@@ -572,7 +572,7 @@ dependencies = [
572572

573573
[[package]]
574574
name = "clippy_config"
575-
version = "0.1.85"
575+
version = "0.1.86"
576576
dependencies = [
577577
"clippy_utils",
578578
"itertools",
@@ -597,7 +597,7 @@ dependencies = [
597597

598598
[[package]]
599599
name = "clippy_lints"
600-
version = "0.1.85"
600+
version = "0.1.86"
601601
dependencies = [
602602
"arrayvec",
603603
"cargo_metadata 0.18.1",
@@ -620,7 +620,7 @@ dependencies = [
620620

621621
[[package]]
622622
name = "clippy_utils"
623-
version = "0.1.85"
623+
version = "0.1.86"
624624
dependencies = [
625625
"arrayvec",
626626
"itertools",
@@ -4115,7 +4115,6 @@ name = "rustc_middle"
41154115
version = "0.0.0"
41164116
dependencies = [
41174117
"bitflags",
4118-
"derive-where",
41194118
"either",
41204119
"field-offset",
41214120
"gsgdt",
@@ -4159,6 +4158,7 @@ dependencies = [
41594158
"rustc_apfloat",
41604159
"rustc_arena",
41614160
"rustc_ast",
4161+
"rustc_attr_parsing",
41624162
"rustc_data_structures",
41634163
"rustc_errors",
41644164
"rustc_fluent_macro",

RELEASES.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Libraries
3737
- [Move `<float>::copysign`, `<float>::abs`, `<float>::signum` to `core`](https://github.com/rust-lang/rust/pull/131304)
3838
- [Add `LowerExp` and `UpperExp` implementations to `NonZero`](https://github.com/rust-lang/rust/pull/131377)
3939
- [Implement `FromStr` for `CString` and `TryFrom<CString>` for `String`](https://github.com/rust-lang/rust/pull/130608)
40-
- [`std::os::darwin` has been made public](https://github.com/rust-lang/rust/pull/130635)
40+
- [`std::os::darwin` has been made public](https://github.com/rust-lang/rust/pull/123723)
4141

4242
<a id="1.84.0-Stabilized-APIs"></a>
4343

@@ -60,6 +60,7 @@ Stabilized APIs
6060
- [`core::ptr::without_provenance_mut`](https://doc.rust-lang.org/stable/core/ptr/fn.without_provenance_mut.html)
6161
- [`core::ptr::dangling`](https://doc.rust-lang.org/stable/core/ptr/fn.dangling.html)
6262
- [`core::ptr::dangling_mut`](https://doc.rust-lang.org/stable/core/ptr/fn.dangling_mut.html)
63+
- [`Pin::as_deref_mut`](https://doc.rust-lang.org/stable/core/pin/struct.Pin.html#method.as_deref_mut)
6364

6465
These APIs are now stable in const contexts
6566

compiler/rustc_abi/src/layout.rs

+36-7
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
119119
.chain(Niche::from_scalar(dl, Size::ZERO, a))
120120
.max_by_key(|niche| niche.available(dl));
121121

122+
let combined_seed = a.size(&self.cx).bytes().wrapping_add(b.size(&self.cx).bytes());
123+
122124
LayoutData {
123125
variants: Variants::Single { index: VariantIdx::new(0) },
124126
fields: FieldsShape::Arbitrary {
@@ -131,6 +133,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
131133
size,
132134
max_repr_align: None,
133135
unadjusted_abi_align: align.abi,
136+
randomization_seed: combined_seed,
134137
}
135138
}
136139

@@ -223,6 +226,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
223226
size: Size::ZERO,
224227
max_repr_align: None,
225228
unadjusted_abi_align: dl.i8_align.abi,
229+
randomization_seed: 0,
226230
}
227231
}
228232

@@ -385,6 +389,11 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
385389
return Err(LayoutCalculatorError::EmptyUnion);
386390
};
387391

392+
let combined_seed = only_variant
393+
.iter()
394+
.map(|v| v.randomization_seed)
395+
.fold(repr.field_shuffle_seed, |acc, seed| acc.wrapping_add(seed));
396+
388397
Ok(LayoutData {
389398
variants: Variants::Single { index: only_variant_idx },
390399
fields: FieldsShape::Union(union_field_count),
@@ -394,6 +403,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
394403
size: size.align_to(align.abi),
395404
max_repr_align,
396405
unadjusted_abi_align,
406+
randomization_seed: combined_seed,
397407
})
398408
}
399409

@@ -650,6 +660,11 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
650660
BackendRepr::Memory { sized: true }
651661
};
652662

663+
let combined_seed = variant_layouts
664+
.iter()
665+
.map(|v| v.randomization_seed)
666+
.fold(repr.field_shuffle_seed, |acc, seed| acc.wrapping_add(seed));
667+
653668
let layout = LayoutData {
654669
variants: Variants::Multiple {
655670
tag: niche_scalar,
@@ -671,6 +686,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
671686
align,
672687
max_repr_align,
673688
unadjusted_abi_align,
689+
randomization_seed: combined_seed,
674690
};
675691

676692
Some(TmpLayout { layout, variants: variant_layouts })
@@ -961,6 +977,11 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
961977

962978
let largest_niche = Niche::from_scalar(dl, Size::ZERO, tag);
963979

980+
let combined_seed = layout_variants
981+
.iter()
982+
.map(|v| v.randomization_seed)
983+
.fold(repr.field_shuffle_seed, |acc, seed| acc.wrapping_add(seed));
984+
964985
let tagged_layout = LayoutData {
965986
variants: Variants::Multiple {
966987
tag,
@@ -978,6 +999,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
978999
size,
9791000
max_repr_align,
9801001
unadjusted_abi_align,
1002+
randomization_seed: combined_seed,
9811003
};
9821004

9831005
let tagged_layout = TmpLayout { layout: tagged_layout, variants: layout_variants };
@@ -1030,12 +1052,15 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
10301052
let mut max_repr_align = repr.align;
10311053
let mut inverse_memory_index: IndexVec<u32, FieldIdx> = fields.indices().collect();
10321054
let optimize_field_order = !repr.inhibit_struct_field_reordering();
1033-
if optimize_field_order && fields.len() > 1 {
1034-
let end =
1035-
if let StructKind::MaybeUnsized = kind { fields.len() - 1 } else { fields.len() };
1036-
let optimizing = &mut inverse_memory_index.raw[..end];
1037-
let fields_excluding_tail = &fields.raw[..end];
1055+
let end = if let StructKind::MaybeUnsized = kind { fields.len() - 1 } else { fields.len() };
1056+
let optimizing = &mut inverse_memory_index.raw[..end];
1057+
let fields_excluding_tail = &fields.raw[..end];
1058+
// unsizable tail fields are excluded so that we use the same seed for the sized and unsized layouts.
1059+
let field_seed = fields_excluding_tail
1060+
.iter()
1061+
.fold(0u64, |acc, f| acc.wrapping_add(f.randomization_seed));
10381062

1063+
if optimize_field_order && fields.len() > 1 {
10391064
// If `-Z randomize-layout` was enabled for the type definition we can shuffle
10401065
// the field ordering to try and catch some code making assumptions about layouts
10411066
// we don't guarantee.
@@ -1046,8 +1071,9 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
10461071
use rand::seq::SliceRandom;
10471072
// `ReprOptions.field_shuffle_seed` is a deterministic seed we can use to randomize field
10481073
// ordering.
1049-
let mut rng =
1050-
rand_xoshiro::Xoshiro128StarStar::seed_from_u64(repr.field_shuffle_seed);
1074+
let mut rng = rand_xoshiro::Xoshiro128StarStar::seed_from_u64(
1075+
field_seed.wrapping_add(repr.field_shuffle_seed),
1076+
);
10511077

10521078
// Shuffle the ordering of the fields.
10531079
optimizing.shuffle(&mut rng);
@@ -1344,6 +1370,8 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
13441370
unadjusted_abi_align
13451371
};
13461372

1373+
let seed = field_seed.wrapping_add(repr.field_shuffle_seed);
1374+
13471375
Ok(LayoutData {
13481376
variants: Variants::Single { index: VariantIdx::new(0) },
13491377
fields: FieldsShape::Arbitrary { offsets, memory_index },
@@ -1353,6 +1381,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
13531381
size,
13541382
max_repr_align,
13551383
unadjusted_abi_align,
1384+
randomization_seed: seed,
13561385
})
13571386
}
13581387

compiler/rustc_abi/src/lib.rs

+39
Original file line numberDiff line numberDiff line change
@@ -1719,6 +1719,18 @@ pub struct LayoutData<FieldIdx: Idx, VariantIdx: Idx> {
17191719
/// Only used on aarch64-linux, where the argument passing ABI ignores the requested alignment
17201720
/// in some cases.
17211721
pub unadjusted_abi_align: Align,
1722+
1723+
/// The randomization seed based on this type's own repr and its fields.
1724+
///
1725+
/// Since randomization is toggled on a per-crate basis even crates that do not have randomization
1726+
/// enabled should still calculate a seed so that downstream uses can use it to distinguish different
1727+
/// types.
1728+
///
1729+
/// For every T and U for which we do not guarantee that a repr(Rust) `Foo<T>` can be coerced or
1730+
/// transmuted to `Foo<U>` we aim to create probalistically distinct seeds so that Foo can choose
1731+
/// to reorder its fields based on that information. The current implementation is a conservative
1732+
/// approximation of this goal.
1733+
pub randomization_seed: u64,
17221734
}
17231735

17241736
impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
@@ -1739,6 +1751,30 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
17391751
let largest_niche = Niche::from_scalar(cx, Size::ZERO, scalar);
17401752
let size = scalar.size(cx);
17411753
let align = scalar.align(cx);
1754+
1755+
let range = scalar.valid_range(cx);
1756+
1757+
// All primitive types for which we don't have subtype coercions should get a distinct seed,
1758+
// so that types wrapping them can use randomization to arrive at distinct layouts.
1759+
//
1760+
// Some type information is already lost at this point, so as an approximation we derive
1761+
// the seed from what remains. For example on 64-bit targets usize and u64 can no longer
1762+
// be distinguished.
1763+
let randomization_seed = size
1764+
.bytes()
1765+
.wrapping_add(
1766+
match scalar.primitive() {
1767+
Primitive::Int(_, true) => 1,
1768+
Primitive::Int(_, false) => 2,
1769+
Primitive::Float(_) => 3,
1770+
Primitive::Pointer(_) => 4,
1771+
} << 32,
1772+
)
1773+
// distinguishes references from pointers
1774+
.wrapping_add((range.start as u64).rotate_right(16))
1775+
// distinguishes char from u32 and bool from u8
1776+
.wrapping_add((range.end as u64).rotate_right(16));
1777+
17421778
LayoutData {
17431779
variants: Variants::Single { index: VariantIdx::new(0) },
17441780
fields: FieldsShape::Primitive,
@@ -1748,6 +1784,7 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
17481784
align,
17491785
max_repr_align: None,
17501786
unadjusted_abi_align: align.abi,
1787+
randomization_seed,
17511788
}
17521789
}
17531790
}
@@ -1770,6 +1807,7 @@ where
17701807
variants,
17711808
max_repr_align,
17721809
unadjusted_abi_align,
1810+
ref randomization_seed,
17731811
} = self;
17741812
f.debug_struct("Layout")
17751813
.field("size", size)
@@ -1780,6 +1818,7 @@ where
17801818
.field("variants", variants)
17811819
.field("max_repr_align", max_repr_align)
17821820
.field("unadjusted_abi_align", unadjusted_abi_align)
1821+
.field("randomization_seed", randomization_seed)
17831822
.finish()
17841823
}
17851824
}

compiler/rustc_ast/src/ast.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,7 @@ impl Pat {
623623
PatKind::Wild
624624
| PatKind::Rest
625625
| PatKind::Never
626-
| PatKind::Lit(_)
626+
| PatKind::Expr(_)
627627
| PatKind::Range(..)
628628
| PatKind::Ident(..)
629629
| PatKind::Path(..)
@@ -801,8 +801,8 @@ pub enum PatKind {
801801
/// A reference pattern (e.g., `&mut (a, b)`).
802802
Ref(P<Pat>, Mutability),
803803

804-
/// A literal.
805-
Lit(P<Expr>),
804+
/// A literal, const block or path.
805+
Expr(P<Expr>),
806806

807807
/// A range pattern (e.g., `1...2`, `1..2`, `1..`, `..2`, `1..=2`, `..=2`).
808808
Range(Option<P<Expr>>, Option<P<Expr>>, Spanned<RangeEnd>),

compiler/rustc_ast/src/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ pub fn walk_pat<T: MutVisitor>(vis: &mut T, pat: &mut P<Pat>) {
15121512
vis.visit_ident(ident);
15131513
visit_opt(sub, |sub| vis.visit_pat(sub));
15141514
}
1515-
PatKind::Lit(e) => vis.visit_expr(e),
1515+
PatKind::Expr(e) => vis.visit_expr(e),
15161516
PatKind::TupleStruct(qself, path, elems) => {
15171517
vis.visit_qself(qself);
15181518
vis.visit_path(path);

compiler/rustc_ast/src/util/comments/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg_attr(not(bootstrap), allow(rustc::symbol_intern_string_literal))]
1+
#![allow(rustc::symbol_intern_string_literal)]
22

33
use rustc_span::create_default_session_globals_then;
44

compiler/rustc_ast/src/visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -680,7 +680,7 @@ pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) -> V::Res
680680
try_visit!(visitor.visit_ident(ident));
681681
visit_opt!(visitor, visit_pat, optional_subpattern);
682682
}
683-
PatKind::Lit(expression) => try_visit!(visitor.visit_expr(expression)),
683+
PatKind::Expr(expression) => try_visit!(visitor.visit_expr(expression)),
684684
PatKind::Range(lower_bound, upper_bound, _end) => {
685685
visit_opt!(visitor, visit_expr, lower_bound);
686686
visit_opt!(visitor, visit_expr, upper_bound);

0 commit comments

Comments
 (0)