Skip to content

Commit 24d2ac0

Browse files
committed
Auto merge of rust-lang#127777 - matthiaskrgr:rollup-qp2vkan, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#124921 (offset_from: always allow pointers to point to the same address) - rust-lang#127407 (Make parse error suggestions verbose and fix spans) - rust-lang#127684 (consolidate miri-unleashed tests for mutable refs into one file) - rust-lang#127729 (Stop using the `gen` identifier in the compiler) - rust-lang#127736 (Add myself to the review rotation) - rust-lang#127758 (coverage: Restrict `ExpressionUsed` simplification to `Code` mappings) r? `@ghost` `@rustbot` modify labels: rollup
2 parents eb72697 + e5d65e4 commit 24d2ac0

File tree

199 files changed

+3635
-1359
lines changed

Some content is hidden

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

199 files changed

+3635
-1359
lines changed

compiler/rustc_borrowck/src/dataflow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ impl<'tcx> rustc_mir_dataflow::GenKillAnalysis<'tcx> for Borrows<'_, '_, 'tcx> {
553553
panic!("could not find BorrowIndex for location {location:?}");
554554
});
555555

556-
trans.gen(index);
556+
trans.gen_(index);
557557
}
558558

559559
// Make sure there are no remaining borrows for variables

compiler/rustc_codegen_llvm/src/coverageinfo/map_data.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,15 @@ impl<'tcx> FunctionCoverageCollector<'tcx> {
6666
// For each expression ID that is directly used by one or more mappings,
6767
// mark it as not-yet-seen. This indicates that we expect to see a
6868
// corresponding `ExpressionUsed` statement during MIR traversal.
69-
for term in function_coverage_info.mappings.iter().flat_map(|m| m.kind.terms()) {
70-
if let CovTerm::Expression(id) = term {
69+
for mapping in function_coverage_info.mappings.iter() {
70+
// Currently we only worry about ordinary code mappings.
71+
// For branch and MC/DC mappings, expressions might not correspond
72+
// to any particular point in the control-flow graph.
73+
// (Keep this in sync with the injection of `ExpressionUsed`
74+
// statements in the `InstrumentCoverage` MIR pass.)
75+
if let MappingKind::Code(term) = mapping.kind
76+
&& let CovTerm::Expression(id) = term
77+
{
7178
expressions_seen.remove(id);
7279
}
7380
}

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+18-15
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use super::{
2020
err_inval, err_ub_custom, err_unsup_format, memory::MemoryKind, throw_inval, throw_ub_custom,
2121
throw_ub_format, util::ensure_monomorphic_enough, Allocation, CheckInAllocMsg, ConstAllocation,
2222
GlobalId, ImmTy, InterpCx, InterpResult, MPlaceTy, Machine, OpTy, Pointer, PointerArithmetic,
23-
Scalar,
23+
Provenance, Scalar,
2424
};
2525

2626
use crate::fluent_generated as fluent;
@@ -259,25 +259,28 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
259259
// This will always return 0.
260260
(a, b)
261261
}
262-
(Err(_), _) | (_, Err(_)) => {
263-
// We managed to find a valid allocation for one pointer, but not the other.
264-
// That means they are definitely not pointing to the same allocation.
262+
_ if M::Provenance::OFFSET_IS_ADDR && a.addr() == b.addr() => {
263+
// At least one of the pointers has provenance, but they also point to
264+
// the same address so it doesn't matter; this is fine. `(0, 0)` means
265+
// we pass all the checks below and return 0.
266+
(0, 0)
267+
}
268+
// From here onwards, the pointers are definitely for different addresses
269+
// (or we can't determine their absolute address).
270+
(Ok((a_alloc_id, a_offset, _)), Ok((b_alloc_id, b_offset, _)))
271+
if a_alloc_id == b_alloc_id =>
272+
{
273+
// Found allocation for both, and it's the same.
274+
// Use these offsets for distance calculation.
275+
(a_offset.bytes(), b_offset.bytes())
276+
}
277+
_ => {
278+
// Not into the same allocation -- this is UB.
265279
throw_ub_custom!(
266280
fluent::const_eval_offset_from_different_allocations,
267281
name = intrinsic_name,
268282
);
269283
}
270-
(Ok((a_alloc_id, a_offset, _)), Ok((b_alloc_id, b_offset, _))) => {
271-
// Found allocation for both. They must be into the same allocation.
272-
if a_alloc_id != b_alloc_id {
273-
throw_ub_custom!(
274-
fluent::const_eval_offset_from_different_allocations,
275-
name = intrinsic_name,
276-
);
277-
}
278-
// Use these offsets for distance calculation.
279-
(a_offset.bytes(), b_offset.bytes())
280-
}
281284
};
282285

283286
// Compute distance.

compiler/rustc_hir/src/hir.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -3218,10 +3218,10 @@ impl<'hir> Item<'hir> {
32183218
ItemKind::Static(ty, mutbl, body), (ty, *mutbl, *body);
32193219

32203220
expect_const, (&'hir Ty<'hir>, &'hir Generics<'hir>, BodyId),
3221-
ItemKind::Const(ty, gen, body), (ty, gen, *body);
3221+
ItemKind::Const(ty, generics, body), (ty, generics, *body);
32223222

32233223
expect_fn, (&FnSig<'hir>, &'hir Generics<'hir>, BodyId),
3224-
ItemKind::Fn(sig, gen, body), (sig, gen, *body);
3224+
ItemKind::Fn(sig, generics, body), (sig, generics, *body);
32253225

32263226
expect_macro, (&ast::MacroDef, MacroKind), ItemKind::Macro(def, mk), (def, *mk);
32273227

@@ -3233,25 +3233,25 @@ impl<'hir> Item<'hir> {
32333233
expect_global_asm, &'hir InlineAsm<'hir>, ItemKind::GlobalAsm(asm), asm;
32343234

32353235
expect_ty_alias, (&'hir Ty<'hir>, &'hir Generics<'hir>),
3236-
ItemKind::TyAlias(ty, gen), (ty, gen);
3236+
ItemKind::TyAlias(ty, generics), (ty, generics);
32373237

32383238
expect_opaque_ty, &OpaqueTy<'hir>, ItemKind::OpaqueTy(ty), ty;
32393239

3240-
expect_enum, (&EnumDef<'hir>, &'hir Generics<'hir>), ItemKind::Enum(def, gen), (def, gen);
3240+
expect_enum, (&EnumDef<'hir>, &'hir Generics<'hir>), ItemKind::Enum(def, generics), (def, generics);
32413241

32423242
expect_struct, (&VariantData<'hir>, &'hir Generics<'hir>),
3243-
ItemKind::Struct(data, gen), (data, gen);
3243+
ItemKind::Struct(data, generics), (data, generics);
32443244

32453245
expect_union, (&VariantData<'hir>, &'hir Generics<'hir>),
3246-
ItemKind::Union(data, gen), (data, gen);
3246+
ItemKind::Union(data, generics), (data, generics);
32473247

32483248
expect_trait,
32493249
(IsAuto, Safety, &'hir Generics<'hir>, GenericBounds<'hir>, &'hir [TraitItemRef]),
3250-
ItemKind::Trait(is_auto, safety, gen, bounds, items),
3251-
(*is_auto, *safety, gen, bounds, items);
3250+
ItemKind::Trait(is_auto, safety, generics, bounds, items),
3251+
(*is_auto, *safety, generics, bounds, items);
32523252

32533253
expect_trait_alias, (&'hir Generics<'hir>, GenericBounds<'hir>),
3254-
ItemKind::TraitAlias(gen, bounds), (gen, bounds);
3254+
ItemKind::TraitAlias(generics, bounds), (generics, bounds);
32553255

32563256
expect_impl, &'hir Impl<'hir>, ItemKind::Impl(imp), imp;
32573257
}

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2554,7 +2554,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25542554
.and_then(|node| node.generics())
25552555
.into_iter()
25562556
.flat_map(|generics| generics.params)
2557-
.find(|gen| &gen.def_id.to_def_id() == res_def_id)
2557+
.find(|param| &param.def_id.to_def_id() == res_def_id)
25582558
} else {
25592559
None
25602560
}

compiler/rustc_macros/src/diagnostics/diagnostic.rs

+4
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ impl<'a> DiagnosticDerive<'a> {
7171
});
7272

7373
// A lifetime of `'a` causes conflicts, but `_sess` is fine.
74+
// FIXME(edition_2024): Fix the `keyword_idents_2024` lint to not trigger here?
75+
#[allow(keyword_idents_2024)]
7476
let mut imp = structure.gen_impl(quote! {
7577
gen impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for @Self
7678
where G: rustc_errors::EmissionGuarantee
@@ -148,6 +150,8 @@ impl<'a> LintDiagnosticDerive<'a> {
148150
}
149151
});
150152

153+
// FIXME(edition_2024): Fix the `keyword_idents_2024` lint to not trigger here?
154+
#[allow(keyword_idents_2024)]
151155
let mut imp = structure.gen_impl(quote! {
152156
gen impl<'__a> rustc_errors::LintDiagnostic<'__a, ()> for @Self {
153157
#[track_caller]

compiler/rustc_macros/src/diagnostics/subdiagnostic.rs

+4
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ impl SubdiagnosticDerive {
8686

8787
let diag = &self.diag;
8888
let f = &self.f;
89+
90+
// FIXME(edition_2024): Fix the `keyword_idents_2024` lint to not trigger here?
91+
#[allow(keyword_idents_2024)]
8992
let ret = structure.gen_impl(quote! {
9093
gen impl rustc_errors::Subdiagnostic for @Self {
9194
fn add_to_diag_with<__G, __F>(
@@ -100,6 +103,7 @@ impl SubdiagnosticDerive {
100103
}
101104
}
102105
});
106+
103107
ret
104108
}
105109
}

compiler/rustc_middle/src/mir/coverage.rs

-13
Original file line numberDiff line numberDiff line change
@@ -220,19 +220,6 @@ pub enum MappingKind {
220220
}
221221

222222
impl MappingKind {
223-
/// Iterator over all coverage terms in this mapping kind.
224-
pub fn terms(&self) -> impl Iterator<Item = CovTerm> {
225-
let zero = || None.into_iter().chain(None);
226-
let one = |a| Some(a).into_iter().chain(None);
227-
let two = |a, b| Some(a).into_iter().chain(Some(b));
228-
match *self {
229-
Self::Code(term) => one(term),
230-
Self::Branch { true_term, false_term } => two(true_term, false_term),
231-
Self::MCDCBranch { true_term, false_term, .. } => two(true_term, false_term),
232-
Self::MCDCDecision(_) => zero(),
233-
}
234-
}
235-
236223
/// Returns a copy of this mapping kind, in which all coverage terms have
237224
/// been replaced with ones returned by the given function.
238225
pub fn map_terms(&self, map_fn: impl Fn(CovTerm) -> CovTerm) -> Self {

compiler/rustc_middle/src/mir/visit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1016,14 +1016,14 @@ macro_rules! extra_body_methods {
10161016
macro_rules! super_body {
10171017
($self:ident, $body:ident, $($mutability:ident, $invalidate:tt)?) => {
10181018
let span = $body.span;
1019-
if let Some(gen) = &$($mutability)? $body.coroutine {
1020-
if let Some(yield_ty) = $(& $mutability)? gen.yield_ty {
1019+
if let Some(coroutine) = &$($mutability)? $body.coroutine {
1020+
if let Some(yield_ty) = $(& $mutability)? coroutine.yield_ty {
10211021
$self.visit_ty(
10221022
yield_ty,
10231023
TyContext::YieldTy(SourceInfo::outermost(span))
10241024
);
10251025
}
1026-
if let Some(resume_ty) = $(& $mutability)? gen.resume_ty {
1026+
if let Some(resume_ty) = $(& $mutability)? coroutine.resume_ty {
10271027
$self.visit_ty(
10281028
resume_ty,
10291029
TyContext::ResumeTy(SourceInfo::outermost(span))

compiler/rustc_mir_dataflow/src/framework/mod.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -402,15 +402,15 @@ where
402402
/// building up a `GenKillSet` and then throwing it away.
403403
pub trait GenKill<T> {
404404
/// Inserts `elem` into the state vector.
405-
fn gen(&mut self, elem: T);
405+
fn gen_(&mut self, elem: T);
406406

407407
/// Removes `elem` from the state vector.
408408
fn kill(&mut self, elem: T);
409409

410410
/// Calls `gen` for each element in `elems`.
411411
fn gen_all(&mut self, elems: impl IntoIterator<Item = T>) {
412412
for elem in elems {
413-
self.gen(elem);
413+
self.gen_(elem);
414414
}
415415
}
416416

@@ -424,44 +424,44 @@ pub trait GenKill<T> {
424424

425425
/// Stores a transfer function for a gen/kill problem.
426426
///
427-
/// Calling `gen`/`kill` on a `GenKillSet` will "build up" a transfer function so that it can be
428-
/// applied multiple times efficiently. When there are multiple calls to `gen` and/or `kill` for
427+
/// Calling `gen_`/`kill` on a `GenKillSet` will "build up" a transfer function so that it can be
428+
/// applied multiple times efficiently. When there are multiple calls to `gen_` and/or `kill` for
429429
/// the same element, the most recent one takes precedence.
430430
#[derive(Clone)]
431431
pub struct GenKillSet<T> {
432-
gen: HybridBitSet<T>,
432+
gen_: HybridBitSet<T>,
433433
kill: HybridBitSet<T>,
434434
}
435435

436436
impl<T: Idx> GenKillSet<T> {
437437
/// Creates a new transfer function that will leave the dataflow state unchanged.
438438
pub fn identity(universe: usize) -> Self {
439439
GenKillSet {
440-
gen: HybridBitSet::new_empty(universe),
440+
gen_: HybridBitSet::new_empty(universe),
441441
kill: HybridBitSet::new_empty(universe),
442442
}
443443
}
444444

445445
pub fn apply(&self, state: &mut impl BitSetExt<T>) {
446-
state.union(&self.gen);
446+
state.union(&self.gen_);
447447
state.subtract(&self.kill);
448448
}
449449
}
450450

451451
impl<T: Idx> GenKill<T> for GenKillSet<T> {
452-
fn gen(&mut self, elem: T) {
453-
self.gen.insert(elem);
452+
fn gen_(&mut self, elem: T) {
453+
self.gen_.insert(elem);
454454
self.kill.remove(elem);
455455
}
456456

457457
fn kill(&mut self, elem: T) {
458458
self.kill.insert(elem);
459-
self.gen.remove(elem);
459+
self.gen_.remove(elem);
460460
}
461461
}
462462

463463
impl<T: Idx> GenKill<T> for BitSet<T> {
464-
fn gen(&mut self, elem: T) {
464+
fn gen_(&mut self, elem: T) {
465465
self.insert(elem);
466466
}
467467

@@ -471,7 +471,7 @@ impl<T: Idx> GenKill<T> for BitSet<T> {
471471
}
472472

473473
impl<T: Idx> GenKill<T> for ChunkedBitSet<T> {
474-
fn gen(&mut self, elem: T) {
474+
fn gen_(&mut self, elem: T) {
475475
self.insert(elem);
476476
}
477477

@@ -481,11 +481,11 @@ impl<T: Idx> GenKill<T> for ChunkedBitSet<T> {
481481
}
482482

483483
impl<T, S: GenKill<T>> GenKill<T> for MaybeReachable<S> {
484-
fn gen(&mut self, elem: T) {
484+
fn gen_(&mut self, elem: T) {
485485
match self {
486486
// If the state is not reachable, adding an element does nothing.
487487
MaybeReachable::Unreachable => {}
488-
MaybeReachable::Reachable(set) => set.gen(elem),
488+
MaybeReachable::Reachable(set) => set.gen_(elem),
489489
}
490490
}
491491

@@ -499,7 +499,7 @@ impl<T, S: GenKill<T>> GenKill<T> for MaybeReachable<S> {
499499
}
500500

501501
impl<T: Idx> GenKill<T> for lattice::Dual<BitSet<T>> {
502-
fn gen(&mut self, elem: T) {
502+
fn gen_(&mut self, elem: T) {
503503
self.0.insert(elem);
504504
}
505505

compiler/rustc_mir_dataflow/src/impls/borrowed_locals.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ where
9797
Rvalue::AddressOf(_, borrowed_place)
9898
| Rvalue::Ref(_, BorrowKind::Mut { .. } | BorrowKind::Shared, borrowed_place) => {
9999
if !borrowed_place.is_indirect() {
100-
self.trans.gen(borrowed_place.local);
100+
self.trans.gen_(borrowed_place.local);
101101
}
102102
}
103103

@@ -131,7 +131,7 @@ where
131131
//
132132
// [#61069]: https://github.com/rust-lang/rust/pull/61069
133133
if !dropped_place.is_indirect() {
134-
self.trans.gen(dropped_place.local);
134+
self.trans.gen_(dropped_place.local);
135135
}
136136
}
137137

@@ -159,8 +159,8 @@ pub fn borrowed_locals(body: &Body<'_>) -> BitSet<Local> {
159159

160160
impl GenKill<Local> for Borrowed {
161161
#[inline]
162-
fn gen(&mut self, elem: Local) {
163-
self.0.gen(elem)
162+
fn gen_(&mut self, elem: Local) {
163+
self.0.gen_(elem)
164164
}
165165
#[inline]
166166
fn kill(&mut self, _: Local) {

0 commit comments

Comments
 (0)