mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-02 10:18:25 +00:00
Loop check anon consts on their own
This commit is contained in:
parent
1b9d38dd08
commit
7f4093e78b
@ -191,12 +191,7 @@ fn typeck_with_inspect<'tcx>(
|
||||
tcx.type_of(def_id).instantiate_identity()
|
||||
};
|
||||
|
||||
// TODO: anon consts are currently loop checked with their containing body, even though
|
||||
// they are typecked on their own.
|
||||
if let DefKind::AssocConst | DefKind::Const | DefKind::Static { .. } = tcx.def_kind(def_id)
|
||||
{
|
||||
loops::check(tcx, def_id, body);
|
||||
}
|
||||
loops::check(tcx, def_id, body);
|
||||
|
||||
let expected_type = fcx.normalize(body.value.span, expected_type);
|
||||
|
||||
|
@ -3,6 +3,7 @@ use std::fmt;
|
||||
|
||||
use Context::*;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_hir::intravisit::{self, Visitor};
|
||||
use rustc_hir::{Destination, Node};
|
||||
@ -72,10 +73,14 @@ struct CheckLoopVisitor<'tcx> {
|
||||
block_breaks: BTreeMap<Span, BlockInfo>,
|
||||
}
|
||||
|
||||
pub(crate) fn check<'tcx>(tcx: TyCtxt<'tcx>, _def_id: LocalDefId, body: &'tcx hir::Body<'tcx>) {
|
||||
pub(crate) fn check<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &'tcx hir::Body<'tcx>) {
|
||||
let mut check =
|
||||
CheckLoopVisitor { tcx, cx_stack: vec![Normal], block_breaks: Default::default() };
|
||||
check.with_context(Fn, |v| v.visit_body(body));
|
||||
let cx = match tcx.def_kind(def_id) {
|
||||
DefKind::AnonConst => AnonConst,
|
||||
_ => Fn,
|
||||
};
|
||||
check.with_context(cx, |v| v.visit_body(body));
|
||||
check.report_outside_loop_error();
|
||||
}
|
||||
|
||||
@ -86,8 +91,8 @@ impl<'hir> Visitor<'hir> for CheckLoopVisitor<'hir> {
|
||||
self.tcx
|
||||
}
|
||||
|
||||
fn visit_anon_const(&mut self, c: &'hir hir::AnonConst) {
|
||||
self.with_context(AnonConst, |v| intravisit::walk_anon_const(v, c));
|
||||
fn visit_anon_const(&mut self, _: &'hir hir::AnonConst) {
|
||||
// Typecked on its own.
|
||||
}
|
||||
|
||||
fn visit_inline_const(&mut self, c: &'hir hir::ConstBlock) {
|
||||
|
@ -10,17 +10,6 @@ error[E0268]: `break` outside of a loop or labeled block
|
||||
LL | break;
|
||||
| ^^^^^ cannot `break` outside of a loop or labeled block
|
||||
|
||||
error[E0268]: `break` outside of a loop or labeled block
|
||||
--> $DIR/break-inside-inline-const-issue-128604.rs:2:21
|
||||
|
|
||||
LL | let _ = ['a'; { break 2; 1 }];
|
||||
| ^^^^^^^ cannot `break` outside of a loop or labeled block
|
||||
|
|
||||
help: consider labeling this block to be able to break within it
|
||||
|
|
||||
LL | let _ = ['a'; 'block: { break 'block 2; 1 }];
|
||||
| +++++++ ++++++
|
||||
|
||||
error[E0268]: `break` outside of a loop or labeled block
|
||||
--> $DIR/break-inside-inline-const-issue-128604.rs:9:13
|
||||
|
|
||||
@ -34,6 +23,17 @@ LL |
|
||||
LL ~ break 'block;
|
||||
|
|
||||
|
||||
error[E0268]: `break` outside of a loop or labeled block
|
||||
--> $DIR/break-inside-inline-const-issue-128604.rs:2:21
|
||||
|
|
||||
LL | let _ = ['a'; { break 2; 1 }];
|
||||
| ^^^^^^^ cannot `break` outside of a loop or labeled block
|
||||
|
|
||||
help: consider labeling this block to be able to break within it
|
||||
|
|
||||
LL | let _ = ['a'; 'block: { break 'block 2; 1 }];
|
||||
| +++++++ ++++++
|
||||
|
||||
error[E0268]: `break` outside of a loop or labeled block
|
||||
--> $DIR/break-inside-inline-const-issue-128604.rs:27:17
|
||||
|
|
||||
|
@ -1,3 +1,21 @@
|
||||
error[E0571]: `break` with value from a `while` loop
|
||||
--> $DIR/issue-114529-illegal-break-with-value.rs:22:9
|
||||
|
|
||||
LL | while true {
|
||||
| ---------- you can't `break` with a value in a `while` loop
|
||||
LL | / break (|| {
|
||||
LL | | let local = 9;
|
||||
LL | | });
|
||||
| |__________^ can only break with a value inside `loop` or breakable block
|
||||
|
|
||||
help: use `break` on its own without a value inside this `while` loop
|
||||
|
|
||||
LL - break (|| {
|
||||
LL - let local = 9;
|
||||
LL - });
|
||||
LL + break;
|
||||
|
|
||||
|
||||
error[E0571]: `break` with value from a `while` loop
|
||||
--> $DIR/issue-114529-illegal-break-with-value.rs:9:13
|
||||
|
|
||||
@ -26,24 +44,6 @@ LL - break v;
|
||||
LL + break;
|
||||
|
|
||||
|
||||
error[E0571]: `break` with value from a `while` loop
|
||||
--> $DIR/issue-114529-illegal-break-with-value.rs:22:9
|
||||
|
|
||||
LL | while true {
|
||||
| ---------- you can't `break` with a value in a `while` loop
|
||||
LL | / break (|| {
|
||||
LL | | let local = 9;
|
||||
LL | | });
|
||||
| |__________^ can only break with a value inside `loop` or breakable block
|
||||
|
|
||||
help: use `break` on its own without a value inside this `while` loop
|
||||
|
|
||||
LL - break (|| {
|
||||
LL - let local = 9;
|
||||
LL - });
|
||||
LL + break;
|
||||
|
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0571`.
|
||||
|
@ -1,9 +1,3 @@
|
||||
error[E0268]: `break` outside of a loop or labeled block
|
||||
--> $DIR/break-inside-unsafe-block-issue-128604.rs:2:28
|
||||
|
|
||||
LL | let a = ["_"; unsafe { break; 1 + 2 }];
|
||||
| ^^^^^ cannot `break` outside of a loop or labeled block
|
||||
|
||||
error[E0268]: `break` outside of a loop or labeled block
|
||||
--> $DIR/break-inside-unsafe-block-issue-128604.rs:14:9
|
||||
|
|
||||
@ -37,6 +31,12 @@ LL | unsafe {
|
||||
LL ~ break 'block;
|
||||
|
|
||||
|
||||
error[E0268]: `break` outside of a loop or labeled block
|
||||
--> $DIR/break-inside-unsafe-block-issue-128604.rs:2:28
|
||||
|
|
||||
LL | let a = ["_"; unsafe { break; 1 + 2 }];
|
||||
| ^^^^^ cannot `break` outside of a loop or labeled block
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0268`.
|
||||
|
Loading…
x
Reference in New Issue
Block a user