Skip to content

Commit 94b2b15

Browse files
committed
Auto merge of rust-lang#101143 - matthiaskrgr:rollup-g8y5k0g, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#94890 (Support parsing IP addresses from a byte string) - rust-lang#96334 (socket `set_mark` addition.) - rust-lang#99027 (Replace `Body::basic_blocks()` with field access) - rust-lang#100437 (Improve const mismatch `FulfillmentError`) - rust-lang#100843 (Migrate part of rustc_infer to session diagnostic) - rust-lang#100897 (extra sanity check against consts pointing to mutable memory) - rust-lang#100959 (translations: rename warn_ to warning) - rust-lang#101111 (Use the declaration's SourceInfo for FnEntry retags, not the outermost) - rust-lang#101116 ([rustdoc] Remove Attrs type alias) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7c142a6 + fa177a9 commit 94b2b15

File tree

115 files changed

+1289
-524
lines changed

Some content is hidden

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

115 files changed

+1289
-524
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3631,6 +3631,7 @@ dependencies = [
36313631
"rustc_macros",
36323632
"rustc_middle",
36333633
"rustc_serialize",
3634+
"rustc_session",
36343635
"rustc_span",
36353636
"rustc_target",
36363637
"smallvec",

compiler/rustc_borrowck/src/constraint_generation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(super) fn generate_constraints<'cx, 'tcx>(
3131
body,
3232
};
3333

34-
for (bb, data) in body.basic_blocks().iter_enumerated() {
34+
for (bb, data) in body.basic_blocks.iter_enumerated() {
3535
cg.visit_basic_block_data(bb, data);
3636
}
3737
}

compiler/rustc_borrowck/src/dataflow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ struct OutOfScopePrecomputer<'a, 'tcx> {
143143
impl<'a, 'tcx> OutOfScopePrecomputer<'a, 'tcx> {
144144
fn new(body: &'a Body<'tcx>, regioncx: &'a RegionInferenceContext<'tcx>) -> Self {
145145
OutOfScopePrecomputer {
146-
visited: BitSet::new_empty(body.basic_blocks().len()),
146+
visited: BitSet::new_empty(body.basic_blocks.len()),
147147
visit_stack: vec![],
148148
body,
149149
regioncx,

compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
459459
return outmost_back_edge;
460460
}
461461

462-
let block = &self.body.basic_blocks()[location.block];
462+
let block = &self.body.basic_blocks[location.block];
463463

464464
if location.statement_index < block.statements.len() {
465465
let successor = location.successor_within_block();
@@ -518,7 +518,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
518518
}
519519

520520
if loop_head.dominates(from, &self.dominators) {
521-
let block = &self.body.basic_blocks()[from.block];
521+
let block = &self.body.basic_blocks[from.block];
522522

523523
if from.statement_index < block.statements.len() {
524524
let successor = from.successor_within_block();
@@ -568,7 +568,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
568568
UseSpans::PatUse(span)
569569
| UseSpans::OtherUse(span)
570570
| UseSpans::FnSelfUse { var_span: span, .. } => {
571-
let block = &self.body.basic_blocks()[location.block];
571+
let block = &self.body.basic_blocks[location.block];
572572

573573
let kind = if let Some(&Statement {
574574
kind: StatementKind::FakeRead(box (FakeReadCause::ForLet(_), _)),

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
8888
if let Some(StatementKind::Assign(box (
8989
place,
9090
Rvalue::Use(Operand::Move(move_from)),
91-
))) = self.body.basic_blocks()[location.block]
91+
))) = self.body.basic_blocks[location.block]
9292
.statements
9393
.get(location.statement_index)
9494
.map(|stmt| &stmt.kind)

compiler/rustc_borrowck/src/location.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl LocationTable {
3333
pub(crate) fn new(body: &Body<'_>) -> Self {
3434
let mut num_points = 0;
3535
let statements_before_block = body
36-
.basic_blocks()
36+
.basic_blocks
3737
.iter()
3838
.map(|block_data| {
3939
let v = num_points;

compiler/rustc_borrowck/src/region_infer/values.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl RegionValueElements {
2525
pub(crate) fn new(body: &Body<'_>) -> Self {
2626
let mut num_points = 0;
2727
let statements_before_block: IndexVec<BasicBlock, usize> = body
28-
.basic_blocks()
28+
.basic_blocks
2929
.iter()
3030
.map(|block_data| {
3131
let v = num_points;
@@ -37,7 +37,7 @@ impl RegionValueElements {
3737
debug!("RegionValueElements: num_points={:#?}", num_points);
3838

3939
let mut basic_blocks = IndexVec::with_capacity(num_points);
40-
for (bb, bb_data) in body.basic_blocks().iter_enumerated() {
40+
for (bb, bb_data) in body.basic_blocks.iter_enumerated() {
4141
basic_blocks.extend((0..=bb_data.statements.len()).map(|_| bb));
4242
}
4343

compiler/rustc_borrowck/src/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2633,7 +2633,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
26332633
self.check_local(&body, local, local_decl);
26342634
}
26352635

2636-
for (block, block_data) in body.basic_blocks().iter_enumerated() {
2636+
for (block, block_data) in body.basic_blocks.iter_enumerated() {
26372637
let mut location = Location { block, statement_index: 0 };
26382638
for stmt in &block_data.statements {
26392639
if !stmt.source_info.span.is_dummy() {

compiler/rustc_codegen_cranelift/src/analyze.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(crate) fn analyze(fx: &FunctionCx<'_, '_, '_>) -> IndexVec<Local, SsaKind> {
2626
})
2727
.collect::<IndexVec<Local, SsaKind>>();
2828

29-
for bb in fx.mir.basic_blocks().iter() {
29+
for bb in fx.mir.basic_blocks.iter() {
3030
for stmt in bb.statements.iter() {
3131
match &stmt.kind {
3232
Assign(place_and_rval) => match &place_and_rval.1 {

compiler/rustc_codegen_cranelift/src/base.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub(crate) fn codegen_fn<'tcx>(
7373
// Predefine blocks
7474
let start_block = bcx.create_block();
7575
let block_map: IndexVec<BasicBlock, Block> =
76-
(0..mir.basic_blocks().len()).map(|_| bcx.create_block()).collect();
76+
(0..mir.basic_blocks.len()).map(|_| bcx.create_block()).collect();
7777

7878
// Make FunctionCx
7979
let target_config = module.target_config();
@@ -271,7 +271,7 @@ fn codegen_fn_body(fx: &mut FunctionCx<'_, '_, '_>, start_block: Block) {
271271
}
272272
fx.tcx.sess.time("codegen prelude", || crate::abi::codegen_fn_prelude(fx, start_block));
273273

274-
for (bb, bb_data) in fx.mir.basic_blocks().iter_enumerated() {
274+
for (bb, bb_data) in fx.mir.basic_blocks.iter_enumerated() {
275275
let block = fx.get_block(bb);
276276
fx.bcx.switch_to_block(block);
277277

compiler/rustc_codegen_cranelift/src/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ pub(crate) fn mir_operand_get_const_val<'tcx>(
505505
return None;
506506
}
507507
let mut computed_const_val = None;
508-
for bb_data in fx.mir.basic_blocks() {
508+
for bb_data in fx.mir.basic_blocks.iter() {
509509
for stmt in &bb_data.statements {
510510
match &stmt.kind {
511511
StatementKind::Assign(local_and_rvalue) if &local_and_rvalue.0 == place => {

compiler/rustc_codegen_ssa/src/mir/analyze.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ pub fn cleanup_kinds(mir: &mir::Body<'_>) -> IndexVec<mir::BasicBlock, CleanupKi
266266
result: &mut IndexVec<mir::BasicBlock, CleanupKind>,
267267
mir: &mir::Body<'tcx>,
268268
) {
269-
for (bb, data) in mir.basic_blocks().iter_enumerated() {
269+
for (bb, data) in mir.basic_blocks.iter_enumerated() {
270270
match data.terminator().kind {
271271
TerminatorKind::Goto { .. }
272272
| TerminatorKind::Resume
@@ -296,7 +296,7 @@ pub fn cleanup_kinds(mir: &mir::Body<'_>) -> IndexVec<mir::BasicBlock, CleanupKi
296296
}
297297

298298
fn propagate<'tcx>(result: &mut IndexVec<mir::BasicBlock, CleanupKind>, mir: &mir::Body<'tcx>) {
299-
let mut funclet_succs = IndexVec::from_elem(None, mir.basic_blocks());
299+
let mut funclet_succs = IndexVec::from_elem(None, &mir.basic_blocks);
300300

301301
let mut set_successor = |funclet: mir::BasicBlock, succ| match funclet_succs[funclet] {
302302
ref mut s @ None => {
@@ -359,7 +359,7 @@ pub fn cleanup_kinds(mir: &mir::Body<'_>) -> IndexVec<mir::BasicBlock, CleanupKi
359359
}
360360
}
361361

362-
let mut result = IndexVec::from_elem(CleanupKind::NotCleanup, mir.basic_blocks());
362+
let mut result = IndexVec::from_elem(CleanupKind::NotCleanup, &mir.basic_blocks);
363363

364364
discover_masters(&mut result, mir);
365365
propagate(&mut result, mir);

compiler/rustc_codegen_ssa/src/mir/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
150150
let start_llbb = Bx::append_block(cx, llfn, "start");
151151
let mut bx = Bx::build(cx, start_llbb);
152152

153-
if mir.basic_blocks().iter().any(|bb| bb.is_cleanup) {
153+
if mir.basic_blocks.iter().any(|bb| bb.is_cleanup) {
154154
bx.set_personality_fn(cx.eh_personality());
155155
}
156156

157157
let cleanup_kinds = analyze::cleanup_kinds(&mir);
158158
let cached_llbbs: IndexVec<mir::BasicBlock, Option<Bx::BasicBlock>> = mir
159-
.basic_blocks()
159+
.basic_blocks
160160
.indices()
161161
.map(|bb| if bb == mir::START_BLOCK { Some(start_llbb) } else { None })
162162
.collect();
@@ -172,8 +172,8 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
172172
unreachable_block: None,
173173
double_unwind_guard: None,
174174
cleanup_kinds,
175-
landing_pads: IndexVec::from_elem(None, mir.basic_blocks()),
176-
funclets: IndexVec::from_fn_n(|_| None, mir.basic_blocks().len()),
175+
landing_pads: IndexVec::from_elem(None, &mir.basic_blocks),
176+
funclets: IndexVec::from_fn_n(|_| None, mir.basic_blocks.len()),
177177
locals: IndexVec::new(),
178178
debug_context,
179179
per_local_var_debug_info: None,

compiler/rustc_const_eval/src/interpret/eval_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
782782
assert_eq!(
783783
unwinding,
784784
match self.frame().loc {
785-
Ok(loc) => self.body().basic_blocks()[loc.block].is_cleanup,
785+
Ok(loc) => self.body().basic_blocks[loc.block].is_cleanup,
786786
Err(_) => true,
787787
}
788788
);

compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
2828
let mut source_info = *frame.body.source_info(loc);
2929

3030
// If this is a `Call` terminator, use the `fn_span` instead.
31-
let block = &frame.body.basic_blocks()[loc.block];
31+
let block = &frame.body.basic_blocks[loc.block];
3232
if loc.statement_index == block.statements.len() {
3333
debug!(
3434
"find_closest_untracked_caller_location: got terminator {:?} ({:?})",

compiler/rustc_const_eval/src/interpret/step.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
5353
self.pop_stack_frame(/* unwinding */ true)?;
5454
return Ok(true);
5555
};
56-
let basic_block = &self.body().basic_blocks()[loc.block];
56+
let basic_block = &self.body().basic_blocks[loc.block];
5757

5858
if let Some(stmt) = basic_block.statements.get(loc.statement_index) {
5959
let old_frames = self.frame_idx();

compiler/rustc_const_eval/src/interpret/validity.rs

+45-27
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use std::convert::TryFrom;
88
use std::fmt::Write;
99
use std::num::NonZeroUsize;
1010

11+
use rustc_ast::Mutability;
1112
use rustc_data_structures::fx::FxHashSet;
1213
use rustc_hir as hir;
1314
use rustc_middle::mir::interpret::InterpError;
@@ -423,34 +424,51 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
423424
// Proceed recursively even for ZST, no reason to skip them!
424425
// `!` is a ZST and we want to validate it.
425426
if let Ok((alloc_id, _offset, _prov)) = self.ecx.ptr_try_get_alloc_id(place.ptr) {
426-
// Special handling for pointers to statics (irrespective of their type).
427+
// Let's see what kind of memory this points to.
427428
let alloc_kind = self.ecx.tcx.try_get_global_alloc(alloc_id);
428-
if let Some(GlobalAlloc::Static(did)) = alloc_kind {
429-
assert!(!self.ecx.tcx.is_thread_local_static(did));
430-
assert!(self.ecx.tcx.is_static(did));
431-
if matches!(
432-
self.ctfe_mode,
433-
Some(CtfeValidationMode::Const { allow_static_ptrs: false, .. })
434-
) {
435-
// See const_eval::machine::MemoryExtra::can_access_statics for why
436-
// this check is so important.
437-
// This check is reachable when the const just referenced the static,
438-
// but never read it (so we never entered `before_access_global`).
439-
throw_validation_failure!(self.path,
440-
{ "a {} pointing to a static variable", kind }
441-
);
429+
match alloc_kind {
430+
Some(GlobalAlloc::Static(did)) => {
431+
// Special handling for pointers to statics (irrespective of their type).
432+
assert!(!self.ecx.tcx.is_thread_local_static(did));
433+
assert!(self.ecx.tcx.is_static(did));
434+
if matches!(
435+
self.ctfe_mode,
436+
Some(CtfeValidationMode::Const { allow_static_ptrs: false, .. })
437+
) {
438+
// See const_eval::machine::MemoryExtra::can_access_statics for why
439+
// this check is so important.
440+
// This check is reachable when the const just referenced the static,
441+
// but never read it (so we never entered `before_access_global`).
442+
throw_validation_failure!(self.path,
443+
{ "a {} pointing to a static variable in a constant", kind }
444+
);
445+
}
446+
// We skip recursively checking other statics. These statics must be sound by
447+
// themselves, and the only way to get broken statics here is by using
448+
// unsafe code.
449+
// The reasons we don't check other statics is twofold. For one, in all
450+
// sound cases, the static was already validated on its own, and second, we
451+
// trigger cycle errors if we try to compute the value of the other static
452+
// and that static refers back to us.
453+
// We might miss const-invalid data,
454+
// but things are still sound otherwise (in particular re: consts
455+
// referring to statics).
456+
return Ok(());
442457
}
443-
// We skip checking other statics. These statics must be sound by
444-
// themselves, and the only way to get broken statics here is by using
445-
// unsafe code.
446-
// The reasons we don't check other statics is twofold. For one, in all
447-
// sound cases, the static was already validated on its own, and second, we
448-
// trigger cycle errors if we try to compute the value of the other static
449-
// and that static refers back to us.
450-
// We might miss const-invalid data,
451-
// but things are still sound otherwise (in particular re: consts
452-
// referring to statics).
453-
return Ok(());
458+
Some(GlobalAlloc::Memory(alloc)) => {
459+
if alloc.inner().mutability == Mutability::Mut
460+
&& matches!(self.ctfe_mode, Some(CtfeValidationMode::Const { .. }))
461+
{
462+
// This should be unreachable, but if someone manages to copy a pointer
463+
// out of a `static`, then that pointer might point to mutable memory,
464+
// and we would catch that here.
465+
throw_validation_failure!(self.path,
466+
{ "a {} pointing to mutable memory in a constant", kind }
467+
);
468+
}
469+
}
470+
// Nothing to check for these.
471+
None | Some(GlobalAlloc::Function(..) | GlobalAlloc::VTable(..)) => {}
454472
}
455473
}
456474
let path = &self.path;
@@ -528,7 +546,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
528546
}
529547
ty::Ref(_, ty, mutbl) => {
530548
if matches!(self.ctfe_mode, Some(CtfeValidationMode::Const { .. }))
531-
&& *mutbl == hir::Mutability::Mut
549+
&& *mutbl == Mutability::Mut
532550
{
533551
// A mutable reference inside a const? That does not seem right (except if it is
534552
// a ZST).

compiler/rustc_const_eval/src/transform/check_consts/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ impl<'mir, 'tcx> Qualifs<'mir, 'tcx> {
135135
// qualifs for the return type.
136136
let return_block = ccx
137137
.body
138-
.basic_blocks()
138+
.basic_blocks
139139
.iter_enumerated()
140140
.find(|(_, block)| matches!(block.terminator().kind, TerminatorKind::Return))
141141
.map(|(bb, _)| bb);

compiler/rustc_const_eval/src/transform/promote_consts.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
710710
}
711711

712712
fn assign(&mut self, dest: Local, rvalue: Rvalue<'tcx>, span: Span) {
713-
let last = self.promoted.basic_blocks().last().unwrap();
713+
let last = self.promoted.basic_blocks.last().unwrap();
714714
let data = &mut self.promoted[last];
715715
data.statements.push(Statement {
716716
source_info: SourceInfo::outermost(span),
@@ -803,7 +803,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
803803
self.visit_operand(arg, loc);
804804
}
805805

806-
let last = self.promoted.basic_blocks().last().unwrap();
806+
let last = self.promoted.basic_blocks.last().unwrap();
807807
let new_target = self.new_block();
808808

809809
*self.promoted[last].terminator_mut() = Terminator {
@@ -1041,7 +1041,7 @@ pub fn is_const_fn_in_array_repeat_expression<'tcx>(
10411041
_ => {}
10421042
}
10431043

1044-
for block in body.basic_blocks() {
1044+
for block in body.basic_blocks.iter() {
10451045
if let Some(Terminator { kind: TerminatorKind::Call { func, destination, .. }, .. }) =
10461046
&block.terminator
10471047
{

compiler/rustc_const_eval/src/transform/validate.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
140140
if bb == START_BLOCK {
141141
self.fail(location, "start block must not have predecessors")
142142
}
143-
if let Some(bb) = self.body.basic_blocks().get(bb) {
144-
let src = self.body.basic_blocks().get(location.block).unwrap();
143+
if let Some(bb) = self.body.basic_blocks.get(bb) {
144+
let src = self.body.basic_blocks.get(location.block).unwrap();
145145
match (src.is_cleanup, bb.is_cleanup, edge_kind) {
146146
// Non-cleanup blocks can jump to non-cleanup blocks along non-unwind edges
147147
(false, false, EdgeKind::Normal)
@@ -881,13 +881,13 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
881881
}
882882
TerminatorKind::Resume | TerminatorKind::Abort => {
883883
let bb = location.block;
884-
if !self.body.basic_blocks()[bb].is_cleanup {
884+
if !self.body.basic_blocks[bb].is_cleanup {
885885
self.fail(location, "Cannot `Resume` or `Abort` from non-cleanup basic block")
886886
}
887887
}
888888
TerminatorKind::Return => {
889889
let bb = location.block;
890-
if self.body.basic_blocks()[bb].is_cleanup {
890+
if self.body.basic_blocks[bb].is_cleanup {
891891
self.fail(location, "Cannot `Return` from cleanup basic block")
892892
}
893893
}

0 commit comments

Comments
 (0)