Skip to content

Commit b2e36e6

Browse files
committed
Auto merge of #71431 - Dylan-DPC:rollup-rvm6tfy, r=Dylan-DPC
Rollup of 4 pull requests Successful merges: - #71280 (Miri: mplace_access_checked: offer option to force different alignment on place) - #71336 (Exhaustively match on `{Statement,Terminator}Kind` during const checking) - #71370 (Added detailed error code explanation for issue E0696 in Rust compiler.) - #71401 (visit_place_base is just visit_local) Failed merges: r? @ghost
2 parents 82e90d6 + 238e822 commit b2e36e6

File tree

14 files changed

+128
-35
lines changed

14 files changed

+128
-35
lines changed

Diff for: src/librustc_codegen_ssa/mir/analyze.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
204204
};
205205
}
206206

207-
self.visit_place_base(&place_ref.local, context, location);
207+
self.visit_local(&place_ref.local, context, location);
208208
self.visit_projection(place_ref.local, place_ref.projection, context, location);
209209
}
210210
}

Diff for: src/librustc_error_codes/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,7 @@ E0691: include_str!("./error_codes/E0691.md"),
386386
E0692: include_str!("./error_codes/E0692.md"),
387387
E0693: include_str!("./error_codes/E0693.md"),
388388
E0695: include_str!("./error_codes/E0695.md"),
389+
E0696: include_str!("./error_codes/E0696.md"),
389390
E0697: include_str!("./error_codes/E0697.md"),
390391
E0698: include_str!("./error_codes/E0698.md"),
391392
E0699: include_str!("./error_codes/E0699.md"),
@@ -604,7 +605,6 @@ E0753: include_str!("./error_codes/E0753.md"),
604605
E0687, // in-band lifetimes cannot be used in `fn`/`Fn` syntax
605606
E0688, // in-band lifetimes cannot be mixed with explicit lifetime binders
606607
// E0694, // an unknown tool name found in scoped attributes
607-
E0696, // `continue` pointing to a labeled block
608608
// E0702, // replaced with a generic attribute input check
609609
// E0707, // multiple elided lifetimes used in arguments of `async fn`
610610
// E0709, // multiple different lifetimes used in arguments of `async fn`

Diff for: src/librustc_error_codes/error_codes/E0696.md

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
A function is using `continue` keyword incorrectly.
2+
3+
Erroneous code example:
4+
5+
```compile_fail,E0696
6+
fn continue_simple() {
7+
'b: {
8+
continue; // error!
9+
}
10+
}
11+
fn continue_labeled() {
12+
'b: {
13+
continue 'b; // error!
14+
}
15+
}
16+
fn continue_crossing() {
17+
loop {
18+
'b: {
19+
continue; // error!
20+
}
21+
}
22+
}
23+
```
24+
25+
Here we have used the `continue` keyword incorrectly. As we
26+
have seen above that `continue` pointing to a labeled block.
27+
28+
To fix this we have to use the labeled block properly.
29+
For example:
30+
31+
```
32+
fn continue_simple() {
33+
'b: loop {
34+
continue ; // ok!
35+
}
36+
}
37+
fn continue_labeled() {
38+
'b: loop {
39+
continue 'b; // ok!
40+
}
41+
}
42+
fn continue_crossing() {
43+
loop {
44+
'b: loop {
45+
continue; // ok!
46+
}
47+
}
48+
}
49+
```

Diff for: src/librustc_middle/mir/visit.rs

+2-16
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,6 @@ macro_rules! make_mir_visitor {
163163
self.super_place(place, context, location);
164164
}
165165

166-
fn visit_place_base(&mut self,
167-
local: & $($mutability)? Local,
168-
context: PlaceContext,
169-
location: Location) {
170-
self.super_place_base(local, context, location);
171-
}
172-
173166
visit_place_fns!($($mutability)?);
174167

175168
fn visit_constant(&mut self,
@@ -710,13 +703,6 @@ macro_rules! make_mir_visitor {
710703
);
711704
}
712705

713-
fn super_place_base(&mut self,
714-
local: & $($mutability)? Local,
715-
context: PlaceContext,
716-
location: Location) {
717-
self.visit_local(local, context, location);
718-
}
719-
720706
fn super_local_decl(&mut self,
721707
local: Local,
722708
local_decl: & $($mutability)? LocalDecl<'tcx>) {
@@ -847,7 +833,7 @@ macro_rules! visit_place_fns {
847833
context: PlaceContext,
848834
location: Location,
849835
) {
850-
self.visit_place_base(&mut place.local, context, location);
836+
self.visit_local(&mut place.local, context, location);
851837

852838
if let Some(new_projection) = self.process_projection(&place.projection, location) {
853839
place.projection = self.tcx().intern_place_elems(&new_projection);
@@ -936,7 +922,7 @@ macro_rules! visit_place_fns {
936922
};
937923
}
938924

939-
self.visit_place_base(&place.local, context, location);
925+
self.visit_local(&place.local, context, location);
940926

941927
self.visit_projection(place.local, &place.projection, context, location);
942928
}

Diff for: src/librustc_mir/interpret/place.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ where
333333
let val = self.read_immediate(src)?;
334334
trace!("deref to {} on {:?}", val.layout.ty, *val);
335335
let place = self.ref_to_mplace(val)?;
336-
self.mplace_access_checked(place)
336+
self.mplace_access_checked(place, None)
337337
}
338338

339339
/// Check if the given place is good for memory access with the given
@@ -358,15 +358,20 @@ where
358358

359359
/// Return the "access-checked" version of this `MPlace`, where for non-ZST
360360
/// this is definitely a `Pointer`.
361+
///
362+
/// `force_align` must only be used when correct alignment does not matter,
363+
/// like in Stacked Borrows.
361364
pub fn mplace_access_checked(
362365
&self,
363366
mut place: MPlaceTy<'tcx, M::PointerTag>,
367+
force_align: Option<Align>,
364368
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
365369
let (size, align) = self
366370
.size_and_align_of_mplace(place)?
367371
.unwrap_or((place.layout.size, place.layout.align.abi));
368372
assert!(place.mplace.align <= align, "dynamic alignment less strict than static one?");
369-
place.mplace.align = align; // maximally strict checking
373+
// Check (stricter) dynamic alignment, unless forced otherwise.
374+
place.mplace.align = force_align.unwrap_or(align);
370375
// When dereferencing a pointer, it must be non-NULL, aligned, and live.
371376
if let Some(ptr) = self.check_mplace_access(place, Some(size))? {
372377
place.mplace.ptr = ptr.into();

Diff for: src/librustc_mir/monomorphize/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
648648
self.super_terminator_kind(kind, location);
649649
}
650650

651-
fn visit_place_base(
651+
fn visit_local(
652652
&mut self,
653653
_place_local: &Local,
654654
_context: mir::visit::PlaceContext,

Diff for: src/librustc_mir/transform/check_consts/ops.rs

+4
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ impl NonConstOp for IfOrMatch {
147147
}
148148
}
149149

150+
#[derive(Debug)]
151+
pub struct InlineAsm;
152+
impl NonConstOp for InlineAsm {}
153+
150154
#[derive(Debug)]
151155
pub struct LiveDrop;
152156
impl NonConstOp for LiveDrop {

Diff for: src/librustc_mir/transform/check_consts/validation.rs

+31-10
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
276276
PlaceContext::MutatingUse(MutatingUseContext::Borrow)
277277
}
278278
};
279-
self.visit_place_base(&place.local, ctx, location);
279+
self.visit_local(&place.local, ctx, location);
280280
self.visit_projection(place.local, reborrowed_proj, ctx, location);
281281
return;
282282
}
@@ -289,7 +289,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
289289
}
290290
Mutability::Mut => PlaceContext::MutatingUse(MutatingUseContext::AddressOf),
291291
};
292-
self.visit_place_base(&place.local, ctx, location);
292+
self.visit_local(&place.local, ctx, location);
293293
self.visit_projection(place.local, reborrowed_proj, ctx, location);
294294
return;
295295
}
@@ -386,14 +386,13 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
386386
}
387387
}
388388

389-
fn visit_place_base(&mut self, place_local: &Local, context: PlaceContext, location: Location) {
389+
fn visit_local(&mut self, place_local: &Local, context: PlaceContext, location: Location) {
390390
trace!(
391-
"visit_place_base: place_local={:?} context={:?} location={:?}",
391+
"visit_local: place_local={:?} context={:?} location={:?}",
392392
place_local,
393393
context,
394394
location,
395395
);
396-
self.super_place_base(place_local, context, location);
397396
}
398397

399398
fn visit_operand(&mut self, op: &Operand<'tcx>, location: Location) {
@@ -478,14 +477,24 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
478477
StatementKind::Assign(..) | StatementKind::SetDiscriminant { .. } => {
479478
self.super_statement(statement, location);
480479
}
481-
StatementKind::FakeRead(FakeReadCause::ForMatchedPlace, _) => {
480+
481+
StatementKind::FakeRead(
482+
FakeReadCause::ForMatchedPlace
483+
| FakeReadCause::ForMatchGuard
484+
| FakeReadCause::ForGuardBinding,
485+
_,
486+
) => {
487+
self.super_statement(statement, location);
482488
self.check_op(ops::IfOrMatch);
483489
}
484-
// FIXME(eddyb) should these really do nothing?
485-
StatementKind::FakeRead(..)
490+
StatementKind::LlvmInlineAsm { .. } => {
491+
self.super_statement(statement, location);
492+
self.check_op(ops::InlineAsm);
493+
}
494+
495+
StatementKind::FakeRead(FakeReadCause::ForLet | FakeReadCause::ForIndex, _)
486496
| StatementKind::StorageLive(_)
487497
| StatementKind::StorageDead(_)
488-
| StatementKind::LlvmInlineAsm { .. }
489498
| StatementKind::Retag { .. }
490499
| StatementKind::AscribeUserType(..)
491500
| StatementKind::Nop => {}
@@ -572,7 +581,19 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> {
572581
}
573582
}
574583

575-
_ => {}
584+
// FIXME: Some of these are only caught by `min_const_fn`, but should error here
585+
// instead.
586+
TerminatorKind::Abort
587+
| TerminatorKind::Assert { .. }
588+
| TerminatorKind::FalseEdges { .. }
589+
| TerminatorKind::FalseUnwind { .. }
590+
| TerminatorKind::GeneratorDrop
591+
| TerminatorKind::Goto { .. }
592+
| TerminatorKind::Resume
593+
| TerminatorKind::Return
594+
| TerminatorKind::SwitchInt { .. }
595+
| TerminatorKind::Unreachable
596+
| TerminatorKind::Yield { .. } => {}
576597
}
577598
}
578599
}

Diff for: src/librustc_mir/transform/generator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl<'tcx> MutVisitor<'tcx> for DerefArgVisitor<'tcx> {
115115
self.tcx,
116116
);
117117
} else {
118-
self.visit_place_base(&mut place.local, context, location);
118+
self.visit_local(&mut place.local, context, location);
119119

120120
for elem in place.projection.iter() {
121121
if let PlaceElem::Index(local) = elem {
@@ -154,7 +154,7 @@ impl<'tcx> MutVisitor<'tcx> for PinArgVisitor<'tcx> {
154154
self.tcx,
155155
);
156156
} else {
157-
self.visit_place_base(&mut place.local, context, location);
157+
self.visit_local(&mut place.local, context, location);
158158

159159
for elem in place.projection.iter() {
160160
if let PlaceElem::Index(local) = elem {

Diff for: src/test/ui/consts/inline_asm.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#![feature(llvm_asm)]
2+
3+
const _: () = unsafe { llvm_asm!("nop") };
4+
//~^ ERROR contains unimplemented expression type
5+
6+
fn main() {}

Diff for: src/test/ui/consts/inline_asm.stderr

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0019]: constant contains unimplemented expression type
2+
--> $DIR/inline_asm.rs:3:24
3+
|
4+
LL | const _: () = unsafe { llvm_asm!("nop") };
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0019`.

Diff for: src/test/ui/consts/miri_unleashed/inline_asm.rs

+2
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,6 @@ static TEST_BAD: () = {
1111
//~^ ERROR could not evaluate static initializer
1212
//~| NOTE in this expansion of llvm_asm!
1313
//~| NOTE inline assembly is not supported
14+
//~| WARN skipping const checks
15+
//~| NOTE in this expansion of llvm_asm!
1416
};

Diff for: src/test/ui/consts/miri_unleashed/inline_asm.stderr

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
warning: skipping const checks
2+
--> $DIR/inline_asm.rs:10:14
3+
|
4+
LL | unsafe { llvm_asm!("xor %eax, %eax" ::: "eax"); }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: this warning originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
8+
19
error[E0080]: could not evaluate static initializer
210
--> $DIR/inline_asm.rs:10:14
311
|
@@ -6,6 +14,6 @@ LL | unsafe { llvm_asm!("xor %eax, %eax" ::: "eax"); }
614
|
715
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
816

9-
error: aborting due to previous error
17+
error: aborting due to previous error; 1 warning emitted
1018

1119
For more information about this error, try `rustc --explain E0080`.

Diff for: src/test/ui/label/label_break_value_continue.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ LL | continue;
2121

2222
error: aborting due to 3 previous errors
2323

24-
For more information about this error, try `rustc --explain E0695`.
24+
Some errors have detailed explanations: E0695, E0696.
25+
For more information about an error, try `rustc --explain E0695`.

0 commit comments

Comments
 (0)