Skip to content

Commit

Permalink
Cleaned up unused labels
Browse files Browse the repository at this point in the history
Deleted unused labels from compiler and fixed or allowed
unused labels in tests. This patch removes some gratuitous
unused labels and turns off the warning for unused labels
that are a necessary part of tests.  This will permit
setting the `unused_labels` lint to `warn`.
  • Loading branch information
BartMassey committed Nov 16, 2019
1 parent 1bd30ce commit ed56f86
Show file tree
Hide file tree
Showing 12 changed files with 67 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/librustc/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2557,7 +2557,7 @@ where
'descend_newtypes: while !fat_pointer_layout.ty.is_unsafe_ptr()
&& !fat_pointer_layout.ty.is_region_ptr()
{
'iter_fields: for i in 0..fat_pointer_layout.fields.count() {
for i in 0..fat_pointer_layout.fields.count() {
let field_layout = fat_pointer_layout.field(cx, i);

if !field_layout.is_zst() {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
'descend_newtypes: while !op.layout.ty.is_unsafe_ptr()
&& !op.layout.ty.is_region_ptr()
{
'iter_fields: for i in 0..op.layout.fields.count() {
for i in 0..op.layout.fields.count() {
let field = op.extract_field(&mut bx, i);
if !field.layout.is_zst() {
// we found the one non-zero-sized field that is allowed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl LivenessResults<'me, 'typeck, 'flow, 'tcx> {
// Reverse DFS. But for drops, we do it a bit differently.
// The stack only ever stores *terminators of blocks*. Within
// a block, we walk back the statements in an inner loop.
'next_block: while let Some(term_point) = self.stack.pop() {
while let Some(term_point) = self.stack.pop() {
self.compute_drop_live_points_for_block(mpi, term_point);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/keyword_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ mod as_keyword { }
/// 'outer: for i in 1..=5 {
/// println!("outer iteration (i): {}", i);
///
/// 'inner: for j in 1..=200 {
/// '_inner: for j in 1..=200 {
/// println!(" inner iteration (j): {}", j);
/// if j >= 3 {
/// // breaks from inner loop, let's outer loop continue.
Expand Down Expand Up @@ -178,7 +178,7 @@ mod const_keyword { }
///```rust
/// // Print Odd numbers under 30 with unit <= 5
/// 'tens: for ten in 0..3 {
/// 'units: for unit in 0..=9 {
/// '_units: for unit in 0..=9 {
/// if unit % 2 == 0 {
/// continue;
/// }
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/for-loop-while/label_break_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn label_break_mixed(v: u32) -> u32 {
}
// Labeled breaking an outer loop still works
'd: loop {
'e: {
{
if v == r {
break 'b;
}
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/for-loop-while/loop-label-shadowing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

fn main() {
let mut foo = Vec::new();
#[allow(unused_labels)]
'foo: for i in &[1, 2, 3] {
foo.push(*i);
}
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/hygiene/hygienic-labels-in-let.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// run-pass
#![allow(unreachable_code)]
#![allow(unused_labels)]

// Test that labels injected by macros do not break hygiene. This
// checks cases where the macros invocations are under the rhs of a
Expand Down
56 changes: 28 additions & 28 deletions src/test/ui/hygiene/hygienic-labels-in-let.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:15:9
--> $DIR/hygienic-labels-in-let.rs:16:9
|
LL | 'x: loop { $e }
| ^^ lifetime 'x already in scope
Expand All @@ -11,7 +11,7 @@ LL | loop_x!(break 'x);
| ------------------ in this macro invocation

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:63:9
--> $DIR/hygienic-labels-in-let.rs:64:9
|
LL | 'x: loop {
| -- first declared here
Expand All @@ -20,7 +20,7 @@ LL | 'x: for _ in 0..1 {
| ^^ lifetime 'x already in scope

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:63:9
--> $DIR/hygienic-labels-in-let.rs:64:9
|
LL | 'x: loop { $e }
| -- first declared here
Expand All @@ -29,7 +29,7 @@ LL | 'x: for _ in 0..1 {
| ^^ lifetime 'x already in scope

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:15:9
--> $DIR/hygienic-labels-in-let.rs:16:9
|
LL | 'x: loop { $e }
| ^^ lifetime 'x already in scope
Expand All @@ -41,7 +41,7 @@ LL | loop_x!(break 'x);
| ------------------ in this macro invocation

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:15:9
--> $DIR/hygienic-labels-in-let.rs:16:9
|
LL | 'x: loop { $e }
| ^^
Expand All @@ -53,7 +53,7 @@ LL | loop_x!(break 'x);
| ------------------ in this macro invocation

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:15:9
--> $DIR/hygienic-labels-in-let.rs:16:9
|
LL | 'x: loop { $e }
| ^^ lifetime 'x already in scope
Expand All @@ -65,7 +65,7 @@ LL | loop_x!(break 'x);
| ------------------ in this macro invocation

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:75:9
--> $DIR/hygienic-labels-in-let.rs:76:9
|
LL | 'x: loop {
| -- first declared here
Expand All @@ -74,7 +74,7 @@ LL | 'x: for _ in 0..1 {
| ^^ lifetime 'x already in scope

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:75:9
--> $DIR/hygienic-labels-in-let.rs:76:9
|
LL | 'x: loop { $e }
| -- first declared here
Expand All @@ -83,7 +83,7 @@ LL | 'x: for _ in 0..1 {
| ^^ lifetime 'x already in scope

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:75:9
--> $DIR/hygienic-labels-in-let.rs:76:9
|
LL | 'x: for _ in 0..1 {
| -- first declared here
Expand All @@ -92,7 +92,7 @@ LL | 'x: for _ in 0..1 {
| ^^ lifetime 'x already in scope

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:75:9
--> $DIR/hygienic-labels-in-let.rs:76:9
|
LL | 'x: loop { $e }
| -- first declared here
Expand All @@ -101,7 +101,7 @@ LL | 'x: for _ in 0..1 {
| ^^ lifetime 'x already in scope

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:26:9
--> $DIR/hygienic-labels-in-let.rs:27:9
|
LL | 'x: while 1 + 1 == 2 { $e }
| ^^ lifetime 'x already in scope
Expand All @@ -113,7 +113,7 @@ LL | while_true!(break 'x);
| ---------------------- in this macro invocation

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:26:9
--> $DIR/hygienic-labels-in-let.rs:27:9
|
LL | 'x: loop { $e }
| -- first declared here
Expand All @@ -125,7 +125,7 @@ LL | while_true!(break 'x);
| ---------------------- in this macro invocation

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:26:9
--> $DIR/hygienic-labels-in-let.rs:27:9
|
LL | 'x: while 1 + 1 == 2 { $e }
| ^^ lifetime 'x already in scope
Expand All @@ -137,7 +137,7 @@ LL | while_true!(break 'x);
| ---------------------- in this macro invocation

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:26:9
--> $DIR/hygienic-labels-in-let.rs:27:9
|
LL | 'x: loop { $e }
| -- first declared here
Expand All @@ -149,7 +149,7 @@ LL | while_true!(break 'x);
| ---------------------- in this macro invocation

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:26:9
--> $DIR/hygienic-labels-in-let.rs:27:9
|
LL | 'x: while 1 + 1 == 2 { $e }
| ^^ lifetime 'x already in scope
Expand All @@ -161,7 +161,7 @@ LL | while_true!(break 'x);
| ---------------------- in this macro invocation

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:89:9
--> $DIR/hygienic-labels-in-let.rs:90:9
|
LL | 'x: loop {
| -- first declared here
Expand All @@ -170,7 +170,7 @@ LL | 'x: for _ in 0..1 {
| ^^ lifetime 'x already in scope

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:89:9
--> $DIR/hygienic-labels-in-let.rs:90:9
|
LL | 'x: loop { $e }
| -- first declared here
Expand All @@ -179,7 +179,7 @@ LL | 'x: for _ in 0..1 {
| ^^ lifetime 'x already in scope

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:89:9
--> $DIR/hygienic-labels-in-let.rs:90:9
|
LL | 'x: for _ in 0..1 {
| -- first declared here
Expand All @@ -188,7 +188,7 @@ LL | 'x: for _ in 0..1 {
| ^^ lifetime 'x already in scope

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:89:9
--> $DIR/hygienic-labels-in-let.rs:90:9
|
LL | 'x: loop { $e }
| -- first declared here
Expand All @@ -197,7 +197,7 @@ LL | 'x: for _ in 0..1 {
| ^^ lifetime 'x already in scope

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:89:9
--> $DIR/hygienic-labels-in-let.rs:90:9
|
LL | 'x: for _ in 0..1 {
| -- first declared here
Expand All @@ -206,7 +206,7 @@ LL | 'x: for _ in 0..1 {
| ^^ lifetime 'x already in scope

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:89:9
--> $DIR/hygienic-labels-in-let.rs:90:9
|
LL | 'x: while 1 + 1 == 2 { $e }
| -- first declared here
Expand All @@ -215,7 +215,7 @@ LL | 'x: for _ in 0..1 {
| ^^ lifetime 'x already in scope

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:38:9
--> $DIR/hygienic-labels-in-let.rs:39:9
|
LL | 'x: for _ in 0..1 { $e }
| ^^ lifetime 'x already in scope
Expand All @@ -227,7 +227,7 @@ LL | run_once!(continue 'x);
| ----------------------- in this macro invocation

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:38:9
--> $DIR/hygienic-labels-in-let.rs:39:9
|
LL | 'x: loop { $e }
| -- first declared here
Expand All @@ -239,7 +239,7 @@ LL | run_once!(continue 'x);
| ----------------------- in this macro invocation

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:38:9
--> $DIR/hygienic-labels-in-let.rs:39:9
|
LL | 'x: for _ in 0..1 { $e }
| ^^ lifetime 'x already in scope
Expand All @@ -251,7 +251,7 @@ LL | run_once!(continue 'x);
| ----------------------- in this macro invocation

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:38:9
--> $DIR/hygienic-labels-in-let.rs:39:9
|
LL | 'x: loop { $e }
| -- first declared here
Expand All @@ -263,7 +263,7 @@ LL | run_once!(continue 'x);
| ----------------------- in this macro invocation

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:38:9
--> $DIR/hygienic-labels-in-let.rs:39:9
|
LL | 'x: for _ in 0..1 { $e }
| ^^ lifetime 'x already in scope
Expand All @@ -275,7 +275,7 @@ LL | run_once!(continue 'x);
| ----------------------- in this macro invocation

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:38:9
--> $DIR/hygienic-labels-in-let.rs:39:9
|
LL | 'x: while 1 + 1 == 2 { $e }
| -- first declared here
Expand All @@ -287,7 +287,7 @@ LL | run_once!(continue 'x);
| ----------------------- in this macro invocation

warning: label name `'x` shadows a label name that is already in scope
--> $DIR/hygienic-labels-in-let.rs:38:9
--> $DIR/hygienic-labels-in-let.rs:39:9
|
LL | 'x: for _ in 0..1 { $e }
| ^^ lifetime 'x already in scope
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/hygiene/hygienic-labels.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// run-pass
#![allow(unreachable_code)]
#![allow(unused_labels)]
// Test that labels injected by macros do not break hygiene.

// Issue #24278: The label/lifetime shadowing checker from #24162
Expand Down
Loading

0 comments on commit ed56f86

Please sign in to comment.