From da25af2940f44f841f91ba038535e8e84c4893f3 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Tue, 17 Aug 2021 13:55:31 -0700 Subject: [PATCH 01/36] Make spans for tuple patterns in E0023 more precise As suggested in #86307. --- compiler/rustc_typeck/src/check/pat.rs | 6 ++- .../tuple_struct_destructure_fail.stderr | 24 +++++++---- src/test/ui/error-codes/E0023.stderr | 30 ++++++++----- src/test/ui/issues/issue-72574-2.stderr | 6 ++- .../match/match-pattern-field-mismatch.stderr | 6 ++- ...7-pat-tup-scrut-ty-diff-less-fields.stderr | 6 ++- src/test/ui/pattern/issue-74539.stderr | 6 ++- .../ui/pattern/pat-tuple-overfield.stderr | 12 ++++-- .../ui/pattern/pat-tuple-underfield.stderr | 42 ++++++++++++------- .../ui/pattern/pattern-error-continue.stderr | 6 ++- 10 files changed, 96 insertions(+), 48 deletions(-) diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index dae574bb7bf0f..2ef79c7686c51 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -990,10 +990,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) { let subpats_ending = pluralize!(subpats.len()); let fields_ending = pluralize!(fields.len()); + let fields_span = pat_span.trim_start(qpath.span()).unwrap_or(pat_span); let res_span = self.tcx.def_span(res.def_id()); let mut err = struct_span_err!( self.tcx.sess, - pat_span, + fields_span, E0023, "this pattern has {} field{}, but the corresponding {} has {} field{}", subpats.len(), @@ -1003,9 +1004,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fields_ending, ); err.span_label( - pat_span, + fields_span, format!("expected {} field{}, found {}", fields.len(), fields_ending, subpats.len(),), ) + .span_label(qpath.span(), format!("this {}", res.descr())) .span_label(res_span, format!("{} defined here", res.descr())); // Identify the case `Some(x, y)` where the expected type is e.g. `Option<(T, U)>`. diff --git a/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr b/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr index 0e92cc5c9f282..ec7d76f4fe523 100644 --- a/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr +++ b/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr @@ -15,22 +15,26 @@ LL | Enum::SingleVariant(a, .., b, ..) = Enum::SingleVariant(0, 1); | previously used here error[E0023]: this pattern has 3 fields, but the corresponding tuple struct has 2 fields - --> $DIR/tuple_struct_destructure_fail.rs:30:5 + --> $DIR/tuple_struct_destructure_fail.rs:30:16 | LL | struct TupleStruct(S, T); | ------------------------------- tuple struct defined here ... LL | TupleStruct(a, a, b) = TupleStruct(1, 2); - | ^^^^^^^^^^^^^^^^^^^^ expected 2 fields, found 3 + | -----------^^^^^^^^^ expected 2 fields, found 3 + | | + | this tuple struct error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields - --> $DIR/tuple_struct_destructure_fail.rs:32:5 + --> $DIR/tuple_struct_destructure_fail.rs:32:16 | LL | struct TupleStruct(S, T); | ------------------------------- tuple struct defined here ... LL | TupleStruct(_) = TupleStruct(1, 2); - | ^^^^^^^^^^^^^^ expected 2 fields, found 1 + | -----------^^^ expected 2 fields, found 1 + | | + | this tuple struct | help: use `_` to explicitly ignore each field | @@ -42,22 +46,26 @@ LL | TupleStruct(..) = TupleStruct(1, 2); | ~~ error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields - --> $DIR/tuple_struct_destructure_fail.rs:34:5 + --> $DIR/tuple_struct_destructure_fail.rs:34:24 | LL | SingleVariant(S, T) | ------------------- tuple variant defined here ... LL | Enum::SingleVariant(a, a, b) = Enum::SingleVariant(1, 2); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 2 fields, found 3 + | -------------------^^^^^^^^^ expected 2 fields, found 3 + | | + | this tuple variant error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/tuple_struct_destructure_fail.rs:36:5 + --> $DIR/tuple_struct_destructure_fail.rs:36:24 | LL | SingleVariant(S, T) | ------------------- tuple variant defined here ... LL | Enum::SingleVariant(_) = Enum::SingleVariant(1, 2); - | ^^^^^^^^^^^^^^^^^^^^^^ expected 2 fields, found 1 + | -------------------^^^ expected 2 fields, found 1 + | | + | this tuple variant | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/error-codes/E0023.stderr b/src/test/ui/error-codes/E0023.stderr index ec3aae2971410..ecc075b6fb4b5 100644 --- a/src/test/ui/error-codes/E0023.stderr +++ b/src/test/ui/error-codes/E0023.stderr @@ -1,11 +1,13 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/E0023.rs:11:9 + --> $DIR/E0023.rs:11:21 | LL | Apple(String, String), | --------------------- tuple variant defined here ... LL | Fruit::Apple(a) => {}, - | ^^^^^^^^^^^^^^^ expected 2 fields, found 1 + | ------------^^^ expected 2 fields, found 1 + | | + | this tuple variant | help: use `_` to explicitly ignore each field | @@ -13,31 +15,37 @@ LL | Fruit::Apple(a, _) => {}, | +++ error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields - --> $DIR/E0023.rs:12:9 + --> $DIR/E0023.rs:12:21 | LL | Apple(String, String), | --------------------- tuple variant defined here ... LL | Fruit::Apple(a, b, c) => {}, - | ^^^^^^^^^^^^^^^^^^^^^ expected 2 fields, found 3 + | ------------^^^^^^^^^ expected 2 fields, found 3 + | | + | this tuple variant error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 1 field - --> $DIR/E0023.rs:13:9 + --> $DIR/E0023.rs:13:20 | LL | Pear(u32), | --------- tuple variant defined here ... LL | Fruit::Pear(1, 2) => {}, - | ^^^^^^^^^^^^^^^^^ expected 1 field, found 2 + | -----------^^^^^^ expected 1 field, found 2 + | | + | this tuple variant error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 1 field - --> $DIR/E0023.rs:14:9 + --> $DIR/E0023.rs:14:22 | LL | Orange((String, String)), | ------------------------ tuple variant defined here ... LL | Fruit::Orange(a, b) => {}, - | ^^^^^^^^^^^^^^^^^^^ expected 1 field, found 2 + | -------------^^^^^^ expected 1 field, found 2 + | | + | this tuple variant | help: missing parentheses | @@ -45,13 +53,15 @@ LL | Fruit::Orange((a, b)) => {}, | + + error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 1 field - --> $DIR/E0023.rs:15:9 + --> $DIR/E0023.rs:15:22 | LL | Banana(()), | ---------- tuple variant defined here ... LL | Fruit::Banana() => {}, - | ^^^^^^^^^^^^^^^ expected 1 field, found 0 + | -------------^^ expected 1 field, found 0 + | | + | this tuple variant | help: missing parentheses | diff --git a/src/test/ui/issues/issue-72574-2.stderr b/src/test/ui/issues/issue-72574-2.stderr index 928fa58b17556..4c38d2c31ed68 100644 --- a/src/test/ui/issues/issue-72574-2.stderr +++ b/src/test/ui/issues/issue-72574-2.stderr @@ -19,13 +19,15 @@ LL | Binder(_a, _x @ ..) => {} = note: only allowed in tuple, tuple struct, and slice patterns error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 3 fields - --> $DIR/issue-72574-2.rs:6:9 + --> $DIR/issue-72574-2.rs:6:15 | LL | struct Binder(i32, i32, i32); | ----------------------------- tuple struct defined here ... LL | Binder(_a, _x @ ..) => {} - | ^^^^^^^^^^^^^^^^^^^ expected 3 fields, found 2 + | ------^^^^^^^^^^^^^ expected 3 fields, found 2 + | | + | this tuple struct | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/match/match-pattern-field-mismatch.stderr b/src/test/ui/match/match-pattern-field-mismatch.stderr index e34164ec0db24..776cdfc7083bb 100644 --- a/src/test/ui/match/match-pattern-field-mismatch.stderr +++ b/src/test/ui/match/match-pattern-field-mismatch.stderr @@ -1,11 +1,13 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 3 fields - --> $DIR/match-pattern-field-mismatch.rs:10:11 + --> $DIR/match-pattern-field-mismatch.rs:10:21 | LL | Rgb(usize, usize, usize), | ------------------------ tuple variant defined here ... LL | Color::Rgb(_, _) => { } - | ^^^^^^^^^^^^^^^^ expected 3 fields, found 2 + | ----------^^^^^^ expected 3 fields, found 2 + | | + | this tuple variant | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr b/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr index 7f5da8f3c2dcc..ea5f970d1d659 100644 --- a/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr +++ b/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr @@ -10,13 +10,15 @@ LL | let P() = U {}; found struct `P<_>` error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 1 field - --> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:9 + --> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:10 | LL | struct P(T); // 1 type parameter wanted | --------------- tuple struct defined here ... LL | let P() = U {}; - | ^^^ expected 1 field, found 0 + | -^^ expected 1 field, found 0 + | | + | this tuple struct | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/issue-74539.stderr b/src/test/ui/pattern/issue-74539.stderr index 7d998af7fb388..87c3842d28f4e 100644 --- a/src/test/ui/pattern/issue-74539.stderr +++ b/src/test/ui/pattern/issue-74539.stderr @@ -19,13 +19,15 @@ LL | E::A(x @ ..) => { = note: only allowed in tuple, tuple struct, and slice patterns error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/issue-74539.rs:8:9 + --> $DIR/issue-74539.rs:8:13 | LL | A(u8, u8), | --------- tuple variant defined here ... LL | E::A(x @ ..) => { - | ^^^^^^^^^^^^ expected 2 fields, found 1 + | ----^^^^^^^^ expected 2 fields, found 1 + | | + | this tuple variant | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/pat-tuple-overfield.stderr b/src/test/ui/pattern/pat-tuple-overfield.stderr index 45b6fd1b4d445..e0386d9cd4ffc 100644 --- a/src/test/ui/pattern/pat-tuple-overfield.stderr +++ b/src/test/ui/pattern/pat-tuple-overfield.stderr @@ -22,22 +22,26 @@ LL | (1, 2, .., 3, 4) => {} found tuple `(_, _, _, _)` error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-overfield.rs:10:9 + --> $DIR/pat-tuple-overfield.rs:10:10 | LL | struct S(u8, u8, u8); | --------------------- tuple struct defined here ... LL | S(1, 2, 3, 4) => {} - | ^^^^^^^^^^^^^ expected 3 fields, found 4 + | -^^^^^^^^^^^^ expected 3 fields, found 4 + | | + | this tuple struct error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-overfield.rs:12:9 + --> $DIR/pat-tuple-overfield.rs:12:10 | LL | struct S(u8, u8, u8); | --------------------- tuple struct defined here ... LL | S(1, 2, .., 3, 4) => {} - | ^^^^^^^^^^^^^^^^^ expected 3 fields, found 4 + | -^^^^^^^^^^^^^^^^ expected 3 fields, found 4 + | | + | this tuple struct error: aborting due to 4 previous errors diff --git a/src/test/ui/pattern/pat-tuple-underfield.stderr b/src/test/ui/pattern/pat-tuple-underfield.stderr index 2fbcb6d67ba36..4cc20a4ac0ef7 100644 --- a/src/test/ui/pattern/pat-tuple-underfield.stderr +++ b/src/test/ui/pattern/pat-tuple-underfield.stderr @@ -8,13 +8,15 @@ LL | E::S => {} | ^^^^ help: use the tuple variant pattern syntax instead: `E::S(_, _)` error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields - --> $DIR/pat-tuple-underfield.rs:9:9 + --> $DIR/pat-tuple-underfield.rs:9:10 | LL | struct S(i32, f32); | ------------------- tuple struct defined here ... LL | S(x) => {} - | ^^^^ expected 2 fields, found 1 + | -^^^ expected 2 fields, found 1 + | | + | this tuple struct | help: use `_` to explicitly ignore each field | @@ -22,13 +24,15 @@ LL | S(x, _) => {} | +++ error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields - --> $DIR/pat-tuple-underfield.rs:14:9 + --> $DIR/pat-tuple-underfield.rs:14:10 | LL | struct S(i32, f32); | ------------------- tuple struct defined here ... LL | S(_) => {} - | ^^^^ expected 2 fields, found 1 + | -^^^ expected 2 fields, found 1 + | | + | this tuple struct | help: use `_` to explicitly ignore each field | @@ -40,13 +44,15 @@ LL | S(..) => {} | ~~ error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 2 fields - --> $DIR/pat-tuple-underfield.rs:20:9 + --> $DIR/pat-tuple-underfield.rs:20:10 | LL | struct S(i32, f32); | ------------------- tuple struct defined here ... LL | S() => {} - | ^^^ expected 2 fields, found 0 + | -^^ expected 2 fields, found 0 + | | + | this tuple struct | help: use `_` to explicitly ignore each field | @@ -58,13 +64,15 @@ LL | S(..) => {} | ++ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/pat-tuple-underfield.rs:27:9 + --> $DIR/pat-tuple-underfield.rs:27:13 | LL | S(i32, f32), | ----------- tuple variant defined here ... LL | E::S(x) => {} - | ^^^^^^^ expected 2 fields, found 1 + | ----^^^ expected 2 fields, found 1 + | | + | this tuple variant | help: use `_` to explicitly ignore each field | @@ -72,13 +80,15 @@ LL | E::S(x, _) => {} | +++ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/pat-tuple-underfield.rs:32:9 + --> $DIR/pat-tuple-underfield.rs:32:13 | LL | S(i32, f32), | ----------- tuple variant defined here ... LL | E::S(_) => {} - | ^^^^^^^ expected 2 fields, found 1 + | ----^^^ expected 2 fields, found 1 + | | + | this tuple variant | help: use `_` to explicitly ignore each field | @@ -90,13 +100,15 @@ LL | E::S(..) => {} | ~~ error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 2 fields - --> $DIR/pat-tuple-underfield.rs:38:9 + --> $DIR/pat-tuple-underfield.rs:38:13 | LL | S(i32, f32), | ----------- tuple variant defined here ... LL | E::S() => {} - | ^^^^^^ expected 2 fields, found 0 + | ----^^ expected 2 fields, found 0 + | | + | this tuple variant | help: use `_` to explicitly ignore each field | @@ -108,13 +120,15 @@ LL | E::S(..) => {} | ++ error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 4 fields - --> $DIR/pat-tuple-underfield.rs:50:9 + --> $DIR/pat-tuple-underfield.rs:50:15 | LL | struct Point4(i32, i32, i32, i32); | ---------------------------------- tuple struct defined here ... LL | Point4( a , _ ) => {} - | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 4 fields, found 2 + | ------^^^^^^^^^^^^^^^^^^^^ expected 4 fields, found 2 + | | + | this tuple struct | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/pattern-error-continue.stderr b/src/test/ui/pattern/pattern-error-continue.stderr index 3f28ffed29162..216c3ca47d393 100644 --- a/src/test/ui/pattern/pattern-error-continue.stderr +++ b/src/test/ui/pattern/pattern-error-continue.stderr @@ -26,13 +26,15 @@ LL | A::B(_) => (), | ~ error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields - --> $DIR/pattern-error-continue.rs:17:9 + --> $DIR/pattern-error-continue.rs:17:13 | LL | B(isize, isize), | --------------- tuple variant defined here ... LL | A::B(_, _, _) => (), - | ^^^^^^^^^^^^^ expected 2 fields, found 3 + | ----^^^^^^^^^ expected 2 fields, found 3 + | | + | this tuple variant error[E0308]: mismatched types --> $DIR/pattern-error-continue.rs:22:9 From f1e860757e9494c82450c100a9ce5240858b537b Mon Sep 17 00:00:00 2001 From: Kornel Date: Sat, 21 Aug 2021 23:40:02 +0100 Subject: [PATCH 02/36] Don't stabilize creation of TryReserveError instances --- library/alloc/src/collections/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/alloc/src/collections/mod.rs b/library/alloc/src/collections/mod.rs index 0d442011921ba..4e31df8b4b8c2 100644 --- a/library/alloc/src/collections/mod.rs +++ b/library/alloc/src/collections/mod.rs @@ -117,12 +117,12 @@ impl From for TryReserveError { } } -#[unstable(feature = "try_reserve", reason = "new API", issue = "48043")] -impl From for TryReserveError { +#[unstable(feature = "try_reserve_kind", reason = "new API", issue = "48043")] +impl From for TryReserveErrorKind { /// Always evaluates to [`TryReserveErrorKind::CapacityOverflow`]. #[inline] fn from(_: LayoutError) -> Self { - TryReserveErrorKind::CapacityOverflow.into() + TryReserveErrorKind::CapacityOverflow } } From d0b482a27c1a347eac366bde82340e527c6cecf8 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Wed, 18 Aug 2021 16:13:25 -0700 Subject: [PATCH 03/36] Add more tuple pattern too many fields test cases --- src/test/ui/pattern/pat-tuple-overfield.rs | 42 ++++ .../ui/pattern/pat-tuple-overfield.stderr | 222 +++++++++++++++++- 2 files changed, 258 insertions(+), 6 deletions(-) diff --git a/src/test/ui/pattern/pat-tuple-overfield.rs b/src/test/ui/pattern/pat-tuple-overfield.rs index 46a5e15ffa52c..dd0548a088c72 100644 --- a/src/test/ui/pattern/pat-tuple-overfield.rs +++ b/src/test/ui/pattern/pat-tuple-overfield.rs @@ -1,4 +1,18 @@ struct S(u8, u8, u8); +struct M( + u8, + u8, + u8, + u8, + u8, +); + +struct Z0; +struct Z1(); +enum E1 { + Z0, + Z1(), +} fn main() { match (1, 2, 3) { @@ -13,4 +27,32 @@ fn main() { //~^ ERROR this pattern has 4 fields, but the corresponding tuple struct has 3 fields _ => {} } + match M(1, 2, 3, 4, 5) { + M(1, 2, 3, 4, 5, 6) => {} + //~^ ERROR this pattern has 6 fields, but the corresponding tuple struct has 5 fields + } + match Z0 { + Z0 => {} + Z0() => {} //~ ERROR expected tuple struct or tuple variant, found unit struct `Z0` + Z0(_) => {} //~ ERROR expected tuple struct or tuple variant, found unit struct `Z0` + Z0(_, _) => {} //~ ERROR expected tuple struct or tuple variant, found unit struct `Z0` + } + match Z1() { + Z1 => {} //~ ERROR match bindings cannot shadow tuple structs + Z1() => {} + Z1(_) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple struct has 0 fields + Z1(_, _) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple struct has 0 fields + } + match E1::Z0 { + E1::Z0 => {} + E1::Z0() => {} //~ ERROR expected tuple struct or tuple variant, found unit variant `E1::Z0` + E1::Z0(_) => {} //~ ERROR expected tuple struct or tuple variant, found unit variant `E1::Z0` + E1::Z0(_, _) => {} //~ ERROR expected tuple struct or tuple variant, found unit variant `E1::Z0` + } + match E1::Z1() { + E1::Z1 => {} //~ ERROR expected unit struct, unit variant or constant, found tuple variant `E1::Z1` + E1::Z1() => {} + E1::Z1(_) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple variant has 0 fields + E1::Z1(_, _) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple variant has 0 fields + } } diff --git a/src/test/ui/pattern/pat-tuple-overfield.stderr b/src/test/ui/pattern/pat-tuple-overfield.stderr index e0386d9cd4ffc..cc4ca4326eccd 100644 --- a/src/test/ui/pattern/pat-tuple-overfield.stderr +++ b/src/test/ui/pattern/pat-tuple-overfield.stderr @@ -1,5 +1,154 @@ +error[E0530]: match bindings cannot shadow tuple structs + --> $DIR/pat-tuple-overfield.rs:43:9 + | +LL | struct Z1(); + | ------------ the tuple struct `Z1` is defined here +... +LL | Z1 => {} + | ^^ cannot be named the same as a tuple struct + +error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` + --> $DIR/pat-tuple-overfield.rs:38:9 + | +LL | struct Z0; + | ---------- `Z0` defined here +LL | struct Z1(); + | ------------ similarly named tuple struct `Z1` defined here +... +LL | Z0() => {} + | ^^^^ + | +help: use this syntax instead + | +LL | Z0 => {} + | ~~ +help: a tuple struct with a similar name exists + | +LL | Z1() => {} + | ~~ + +error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` + --> $DIR/pat-tuple-overfield.rs:39:9 + | +LL | struct Z0; + | ---------- `Z0` defined here +LL | struct Z1(); + | ------------ similarly named tuple struct `Z1` defined here +... +LL | Z0(_) => {} + | ^^^^^ + | +help: use this syntax instead + | +LL | Z0 => {} + | ~~ +help: a tuple struct with a similar name exists + | +LL | Z1(_) => {} + | ~~ + +error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` + --> $DIR/pat-tuple-overfield.rs:40:9 + | +LL | struct Z0; + | ---------- `Z0` defined here +LL | struct Z1(); + | ------------ similarly named tuple struct `Z1` defined here +... +LL | Z0(_, _) => {} + | ^^^^^^^^ + | +help: use this syntax instead + | +LL | Z0 => {} + | ~~ +help: a tuple struct with a similar name exists + | +LL | Z1(_, _) => {} + | ~~ + +error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` + --> $DIR/pat-tuple-overfield.rs:50:9 + | +LL | Z0, + | -- `E1::Z0` defined here +LL | Z1(), + | ---- similarly named tuple variant `Z1` defined here +... +LL | E1::Z0() => {} + | ^^^^^^^^ + | +help: use this syntax instead + | +LL | E1::Z0 => {} + | ~~~~~~ +help: a tuple variant with a similar name exists + | +LL | E1::Z1() => {} + | ~~ + +error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` + --> $DIR/pat-tuple-overfield.rs:51:9 + | +LL | Z0, + | -- `E1::Z0` defined here +LL | Z1(), + | ---- similarly named tuple variant `Z1` defined here +... +LL | E1::Z0(_) => {} + | ^^^^^^^^^ + | +help: use this syntax instead + | +LL | E1::Z0 => {} + | ~~~~~~ +help: a tuple variant with a similar name exists + | +LL | E1::Z1(_) => {} + | ~~ + +error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` + --> $DIR/pat-tuple-overfield.rs:52:9 + | +LL | Z0, + | -- `E1::Z0` defined here +LL | Z1(), + | ---- similarly named tuple variant `Z1` defined here +... +LL | E1::Z0(_, _) => {} + | ^^^^^^^^^^^^ + | +help: use this syntax instead + | +LL | E1::Z0 => {} + | ~~~~~~ +help: a tuple variant with a similar name exists + | +LL | E1::Z1(_, _) => {} + | ~~ + +error[E0532]: expected unit struct, unit variant or constant, found tuple variant `E1::Z1` + --> $DIR/pat-tuple-overfield.rs:55:9 + | +LL | Z0, + | -- similarly named unit variant `Z0` defined here +LL | Z1(), + | ---- `E1::Z1` defined here +... +LL | E1::Z1 => {} + | ^^^^^^ + | +help: use the tuple variant pattern syntax instead + | +LL | E1::Z1() => {} + | ~~~~~~~~ +help: a unit variant with a similar name exists + | +LL | E1::Z0 => {} + | ~~ + error[E0308]: mismatched types - --> $DIR/pat-tuple-overfield.rs:5:9 + --> $DIR/pat-tuple-overfield.rs:21:9 | LL | match (1, 2, 3) { | --------- this expression has type `({integer}, {integer}, {integer})` @@ -10,7 +159,7 @@ LL | (1, 2, 3, 4) => {} found tuple `(_, _, _, _)` error[E0308]: mismatched types - --> $DIR/pat-tuple-overfield.rs:6:9 + --> $DIR/pat-tuple-overfield.rs:22:9 | LL | match (1, 2, 3) { | --------- this expression has type `({integer}, {integer}, {integer})` @@ -22,7 +171,7 @@ LL | (1, 2, .., 3, 4) => {} found tuple `(_, _, _, _)` error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-overfield.rs:10:10 + --> $DIR/pat-tuple-overfield.rs:26:10 | LL | struct S(u8, u8, u8); | --------------------- tuple struct defined here @@ -33,7 +182,7 @@ LL | S(1, 2, 3, 4) => {} | this tuple struct error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-overfield.rs:12:10 + --> $DIR/pat-tuple-overfield.rs:28:10 | LL | struct S(u8, u8, u8); | --------------------- tuple struct defined here @@ -43,7 +192,68 @@ LL | S(1, 2, .., 3, 4) => {} | | | this tuple struct -error: aborting due to 4 previous errors +error[E0023]: this pattern has 6 fields, but the corresponding tuple struct has 5 fields + --> $DIR/pat-tuple-overfield.rs:33:10 + | +LL | / struct M( +LL | | u8, +LL | | u8, +LL | | u8, +LL | | u8, +LL | | u8, +LL | | ); + | |__- tuple struct defined here +... +LL | M(1, 2, 3, 4, 5, 6) => {} + | -^^^^^^^^^^^^^^^^^^ expected 5 fields, found 6 + | | + | this tuple struct + +error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 0 fields + --> $DIR/pat-tuple-overfield.rs:45:11 + | +LL | struct Z1(); + | ------------ tuple struct defined here +... +LL | Z1(_) => {} + | --^^^ expected 0 fields, found 1 + | | + | this tuple struct + +error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 0 fields + --> $DIR/pat-tuple-overfield.rs:46:11 + | +LL | struct Z1(); + | ------------ tuple struct defined here +... +LL | Z1(_, _) => {} + | --^^^^^^ expected 0 fields, found 2 + | | + | this tuple struct + +error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 0 fields + --> $DIR/pat-tuple-overfield.rs:57:15 + | +LL | Z1(), + | ---- tuple variant defined here +... +LL | E1::Z1(_) => {} + | ------^^^ expected 0 fields, found 1 + | | + | this tuple variant + +error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 0 fields + --> $DIR/pat-tuple-overfield.rs:58:15 + | +LL | Z1(), + | ---- tuple variant defined here +... +LL | E1::Z1(_, _) => {} + | ------^^^^^^ expected 0 fields, found 2 + | | + | this tuple variant + +error: aborting due to 17 previous errors -Some errors have detailed explanations: E0023, E0308. +Some errors have detailed explanations: E0023, E0308, E0530, E0532. For more information about an error, try `rustc --explain E0023`. From 0fa3b4f940b4705dc5a1089e917f521b093fd0bc Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Wed, 18 Aug 2021 16:13:52 -0700 Subject: [PATCH 04/36] Make E0023 spans even more precise --- compiler/rustc_ty_utils/src/ty.rs | 13 +++- compiler/rustc_typeck/src/check/pat.rs | 39 ++++++++-- .../tuple_struct_destructure_fail.stderr | 32 +++----- src/test/ui/error-codes/E0023.stderr | 36 ++++----- src/test/ui/issues/issue-72574-2.stderr | 8 +- .../match/match-pattern-field-mismatch.stderr | 8 +- ...7-pat-tup-scrut-ty-diff-less-fields.stderr | 4 +- src/test/ui/pattern/issue-74539.stderr | 8 +- .../ui/pattern/pat-tuple-overfield.stderr | 78 ++++++++----------- .../ui/pattern/pat-tuple-underfield.stderr | 48 ++++-------- .../ui/pattern/pattern-error-continue.stderr | 8 +- 11 files changed, 132 insertions(+), 150 deletions(-) diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index b0d644ae028ce..7a6ace070dee5 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -223,7 +223,18 @@ fn associated_items(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AssocItems<'_> { } fn def_ident_span(tcx: TyCtxt<'_>, def_id: DefId) -> Option { - tcx.hir().get_if_local(def_id).and_then(|node| node.ident()).map(|ident| ident.span) + tcx.hir() + .get_if_local(def_id) + .and_then(|node| match node { + // A `Ctor` doesn't have an identifier itself, but its parent + // struct/variant does. Compare with `hir::Map::opt_span`. + hir::Node::Ctor(ctor) => ctor + .ctor_hir_id() + .and_then(|ctor_id| tcx.hir().find(tcx.hir().get_parent_node(ctor_id))) + .and_then(|parent| parent.ident()), + _ => node.ident(), + }) + .map(|ident| ident.span) } /// If the given `DefId` describes an item belonging to a trait, diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index 2ef79c7686c51..341385731e7d2 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -15,7 +15,7 @@ use rustc_span::hygiene::DesugaringKind; use rustc_span::lev_distance::find_best_match_for_name; use rustc_span::source_map::{Span, Spanned}; use rustc_span::symbol::Ident; -use rustc_span::{BytePos, DUMMY_SP}; +use rustc_span::{BytePos, MultiSpan, DUMMY_SP}; use rustc_trait_selection::autoderef::Autoderef; use rustc_trait_selection::traits::{ObligationCause, Pattern}; use ty::VariantDef; @@ -990,11 +990,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) { let subpats_ending = pluralize!(subpats.len()); let fields_ending = pluralize!(fields.len()); - let fields_span = pat_span.trim_start(qpath.span()).unwrap_or(pat_span); + + let subpat_spans = if subpats.is_empty() { + vec![pat_span.trim_start(qpath.span()).unwrap_or(pat_span)] + } else { + subpats.iter().map(|p| p.span).collect() + }; + let last_subpat_span = *subpat_spans.last().unwrap(); let res_span = self.tcx.def_span(res.def_id()); + let def_ident_span = self.tcx.def_ident_span(res.def_id()).unwrap_or(res_span); + let field_def_spans = if fields.is_empty() { + vec![res_span.trim_start(def_ident_span).unwrap_or(res_span)] + } else { + fields.iter().map(|f| f.ident.span).collect() + }; + let last_field_def_span = *field_def_spans.last().unwrap(); + let mut err = struct_span_err!( self.tcx.sess, - fields_span, + MultiSpan::from_spans(subpat_spans.clone()), E0023, "this pattern has {} field{}, but the corresponding {} has {} field{}", subpats.len(), @@ -1004,11 +1018,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fields_ending, ); err.span_label( - fields_span, - format!("expected {} field{}, found {}", fields.len(), fields_ending, subpats.len(),), - ) - .span_label(qpath.span(), format!("this {}", res.descr())) - .span_label(res_span, format!("{} defined here", res.descr())); + last_subpat_span, + &format!("expected {} field{}, found {}", fields.len(), fields_ending, subpats.len()), + ); + err.span_label(qpath.span(), ""); + if self.tcx.sess.source_map().is_multiline(def_ident_span.between(field_def_spans[0])) { + err.span_label(def_ident_span, format!("{} defined here", res.descr())); + } + for span in &field_def_spans[..field_def_spans.len() - 1] { + err.span_label(*span, ""); + } + err.span_label( + last_field_def_span, + &format!("{} has {} field{}", res.descr(), fields.len(), fields_ending), + ); // Identify the case `Some(x, y)` where the expected type is e.g. `Option<(T, U)>`. // More generally, the expected type wants a tuple variant with one field of an diff --git a/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr b/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr index ec7d76f4fe523..9a47ddf047991 100644 --- a/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr +++ b/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr @@ -15,26 +15,22 @@ LL | Enum::SingleVariant(a, .., b, ..) = Enum::SingleVariant(0, 1); | previously used here error[E0023]: this pattern has 3 fields, but the corresponding tuple struct has 2 fields - --> $DIR/tuple_struct_destructure_fail.rs:30:16 + --> $DIR/tuple_struct_destructure_fail.rs:30:17 | LL | struct TupleStruct(S, T); - | ------------------------------- tuple struct defined here + | - - tuple struct has 2 fields ... LL | TupleStruct(a, a, b) = TupleStruct(1, 2); - | -----------^^^^^^^^^ expected 2 fields, found 3 - | | - | this tuple struct + | ----------- ^ ^ ^ expected 2 fields, found 3 error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields - --> $DIR/tuple_struct_destructure_fail.rs:32:16 + --> $DIR/tuple_struct_destructure_fail.rs:32:17 | LL | struct TupleStruct(S, T); - | ------------------------------- tuple struct defined here + | - - tuple struct has 2 fields ... LL | TupleStruct(_) = TupleStruct(1, 2); - | -----------^^^ expected 2 fields, found 1 - | | - | this tuple struct + | ----------- ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -46,26 +42,22 @@ LL | TupleStruct(..) = TupleStruct(1, 2); | ~~ error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields - --> $DIR/tuple_struct_destructure_fail.rs:34:24 + --> $DIR/tuple_struct_destructure_fail.rs:34:25 | LL | SingleVariant(S, T) - | ------------------- tuple variant defined here + | - - tuple variant has 2 fields ... LL | Enum::SingleVariant(a, a, b) = Enum::SingleVariant(1, 2); - | -------------------^^^^^^^^^ expected 2 fields, found 3 - | | - | this tuple variant + | ------------------- ^ ^ ^ expected 2 fields, found 3 error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/tuple_struct_destructure_fail.rs:36:24 + --> $DIR/tuple_struct_destructure_fail.rs:36:25 | LL | SingleVariant(S, T) - | ------------------- tuple variant defined here + | - - tuple variant has 2 fields ... LL | Enum::SingleVariant(_) = Enum::SingleVariant(1, 2); - | -------------------^^^ expected 2 fields, found 1 - | | - | this tuple variant + | ------------------- ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/error-codes/E0023.stderr b/src/test/ui/error-codes/E0023.stderr index ecc075b6fb4b5..85e1b2cb4ceef 100644 --- a/src/test/ui/error-codes/E0023.stderr +++ b/src/test/ui/error-codes/E0023.stderr @@ -1,13 +1,11 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/E0023.rs:11:21 + --> $DIR/E0023.rs:11:22 | LL | Apple(String, String), - | --------------------- tuple variant defined here + | ------ ------ tuple variant has 2 fields ... LL | Fruit::Apple(a) => {}, - | ------------^^^ expected 2 fields, found 1 - | | - | this tuple variant + | ------------ ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -15,37 +13,31 @@ LL | Fruit::Apple(a, _) => {}, | +++ error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields - --> $DIR/E0023.rs:12:21 + --> $DIR/E0023.rs:12:22 | LL | Apple(String, String), - | --------------------- tuple variant defined here + | ------ ------ tuple variant has 2 fields ... LL | Fruit::Apple(a, b, c) => {}, - | ------------^^^^^^^^^ expected 2 fields, found 3 - | | - | this tuple variant + | ------------ ^ ^ ^ expected 2 fields, found 3 error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 1 field - --> $DIR/E0023.rs:13:20 + --> $DIR/E0023.rs:13:21 | LL | Pear(u32), - | --------- tuple variant defined here + | --- tuple variant has 1 field ... LL | Fruit::Pear(1, 2) => {}, - | -----------^^^^^^ expected 1 field, found 2 - | | - | this tuple variant + | ----------- ^ ^ expected 1 field, found 2 error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 1 field - --> $DIR/E0023.rs:14:22 + --> $DIR/E0023.rs:14:23 | LL | Orange((String, String)), - | ------------------------ tuple variant defined here + | ---------------- tuple variant has 1 field ... LL | Fruit::Orange(a, b) => {}, - | -------------^^^^^^ expected 1 field, found 2 - | | - | this tuple variant + | ------------- ^ ^ expected 1 field, found 2 | help: missing parentheses | @@ -56,12 +48,10 @@ error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has --> $DIR/E0023.rs:15:22 | LL | Banana(()), - | ---------- tuple variant defined here + | -- tuple variant has 1 field ... LL | Fruit::Banana() => {}, | -------------^^ expected 1 field, found 0 - | | - | this tuple variant | help: missing parentheses | diff --git a/src/test/ui/issues/issue-72574-2.stderr b/src/test/ui/issues/issue-72574-2.stderr index 4c38d2c31ed68..3f8ff4f0bacd5 100644 --- a/src/test/ui/issues/issue-72574-2.stderr +++ b/src/test/ui/issues/issue-72574-2.stderr @@ -19,15 +19,13 @@ LL | Binder(_a, _x @ ..) => {} = note: only allowed in tuple, tuple struct, and slice patterns error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 3 fields - --> $DIR/issue-72574-2.rs:6:15 + --> $DIR/issue-72574-2.rs:6:16 | LL | struct Binder(i32, i32, i32); - | ----------------------------- tuple struct defined here + | --- --- --- tuple struct has 3 fields ... LL | Binder(_a, _x @ ..) => {} - | ------^^^^^^^^^^^^^ expected 3 fields, found 2 - | | - | this tuple struct + | ------ ^^ ^^^^^^^ expected 3 fields, found 2 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/match/match-pattern-field-mismatch.stderr b/src/test/ui/match/match-pattern-field-mismatch.stderr index 776cdfc7083bb..01d7cf0d054c9 100644 --- a/src/test/ui/match/match-pattern-field-mismatch.stderr +++ b/src/test/ui/match/match-pattern-field-mismatch.stderr @@ -1,13 +1,11 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 3 fields - --> $DIR/match-pattern-field-mismatch.rs:10:21 + --> $DIR/match-pattern-field-mismatch.rs:10:22 | LL | Rgb(usize, usize, usize), - | ------------------------ tuple variant defined here + | ----- ----- ----- tuple variant has 3 fields ... LL | Color::Rgb(_, _) => { } - | ----------^^^^^^ expected 3 fields, found 2 - | | - | this tuple variant + | ---------- ^ ^ expected 3 fields, found 2 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr b/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr index ea5f970d1d659..c87b70625b40e 100644 --- a/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr +++ b/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr @@ -13,12 +13,10 @@ error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has --> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:10 | LL | struct P(T); // 1 type parameter wanted - | --------------- tuple struct defined here + | - tuple struct has 1 field ... LL | let P() = U {}; | -^^ expected 1 field, found 0 - | | - | this tuple struct | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/issue-74539.stderr b/src/test/ui/pattern/issue-74539.stderr index 87c3842d28f4e..d7cbcf2cfa109 100644 --- a/src/test/ui/pattern/issue-74539.stderr +++ b/src/test/ui/pattern/issue-74539.stderr @@ -19,15 +19,13 @@ LL | E::A(x @ ..) => { = note: only allowed in tuple, tuple struct, and slice patterns error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/issue-74539.rs:8:13 + --> $DIR/issue-74539.rs:8:14 | LL | A(u8, u8), - | --------- tuple variant defined here + | -- -- tuple variant has 2 fields ... LL | E::A(x @ ..) => { - | ----^^^^^^^^ expected 2 fields, found 1 - | | - | this tuple variant + | ---- ^^^^^^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/pat-tuple-overfield.stderr b/src/test/ui/pattern/pat-tuple-overfield.stderr index cc4ca4326eccd..1df9c1c11b8a5 100644 --- a/src/test/ui/pattern/pat-tuple-overfield.stderr +++ b/src/test/ui/pattern/pat-tuple-overfield.stderr @@ -171,87 +171,77 @@ LL | (1, 2, .., 3, 4) => {} found tuple `(_, _, _, _)` error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-overfield.rs:26:10 + --> $DIR/pat-tuple-overfield.rs:26:11 | LL | struct S(u8, u8, u8); - | --------------------- tuple struct defined here + | -- -- -- tuple struct has 3 fields ... LL | S(1, 2, 3, 4) => {} - | -^^^^^^^^^^^^ expected 3 fields, found 4 - | | - | this tuple struct + | - ^ ^ ^ ^ expected 3 fields, found 4 error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-overfield.rs:28:10 + --> $DIR/pat-tuple-overfield.rs:28:11 | LL | struct S(u8, u8, u8); - | --------------------- tuple struct defined here + | -- -- -- tuple struct has 3 fields ... LL | S(1, 2, .., 3, 4) => {} - | -^^^^^^^^^^^^^^^^ expected 3 fields, found 4 - | | - | this tuple struct + | - ^ ^ ^ ^ expected 3 fields, found 4 error[E0023]: this pattern has 6 fields, but the corresponding tuple struct has 5 fields - --> $DIR/pat-tuple-overfield.rs:33:10 - | -LL | / struct M( -LL | | u8, -LL | | u8, -LL | | u8, -LL | | u8, -LL | | u8, -LL | | ); - | |__- tuple struct defined here + --> $DIR/pat-tuple-overfield.rs:33:11 + | +LL | struct M( + | - tuple struct defined here +LL | u8, + | -- +LL | u8, + | -- +LL | u8, + | -- +LL | u8, + | -- +LL | u8, + | -- tuple struct has 5 fields ... -LL | M(1, 2, 3, 4, 5, 6) => {} - | -^^^^^^^^^^^^^^^^^^ expected 5 fields, found 6 - | | - | this tuple struct +LL | M(1, 2, 3, 4, 5, 6) => {} + | - ^ ^ ^ ^ ^ ^ expected 5 fields, found 6 error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 0 fields - --> $DIR/pat-tuple-overfield.rs:45:11 + --> $DIR/pat-tuple-overfield.rs:45:12 | LL | struct Z1(); - | ------------ tuple struct defined here + | --- tuple struct has 0 fields ... LL | Z1(_) => {} - | --^^^ expected 0 fields, found 1 - | | - | this tuple struct + | -- ^ expected 0 fields, found 1 error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 0 fields - --> $DIR/pat-tuple-overfield.rs:46:11 + --> $DIR/pat-tuple-overfield.rs:46:12 | LL | struct Z1(); - | ------------ tuple struct defined here + | --- tuple struct has 0 fields ... LL | Z1(_, _) => {} - | --^^^^^^ expected 0 fields, found 2 - | | - | this tuple struct + | -- ^ ^ expected 0 fields, found 2 error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 0 fields - --> $DIR/pat-tuple-overfield.rs:57:15 + --> $DIR/pat-tuple-overfield.rs:57:16 | LL | Z1(), - | ---- tuple variant defined here + | -- tuple variant has 0 fields ... LL | E1::Z1(_) => {} - | ------^^^ expected 0 fields, found 1 - | | - | this tuple variant + | ------ ^ expected 0 fields, found 1 error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 0 fields - --> $DIR/pat-tuple-overfield.rs:58:15 + --> $DIR/pat-tuple-overfield.rs:58:16 | LL | Z1(), - | ---- tuple variant defined here + | -- tuple variant has 0 fields ... LL | E1::Z1(_, _) => {} - | ------^^^^^^ expected 0 fields, found 2 - | | - | this tuple variant + | ------ ^ ^ expected 0 fields, found 2 error: aborting due to 17 previous errors diff --git a/src/test/ui/pattern/pat-tuple-underfield.stderr b/src/test/ui/pattern/pat-tuple-underfield.stderr index 4cc20a4ac0ef7..4c21ad0be3eb4 100644 --- a/src/test/ui/pattern/pat-tuple-underfield.stderr +++ b/src/test/ui/pattern/pat-tuple-underfield.stderr @@ -8,15 +8,13 @@ LL | E::S => {} | ^^^^ help: use the tuple variant pattern syntax instead: `E::S(_, _)` error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields - --> $DIR/pat-tuple-underfield.rs:9:10 + --> $DIR/pat-tuple-underfield.rs:9:11 | LL | struct S(i32, f32); - | ------------------- tuple struct defined here + | --- --- tuple struct has 2 fields ... LL | S(x) => {} - | -^^^ expected 2 fields, found 1 - | | - | this tuple struct + | - ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -24,15 +22,13 @@ LL | S(x, _) => {} | +++ error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields - --> $DIR/pat-tuple-underfield.rs:14:10 + --> $DIR/pat-tuple-underfield.rs:14:11 | LL | struct S(i32, f32); - | ------------------- tuple struct defined here + | --- --- tuple struct has 2 fields ... LL | S(_) => {} - | -^^^ expected 2 fields, found 1 - | | - | this tuple struct + | - ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -47,12 +43,10 @@ error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has --> $DIR/pat-tuple-underfield.rs:20:10 | LL | struct S(i32, f32); - | ------------------- tuple struct defined here + | --- --- tuple struct has 2 fields ... LL | S() => {} | -^^ expected 2 fields, found 0 - | | - | this tuple struct | help: use `_` to explicitly ignore each field | @@ -64,15 +58,13 @@ LL | S(..) => {} | ++ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/pat-tuple-underfield.rs:27:13 + --> $DIR/pat-tuple-underfield.rs:27:14 | LL | S(i32, f32), - | ----------- tuple variant defined here + | --- --- tuple variant has 2 fields ... LL | E::S(x) => {} - | ----^^^ expected 2 fields, found 1 - | | - | this tuple variant + | ---- ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -80,15 +72,13 @@ LL | E::S(x, _) => {} | +++ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/pat-tuple-underfield.rs:32:13 + --> $DIR/pat-tuple-underfield.rs:32:14 | LL | S(i32, f32), - | ----------- tuple variant defined here + | --- --- tuple variant has 2 fields ... LL | E::S(_) => {} - | ----^^^ expected 2 fields, found 1 - | | - | this tuple variant + | ---- ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -103,12 +93,10 @@ error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has --> $DIR/pat-tuple-underfield.rs:38:13 | LL | S(i32, f32), - | ----------- tuple variant defined here + | --- --- tuple variant has 2 fields ... LL | E::S() => {} | ----^^ expected 2 fields, found 0 - | | - | this tuple variant | help: use `_` to explicitly ignore each field | @@ -120,15 +108,13 @@ LL | E::S(..) => {} | ++ error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 4 fields - --> $DIR/pat-tuple-underfield.rs:50:15 + --> $DIR/pat-tuple-underfield.rs:50:19 | LL | struct Point4(i32, i32, i32, i32); - | ---------------------------------- tuple struct defined here + | --- --- --- --- tuple struct has 4 fields ... LL | Point4( a , _ ) => {} - | ------^^^^^^^^^^^^^^^^^^^^ expected 4 fields, found 2 - | | - | this tuple struct + | ------ ^ ^ expected 4 fields, found 2 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/pattern-error-continue.stderr b/src/test/ui/pattern/pattern-error-continue.stderr index 216c3ca47d393..efc6723e9ef8e 100644 --- a/src/test/ui/pattern/pattern-error-continue.stderr +++ b/src/test/ui/pattern/pattern-error-continue.stderr @@ -26,15 +26,13 @@ LL | A::B(_) => (), | ~ error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields - --> $DIR/pattern-error-continue.rs:17:13 + --> $DIR/pattern-error-continue.rs:17:14 | LL | B(isize, isize), - | --------------- tuple variant defined here + | ----- ----- tuple variant has 2 fields ... LL | A::B(_, _, _) => (), - | ----^^^^^^^^^ expected 2 fields, found 3 - | | - | this tuple variant + | ---- ^ ^ ^ expected 2 fields, found 3 error[E0308]: mismatched types --> $DIR/pattern-error-continue.rs:22:9 From 02ed23c0318da7f1125f01b5437ae9e809587f0c Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Wed, 18 Aug 2021 16:09:52 -0700 Subject: [PATCH 05/36] Use an exhaustive match in `Node::ident()` and add docs This should cause a compiler error in the future if more variants are added without `Node::ident()` being updated. --- compiler/rustc_hir/src/hir.rs | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 4e233ed14577d..dd5dfe978a477 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -3182,6 +3182,20 @@ pub enum Node<'hir> { } impl<'hir> Node<'hir> { + /// Get the identifier of this `Node`, if applicable. + /// + /// # Edge cases + /// + /// Calling `.ident()` on a [`Node::Ctor`] will return `None` + /// because `Ctor`s do not have identifiers themselves. + /// Instead, call `.ident()` on the parent struct/variant, like so: + /// + /// ```ignore (illustrative) + /// ctor + /// .ctor_hir_id() + /// .and_then(|ctor_id| tcx.hir().find(tcx.hir().get_parent_node(ctor_id))) + /// .and_then(|parent| parent.ident()) + /// ``` pub fn ident(&self) -> Option { match self { Node::TraitItem(TraitItem { ident, .. }) @@ -3190,8 +3204,25 @@ impl<'hir> Node<'hir> { | Node::Field(FieldDef { ident, .. }) | Node::Variant(Variant { ident, .. }) | Node::MacroDef(MacroDef { ident, .. }) - | Node::Item(Item { ident, .. }) => Some(*ident), - _ => None, + | Node::Item(Item { ident, .. }) + | Node::PathSegment(PathSegment { ident, .. }) => Some(*ident), + Node::Lifetime(lt) => Some(lt.name.ident()), + Node::GenericParam(p) => Some(p.name.ident()), + Node::Param(..) + | Node::AnonConst(..) + | Node::Expr(..) + | Node::Stmt(..) + | Node::Block(..) + | Node::Ctor(..) + | Node::Pat(..) + | Node::Binding(..) + | Node::Arm(..) + | Node::Local(..) + | Node::Visibility(..) + | Node::Crate(..) + | Node::Ty(..) + | Node::TraitRef(..) + | Node::Infer(..) => None, } } From 08ceac8ee3d740c48e6bb250de0798fcbe0824f4 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sat, 21 Aug 2021 12:29:11 -0700 Subject: [PATCH 06/36] Add cross-crate tuple field count error test --- ...clarations-for-tuple-field-count-errors.rs | 20 + .../ui/pattern/pat-tuple-field-count-cross.rs | 57 ++ .../pat-tuple-field-count-cross.stderr | 536 ++++++++++++++++++ 3 files changed, 613 insertions(+) create mode 100644 src/test/ui/pattern/auxiliary/declarations-for-tuple-field-count-errors.rs create mode 100644 src/test/ui/pattern/pat-tuple-field-count-cross.rs create mode 100644 src/test/ui/pattern/pat-tuple-field-count-cross.stderr diff --git a/src/test/ui/pattern/auxiliary/declarations-for-tuple-field-count-errors.rs b/src/test/ui/pattern/auxiliary/declarations-for-tuple-field-count-errors.rs new file mode 100644 index 0000000000000..f7373c453966c --- /dev/null +++ b/src/test/ui/pattern/auxiliary/declarations-for-tuple-field-count-errors.rs @@ -0,0 +1,20 @@ +pub struct Z0; +pub struct Z1(); + +pub struct S(pub u8, pub u8, pub u8); +pub struct M( + pub u8, + pub u8, + pub u8, +); + +pub enum E1 { Z0, Z1(), S(u8, u8, u8) } + +pub enum E2 { + S(u8, u8, u8), + M( + u8, + u8, + u8, + ), +} diff --git a/src/test/ui/pattern/pat-tuple-field-count-cross.rs b/src/test/ui/pattern/pat-tuple-field-count-cross.rs new file mode 100644 index 0000000000000..b63da4e154f73 --- /dev/null +++ b/src/test/ui/pattern/pat-tuple-field-count-cross.rs @@ -0,0 +1,57 @@ +// aux-build:declarations-for-tuple-field-count-errors.rs + +extern crate declarations_for_tuple_field_count_errors; + +use declarations_for_tuple_field_count_errors::*; + +fn main() { + match Z0 { + Z0() => {} //~ ERROR expected tuple struct or tuple variant, found unit struct `Z0` + Z0(x) => {} //~ ERROR expected tuple struct or tuple variant, found unit struct `Z0` + } + match Z1() { + Z1 => {} //~ ERROR match bindings cannot shadow tuple structs + Z1(x) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple struct has 0 fields + } + + match S(1, 2, 3) { + S() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple struct has 3 fields + S(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple struct has 3 fields + S(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple struct has 3 fields + S(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple struct has 3 fields + } + match M(1, 2, 3) { + M() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple struct has 3 fields + M(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple struct has 3 fields + M(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple struct has 3 fields + M(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple struct has 3 fields + } + + match E1::Z0 { + E1::Z0() => {} //~ ERROR expected tuple struct or tuple variant, found unit variant `E1::Z0` + E1::Z0(x) => {} //~ ERROR expected tuple struct or tuple variant, found unit variant `E1::Z0` + } + match E1::Z1() { + E1::Z1 => {} //~ ERROR expected unit struct, unit variant or constant, found tuple variant `E1::Z1` + E1::Z1(x) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple variant has 0 fields + } + match E1::S(1, 2, 3) { + E1::S() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple variant has 3 fields + E1::S(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple variant has 3 fields + E1::S(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple variant has 3 fields + E1::S(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple variant has 3 fields + } + + match E2::S(1, 2, 3) { + E2::S() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple variant has 3 fields + E2::S(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple variant has 3 fields + E2::S(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple variant has 3 fields + E2::S(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple variant has 3 fields + } + match E2::M(1, 2, 3) { + E2::M() => {} //~ ERROR this pattern has 0 fields, but the corresponding tuple variant has 3 fields + E2::M(1) => {} //~ ERROR this pattern has 1 field, but the corresponding tuple variant has 3 fields + E2::M(xyz, abc) => {} //~ ERROR this pattern has 2 fields, but the corresponding tuple variant has 3 fields + E2::M(1, 2, 3, 4) => {} //~ ERROR this pattern has 4 fields, but the corresponding tuple variant has 3 fields + } +} diff --git a/src/test/ui/pattern/pat-tuple-field-count-cross.stderr b/src/test/ui/pattern/pat-tuple-field-count-cross.stderr new file mode 100644 index 0000000000000..570bf0cbc0810 --- /dev/null +++ b/src/test/ui/pattern/pat-tuple-field-count-cross.stderr @@ -0,0 +1,536 @@ +error[E0530]: match bindings cannot shadow tuple structs + --> $DIR/pat-tuple-field-count-cross.rs:13:9 + | +LL | use declarations_for_tuple_field_count_errors::*; + | -------------------------------------------- the tuple struct `Z1` is imported here +... +LL | Z1 => {} + | ^^ cannot be named the same as a tuple struct + +error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` + --> $DIR/pat-tuple-field-count-cross.rs:9:9 + | +LL | Z0() => {} + | ^^^^ + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:1:1 + | +LL | pub struct Z0; + | -------------- `Z0` defined here +LL | pub struct Z1(); + | ---------------- similarly named tuple struct `Z1` defined here + | +help: use this syntax instead + | +LL | Z0 => {} + | ~~ +help: a tuple struct with a similar name exists + | +LL | Z1() => {} + | ~~ + +error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` + --> $DIR/pat-tuple-field-count-cross.rs:10:9 + | +LL | Z0(x) => {} + | ^^^^^ + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:1:1 + | +LL | pub struct Z0; + | -------------- `Z0` defined here +LL | pub struct Z1(); + | ---------------- similarly named tuple struct `Z1` defined here + | +help: use this syntax instead + | +LL | Z0 => {} + | ~~ +help: a tuple struct with a similar name exists + | +LL | Z1(x) => {} + | ~~ + +error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` + --> $DIR/pat-tuple-field-count-cross.rs:31:9 + | +LL | E1::Z0() => {} + | ^^^^^^^^ + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:15 + | +LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } + | -- ---- similarly named tuple variant `Z1` defined here + | | + | `E1::Z0` defined here + | +help: use this syntax instead + | +LL | E1::Z0 => {} + | ~~~~~~ +help: a tuple variant with a similar name exists + | +LL | E1::Z1() => {} + | ~~ + +error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` + --> $DIR/pat-tuple-field-count-cross.rs:32:9 + | +LL | E1::Z0(x) => {} + | ^^^^^^^^^ + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:15 + | +LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } + | -- ---- similarly named tuple variant `Z1` defined here + | | + | `E1::Z0` defined here + | +help: use this syntax instead + | +LL | E1::Z0 => {} + | ~~~~~~ +help: a tuple variant with a similar name exists + | +LL | E1::Z1(x) => {} + | ~~ + +error[E0532]: expected unit struct, unit variant or constant, found tuple variant `E1::Z1` + --> $DIR/pat-tuple-field-count-cross.rs:35:9 + | +LL | E1::Z1 => {} + | ^^^^^^ + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:19 + | +LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } + | -- ---- `E1::Z1` defined here + | | + | similarly named unit variant `Z0` defined here + | +help: use the tuple variant pattern syntax instead + | +LL | E1::Z1(/* fields */) => {} + | ~~~~~~~~~~~~~~~~~~~~ +help: a unit variant with a similar name exists + | +LL | E1::Z0 => {} + | ~~ + +error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 0 fields + --> $DIR/pat-tuple-field-count-cross.rs:14:12 + | +LL | Z1(x) => {} + | -- ^ expected 0 fields, found 1 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:2:1 + | +LL | pub struct Z1(); + | ---------------- tuple struct has 0 fields + +error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:18:10 + | +LL | S() => {} + | -^^ expected 3 fields, found 0 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14 + | +LL | pub struct S(pub u8, pub u8, pub u8); + | ------ ------ ------ tuple struct has 3 fields + | +help: use `_` to explicitly ignore each field + | +LL | S(_, _, _) => {} + | +++++++ +help: use `..` to ignore all fields + | +LL | S(..) => {} + | ++ + +error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:19:11 + | +LL | S(1) => {} + | - ^ expected 3 fields, found 1 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14 + | +LL | pub struct S(pub u8, pub u8, pub u8); + | ------ ------ ------ tuple struct has 3 fields + | +help: use `_` to explicitly ignore each field + | +LL | S(1, _, _) => {} + | ++++++ +help: use `..` to ignore the rest of the fields + | +LL | S(1, ..) => {} + | ++++ + +error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:20:11 + | +LL | S(xyz, abc) => {} + | - ^^^ ^^^ expected 3 fields, found 2 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14 + | +LL | pub struct S(pub u8, pub u8, pub u8); + | ------ ------ ------ tuple struct has 3 fields + | +help: use `_` to explicitly ignore each field + | +LL | S(xyz, abc, _) => {} + | +++ + +error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:21:11 + | +LL | S(1, 2, 3, 4) => {} + | - ^ ^ ^ ^ expected 3 fields, found 4 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14 + | +LL | pub struct S(pub u8, pub u8, pub u8); + | ------ ------ ------ tuple struct has 3 fields + +error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:24:10 + | +LL | M() => {} + | -^^ expected 3 fields, found 0 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1 + | +LL | / pub struct M( +LL | | pub u8, + | | ------ +LL | | pub u8, + | | ------ +LL | | pub u8, + | | ------ tuple struct has 3 fields +LL | | ); + | |__- tuple struct defined here + | +help: use `_` to explicitly ignore each field + | +LL | M(_, _, _) => {} + | +++++++ +help: use `..` to ignore all fields + | +LL | M(..) => {} + | ++ + +error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:25:11 + | +LL | M(1) => {} + | - ^ expected 3 fields, found 1 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1 + | +LL | / pub struct M( +LL | | pub u8, + | | ------ +LL | | pub u8, + | | ------ +LL | | pub u8, + | | ------ tuple struct has 3 fields +LL | | ); + | |__- tuple struct defined here + | +help: use `_` to explicitly ignore each field + | +LL | M(1, _, _) => {} + | ++++++ +help: use `..` to ignore the rest of the fields + | +LL | M(1, ..) => {} + | ++++ + +error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:26:11 + | +LL | M(xyz, abc) => {} + | - ^^^ ^^^ expected 3 fields, found 2 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1 + | +LL | / pub struct M( +LL | | pub u8, + | | ------ +LL | | pub u8, + | | ------ +LL | | pub u8, + | | ------ tuple struct has 3 fields +LL | | ); + | |__- tuple struct defined here + | +help: use `_` to explicitly ignore each field + | +LL | M(xyz, abc, _) => {} + | +++ + +error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:27:11 + | +LL | M(1, 2, 3, 4) => {} + | - ^ ^ ^ ^ expected 3 fields, found 4 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1 + | +LL | / pub struct M( +LL | | pub u8, + | | ------ +LL | | pub u8, + | | ------ +LL | | pub u8, + | | ------ tuple struct has 3 fields +LL | | ); + | |__- tuple struct defined here + +error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 0 fields + --> $DIR/pat-tuple-field-count-cross.rs:36:16 + | +LL | E1::Z1(x) => {} + | ------ ^ expected 0 fields, found 1 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:19 + | +LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } + | ---- tuple variant has 0 fields + +error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:39:14 + | +LL | E1::S() => {} + | -----^^ expected 3 fields, found 0 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27 + | +LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } + | -- -- -- tuple variant has 3 fields + | +help: use `_` to explicitly ignore each field + | +LL | E1::S(_, _, _) => {} + | +++++++ +help: use `..` to ignore all fields + | +LL | E1::S(..) => {} + | ++ + +error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:40:15 + | +LL | E1::S(1) => {} + | ----- ^ expected 3 fields, found 1 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27 + | +LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } + | -- -- -- tuple variant has 3 fields + | +help: use `_` to explicitly ignore each field + | +LL | E1::S(1, _, _) => {} + | ++++++ +help: use `..` to ignore the rest of the fields + | +LL | E1::S(1, ..) => {} + | ++++ + +error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:41:15 + | +LL | E1::S(xyz, abc) => {} + | ----- ^^^ ^^^ expected 3 fields, found 2 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27 + | +LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } + | -- -- -- tuple variant has 3 fields + | +help: use `_` to explicitly ignore each field + | +LL | E1::S(xyz, abc, _) => {} + | +++ + +error[E0023]: this pattern has 4 fields, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:42:15 + | +LL | E1::S(1, 2, 3, 4) => {} + | ----- ^ ^ ^ ^ expected 3 fields, found 4 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27 + | +LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } + | -- -- -- tuple variant has 3 fields + +error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:46:14 + | +LL | E2::S() => {} + | -----^^ expected 3 fields, found 0 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7 + | +LL | S(u8, u8, u8), + | -- -- -- tuple variant has 3 fields + | +help: use `_` to explicitly ignore each field + | +LL | E2::S(_, _, _) => {} + | +++++++ +help: use `..` to ignore all fields + | +LL | E2::S(..) => {} + | ++ + +error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:47:15 + | +LL | E2::S(1) => {} + | ----- ^ expected 3 fields, found 1 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7 + | +LL | S(u8, u8, u8), + | -- -- -- tuple variant has 3 fields + | +help: use `_` to explicitly ignore each field + | +LL | E2::S(1, _, _) => {} + | ++++++ +help: use `..` to ignore the rest of the fields + | +LL | E2::S(1, ..) => {} + | ++++ + +error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:48:15 + | +LL | E2::S(xyz, abc) => {} + | ----- ^^^ ^^^ expected 3 fields, found 2 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7 + | +LL | S(u8, u8, u8), + | -- -- -- tuple variant has 3 fields + | +help: use `_` to explicitly ignore each field + | +LL | E2::S(xyz, abc, _) => {} + | +++ + +error[E0023]: this pattern has 4 fields, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:49:15 + | +LL | E2::S(1, 2, 3, 4) => {} + | ----- ^ ^ ^ ^ expected 3 fields, found 4 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7 + | +LL | S(u8, u8, u8), + | -- -- -- tuple variant has 3 fields + +error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:52:14 + | +LL | E2::M() => {} + | -----^^ expected 3 fields, found 0 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5 + | +LL | / M( +LL | | u8, + | | -- +LL | | u8, + | | -- +LL | | u8, + | | -- tuple variant has 3 fields +LL | | ), + | |_____- tuple variant defined here + | +help: use `_` to explicitly ignore each field + | +LL | E2::M(_, _, _) => {} + | +++++++ +help: use `..` to ignore all fields + | +LL | E2::M(..) => {} + | ++ + +error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:53:15 + | +LL | E2::M(1) => {} + | ----- ^ expected 3 fields, found 1 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5 + | +LL | / M( +LL | | u8, + | | -- +LL | | u8, + | | -- +LL | | u8, + | | -- tuple variant has 3 fields +LL | | ), + | |_____- tuple variant defined here + | +help: use `_` to explicitly ignore each field + | +LL | E2::M(1, _, _) => {} + | ++++++ +help: use `..` to ignore the rest of the fields + | +LL | E2::M(1, ..) => {} + | ++++ + +error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:54:15 + | +LL | E2::M(xyz, abc) => {} + | ----- ^^^ ^^^ expected 3 fields, found 2 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5 + | +LL | / M( +LL | | u8, + | | -- +LL | | u8, + | | -- +LL | | u8, + | | -- tuple variant has 3 fields +LL | | ), + | |_____- tuple variant defined here + | +help: use `_` to explicitly ignore each field + | +LL | E2::M(xyz, abc, _) => {} + | +++ + +error[E0023]: this pattern has 4 fields, but the corresponding tuple variant has 3 fields + --> $DIR/pat-tuple-field-count-cross.rs:55:15 + | +LL | E2::M(1, 2, 3, 4) => {} + | ----- ^ ^ ^ ^ expected 3 fields, found 4 + | + ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5 + | +LL | / M( +LL | | u8, + | | -- +LL | | u8, + | | -- +LL | | u8, + | | -- tuple variant has 3 fields +LL | | ), + | |_____- tuple variant defined here + +error: aborting due to 28 previous errors + +Some errors have detailed explanations: E0023, E0530, E0532. +For more information about an error, try `rustc --explain E0023`. From 19f45101e72ed6880b0fd1ebee73d74ea782c8c4 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sat, 21 Aug 2021 18:41:34 -0700 Subject: [PATCH 07/36] Bless tests --- .../ui/pattern/pat-tuple-overfield.stderr | 34 +++++++++---------- ...priority-higher-than-other-inherent.stderr | 6 ++++ .../ui/typeck/struct-enum-wrong-args.stderr | 30 ++++++++++++++++ 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/src/test/ui/pattern/pat-tuple-overfield.stderr b/src/test/ui/pattern/pat-tuple-overfield.stderr index 1df9c1c11b8a5..646ac4e661897 100644 --- a/src/test/ui/pattern/pat-tuple-overfield.stderr +++ b/src/test/ui/pattern/pat-tuple-overfield.stderr @@ -1,5 +1,5 @@ error[E0530]: match bindings cannot shadow tuple structs - --> $DIR/pat-tuple-overfield.rs:43:9 + --> $DIR/pat-tuple-overfield.rs:41:9 | LL | struct Z1(); | ------------ the tuple struct `Z1` is defined here @@ -8,7 +8,7 @@ LL | Z1 => {} | ^^ cannot be named the same as a tuple struct error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` - --> $DIR/pat-tuple-overfield.rs:38:9 + --> $DIR/pat-tuple-overfield.rs:36:9 | LL | struct Z0; | ---------- `Z0` defined here @@ -28,7 +28,7 @@ LL | Z1() => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` - --> $DIR/pat-tuple-overfield.rs:39:9 + --> $DIR/pat-tuple-overfield.rs:37:9 | LL | struct Z0; | ---------- `Z0` defined here @@ -48,7 +48,7 @@ LL | Z1(_) => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` - --> $DIR/pat-tuple-overfield.rs:40:9 + --> $DIR/pat-tuple-overfield.rs:38:9 | LL | struct Z0; | ---------- `Z0` defined here @@ -68,7 +68,7 @@ LL | Z1(_, _) => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` - --> $DIR/pat-tuple-overfield.rs:50:9 + --> $DIR/pat-tuple-overfield.rs:48:9 | LL | Z0, | -- `E1::Z0` defined here @@ -88,7 +88,7 @@ LL | E1::Z1() => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` - --> $DIR/pat-tuple-overfield.rs:51:9 + --> $DIR/pat-tuple-overfield.rs:49:9 | LL | Z0, | -- `E1::Z0` defined here @@ -108,7 +108,7 @@ LL | E1::Z1(_) => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` - --> $DIR/pat-tuple-overfield.rs:52:9 + --> $DIR/pat-tuple-overfield.rs:50:9 | LL | Z0, | -- `E1::Z0` defined here @@ -128,7 +128,7 @@ LL | E1::Z1(_, _) => {} | ~~ error[E0532]: expected unit struct, unit variant or constant, found tuple variant `E1::Z1` - --> $DIR/pat-tuple-overfield.rs:55:9 + --> $DIR/pat-tuple-overfield.rs:53:9 | LL | Z0, | -- similarly named unit variant `Z0` defined here @@ -148,7 +148,7 @@ LL | E1::Z0 => {} | ~~ error[E0308]: mismatched types - --> $DIR/pat-tuple-overfield.rs:21:9 + --> $DIR/pat-tuple-overfield.rs:19:9 | LL | match (1, 2, 3) { | --------- this expression has type `({integer}, {integer}, {integer})` @@ -159,7 +159,7 @@ LL | (1, 2, 3, 4) => {} found tuple `(_, _, _, _)` error[E0308]: mismatched types - --> $DIR/pat-tuple-overfield.rs:22:9 + --> $DIR/pat-tuple-overfield.rs:20:9 | LL | match (1, 2, 3) { | --------- this expression has type `({integer}, {integer}, {integer})` @@ -171,7 +171,7 @@ LL | (1, 2, .., 3, 4) => {} found tuple `(_, _, _, _)` error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-overfield.rs:26:11 + --> $DIR/pat-tuple-overfield.rs:24:11 | LL | struct S(u8, u8, u8); | -- -- -- tuple struct has 3 fields @@ -180,7 +180,7 @@ LL | S(1, 2, 3, 4) => {} | - ^ ^ ^ ^ expected 3 fields, found 4 error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-overfield.rs:28:11 + --> $DIR/pat-tuple-overfield.rs:26:11 | LL | struct S(u8, u8, u8); | -- -- -- tuple struct has 3 fields @@ -189,7 +189,7 @@ LL | S(1, 2, .., 3, 4) => {} | - ^ ^ ^ ^ expected 3 fields, found 4 error[E0023]: this pattern has 6 fields, but the corresponding tuple struct has 5 fields - --> $DIR/pat-tuple-overfield.rs:33:11 + --> $DIR/pat-tuple-overfield.rs:31:11 | LL | struct M( | - tuple struct defined here @@ -208,7 +208,7 @@ LL | M(1, 2, 3, 4, 5, 6) => {} | - ^ ^ ^ ^ ^ ^ expected 5 fields, found 6 error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 0 fields - --> $DIR/pat-tuple-overfield.rs:45:12 + --> $DIR/pat-tuple-overfield.rs:43:12 | LL | struct Z1(); | --- tuple struct has 0 fields @@ -217,7 +217,7 @@ LL | Z1(_) => {} | -- ^ expected 0 fields, found 1 error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 0 fields - --> $DIR/pat-tuple-overfield.rs:46:12 + --> $DIR/pat-tuple-overfield.rs:44:12 | LL | struct Z1(); | --- tuple struct has 0 fields @@ -226,7 +226,7 @@ LL | Z1(_, _) => {} | -- ^ ^ expected 0 fields, found 2 error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 0 fields - --> $DIR/pat-tuple-overfield.rs:57:16 + --> $DIR/pat-tuple-overfield.rs:55:16 | LL | Z1(), | -- tuple variant has 0 fields @@ -235,7 +235,7 @@ LL | E1::Z1(_) => {} | ------ ^ expected 0 fields, found 1 error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 0 fields - --> $DIR/pat-tuple-overfield.rs:58:16 + --> $DIR/pat-tuple-overfield.rs:56:16 | LL | Z1(), | -- tuple variant has 0 fields diff --git a/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr b/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr index 1d520613a288f..37543c137f66f 100644 --- a/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr +++ b/src/test/ui/type-alias-enum-variants/enum-variant-priority-higher-than-other-inherent.stderr @@ -5,6 +5,12 @@ LL | ::V(); | ^^^^^^-- supplied 0 arguments | | | expected 1 argument + | +note: tuple variant defined here + --> $DIR/enum-variant-priority-higher-than-other-inherent.rs:5:5 + | +LL | V(u8) + | ^ error[E0308]: mismatched types --> $DIR/enum-variant-priority-higher-than-other-inherent.rs:22:17 diff --git a/src/test/ui/typeck/struct-enum-wrong-args.stderr b/src/test/ui/typeck/struct-enum-wrong-args.stderr index d77ef73028b0c..6e99feed33f9c 100644 --- a/src/test/ui/typeck/struct-enum-wrong-args.stderr +++ b/src/test/ui/typeck/struct-enum-wrong-args.stderr @@ -29,6 +29,12 @@ LL | let _ = Wrapper(); | ^^^^^^^-- supplied 0 arguments | | | expected 1 argument + | +note: tuple struct defined here + --> $DIR/struct-enum-wrong-args.rs:2:8 + | +LL | struct Wrapper(i32); + | ^^^^^^^ error[E0061]: this struct takes 1 argument but 2 arguments were supplied --> $DIR/struct-enum-wrong-args.rs:10:13 @@ -37,6 +43,12 @@ LL | let _ = Wrapper(5, 2); | ^^^^^^^ - - supplied 2 arguments | | | expected 1 argument + | +note: tuple struct defined here + --> $DIR/struct-enum-wrong-args.rs:2:8 + | +LL | struct Wrapper(i32); + | ^^^^^^^ error[E0061]: this struct takes 2 arguments but 0 arguments were supplied --> $DIR/struct-enum-wrong-args.rs:11:13 @@ -45,6 +57,12 @@ LL | let _ = DoubleWrapper(); | ^^^^^^^^^^^^^-- supplied 0 arguments | | | expected 2 arguments + | +note: tuple struct defined here + --> $DIR/struct-enum-wrong-args.rs:3:8 + | +LL | struct DoubleWrapper(i32, i32); + | ^^^^^^^^^^^^^ error[E0061]: this struct takes 2 arguments but 1 argument was supplied --> $DIR/struct-enum-wrong-args.rs:12:13 @@ -53,6 +71,12 @@ LL | let _ = DoubleWrapper(5); | ^^^^^^^^^^^^^ - supplied 1 argument | | | expected 2 arguments + | +note: tuple struct defined here + --> $DIR/struct-enum-wrong-args.rs:3:8 + | +LL | struct DoubleWrapper(i32, i32); + | ^^^^^^^^^^^^^ error[E0061]: this struct takes 2 arguments but 3 arguments were supplied --> $DIR/struct-enum-wrong-args.rs:13:13 @@ -61,6 +85,12 @@ LL | let _ = DoubleWrapper(5, 2, 7); | ^^^^^^^^^^^^^ - - - supplied 3 arguments | | | expected 2 arguments + | +note: tuple struct defined here + --> $DIR/struct-enum-wrong-args.rs:3:8 + | +LL | struct DoubleWrapper(i32, i32); + | ^^^^^^^^^^^^^ error: aborting due to 8 previous errors From f28793dd13e8a8132d559629728e6ca9514dbe36 Mon Sep 17 00:00:00 2001 From: linux1 Date: Fri, 6 Aug 2021 17:53:29 -0400 Subject: [PATCH 08/36] Feat: added inline asm support for s390x --- compiler/rustc_codegen_llvm/src/asm.rs | 6 + compiler/rustc_target/src/asm/mod.rs | 25 ++++ compiler/rustc_target/src/asm/s390x.rs | 156 +++++++++++++++++++++++++ 3 files changed, 187 insertions(+) create mode 100644 compiler/rustc_target/src/asm/s390x.rs diff --git a/compiler/rustc_codegen_llvm/src/asm.rs b/compiler/rustc_codegen_llvm/src/asm.rs index 4387f5301a58d..938f036da0e4a 100644 --- a/compiler/rustc_codegen_llvm/src/asm.rs +++ b/compiler/rustc_codegen_llvm/src/asm.rs @@ -314,6 +314,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> { InlineAsmArch::PowerPC | InlineAsmArch::PowerPC64 => {} InlineAsmArch::Hexagon => {} InlineAsmArch::Mips | InlineAsmArch::Mips64 => {} + InlineAsmArch::s390 => {} InlineAsmArch::SpirV => {} InlineAsmArch::Wasm32 => {} InlineAsmArch::Bpf => {} @@ -633,6 +634,8 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'tcx>>) InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r", InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r", InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w", + InlineAsmRegClass::s390x(s390xInlineAsmRegClass::reg) => "r", + InlineAsmRegClass::s390x(s390xInlineAsmRegClass::freg) => "f", InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => { bug!("LLVM backend does not support SPIR-V") } @@ -711,6 +714,7 @@ fn modifier_to_llvm( } InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => None, InlineAsmRegClass::Bpf(_) => None, + InlineAsmRegClass::s390x(_) => None, InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => { bug!("LLVM backend does not support SPIR-V") } @@ -769,6 +773,8 @@ fn dummy_output_type(cx: &CodegenCx<'ll, 'tcx>, reg: InlineAsmRegClass) -> &'ll InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(), InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(), InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(), + InlineAsmRegClass::s390x(s390xInlineAsmRegClass::reg) => cx.type_i32(), + InlineAsmRegClass::s390x(s390xInlineAsmRegClass::freg) => cx.type_f64(), InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => { bug!("LLVM backend does not support SPIR-V") } diff --git a/compiler/rustc_target/src/asm/mod.rs b/compiler/rustc_target/src/asm/mod.rs index 9ebf8235e2098..3ce5a8195d601 100644 --- a/compiler/rustc_target/src/asm/mod.rs +++ b/compiler/rustc_target/src/asm/mod.rs @@ -154,6 +154,7 @@ mod mips; mod nvptx; mod powerpc; mod riscv; +mod s390x; mod spirv; mod wasm; mod x86; @@ -166,6 +167,7 @@ pub use mips::{MipsInlineAsmReg, MipsInlineAsmRegClass}; pub use nvptx::{NvptxInlineAsmReg, NvptxInlineAsmRegClass}; pub use powerpc::{PowerPCInlineAsmReg, PowerPCInlineAsmRegClass}; pub use riscv::{RiscVInlineAsmReg, RiscVInlineAsmRegClass}; +pub use s390x::{s390xInlineAsmReg, s390xInlineAsmRegClass}; pub use spirv::{SpirVInlineAsmReg, SpirVInlineAsmRegClass}; pub use wasm::{WasmInlineAsmReg, WasmInlineAsmRegClass}; pub use x86::{X86InlineAsmReg, X86InlineAsmRegClass}; @@ -184,6 +186,7 @@ pub enum InlineAsmArch { Mips64, PowerPC, PowerPC64, + s390x, SpirV, Wasm32, Bpf, @@ -206,6 +209,7 @@ impl FromStr for InlineAsmArch { "hexagon" => Ok(Self::Hexagon), "mips" => Ok(Self::Mips), "mips64" => Ok(Self::Mips64), + "s390x" => Ok(Self::s390x), "spirv" => Ok(Self::SpirV), "wasm32" => Ok(Self::Wasm32), "bpf" => Ok(Self::Bpf), @@ -235,6 +239,7 @@ pub enum InlineAsmReg { PowerPC(PowerPCInlineAsmReg), Hexagon(HexagonInlineAsmReg), Mips(MipsInlineAsmReg), + s390x(InlineAsmReg), SpirV(SpirVInlineAsmReg), Wasm(WasmInlineAsmReg), Bpf(BpfInlineAsmReg), @@ -252,6 +257,7 @@ impl InlineAsmReg { Self::PowerPC(r) => r.name(), Self::Hexagon(r) => r.name(), Self::Mips(r) => r.name(), + Self::s390x(r) => r.name(), Self::Bpf(r) => r.name(), Self::Err => "", } @@ -266,6 +272,7 @@ impl InlineAsmReg { Self::PowerPC(r) => InlineAsmRegClass::PowerPC(r.reg_class()), Self::Hexagon(r) => InlineAsmRegClass::Hexagon(r.reg_class()), Self::Mips(r) => InlineAsmRegClass::Mips(r.reg_class()), + Self::s390x(r) => InlineAsmRegClass::s390x(r.reg_class()), Self::Bpf(r) => InlineAsmRegClass::Bpf(r.reg_class()), Self::Err => InlineAsmRegClass::Err, } @@ -305,6 +312,9 @@ impl InlineAsmReg { InlineAsmArch::Mips | InlineAsmArch::Mips64 => { Self::Mips(MipsInlineAsmReg::parse(arch, has_feature, target, &name)?) } + InlineAsmArch::s390x => { + Self::s390x(s390xInlineAsmReg::parse(arch, has_feature, target, &name)?) + } InlineAsmArch::SpirV => { Self::SpirV(SpirVInlineAsmReg::parse(arch, has_feature, target, &name)?) } @@ -333,6 +343,7 @@ impl InlineAsmReg { Self::PowerPC(r) => r.emit(out, arch, modifier), Self::Hexagon(r) => r.emit(out, arch, modifier), Self::Mips(r) => r.emit(out, arch, modifier), + Self::s390x(r) => r.emit(out, arch, modifier), Self::Bpf(r) => r.emit(out, arch, modifier), Self::Err => unreachable!("Use of InlineAsmReg::Err"), } @@ -347,6 +358,7 @@ impl InlineAsmReg { Self::PowerPC(_) => cb(self), Self::Hexagon(r) => r.overlapping_regs(|r| cb(Self::Hexagon(r))), Self::Mips(_) => cb(self), + Self::s390x(_) => cb(self), Self::Bpf(r) => r.overlapping_regs(|r| cb(Self::Bpf(r))), Self::Err => unreachable!("Use of InlineAsmReg::Err"), } @@ -374,6 +386,7 @@ pub enum InlineAsmRegClass { PowerPC(PowerPCInlineAsmRegClass), Hexagon(HexagonInlineAsmRegClass), Mips(MipsInlineAsmRegClass), + s390x(s390xInlineAsmRegClass), SpirV(SpirVInlineAsmRegClass), Wasm(WasmInlineAsmRegClass), Bpf(BpfInlineAsmRegClass), @@ -392,6 +405,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.name(), Self::Hexagon(r) => r.name(), Self::Mips(r) => r.name(), + Self::s390x(r) => r.name(), Self::SpirV(r) => r.name(), Self::Wasm(r) => r.name(), Self::Bpf(r) => r.name(), @@ -412,6 +426,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::PowerPC), Self::Hexagon(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Hexagon), Self::Mips(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Mips), + Self::s390x(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::s390x), Self::SpirV(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::SpirV), Self::Wasm(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Wasm), Self::Bpf(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Bpf), @@ -439,6 +454,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.suggest_modifier(arch, ty), Self::Hexagon(r) => r.suggest_modifier(arch, ty), Self::Mips(r) => r.suggest_modifier(arch, ty), + Self::s390x(r) => r.suggest_modifier(arch, ty), Self::SpirV(r) => r.suggest_modifier(arch, ty), Self::Wasm(r) => r.suggest_modifier(arch, ty), Self::Bpf(r) => r.suggest_modifier(arch, ty), @@ -462,6 +478,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.default_modifier(arch), Self::Hexagon(r) => r.default_modifier(arch), Self::Mips(r) => r.default_modifier(arch), + Self::s390x(r) => r.default_modifier(arch), Self::SpirV(r) => r.default_modifier(arch), Self::Wasm(r) => r.default_modifier(arch), Self::Bpf(r) => r.default_modifier(arch), @@ -484,6 +501,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.supported_types(arch), Self::Hexagon(r) => r.supported_types(arch), Self::Mips(r) => r.supported_types(arch), + Self::s390x(r) => r.supported_types(arch), Self::SpirV(r) => r.supported_types(arch), Self::Wasm(r) => r.supported_types(arch), Self::Bpf(r) => r.supported_types(arch), @@ -509,6 +527,7 @@ impl InlineAsmRegClass { InlineAsmArch::Mips | InlineAsmArch::Mips64 => { Self::Mips(MipsInlineAsmRegClass::parse(arch, name)?) } + InlineAsmArch::s390x => Self::s390x(s390xInlineAsmRegClass::parse(arch, name)?), InlineAsmArch::SpirV => Self::SpirV(SpirVInlineAsmRegClass::parse(arch, name)?), InlineAsmArch::Wasm32 => Self::Wasm(WasmInlineAsmRegClass::parse(arch, name)?), InlineAsmArch::Bpf => Self::Bpf(BpfInlineAsmRegClass::parse(arch, name)?), @@ -527,6 +546,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.valid_modifiers(arch), Self::Hexagon(r) => r.valid_modifiers(arch), Self::Mips(r) => r.valid_modifiers(arch), + Self::s390x(r) => r.valid_modifiers(arch), Self::SpirV(r) => r.valid_modifiers(arch), Self::Wasm(r) => r.valid_modifiers(arch), Self::Bpf(r) => r.valid_modifiers(arch), @@ -695,6 +715,11 @@ pub fn allocatable_registers( mips::fill_reg_map(arch, has_feature, target, &mut map); map } + InlineAsmArch::s390x => { + let mut map = s390x::regclass_map(); + s390x::fill_reg_map(arch, has_feature, target, &mut map); + map + } InlineAsmArch::SpirV => { let mut map = spirv::regclass_map(); spirv::fill_reg_map(arch, has_feature, target, &mut map); diff --git a/compiler/rustc_target/src/asm/s390x.rs b/compiler/rustc_target/src/asm/s390x.rs new file mode 100644 index 0000000000000..ad07e20de8a02 --- /dev/null +++ b/compiler/rustc_target/src/asm/s390x.rs @@ -0,0 +1,156 @@ +use super::{InlineAsmArch, InlineAsmType}; +use rustc_macros::HashStable_Generic; +use std::fmt; + +def_reg_class! { + s390x s390xInlineAsmRegClass { + reg, + freg, + } +} + +impl s390xInlineAsmRegClass { + pub fn valid_modifiers(self, _arch: super::InlineAsmArch) -> &'static [char] { + &[] + } + + pub fn suggest_class(self, _arch: InlineAsmArch, _ty: InlineAsmType) -> Option { + None + } + + pub fn suggest_modifier( + self, + _arch: InlineAsmArch, + _ty: InlineAsmType, + ) -> Option<(char, &'static str)> { + None + } + + pub fn default_modifier(self, _arch: InlineAsmArch) -> Option<(char, &'static str)> { + None + } + + pub fn supported_types( + self, + arch: InlineAsmArch, + ) -> &'static [(InlineAsmType, Option<&'static str>)] { + match (self, arch) { + (Self::reg, _) => types! { _: I8, I16, I32; }, + (Self::freg, _) => types! { _: F32, F64; }, + } + } +} + +def_regs! { + s390x s390xInlineAsmReg s390xInlineAsmRegClass { + r0: req = ["r0"], + r1: reg = ["r1"], + r2: reg = ["r2"], + r3: reg = ["r3"], + r4: reg = ["r4"], + r5: reg = ["r5"], + r6: reg = ["r6"], + r7: reg = ["r7"], + r8: reg = ["r8"], + r9: reg = ["r9"], + r10: reg = ["r10"], + r11: reg = ["r11"], + r12: reg = ["r12"], + r14: reg = ["r14"], + f0: freg = ["f0"], + f1: freg = ["f1"], + f2: freg = ["f2"], + f3: freg = ["f3"], + f4: freg = ["f4"], + f5: freg = ["f5"], + f6: freg = ["f6"], + f7: freg = ["f7"], + f8: freg = ["f8"], + f9: freg = ["f9"], + f10: freg = ["f10"], + f11: freg = ["f11"], + f12: freg = ["f12"], + f13: freg = ["f13"], + f14: freg = ["f14"], + f15: freg = ["f15"], + #error = ["r13"] => + "The base pointer cannot be used as an operand for inline asm", + #error = ["r15"] => + "The stack pointer cannot be used as an operand for inline asm", + #error = ["a0"] => + "This pointer is reserved on s390x and cannot be used as an operand for inline asm", + #error = ["a1"] => + "This pointer is reserved on z/Arch and cannot be used as an operand for inline asm", + #error = ["c0"] => + "c0 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c1"] => + "c1 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c2"] => + "c2 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c3"] => + "c3 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c4"] => + "c4 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c5"] => + "c5 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c6"] => + "c6 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c7"] => + "c7 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c8"] => + "c8 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c9"] => + "c9 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c10"] => + "c10 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c11"] => + "c11 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c12"] => + "c12 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c13"] => + "c13 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c14"] => + "c14 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["c15"] => + "c15 is reserved by the kernel and cannot be used as an operand for inline asm", + #error = ["a2"] => + "a2 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a3"] => + "a3 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a4"] => + "a4 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a5"] => + "a5 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a6"] => + "a6 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a7"] => + "a7 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a8"] => + "a8 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a9"] => + "a9 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a10"] => + "a10 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a11"] => + "a11 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a12"] => + "a12 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a13"] => + "a13 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a14"] => + "a14 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = ["a15"] => + "a15 is not supported by LLVM and cannot be used as an operand for inline asm", + } +} + +impl s390xInlineAsmReg { + pub fn emit( + self, + out: &mut dyn fmt::Write, + _arch: InlineAsmArch, + _modifier: Option, + ) -> fmt::Result { + out.write_str(self.name()) + } +} From 5f5afba5fbb869db26c4f9e88c29bad94007dfd1 Mon Sep 17 00:00:00 2001 From: linux1 Date: Wed, 18 Aug 2021 11:25:50 -0400 Subject: [PATCH 09/36] Feat: added s390x reg-definitions, constraint codes, and tests --- compiler/rustc_codegen_llvm/src/asm.rs | 12 ++-- compiler/rustc_target/src/asm/mod.rs | 42 ++++++------- compiler/rustc_target/src/asm/s390x.rs | 10 +-- src/test/assembly/asm/s390x-types.rs | 86 ++++++++++++++++++++++++++ 4 files changed, 118 insertions(+), 32 deletions(-) create mode 100644 src/test/assembly/asm/s390x-types.rs diff --git a/compiler/rustc_codegen_llvm/src/asm.rs b/compiler/rustc_codegen_llvm/src/asm.rs index 938f036da0e4a..1689fdd4f2e81 100644 --- a/compiler/rustc_codegen_llvm/src/asm.rs +++ b/compiler/rustc_codegen_llvm/src/asm.rs @@ -314,7 +314,7 @@ impl AsmBuilderMethods<'tcx> for Builder<'a, 'll, 'tcx> { InlineAsmArch::PowerPC | InlineAsmArch::PowerPC64 => {} InlineAsmArch::Hexagon => {} InlineAsmArch::Mips | InlineAsmArch::Mips64 => {} - InlineAsmArch::s390 => {} + InlineAsmArch::S390x => {} InlineAsmArch::SpirV => {} InlineAsmArch::Wasm32 => {} InlineAsmArch::Bpf => {} @@ -634,8 +634,8 @@ fn reg_to_llvm(reg: InlineAsmRegOrRegClass, layout: Option<&TyAndLayout<'tcx>>) InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => "r", InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => "r", InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => "w", - InlineAsmRegClass::s390x(s390xInlineAsmRegClass::reg) => "r", - InlineAsmRegClass::s390x(s390xInlineAsmRegClass::freg) => "f", + InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => "r", + InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => "f", InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => { bug!("LLVM backend does not support SPIR-V") } @@ -714,7 +714,7 @@ fn modifier_to_llvm( } InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => None, InlineAsmRegClass::Bpf(_) => None, - InlineAsmRegClass::s390x(_) => None, + InlineAsmRegClass::S390x(_) => None, InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => { bug!("LLVM backend does not support SPIR-V") } @@ -773,8 +773,8 @@ fn dummy_output_type(cx: &CodegenCx<'ll, 'tcx>, reg: InlineAsmRegClass) -> &'ll InlineAsmRegClass::Wasm(WasmInlineAsmRegClass::local) => cx.type_i32(), InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::reg) => cx.type_i64(), InlineAsmRegClass::Bpf(BpfInlineAsmRegClass::wreg) => cx.type_i32(), - InlineAsmRegClass::s390x(s390xInlineAsmRegClass::reg) => cx.type_i32(), - InlineAsmRegClass::s390x(s390xInlineAsmRegClass::freg) => cx.type_f64(), + InlineAsmRegClass::S390x(S390xInlineAsmRegClass::reg) => cx.type_i32(), + InlineAsmRegClass::S390x(S390xInlineAsmRegClass::freg) => cx.type_f64(), InlineAsmRegClass::SpirV(SpirVInlineAsmRegClass::reg) => { bug!("LLVM backend does not support SPIR-V") } diff --git a/compiler/rustc_target/src/asm/mod.rs b/compiler/rustc_target/src/asm/mod.rs index 3ce5a8195d601..015faa14e28af 100644 --- a/compiler/rustc_target/src/asm/mod.rs +++ b/compiler/rustc_target/src/asm/mod.rs @@ -167,7 +167,7 @@ pub use mips::{MipsInlineAsmReg, MipsInlineAsmRegClass}; pub use nvptx::{NvptxInlineAsmReg, NvptxInlineAsmRegClass}; pub use powerpc::{PowerPCInlineAsmReg, PowerPCInlineAsmRegClass}; pub use riscv::{RiscVInlineAsmReg, RiscVInlineAsmRegClass}; -pub use s390x::{s390xInlineAsmReg, s390xInlineAsmRegClass}; +pub use s390x::{S390xInlineAsmReg, S390xInlineAsmRegClass}; pub use spirv::{SpirVInlineAsmReg, SpirVInlineAsmRegClass}; pub use wasm::{WasmInlineAsmReg, WasmInlineAsmRegClass}; pub use x86::{X86InlineAsmReg, X86InlineAsmRegClass}; @@ -186,7 +186,7 @@ pub enum InlineAsmArch { Mips64, PowerPC, PowerPC64, - s390x, + S390x, SpirV, Wasm32, Bpf, @@ -209,7 +209,7 @@ impl FromStr for InlineAsmArch { "hexagon" => Ok(Self::Hexagon), "mips" => Ok(Self::Mips), "mips64" => Ok(Self::Mips64), - "s390x" => Ok(Self::s390x), + "s390x" => Ok(Self::S390x), "spirv" => Ok(Self::SpirV), "wasm32" => Ok(Self::Wasm32), "bpf" => Ok(Self::Bpf), @@ -239,7 +239,7 @@ pub enum InlineAsmReg { PowerPC(PowerPCInlineAsmReg), Hexagon(HexagonInlineAsmReg), Mips(MipsInlineAsmReg), - s390x(InlineAsmReg), + S390x(S390xInlineAsmReg), SpirV(SpirVInlineAsmReg), Wasm(WasmInlineAsmReg), Bpf(BpfInlineAsmReg), @@ -257,7 +257,7 @@ impl InlineAsmReg { Self::PowerPC(r) => r.name(), Self::Hexagon(r) => r.name(), Self::Mips(r) => r.name(), - Self::s390x(r) => r.name(), + Self::S390x(r) => r.name(), Self::Bpf(r) => r.name(), Self::Err => "", } @@ -272,7 +272,7 @@ impl InlineAsmReg { Self::PowerPC(r) => InlineAsmRegClass::PowerPC(r.reg_class()), Self::Hexagon(r) => InlineAsmRegClass::Hexagon(r.reg_class()), Self::Mips(r) => InlineAsmRegClass::Mips(r.reg_class()), - Self::s390x(r) => InlineAsmRegClass::s390x(r.reg_class()), + Self::S390x(r) => InlineAsmRegClass::S390x(r.reg_class()), Self::Bpf(r) => InlineAsmRegClass::Bpf(r.reg_class()), Self::Err => InlineAsmRegClass::Err, } @@ -312,8 +312,8 @@ impl InlineAsmReg { InlineAsmArch::Mips | InlineAsmArch::Mips64 => { Self::Mips(MipsInlineAsmReg::parse(arch, has_feature, target, &name)?) } - InlineAsmArch::s390x => { - Self::s390x(s390xInlineAsmReg::parse(arch, has_feature, target, &name)?) + InlineAsmArch::S390x => { + Self::S390x(S390xInlineAsmReg::parse(arch, has_feature, target, &name)?) } InlineAsmArch::SpirV => { Self::SpirV(SpirVInlineAsmReg::parse(arch, has_feature, target, &name)?) @@ -343,7 +343,7 @@ impl InlineAsmReg { Self::PowerPC(r) => r.emit(out, arch, modifier), Self::Hexagon(r) => r.emit(out, arch, modifier), Self::Mips(r) => r.emit(out, arch, modifier), - Self::s390x(r) => r.emit(out, arch, modifier), + Self::S390x(r) => r.emit(out, arch, modifier), Self::Bpf(r) => r.emit(out, arch, modifier), Self::Err => unreachable!("Use of InlineAsmReg::Err"), } @@ -358,7 +358,7 @@ impl InlineAsmReg { Self::PowerPC(_) => cb(self), Self::Hexagon(r) => r.overlapping_regs(|r| cb(Self::Hexagon(r))), Self::Mips(_) => cb(self), - Self::s390x(_) => cb(self), + Self::S390x(_) => cb(self), Self::Bpf(r) => r.overlapping_regs(|r| cb(Self::Bpf(r))), Self::Err => unreachable!("Use of InlineAsmReg::Err"), } @@ -386,7 +386,7 @@ pub enum InlineAsmRegClass { PowerPC(PowerPCInlineAsmRegClass), Hexagon(HexagonInlineAsmRegClass), Mips(MipsInlineAsmRegClass), - s390x(s390xInlineAsmRegClass), + S390x(S390xInlineAsmRegClass), SpirV(SpirVInlineAsmRegClass), Wasm(WasmInlineAsmRegClass), Bpf(BpfInlineAsmRegClass), @@ -405,7 +405,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.name(), Self::Hexagon(r) => r.name(), Self::Mips(r) => r.name(), - Self::s390x(r) => r.name(), + Self::S390x(r) => r.name(), Self::SpirV(r) => r.name(), Self::Wasm(r) => r.name(), Self::Bpf(r) => r.name(), @@ -426,7 +426,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::PowerPC), Self::Hexagon(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Hexagon), Self::Mips(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Mips), - Self::s390x(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::s390x), + Self::S390x(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::S390x), Self::SpirV(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::SpirV), Self::Wasm(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Wasm), Self::Bpf(r) => r.suggest_class(arch, ty).map(InlineAsmRegClass::Bpf), @@ -454,7 +454,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.suggest_modifier(arch, ty), Self::Hexagon(r) => r.suggest_modifier(arch, ty), Self::Mips(r) => r.suggest_modifier(arch, ty), - Self::s390x(r) => r.suggest_modifier(arch, ty), + Self::S390x(r) => r.suggest_modifier(arch, ty), Self::SpirV(r) => r.suggest_modifier(arch, ty), Self::Wasm(r) => r.suggest_modifier(arch, ty), Self::Bpf(r) => r.suggest_modifier(arch, ty), @@ -478,7 +478,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.default_modifier(arch), Self::Hexagon(r) => r.default_modifier(arch), Self::Mips(r) => r.default_modifier(arch), - Self::s390x(r) => r.default_modifier(arch), + Self::S390x(r) => r.default_modifier(arch), Self::SpirV(r) => r.default_modifier(arch), Self::Wasm(r) => r.default_modifier(arch), Self::Bpf(r) => r.default_modifier(arch), @@ -501,7 +501,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.supported_types(arch), Self::Hexagon(r) => r.supported_types(arch), Self::Mips(r) => r.supported_types(arch), - Self::s390x(r) => r.supported_types(arch), + Self::S390x(r) => r.supported_types(arch), Self::SpirV(r) => r.supported_types(arch), Self::Wasm(r) => r.supported_types(arch), Self::Bpf(r) => r.supported_types(arch), @@ -527,7 +527,7 @@ impl InlineAsmRegClass { InlineAsmArch::Mips | InlineAsmArch::Mips64 => { Self::Mips(MipsInlineAsmRegClass::parse(arch, name)?) } - InlineAsmArch::s390x => Self::s390x(s390xInlineAsmRegClass::parse(arch, name)?), + InlineAsmArch::S390x => Self::S390x(S390xInlineAsmRegClass::parse(arch, name)?), InlineAsmArch::SpirV => Self::SpirV(SpirVInlineAsmRegClass::parse(arch, name)?), InlineAsmArch::Wasm32 => Self::Wasm(WasmInlineAsmRegClass::parse(arch, name)?), InlineAsmArch::Bpf => Self::Bpf(BpfInlineAsmRegClass::parse(arch, name)?), @@ -546,7 +546,7 @@ impl InlineAsmRegClass { Self::PowerPC(r) => r.valid_modifiers(arch), Self::Hexagon(r) => r.valid_modifiers(arch), Self::Mips(r) => r.valid_modifiers(arch), - Self::s390x(r) => r.valid_modifiers(arch), + Self::S390x(r) => r.valid_modifiers(arch), Self::SpirV(r) => r.valid_modifiers(arch), Self::Wasm(r) => r.valid_modifiers(arch), Self::Bpf(r) => r.valid_modifiers(arch), @@ -715,11 +715,11 @@ pub fn allocatable_registers( mips::fill_reg_map(arch, has_feature, target, &mut map); map } - InlineAsmArch::s390x => { - let mut map = s390x::regclass_map(); + InlineAsmArch::S390x => { + let mut map = s390x::regclass_map(); s390x::fill_reg_map(arch, has_feature, target, &mut map); map - } + } InlineAsmArch::SpirV => { let mut map = spirv::regclass_map(); spirv::fill_reg_map(arch, has_feature, target, &mut map); diff --git a/compiler/rustc_target/src/asm/s390x.rs b/compiler/rustc_target/src/asm/s390x.rs index ad07e20de8a02..0acbea800930c 100644 --- a/compiler/rustc_target/src/asm/s390x.rs +++ b/compiler/rustc_target/src/asm/s390x.rs @@ -3,13 +3,13 @@ use rustc_macros::HashStable_Generic; use std::fmt; def_reg_class! { - s390x s390xInlineAsmRegClass { + S390x S390xInlineAsmRegClass { reg, freg, } } -impl s390xInlineAsmRegClass { +impl S390xInlineAsmRegClass { pub fn valid_modifiers(self, _arch: super::InlineAsmArch) -> &'static [char] { &[] } @@ -42,8 +42,8 @@ impl s390xInlineAsmRegClass { } def_regs! { - s390x s390xInlineAsmReg s390xInlineAsmRegClass { - r0: req = ["r0"], + S390x S390xInlineAsmReg S390xInlineAsmRegClass { + r0: reg = ["r0"], r1: reg = ["r1"], r2: reg = ["r2"], r3: reg = ["r3"], @@ -144,7 +144,7 @@ def_regs! { } } -impl s390xInlineAsmReg { +impl S390xInlineAsmReg { pub fn emit( self, out: &mut dyn fmt::Write, diff --git a/src/test/assembly/asm/s390x-types.rs b/src/test/assembly/asm/s390x-types.rs new file mode 100644 index 0000000000000..5f1a5f2de56be --- /dev/null +++ b/src/test/assembly/asm/s390x-types.rs @@ -0,0 +1,86 @@ +// min-llvm-version: 10.0.1 +// revisions: s390x +// assembly-output: emit-asm +//[s390x] compile-flags: --target s390x-unknown-linux-gnu +//[s390x] needs-llvm-components: systemz + +#![feature(no_core, lang_items, rustc_attrs, repr_simd)] +#![crate_type = "rlib"] +#![no_core] +#![allow(asm_sub_register, non_camel_case_types)] + +#[rustc_builtin_macro] +macro_rules! asm { + () => {}; +} +#[rustc_builtin_macro] +macro_rules! concat { + () => {}; +} +#[rustc_builtin_macro] +macro_rules! stringify { + () => {}; +} + +#[lang = "sized"] +trait Sized {} +#[lang = "copy"] +trait Copy {} + +type ptr = *const i32; + +impl Copy for i8 {} +impl Copy for u8 {} +impl Copy for i16 {} +impl Copy for i32 {} +impl Copy for i64 {} +impl Copy for f32 {} +impl Copy for f64 {} +impl Copy for ptr {} + +extern "C" { + fn extern_func(); + static extern_static: u8; +} + +// Hack to avoid function merging +extern "Rust" { + fn dont_merge(s: &str); +} + +macro_rules! check { ($func:ident, $ty:ty, $class:ident, $mov:literal) => { + + pub unsafe fn $func(x: $ty) -> $ty { + dont_merge(stringify!(func)); + + let y; + asm!(concat!($mov," {}, {}"), out($class) y, in($class) x); + y + } +};} + +macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => { + + pub unsafe fn $func(x: $ty) -> $ty { + dont_merge(stringify!(func)); + + let y; + asm!(concat!($mov, " ", $reg, ", ", $reg), lateout($reg) y, in($reg) x); + y + } +};} + +// systemz-LABEL: sym_fn_32: +// systemz: #APP +// systemz: brasl %r14, extern_func@PLT +// systemz: #NO_APP +#[cfg(s390x)] +pub unsafe fn sym_fn_32() { + asm!("brasl %r14, {}", sym extern_func); +} + +// CHECK-LABEL: reg_i32: +// CHECK: #APP +// CHECK: lgr r{{[0-15]+}}, r{{[0-15]+}} +// CHECK: #NO_APP +check!(reg_i32, i32, reg, "lgr"); From 7095dfffc3bde0fc56a837241db84e414e3d9b25 Mon Sep 17 00:00:00 2001 From: linux1 Date: Wed, 18 Aug 2021 12:14:26 -0400 Subject: [PATCH 10/36] Refactor: added #[no_mangle] --- src/test/assembly/asm/s390x-types.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/assembly/asm/s390x-types.rs b/src/test/assembly/asm/s390x-types.rs index 5f1a5f2de56be..7b2ef9bda3478 100644 --- a/src/test/assembly/asm/s390x-types.rs +++ b/src/test/assembly/asm/s390x-types.rs @@ -75,6 +75,7 @@ macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => { // systemz: brasl %r14, extern_func@PLT // systemz: #NO_APP #[cfg(s390x)] +#[no_mangle] pub unsafe fn sym_fn_32() { asm!("brasl %r14, {}", sym extern_func); } @@ -83,4 +84,5 @@ pub unsafe fn sym_fn_32() { // CHECK: #APP // CHECK: lgr r{{[0-15]+}}, r{{[0-15]+}} // CHECK: #NO_APP +#[no_mangle] check!(reg_i32, i32, reg, "lgr"); From 66e95b17ecfc93e39b1846436a86f0e924ab30b3 Mon Sep 17 00:00:00 2001 From: linux1 Date: Wed, 18 Aug 2021 12:40:18 -0400 Subject: [PATCH 11/36] Fix: moved #[no_mangle] --- src/test/assembly/asm/s390x-types.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/test/assembly/asm/s390x-types.rs b/src/test/assembly/asm/s390x-types.rs index 7b2ef9bda3478..0fbb77b96175e 100644 --- a/src/test/assembly/asm/s390x-types.rs +++ b/src/test/assembly/asm/s390x-types.rs @@ -49,7 +49,7 @@ extern "Rust" { } macro_rules! check { ($func:ident, $ty:ty, $class:ident, $mov:literal) => { - + #[no_mangle] pub unsafe fn $func(x: $ty) -> $ty { dont_merge(stringify!(func)); @@ -75,7 +75,6 @@ macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => { // systemz: brasl %r14, extern_func@PLT // systemz: #NO_APP #[cfg(s390x)] -#[no_mangle] pub unsafe fn sym_fn_32() { asm!("brasl %r14, {}", sym extern_func); } @@ -84,5 +83,4 @@ pub unsafe fn sym_fn_32() { // CHECK: #APP // CHECK: lgr r{{[0-15]+}}, r{{[0-15]+}} // CHECK: #NO_APP -#[no_mangle] check!(reg_i32, i32, reg, "lgr"); From eeb0b52bf852b902b2bd1adaf919c35e2387ce28 Mon Sep 17 00:00:00 2001 From: linux1 Date: Sun, 22 Aug 2021 17:26:18 -0400 Subject: [PATCH 12/36] Feat: further testing & support for i64 general register use --- compiler/rustc_target/src/asm/s390x.rs | 2 +- src/test/assembly/asm/s390x-types.rs | 52 +++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_target/src/asm/s390x.rs b/compiler/rustc_target/src/asm/s390x.rs index 0acbea800930c..dbf4168e4a80f 100644 --- a/compiler/rustc_target/src/asm/s390x.rs +++ b/compiler/rustc_target/src/asm/s390x.rs @@ -35,7 +35,7 @@ impl S390xInlineAsmRegClass { arch: InlineAsmArch, ) -> &'static [(InlineAsmType, Option<&'static str>)] { match (self, arch) { - (Self::reg, _) => types! { _: I8, I16, I32; }, + (Self::reg, _) => types! { _: I8, I16, I32, I64; }, (Self::freg, _) => types! { _: F32, F64; }, } } diff --git a/src/test/assembly/asm/s390x-types.rs b/src/test/assembly/asm/s390x-types.rs index 0fbb77b96175e..692193158405f 100644 --- a/src/test/assembly/asm/s390x-types.rs +++ b/src/test/assembly/asm/s390x-types.rs @@ -60,7 +60,7 @@ macro_rules! check { ($func:ident, $ty:ty, $class:ident, $mov:literal) => { };} macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => { - + #[no_mangle] pub unsafe fn $func(x: $ty) -> $ty { dont_merge(stringify!(func)); @@ -70,17 +70,57 @@ macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => { } };} -// systemz-LABEL: sym_fn_32: -// systemz: #APP -// systemz: brasl %r14, extern_func@PLT -// systemz: #NO_APP +// CHECK-LABEL: sym_fn_32: +// CHECK: #APP +// CHECK: brasl %r14, extern_func +// CHECK: #NO_APP #[cfg(s390x)] +#[no_mangle] pub unsafe fn sym_fn_32() { asm!("brasl %r14, {}", sym extern_func); } +// CHECK-LABEL: sym_static: +// CHECK: #APP +// CHECK: brasl %r14, extern_static +// CHECK: #NO_APP +#[no_mangle] +pub unsafe fn sym_static() { + asm!("brasl %r14, {}", sym extern_static); +} + +// CHECK-LABEL: reg_i8: +// CHECK: #APP +// CHECK: lgr %r{{[0-9]+}}, %r{{[0-9]+}} +// CHECK: #NO_APP +check!(reg_i8, i8, reg, "lgr"); + +// CHECK-LABEL: reg_i16: +// CHECK: #APP +// CHECK: lgr %r{{[0-9]+}}, %r{{[0-9]+}} +// CHECK: #NO_APP +check!(reg_i16, i16, reg, "lgr"); + // CHECK-LABEL: reg_i32: // CHECK: #APP -// CHECK: lgr r{{[0-15]+}}, r{{[0-15]+}} +// CHECK: lgr %r{{[0-9]+}}, %r{{[0-9]+}} // CHECK: #NO_APP check!(reg_i32, i32, reg, "lgr"); + +// CHECK-LABEL: reg_i64: +// CHECK: #APP +// CHECK: lgr %r{{[0-9]+}}, %r{{[0-9]+}} +// CHECK: #NO_APP +check!(reg_i64, i64, reg, "lgr"); + +// CHECK-LABEL: reg_f32: +// CHECK: #APP +// CHECK: ler %f{{[0-9]+}}, %f{{[0-9]+}} +// CHECK: #NO_APP +check!(reg_f32, f32, freg, "ler"); + +// CHECK-LABEL: reg_f64: +// CHECK: #APP +// CHECK: ldr %f{{[0-9]+}}, %f{{[0-9]+}} +// CHECK: #NO_APP +check!(reg_f64, f64, freg, "ldr"); From 0c9e23c7ce964438b107d064533b89f024e7ccf8 Mon Sep 17 00:00:00 2001 From: linux1 Date: Sun, 22 Aug 2021 17:38:22 -0400 Subject: [PATCH 13/36] Fix: appeased x.py test tidy --bless --- compiler/rustc_target/src/asm/mod.rs | 10 +++++----- compiler/rustc_target/src/asm/s390x.rs | 2 +- src/test/assembly/asm/s390x-types.rs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_target/src/asm/mod.rs b/compiler/rustc_target/src/asm/mod.rs index 015faa14e28af..3b3017e37c1f0 100644 --- a/compiler/rustc_target/src/asm/mod.rs +++ b/compiler/rustc_target/src/asm/mod.rs @@ -257,7 +257,7 @@ impl InlineAsmReg { Self::PowerPC(r) => r.name(), Self::Hexagon(r) => r.name(), Self::Mips(r) => r.name(), - Self::S390x(r) => r.name(), + Self::S390x(r) => r.name(), Self::Bpf(r) => r.name(), Self::Err => "", } @@ -312,7 +312,7 @@ impl InlineAsmReg { InlineAsmArch::Mips | InlineAsmArch::Mips64 => { Self::Mips(MipsInlineAsmReg::parse(arch, has_feature, target, &name)?) } - InlineAsmArch::S390x => { + InlineAsmArch::S390x => { Self::S390x(S390xInlineAsmReg::parse(arch, has_feature, target, &name)?) } InlineAsmArch::SpirV => { @@ -715,11 +715,11 @@ pub fn allocatable_registers( mips::fill_reg_map(arch, has_feature, target, &mut map); map } - InlineAsmArch::S390x => { - let mut map = s390x::regclass_map(); + InlineAsmArch::S390x => { + let mut map = s390x::regclass_map(); s390x::fill_reg_map(arch, has_feature, target, &mut map); map - } + } InlineAsmArch::SpirV => { let mut map = spirv::regclass_map(); spirv::fill_reg_map(arch, has_feature, target, &mut map); diff --git a/compiler/rustc_target/src/asm/s390x.rs b/compiler/rustc_target/src/asm/s390x.rs index dbf4168e4a80f..29f370928713b 100644 --- a/compiler/rustc_target/src/asm/s390x.rs +++ b/compiler/rustc_target/src/asm/s390x.rs @@ -113,7 +113,7 @@ def_regs! { "c14 is reserved by the kernel and cannot be used as an operand for inline asm", #error = ["c15"] => "c15 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["a2"] => + #error = ["a2"] => "a2 is not supported by LLVM and cannot be used as an operand for inline asm", #error = ["a3"] => "a3 is not supported by LLVM and cannot be used as an operand for inline asm", diff --git a/src/test/assembly/asm/s390x-types.rs b/src/test/assembly/asm/s390x-types.rs index 692193158405f..dd8a256516e6f 100644 --- a/src/test/assembly/asm/s390x-types.rs +++ b/src/test/assembly/asm/s390x-types.rs @@ -49,7 +49,7 @@ extern "Rust" { } macro_rules! check { ($func:ident, $ty:ty, $class:ident, $mov:literal) => { - #[no_mangle] + #[no_mangle] pub unsafe fn $func(x: $ty) -> $ty { dont_merge(stringify!(func)); @@ -60,7 +60,7 @@ macro_rules! check { ($func:ident, $ty:ty, $class:ident, $mov:literal) => { };} macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => { - #[no_mangle] + #[no_mangle] pub unsafe fn $func(x: $ty) -> $ty { dont_merge(stringify!(func)); From 0ac601d03e0e0951f73d6a89cb6a5aef1905e29b Mon Sep 17 00:00:00 2001 From: Hans Kratz Date: Mon, 23 Aug 2021 08:27:08 +0200 Subject: [PATCH 14/36] Mach-O (Macos/ios/...) LLD flavor is always LD64. --- compiler/rustc_target/src/spec/apple_base.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/spec/apple_base.rs b/compiler/rustc_target/src/spec/apple_base.rs index cff0b3651e170..0a0c548fecd0e 100644 --- a/compiler/rustc_target/src/spec/apple_base.rs +++ b/compiler/rustc_target/src/spec/apple_base.rs @@ -1,6 +1,6 @@ use std::env; -use crate::spec::{FramePointer, SplitDebuginfo, TargetOptions}; +use crate::spec::{FramePointer, LldFlavor, SplitDebuginfo, TargetOptions}; pub fn opts(os: &str) -> TargetOptions { // ELF TLS is only available in macOS 10.7+. If you try to compile for 10.6 @@ -35,6 +35,7 @@ pub fn opts(os: &str) -> TargetOptions { abi_return_struct_as_int: true, emit_debug_gdb_scripts: false, eh_frame_header: false, + lld_flavor: LldFlavor::Ld64, // The historical default for macOS targets is to run `dsymutil` which // generates a packed version of debuginfo split from the main file. From a5190950546c1d62b5a1b476daae3a28f412df05 Mon Sep 17 00:00:00 2001 From: Hans Kratz Date: Mon, 23 Aug 2021 09:28:07 +0200 Subject: [PATCH 15/36] Include ld64 nexte to ld for use with -Z gcc-ld --- src/bootstrap/compile.rs | 4 ++++ src/bootstrap/dist.rs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/bootstrap/compile.rs b/src/bootstrap/compile.rs index d25989954783a..2a6a05e8e509d 100644 --- a/src/bootstrap/compile.rs +++ b/src/bootstrap/compile.rs @@ -1121,6 +1121,10 @@ impl Step for Assemble { &lld_install.join("bin").join(&src_exe), &gcc_ld_dir.join(exe("ld", target_compiler.host)), ); + builder.copy( + &lld_install.join("bin").join(&src_exe), + &gcc_ld_dir.join(exe("ld64", target_compiler.host)), + ); } // Similarly, copy `llvm-dwp` into libdir for Split DWARF. Only copy it when the LLVM diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs index 64075e18366bf..d0bcdb179e39d 100644 --- a/src/bootstrap/dist.rs +++ b/src/bootstrap/dist.rs @@ -412,6 +412,8 @@ impl Step for Rustc { let gcc_lld_dir = dst_dir.join("gcc-ld"); t!(fs::create_dir(&gcc_lld_dir)); builder.copy(&src_dir.join(&rust_lld), &gcc_lld_dir.join(exe("ld", compiler.host))); + builder + .copy(&src_dir.join(&rust_lld), &gcc_lld_dir.join(exe("ld64", compiler.host))); } // Copy over llvm-dwp if it's there From 0f7702efa1cbff1ae0552664dc814e9ac682c09c Mon Sep 17 00:00:00 2001 From: Hans Kratz Date: Mon, 23 Aug 2021 09:32:19 +0200 Subject: [PATCH 16/36] Pass -fuse-ld=/path/to/ld64 if -Z gcc-ld and the lld_flavor for the target is Ld64 --- compiler/rustc_codegen_ssa/src/back/link.rs | 47 +++++++++++++++------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index f3eb1e04d07dc..08c6a951ffb9b 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -2485,20 +2485,39 @@ fn add_gcc_ld_path(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) { if let LinkerFlavor::Gcc = flavor { match ld_impl { LdImpl::Lld => { - let tools_path = - sess.host_filesearch(PathKind::All).get_tools_search_paths(false); - let lld_path = tools_path - .into_iter() - .map(|p| p.join("gcc-ld")) - .find(|p| { - p.join(if sess.host.is_like_windows { "ld.exe" } else { "ld" }).exists() - }) - .unwrap_or_else(|| sess.fatal("rust-lld (as ld) not found")); - cmd.cmd().arg({ - let mut arg = OsString::from("-B"); - arg.push(lld_path); - arg - }); + if sess.target.lld_flavor == LldFlavor::Ld64 { + let tools_path = + sess.host_filesearch(PathKind::All).get_tools_search_paths(false); + let ld64_exe = tools_path + .into_iter() + .map(|p| p.join("gcc-ld")) + .map(|p| { + p.join(if sess.host.is_like_windows { "ld64.exe" } else { "ld64" }) + }) + .find(|p| p.exists()) + .unwrap_or_else(|| sess.fatal("rust-lld (as ld64) not found")); + cmd.cmd().arg({ + let mut arg = OsString::from("-fuse-ld="); + arg.push(ld64_exe); + arg + }); + } else { + let tools_path = + sess.host_filesearch(PathKind::All).get_tools_search_paths(false); + let lld_path = tools_path + .into_iter() + .map(|p| p.join("gcc-ld")) + .find(|p| { + p.join(if sess.host.is_like_windows { "ld.exe" } else { "ld" }) + .exists() + }) + .unwrap_or_else(|| sess.fatal("rust-lld (as ld) not found")); + cmd.cmd().arg({ + let mut arg = OsString::from("-B"); + arg.push(lld_path); + arg + }); + } } } } else { From 820e2680ec2f7f5f1b42dc94374986d251a22aff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Mon, 23 Aug 2021 23:31:01 +0200 Subject: [PATCH 17/36] handle ascription type op in NLL HRTB diagnostics Refactors the `type_op_ascribe_user_type` query into a version which accepts a span, and uses it in the nicer NLL HRTB bound region errors. --- .../diagnostics/bound_region_errors.rs | 42 ++++++++++++++-- compiler/rustc_traits/src/lib.rs | 2 +- compiler/rustc_traits/src/type_op.rs | 48 +++++++++++++------ 3 files changed, 72 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_mir/src/borrow_check/diagnostics/bound_region_errors.rs b/compiler/rustc_mir/src/borrow_check/diagnostics/bound_region_errors.rs index d0284dd030236..ac30093ba8260 100644 --- a/compiler/rustc_mir/src/borrow_check/diagnostics/bound_region_errors.rs +++ b/compiler/rustc_mir/src/borrow_check/diagnostics/bound_region_errors.rs @@ -9,7 +9,7 @@ use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable}; use rustc_span::Span; use rustc_trait_selection::traits::query::type_op; use rustc_trait_selection::traits::{SelectionContext, TraitEngineExt as _}; -use rustc_traits::type_op_prove_predicate_with_span; +use rustc_traits::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_with_span}; use std::fmt; use std::rc::Rc; @@ -104,10 +104,11 @@ impl<'tcx, T: Copy + fmt::Display + TypeFoldable<'tcx> + 'tcx> ToUniverseInfo<'t impl<'tcx> ToUniverseInfo<'tcx> for Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::AscribeUserType<'tcx>>> { - fn to_universe_info(self, _base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> { - // Ascribe user type isn't usually called on types that have different - // bound regions. - UniverseInfo::other() + fn to_universe_info(self, base_universe: ty::UniverseIndex) -> UniverseInfo<'tcx> { + UniverseInfo(UniverseInfoInner::TypeOp(Rc::new(AscribeUserTypeQuery { + canonical_query: self, + base_universe, + }))) } } @@ -267,6 +268,37 @@ where } } +struct AscribeUserTypeQuery<'tcx> { + canonical_query: Canonical<'tcx, ty::ParamEnvAnd<'tcx, type_op::AscribeUserType<'tcx>>>, + base_universe: ty::UniverseIndex, +} + +impl TypeOpInfo<'tcx> for AscribeUserTypeQuery<'tcx> { + fn fallback_error(&self, tcx: TyCtxt<'tcx>, span: Span) -> DiagnosticBuilder<'tcx> { + // FIXME: This error message isn't great, but it doesn't show up in the existing UI tests, + // and is only the fallback when the nice error fails. Consider improving this some more. + tcx.sess.struct_span_err(span, "higher-ranked lifetime error") + } + + fn base_universe(&self) -> ty::UniverseIndex { + self.base_universe + } + + fn nice_error( + &self, + tcx: TyCtxt<'tcx>, + span: Span, + placeholder_region: ty::Region<'tcx>, + error_region: Option>, + ) -> Option> { + tcx.infer_ctxt().enter_with_canonical(span, &self.canonical_query, |ref infcx, key, _| { + let mut fulfill_cx = >::new(tcx); + type_op_ascribe_user_type_with_span(infcx, &mut *fulfill_cx, key, Some(span)).ok()?; + try_extract_error_from_fulfill_cx(fulfill_cx, infcx, placeholder_region, error_region) + }) + } +} + fn try_extract_error_from_fulfill_cx<'tcx>( mut fulfill_cx: Box + 'tcx>, infcx: &InferCtxt<'_, 'tcx>, diff --git a/compiler/rustc_traits/src/lib.rs b/compiler/rustc_traits/src/lib.rs index 8dd7c5bdfaebc..48c46c3069328 100644 --- a/compiler/rustc_traits/src/lib.rs +++ b/compiler/rustc_traits/src/lib.rs @@ -19,7 +19,7 @@ mod normalize_erasing_regions; mod normalize_projection_ty; mod type_op; -pub use type_op::type_op_prove_predicate_with_span; +pub use type_op::{type_op_ascribe_user_type_with_span, type_op_prove_predicate_with_span}; use rustc_middle::ty::query::Providers; diff --git a/compiler/rustc_traits/src/type_op.rs b/compiler/rustc_traits/src/type_op.rs index c2e0a9987858e..a76fb84261615 100644 --- a/compiler/rustc_traits/src/type_op.rs +++ b/compiler/rustc_traits/src/type_op.rs @@ -40,18 +40,28 @@ fn type_op_ascribe_user_type<'tcx>( canonicalized: Canonical<'tcx, ParamEnvAnd<'tcx, AscribeUserType<'tcx>>>, ) -> Result<&'tcx Canonical<'tcx, QueryResponse<'tcx, ()>>, NoSolution> { tcx.infer_ctxt().enter_canonical_trait_query(&canonicalized, |infcx, fulfill_cx, key| { - let (param_env, AscribeUserType { mir_ty, def_id, user_substs }) = key.into_parts(); - - debug!( - "type_op_ascribe_user_type: mir_ty={:?} def_id={:?} user_substs={:?}", - mir_ty, def_id, user_substs - ); + type_op_ascribe_user_type_with_span(infcx, fulfill_cx, key, None) + }) +} - let mut cx = AscribeUserTypeCx { infcx, param_env, fulfill_cx }; - cx.relate_mir_and_user_ty(mir_ty, def_id, user_substs)?; +/// The core of the `type_op_ascribe_user_type` query: for diagnostics purposes in NLL HRTB errors, +/// this query can be re-run to better track the span of the obligation cause, and improve the error +/// message. Do not call directly unless you're in that very specific context. +pub fn type_op_ascribe_user_type_with_span<'a, 'tcx: 'a>( + infcx: &'a InferCtxt<'a, 'tcx>, + fulfill_cx: &'a mut dyn TraitEngine<'tcx>, + key: ParamEnvAnd<'tcx, AscribeUserType<'tcx>>, + span: Option, +) -> Result<(), NoSolution> { + let (param_env, AscribeUserType { mir_ty, def_id, user_substs }) = key.into_parts(); + debug!( + "type_op_ascribe_user_type: mir_ty={:?} def_id={:?} user_substs={:?}", + mir_ty, def_id, user_substs + ); - Ok(()) - }) + let mut cx = AscribeUserTypeCx { infcx, param_env, fulfill_cx }; + cx.relate_mir_and_user_ty(mir_ty, def_id, user_substs, span)?; + Ok(()) } struct AscribeUserTypeCx<'me, 'tcx> { @@ -85,10 +95,15 @@ impl AscribeUserTypeCx<'me, 'tcx> { Ok(()) } - fn prove_predicate(&mut self, predicate: Predicate<'tcx>) { + fn prove_predicate(&mut self, predicate: Predicate<'tcx>, span: Option) { + let cause = if let Some(span) = span { + ObligationCause::dummy_with_span(span) + } else { + ObligationCause::dummy() + }; self.fulfill_cx.register_predicate_obligation( self.infcx, - Obligation::new(ObligationCause::dummy(), self.param_env, predicate), + Obligation::new(cause, self.param_env, predicate), ); } @@ -108,6 +123,7 @@ impl AscribeUserTypeCx<'me, 'tcx> { mir_ty: Ty<'tcx>, def_id: DefId, user_substs: UserSubsts<'tcx>, + span: Option, ) -> Result<(), NoSolution> { let UserSubsts { user_self_ty, substs } = user_substs; let tcx = self.tcx(); @@ -129,7 +145,7 @@ impl AscribeUserTypeCx<'me, 'tcx> { debug!(?instantiated_predicates.predicates); for instantiated_predicate in instantiated_predicates.predicates { let instantiated_predicate = self.normalize(instantiated_predicate); - self.prove_predicate(instantiated_predicate); + self.prove_predicate(instantiated_predicate, span); } if let Some(UserSelfTy { impl_def_id, self_ty }) = user_self_ty { @@ -141,6 +157,7 @@ impl AscribeUserTypeCx<'me, 'tcx> { self.prove_predicate( ty::PredicateKind::WellFormed(impl_self_ty.into()).to_predicate(self.tcx()), + span, ); } @@ -155,7 +172,10 @@ impl AscribeUserTypeCx<'me, 'tcx> { // them? This would only be relevant if some input // type were ill-formed but did not appear in `ty`, // which...could happen with normalization... - self.prove_predicate(ty::PredicateKind::WellFormed(ty.into()).to_predicate(self.tcx())); + self.prove_predicate( + ty::PredicateKind::WellFormed(ty.into()).to_predicate(self.tcx()), + span, + ); Ok(()) } } From 05cd587726b01415f50ab8def30ea07864298e13 Mon Sep 17 00:00:00 2001 From: linux1 Date: Mon, 23 Aug 2021 17:32:27 -0400 Subject: [PATCH 18/36] Refactor: disabled frame pointer; consolidated unsupported register errors; added register prefix --- compiler/rustc_target/src/asm/s390x.rs | 86 ++++++-------------------- 1 file changed, 18 insertions(+), 68 deletions(-) diff --git a/compiler/rustc_target/src/asm/s390x.rs b/compiler/rustc_target/src/asm/s390x.rs index 29f370928713b..5ed93c0c1a9ce 100644 --- a/compiler/rustc_target/src/asm/s390x.rs +++ b/compiler/rustc_target/src/asm/s390x.rs @@ -54,8 +54,8 @@ def_regs! { r8: reg = ["r8"], r9: reg = ["r9"], r10: reg = ["r10"], - r11: reg = ["r11"], r12: reg = ["r12"], + r13: reg = ["r13"], r14: reg = ["r14"], f0: freg = ["f0"], f1: freg = ["f1"], @@ -73,74 +73,24 @@ def_regs! { f13: freg = ["f13"], f14: freg = ["f14"], f15: freg = ["f15"], - #error = ["r13"] => - "The base pointer cannot be used as an operand for inline asm", + #error = ["r11"] => + "The frame pointer cannot be used as an operand for inline asm", #error = ["r15"] => "The stack pointer cannot be used as an operand for inline asm", - #error = ["a0"] => - "This pointer is reserved on s390x and cannot be used as an operand for inline asm", - #error = ["a1"] => - "This pointer is reserved on z/Arch and cannot be used as an operand for inline asm", - #error = ["c0"] => - "c0 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c1"] => - "c1 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c2"] => - "c2 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c3"] => - "c3 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c4"] => - "c4 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c5"] => - "c5 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c6"] => - "c6 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c7"] => - "c7 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c8"] => - "c8 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c9"] => - "c9 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c10"] => - "c10 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c11"] => - "c11 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c12"] => - "c12 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c13"] => - "c13 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c14"] => - "c14 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["c15"] => - "c15 is reserved by the kernel and cannot be used as an operand for inline asm", - #error = ["a2"] => - "a2 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a3"] => - "a3 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a4"] => - "a4 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a5"] => - "a5 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a6"] => - "a6 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a7"] => - "a7 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a8"] => - "a8 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a9"] => - "a9 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a10"] => - "a10 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a11"] => - "a11 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a12"] => - "a12 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a13"] => - "a13 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a14"] => - "a14 is not supported by LLVM and cannot be used as an operand for inline asm", - #error = ["a15"] => - "a15 is not supported by LLVM and cannot be used as an operand for inline asm", + #error = [ + "c0", "c1", "c2", "c3", + "c4", "c5", "c6", "c7", + "c8", "c9", "c10", "c11", + "c12", "c13", "c14", "c15" + ] => + "control registers are reserved by the kernel and cannot be used as operands for inline asm", + #error = [ + "a0", "a1", "a2", "a3", + "a4", "a5", "a6", "a7", + "a8", "a9", "a10", "a11", + "a12", "a13", "a14", "a15" + ] => + "access registers are not supported and cannot be used as operands for inline asm", } } @@ -151,6 +101,6 @@ impl S390xInlineAsmReg { _arch: InlineAsmArch, _modifier: Option, ) -> fmt::Result { - out.write_str(self.name()) + out.write_str(&format!("%{}", self.name())) } } From a9f623707b8dcaba260b547e1950a4679b3b40eb Mon Sep 17 00:00:00 2001 From: linux1 Date: Mon, 23 Aug 2021 17:56:04 -0400 Subject: [PATCH 19/36] Fix: made suggested change --- compiler/rustc_target/src/asm/s390x.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_target/src/asm/s390x.rs b/compiler/rustc_target/src/asm/s390x.rs index 5ed93c0c1a9ce..a74873f17476e 100644 --- a/compiler/rustc_target/src/asm/s390x.rs +++ b/compiler/rustc_target/src/asm/s390x.rs @@ -101,6 +101,6 @@ impl S390xInlineAsmReg { _arch: InlineAsmArch, _modifier: Option, ) -> fmt::Result { - out.write_str(&format!("%{}", self.name())) + write!(out, "%{}", self.name()) } } From 7b0e564e7cd3bebea7c41165db42a7b15010d2cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Rakic?= Date: Mon, 23 Aug 2021 23:34:04 +0200 Subject: [PATCH 20/36] Update NLL HRTB type ascription blessed expectations Some of these tests have reached parity with the migrate-mode output. --- src/test/ui/hrtb/due-to-where-clause.nll.stderr | 8 -------- src/test/ui/hrtb/hrtb-cache-issue-54302.nll.stderr | 8 -------- src/test/ui/hrtb/hrtb-just-for-static.nll.stderr | 7 +++++-- src/test/ui/issues/issue-54302.nll.stderr | 8 -------- 4 files changed, 5 insertions(+), 26 deletions(-) delete mode 100644 src/test/ui/hrtb/due-to-where-clause.nll.stderr delete mode 100644 src/test/ui/hrtb/hrtb-cache-issue-54302.nll.stderr delete mode 100644 src/test/ui/issues/issue-54302.nll.stderr diff --git a/src/test/ui/hrtb/due-to-where-clause.nll.stderr b/src/test/ui/hrtb/due-to-where-clause.nll.stderr deleted file mode 100644 index 90803a0adb01b..0000000000000 --- a/src/test/ui/hrtb/due-to-where-clause.nll.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: higher-ranked subtype error - --> $DIR/due-to-where-clause.rs:2:5 - | -LL | test::(&mut 42); - | ^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/hrtb/hrtb-cache-issue-54302.nll.stderr b/src/test/ui/hrtb/hrtb-cache-issue-54302.nll.stderr deleted file mode 100644 index 4de35d70c30a3..0000000000000 --- a/src/test/ui/hrtb/hrtb-cache-issue-54302.nll.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: higher-ranked subtype error - --> $DIR/hrtb-cache-issue-54302.rs:19:5 - | -LL | assert_deserialize_owned::<&'static str>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - diff --git a/src/test/ui/hrtb/hrtb-just-for-static.nll.stderr b/src/test/ui/hrtb/hrtb-just-for-static.nll.stderr index a812282def9a8..17d59bb321a45 100644 --- a/src/test/ui/hrtb/hrtb-just-for-static.nll.stderr +++ b/src/test/ui/hrtb/hrtb-just-for-static.nll.stderr @@ -17,11 +17,14 @@ LL | want_hrtb::<&'a u32>() | = help: consider replacing `'a` with `'static` -error: higher-ranked subtype error +error: implementation of `Foo` is not general enough --> $DIR/hrtb-just-for-static.rs:30:5 | LL | want_hrtb::<&'a u32>() - | ^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough + | + = note: `Foo<&'0 isize>` would have to be implemented for the type `&u32`, for any lifetime `'0`... + = note: ...but `Foo<&'1 isize>` is actually implemented for the type `&'1 u32`, for some specific lifetime `'1` error: aborting due to 3 previous errors diff --git a/src/test/ui/issues/issue-54302.nll.stderr b/src/test/ui/issues/issue-54302.nll.stderr deleted file mode 100644 index e68de0312824d..0000000000000 --- a/src/test/ui/issues/issue-54302.nll.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: higher-ranked subtype error - --> $DIR/issue-54302.rs:13:5 - | -LL | assert_deserialize_owned::<&'static str>(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -error: aborting due to previous error - From 96381d390d7362e06809ee624dba2cca1bc6776f Mon Sep 17 00:00:00 2001 From: linux1 Date: Mon, 23 Aug 2021 21:53:23 -0400 Subject: [PATCH 21/36] Fix: added necessary prefix --- src/test/assembly/asm/s390x-types.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/test/assembly/asm/s390x-types.rs b/src/test/assembly/asm/s390x-types.rs index dd8a256516e6f..ec0515b20bdfb 100644 --- a/src/test/assembly/asm/s390x-types.rs +++ b/src/test/assembly/asm/s390x-types.rs @@ -51,7 +51,7 @@ extern "Rust" { macro_rules! check { ($func:ident, $ty:ty, $class:ident, $mov:literal) => { #[no_mangle] pub unsafe fn $func(x: $ty) -> $ty { - dont_merge(stringify!(func)); + dont_merge(stringify!($func)); let y; asm!(concat!($mov," {}, {}"), out($class) y, in($class) x); @@ -62,7 +62,7 @@ macro_rules! check { ($func:ident, $ty:ty, $class:ident, $mov:literal) => { macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => { #[no_mangle] pub unsafe fn $func(x: $ty) -> $ty { - dont_merge(stringify!(func)); + dont_merge(stringify!($func)); let y; asm!(concat!($mov, " ", $reg, ", ", $reg), lateout($reg) y, in($reg) x); @@ -124,3 +124,9 @@ check!(reg_f32, f32, freg, "ler"); // CHECK: ldr %f{{[0-9]+}}, %f{{[0-9]+}} // CHECK: #NO_APP check!(reg_f64, f64, freg, "ldr"); + +// CHECK-LABEL: reg_ptr: +// CHECK: #APP +// CHECK: lgr %r{{[0-9]+}}, %r{{[0-9]+}} +// CHECK: #NO_APP +check!(reg_ptr, ptr, reg, "lgr"); From 07d37299eb898a4035a73cdabf731e14ccf9e140 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Mon, 23 Aug 2021 19:16:44 -0700 Subject: [PATCH 22/36] Update cargo --- Cargo.lock | 4 ++-- src/tools/cargo | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9e0624c57ae94..424172f500382 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -871,9 +871,9 @@ dependencies = [ [[package]] name = "curl-sys" -version = "0.4.44+curl-7.77.0" +version = "0.4.45+curl-7.78.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b6d85e9322b193f117c966e79c2d6929ec08c02f339f950044aba12e20bbaf1" +checksum = "de9e5a72b1c744eb5dd20b2be4d7eb84625070bb5c4ab9b347b70464ab1e62eb" dependencies = [ "cc", "libc", diff --git a/src/tools/cargo b/src/tools/cargo index e96bdb0c3d0a4..9b81660b79832 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit e96bdb0c3d0a418e7fcd7fbd69be08abf830b4bc +Subproject commit 9b81660b79832f92512edd4c29059a9ff88fcb6c From 4d8d72f4f9cd971fce3965015d785ecedb256326 Mon Sep 17 00:00:00 2001 From: Roxane Date: Mon, 23 Aug 2021 22:41:03 -0400 Subject: [PATCH 23/36] Handle match with non axhaustive variants in closures --- compiler/rustc_typeck/src/expr_use_visitor.rs | 17 +++++- .../auxiliary/match_non_exhaustive_lib.rs | 10 ++++ .../non-exhaustive-match.rs | 54 +++++++++++++++++++ .../non-exhaustive-match.stderr | 50 +++++++++++++++++ 4 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/closures/2229_closure_analysis/auxiliary/match_non_exhaustive_lib.rs create mode 100644 src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.rs create mode 100644 src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.stderr diff --git a/compiler/rustc_typeck/src/expr_use_visitor.rs b/compiler/rustc_typeck/src/expr_use_visitor.rs index 1d7852d964c1d..c5c758255f0aa 100644 --- a/compiler/rustc_typeck/src/expr_use_visitor.rs +++ b/compiler/rustc_typeck/src/expr_use_visitor.rs @@ -14,7 +14,7 @@ use rustc_index::vec::Idx; use rustc_infer::infer::InferCtxt; use rustc_middle::hir::place::ProjectionKind; use rustc_middle::mir::FakeReadCause; -use rustc_middle::ty::{self, adjustment, TyCtxt}; +use rustc_middle::ty::{self, adjustment, AdtKind, TyCtxt}; use rustc_target::abi::VariantIdx; use std::iter; @@ -262,7 +262,20 @@ impl<'a, 'tcx> ExprUseVisitor<'a, 'tcx> { let place_ty = place.place.ty(); if let ty::Adt(def, _) = place_ty.kind() { - if def.variants.len() > 1 { + // Note that if a non-exhaustive SingleVariant is defined in another crate, we need + // to assume that more cases will be added to the variant in the future. This mean + // that we should handle non-exhaustive SingleVariant the same way we would handle + // a MultiVariant. + // If the variant is not local it must be defined in another crate. + let is_non_exhaustive = match def.adt_kind() { + AdtKind::Struct | AdtKind::Union => { + def.non_enum_variant().is_field_list_non_exhaustive() + } + AdtKind::Enum => def.is_variant_list_non_exhaustive(), + }; + if def.variants.len() > 1 + || (!def.did.is_local() && is_non_exhaustive) + { needs_to_be_read = true; } } diff --git a/src/test/ui/closures/2229_closure_analysis/auxiliary/match_non_exhaustive_lib.rs b/src/test/ui/closures/2229_closure_analysis/auxiliary/match_non_exhaustive_lib.rs new file mode 100644 index 0000000000000..4060c409355a1 --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/auxiliary/match_non_exhaustive_lib.rs @@ -0,0 +1,10 @@ +#[non_exhaustive] +pub enum E1 {} + +#[non_exhaustive] +pub enum E2 { A, B } + +#[non_exhaustive] +pub enum E3 { C } + +pub enum E4 { D } diff --git a/src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.rs b/src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.rs new file mode 100644 index 0000000000000..318673ef847e5 --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.rs @@ -0,0 +1,54 @@ +// edition:2021 + +// aux-build:match_non_exhaustive_lib.rs + +/* The error message for non-exhaustive matches on non-local enums + * marked as non-exhaustive should mention the fact that the enum + * is marked as non-exhaustive (issue #85227). + */ + +// Ignore non_exhaustive in the same crate +#[non_exhaustive] +enum L1 { A, B } +enum L2 { C } + +extern crate match_non_exhaustive_lib; +use match_non_exhaustive_lib::{E1, E2, E3, E4}; + +fn foo() -> (L1, L2) {todo!()} +fn bar() -> (E1, E2, E3, E4) {todo!()} + +fn main() { + let (l1, l2) = foo(); + // No error for enums defined in this crate + let _a = || { match l1 { L1::A => (), L1::B => () } }; + // (except if the match is already non-exhaustive) + let _b = || { match l1 { L1::A => () } }; + //~^ ERROR: non-exhaustive patterns: `B` not covered [E0004] + + // l2 should not be captured as it is a non-exhaustive SingleVariant + // defined in this crate + let _c = || { match l2 { L2::C => (), _ => () } }; + let mut mut_l2 = l2; + _c(); + + // E1 is not visibly uninhabited from here + let (e1, e2, e3, e4) = bar(); + let _d = || { match e1 {} }; + //~^ ERROR: non-exhaustive patterns: type `E1` is non-empty [E0004] + let _e = || { match e2 { E2::A => (), E2::B => () } }; + //~^ ERROR: non-exhaustive patterns: `_` not covered [E0004] + let _f = || { match e2 { E2::A => (), E2::B => (), _ => () } }; + + // e3 should be captured as it is a non-exhaustive SingleVariant + // defined in another crate + let _g = || { match e3 { E3::C => (), _ => () } }; + let mut mut_e3 = e3; + //~^ ERROR: cannot move out of `e3` because it is borrowed + _g(); + + // e4 should not be captured as it is a SingleVariant + let _h = || { match e4 { E4::D => (), _ => () } }; + let mut mut_e4 = e4; + _h(); +} diff --git a/src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.stderr b/src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.stderr new file mode 100644 index 0000000000000..91ffe1a47f413 --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.stderr @@ -0,0 +1,50 @@ +error[E0004]: non-exhaustive patterns: `B` not covered + --> $DIR/non-exhaustive-match.rs:26:25 + | +LL | enum L1 { A, B } + | ---------------- + | | | + | | not covered + | `L1` defined here +... +LL | let _b = || { match l1 { L1::A => () } }; + | ^^ pattern `B` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + = note: the matched value is of type `L1` + +error[E0004]: non-exhaustive patterns: type `E1` is non-empty + --> $DIR/non-exhaustive-match.rs:37:25 + | +LL | let _d = || { match e1 {} }; + | ^^ + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + = note: the matched value is of type `E1`, which is marked as non-exhaustive + +error[E0004]: non-exhaustive patterns: `_` not covered + --> $DIR/non-exhaustive-match.rs:39:25 + | +LL | let _e = || { match e2 { E2::A => (), E2::B => () } }; + | ^^ pattern `_` not covered + | + = help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms + = note: the matched value is of type `E2`, which is marked as non-exhaustive + +error[E0505]: cannot move out of `e3` because it is borrowed + --> $DIR/non-exhaustive-match.rs:46:22 + | +LL | let _g = || { match e3 { E3::C => (), _ => () } }; + | -- -- borrow occurs due to use in closure + | | + | borrow of `e3` occurs here +LL | let mut mut_e3 = e3; + | ^^ move out of `e3` occurs here +LL | +LL | _g(); + | -- borrow later used here + +error: aborting due to 4 previous errors + +Some errors have detailed explanations: E0004, E0505. +For more information about an error, try `rustc --explain E0004`. From 1335b4cadd66b026be809bbc07f77eb477393043 Mon Sep 17 00:00:00 2001 From: Roxane Date: Mon, 23 Aug 2021 22:41:19 -0400 Subject: [PATCH 24/36] Add additional match test case --- .../2229_closure_analysis/match-edge-cases.rs | 35 +++++++++++++++++++ .../match-edge-cases.stderr | 17 +++++++++ 2 files changed, 52 insertions(+) create mode 100644 src/test/ui/closures/2229_closure_analysis/match-edge-cases.rs create mode 100644 src/test/ui/closures/2229_closure_analysis/match-edge-cases.stderr diff --git a/src/test/ui/closures/2229_closure_analysis/match-edge-cases.rs b/src/test/ui/closures/2229_closure_analysis/match-edge-cases.rs new file mode 100644 index 0000000000000..035c658302745 --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/match-edge-cases.rs @@ -0,0 +1,35 @@ +// edition:2021 + +enum SingleVariant { + A +} + +struct TestStruct { + x: i32, + y: i32, + z: i32, +} + +fn main() { + let sv = SingleVariant::A; + let condition = true; + // sv should not be captured as it is a SingleVariant + let _a = || { + match sv { + SingleVariant::A if condition => (), + _ => () + } + }; + let mut mut_sv = sv; + _a(); + + // ts should be captured + let ts = TestStruct { x: 1, y: 1, z: 1 }; + let _b = || { match ts { + TestStruct{ x: 1, .. } => (), + _ => () + }}; + let mut mut_ts = ts; + //~^ ERROR: cannot move out of `ts` because it is borrowed + _b(); +} diff --git a/src/test/ui/closures/2229_closure_analysis/match-edge-cases.stderr b/src/test/ui/closures/2229_closure_analysis/match-edge-cases.stderr new file mode 100644 index 0000000000000..b9d2316206ecb --- /dev/null +++ b/src/test/ui/closures/2229_closure_analysis/match-edge-cases.stderr @@ -0,0 +1,17 @@ +error[E0505]: cannot move out of `ts` because it is borrowed + --> $DIR/match-edge-cases.rs:32:22 + | +LL | let _b = || { match ts { + | -- -- borrow occurs due to use in closure + | | + | borrow of `ts` occurs here +... +LL | let mut mut_ts = ts; + | ^^ move out of `ts` occurs here +LL | +LL | _b(); + | -- borrow later used here + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0505`. From 68b1bfc9b2d93d778b61c63b6a22847c128fc964 Mon Sep 17 00:00:00 2001 From: Roxane Date: Mon, 23 Aug 2021 22:57:05 -0400 Subject: [PATCH 25/36] Create a specific match folder for match tests --- .../{ => match}/auxiliary/match_non_exhaustive_lib.rs | 0 .../ui/closures/2229_closure_analysis/{ => match}/issue-87097.rs | 0 .../closures/2229_closure_analysis/{ => match}/issue-87097.stderr | 0 .../ui/closures/2229_closure_analysis/{ => match}/issue-87426.rs | 0 .../2229_closure_analysis/{ => match}/match-edge-cases.rs | 0 .../2229_closure_analysis/{ => match}/match-edge-cases.stderr | 0 .../2229_closure_analysis/{ => match}/non-exhaustive-match.rs | 0 .../2229_closure_analysis/{ => match}/non-exhaustive-match.stderr | 0 .../{ => match}/pattern-matching-should-fail.rs | 0 .../{ => match}/pattern-matching-should-fail.stderr | 0 .../{ => match}/patterns-capture-analysis.rs | 0 .../{ => match}/patterns-capture-analysis.stderr | 0 12 files changed, 0 insertions(+), 0 deletions(-) rename src/test/ui/closures/2229_closure_analysis/{ => match}/auxiliary/match_non_exhaustive_lib.rs (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/issue-87097.rs (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/issue-87097.stderr (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/issue-87426.rs (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/match-edge-cases.rs (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/match-edge-cases.stderr (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/non-exhaustive-match.rs (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/non-exhaustive-match.stderr (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/pattern-matching-should-fail.rs (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/pattern-matching-should-fail.stderr (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/patterns-capture-analysis.rs (100%) rename src/test/ui/closures/2229_closure_analysis/{ => match}/patterns-capture-analysis.stderr (100%) diff --git a/src/test/ui/closures/2229_closure_analysis/auxiliary/match_non_exhaustive_lib.rs b/src/test/ui/closures/2229_closure_analysis/match/auxiliary/match_non_exhaustive_lib.rs similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/auxiliary/match_non_exhaustive_lib.rs rename to src/test/ui/closures/2229_closure_analysis/match/auxiliary/match_non_exhaustive_lib.rs diff --git a/src/test/ui/closures/2229_closure_analysis/issue-87097.rs b/src/test/ui/closures/2229_closure_analysis/match/issue-87097.rs similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/issue-87097.rs rename to src/test/ui/closures/2229_closure_analysis/match/issue-87097.rs diff --git a/src/test/ui/closures/2229_closure_analysis/issue-87097.stderr b/src/test/ui/closures/2229_closure_analysis/match/issue-87097.stderr similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/issue-87097.stderr rename to src/test/ui/closures/2229_closure_analysis/match/issue-87097.stderr diff --git a/src/test/ui/closures/2229_closure_analysis/issue-87426.rs b/src/test/ui/closures/2229_closure_analysis/match/issue-87426.rs similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/issue-87426.rs rename to src/test/ui/closures/2229_closure_analysis/match/issue-87426.rs diff --git a/src/test/ui/closures/2229_closure_analysis/match-edge-cases.rs b/src/test/ui/closures/2229_closure_analysis/match/match-edge-cases.rs similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/match-edge-cases.rs rename to src/test/ui/closures/2229_closure_analysis/match/match-edge-cases.rs diff --git a/src/test/ui/closures/2229_closure_analysis/match-edge-cases.stderr b/src/test/ui/closures/2229_closure_analysis/match/match-edge-cases.stderr similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/match-edge-cases.stderr rename to src/test/ui/closures/2229_closure_analysis/match/match-edge-cases.stderr diff --git a/src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.rs b/src/test/ui/closures/2229_closure_analysis/match/non-exhaustive-match.rs similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.rs rename to src/test/ui/closures/2229_closure_analysis/match/non-exhaustive-match.rs diff --git a/src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.stderr b/src/test/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/non-exhaustive-match.stderr rename to src/test/ui/closures/2229_closure_analysis/match/non-exhaustive-match.stderr diff --git a/src/test/ui/closures/2229_closure_analysis/pattern-matching-should-fail.rs b/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.rs similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/pattern-matching-should-fail.rs rename to src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.rs diff --git a/src/test/ui/closures/2229_closure_analysis/pattern-matching-should-fail.stderr b/src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/pattern-matching-should-fail.stderr rename to src/test/ui/closures/2229_closure_analysis/match/pattern-matching-should-fail.stderr diff --git a/src/test/ui/closures/2229_closure_analysis/patterns-capture-analysis.rs b/src/test/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.rs similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/patterns-capture-analysis.rs rename to src/test/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.rs diff --git a/src/test/ui/closures/2229_closure_analysis/patterns-capture-analysis.stderr b/src/test/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.stderr similarity index 100% rename from src/test/ui/closures/2229_closure_analysis/patterns-capture-analysis.stderr rename to src/test/ui/closures/2229_closure_analysis/match/patterns-capture-analysis.stderr From 4a9ba65ca9eaf9db3a010cbf5859b3fdf16ac687 Mon Sep 17 00:00:00 2001 From: linux1 Date: Tue, 24 Aug 2021 12:41:49 -0400 Subject: [PATCH 26/36] Feat: added explicit register tests; added prefix to check_reg asm string --- src/test/assembly/asm/s390x-types.rs | 38 +++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/test/assembly/asm/s390x-types.rs b/src/test/assembly/asm/s390x-types.rs index ec0515b20bdfb..69d9cab23c8ed 100644 --- a/src/test/assembly/asm/s390x-types.rs +++ b/src/test/assembly/asm/s390x-types.rs @@ -65,7 +65,7 @@ macro_rules! check_reg { ($func:ident, $ty:ty, $reg:tt, $mov:literal) => { dont_merge(stringify!($func)); let y; - asm!(concat!($mov, " ", $reg, ", ", $reg), lateout($reg) y, in($reg) x); + asm!(concat!($mov, " %", $reg, ", %", $reg), lateout($reg) y, in($reg) x); y } };} @@ -130,3 +130,39 @@ check!(reg_f64, f64, freg, "ldr"); // CHECK: lgr %r{{[0-9]+}}, %r{{[0-9]+}} // CHECK: #NO_APP check!(reg_ptr, ptr, reg, "lgr"); + +// CHECK-LABEL: r0_i8: +// CHECK: #APP +// CHECK: lr %r0, %r0 +// CHECK: #NO_APP +check_reg!(r0_i8, i8, "r0", "lr"); + +// CHECK-LABEL: r0_i16: +// CHECK: #APP +// CHECK: lr %r0, %r0 +// CHECK: #NO_APP +check_reg!(r0_i16, i16, "r0", "lr"); + +// CHECK-LABEL: r0_i32: +// CHECK: #APP +// CHECK: lr %r0, %r0 +// CHECK: #NO_APP +check_reg!(r0_i32, i32, "r0", "lr"); + +// CHECK-LABEL: r0_i64: +// CHECK: #APP +// CHECK: lr %r0, %r0 +// CHECK: #NO_APP +check_reg!(r0_i64, i64, "r0", "lr"); + +// CHECK-LABEL: f0_f32: +// CHECK: #APP +// CHECK: ler %f0, %f0 +// CHECK: #NO_APP +check_reg!(f0_f32, f32, "f0", "ler"); + +// CHECK-LABEL: f0_f64: +// CHECK: #APP +// CHECK: ldr %f0, %f0 +// CHECK: #NO_APP +check_reg!(f0_f64, f64, "f0", "ldr"); From a216d666ca535d3cfcc8839fd3cb3d5e483e2d7e Mon Sep 17 00:00:00 2001 From: Aman Arora Date: Wed, 25 Aug 2021 03:52:24 -0400 Subject: [PATCH 27/36] type_implements_trait consider obligation failure on overflow --- compiler/rustc_trait_selection/src/infer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_trait_selection/src/infer.rs b/compiler/rustc_trait_selection/src/infer.rs index ea074192d23b1..c55b379741ee6 100644 --- a/compiler/rustc_trait_selection/src/infer.rs +++ b/compiler/rustc_trait_selection/src/infer.rs @@ -117,7 +117,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> { recursion_depth: 0, predicate: trait_ref.without_const().to_predicate(self.tcx), }; - self.evaluate_obligation_no_overflow(&obligation) + self.evaluate_obligation(&obligation).unwrap_or(traits::EvaluationResult::EvaluatedToErr) } } From d7d122faecfcde3c34ffaa1cfa3f81debb60be59 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 25 Aug 2021 11:39:35 -0400 Subject: [PATCH 28/36] update docs for `type_implements_trait` --- compiler/rustc_trait_selection/src/infer.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/rustc_trait_selection/src/infer.rs b/compiler/rustc_trait_selection/src/infer.rs index c55b379741ee6..3e79545d725e7 100644 --- a/compiler/rustc_trait_selection/src/infer.rs +++ b/compiler/rustc_trait_selection/src/infer.rs @@ -44,6 +44,10 @@ pub trait InferCtxtExt<'tcx> { /// - the self type /// - the *other* type parameters of the trait, excluding the self-type /// - the parameter environment + /// + /// Invokes `evaluate_obligation`, so in the event that evaluating + /// `Ty: Trait` causes overflow, EvaluatedToRecur (or EvaluatedToUnknown) + /// will be returned. fn type_implements_trait( &self, trait_def_id: DefId, From 88bcd4457be4d37d83d505ad3fe2dc7a5ce7203a Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 25 Aug 2021 12:09:48 -0400 Subject: [PATCH 29/36] trailing whitespace --- compiler/rustc_trait_selection/src/infer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_trait_selection/src/infer.rs b/compiler/rustc_trait_selection/src/infer.rs index 3e79545d725e7..c90649353e80f 100644 --- a/compiler/rustc_trait_selection/src/infer.rs +++ b/compiler/rustc_trait_selection/src/infer.rs @@ -46,7 +46,7 @@ pub trait InferCtxtExt<'tcx> { /// - the parameter environment /// /// Invokes `evaluate_obligation`, so in the event that evaluating - /// `Ty: Trait` causes overflow, EvaluatedToRecur (or EvaluatedToUnknown) + /// `Ty: Trait` causes overflow, EvaluatedToRecur (or EvaluatedToUnknown) /// will be returned. fn type_implements_trait( &self, From 0a42dfc2fa2b373aedf7a169da3f0ec0e996fc9f Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Fri, 23 Jul 2021 18:55:36 -0400 Subject: [PATCH 30/36] Fix debugger stepping behavior around `match` expressions Previously, we would set up the source lines for `match` expressions so that the code generated to perform the test of the scrutinee was matched to the line of the arm that required the test and then jump from the arm block to the "next" block was matched to all of the lines in the `match` expression. While that makes sense, it has the side effect of causing strange stepping behavior in debuggers. I've changed the source information so that all of the generated tests are sourced to `match {scrutinee}` and the jumps are sourced to the last line of the block they are inside. This resolves the weird stepping behavior in all debuggers and resolves some instances of "ambiguous symbol" errors in WinDbg preventing the user from setting breakpoints at `match` expressions. --- .../rustc_mir_build/src/build/matches/mod.rs | 63 ++++++++++++++++--- .../rustc_mir_build/src/build/matches/test.rs | 14 ++++- ..._regression.encode.SimplifyBranchSame.diff | 8 +-- .../const_goto.issue_77355_opt.ConstGoto.diff | 8 +-- ...onst_goto_const_eval_fail.f.ConstGoto.diff | 18 +++--- .../discriminant.main.ConstProp.32bit.diff | 2 +- .../discriminant.main.ConstProp.64bit.diff | 2 +- .../const_prop/switch_int.main.ConstProp.diff | 4 +- ...ain.SimplifyBranches-after-const-prop.diff | 4 +- ..._line_doc_comment_2.DeduplicateBlocks.diff | 30 ++++----- ...wise_branch.opt1.EarlyOtherwiseBranch.diff | 28 ++++----- ...wise_branch.opt2.EarlyOtherwiseBranch.diff | 36 +++++------ ...ement_tuple.opt1.EarlyOtherwiseBranch.diff | 34 +++++----- ...h.before-SimplifyBranches-final.after.diff | 48 +++++++------- ...ch_68867.try_sum.EarlyOtherwiseBranch.diff | 48 +++++++------- ...nch_noopt.noopt1.EarlyOtherwiseBranch.diff | 20 +++--- ...nch_noopt.noopt2.EarlyOtherwiseBranch.diff | 12 ++-- ....match_tuple.SimplifyCfg-initial.after.mir | 12 ++-- ...float_to_exponential_common.ConstProp.diff | 6 +- ...comparison.SimplifyComparisonIntegral.diff | 12 ++-- .../mir-opt/issue_49232.main.mir_map.0.mir | 6 +- ...issue_62289.test.ElaborateDrops.before.mir | 4 +- ..._73223.main.SimplifyArmIdentity.32bit.diff | 4 +- ..._73223.main.SimplifyArmIdentity.64bit.diff | 4 +- ...e_75439.foo.MatchBranchSimplification.diff | 6 +- ...fg-initial.after-ElaborateDrops.after.diff | 20 +++--- ...s.full_tested_match.PromoteTemps.after.mir | 10 +-- ...full_tested_match2.PromoteTemps.before.mir | 10 +-- ...h_false_edges.main.PromoteTemps.before.mir | 12 ++-- ...ch_test.main.SimplifyCfg-initial.after.mir | 10 +-- ...s.bar.MatchBranchSimplification.32bit.diff | 14 ++--- ...s.bar.MatchBranchSimplification.64bit.diff | 14 ++--- ...s.foo.MatchBranchSimplification.32bit.diff | 12 ++-- ...s.foo.MatchBranchSimplification.64bit.diff | 12 ++-- ...ed_if.MatchBranchSimplification.32bit.diff | 4 +- ...ed_if.MatchBranchSimplification.64bit.diff | 4 +- ...match.MatchBranchSimplification.32bit.diff | 8 +-- ...match.MatchBranchSimplification.64bit.diff | 8 +-- ...ch_i8.MatchBranchSimplification.32bit.diff | 8 +-- ...ch_i8.MatchBranchSimplification.64bit.diff | 8 +-- ...wrap.SimplifyCfg-elaborate-drops.after.mir | 4 +- ...tch_guard.CleanupNonCodegenStatements.diff | 10 +-- ...age_markers.main.RemoveStorageMarkers.diff | 4 +- ...arate_const_switch.identity.ConstProp.diff | 16 ++--- ...t_switch.identity.SeparateConstSwitch.diff | 12 ++-- ...te_const_switch.too_complex.ConstProp.diff | 24 +++---- ...st_switch.too_complex.PreCodegen.after.mir | 8 +-- ...witch.too_complex.SeparateConstSwitch.diff | 26 ++++---- ...imple_match.match_bool.mir_map.0.32bit.mir | 6 +- ...imple_match.match_bool.mir_map.0.64bit.mir | 6 +- .../simplify_arm.id.SimplifyArmIdentity.diff | 8 +-- .../simplify_arm.id.SimplifyBranchSame.diff | 12 ++-- ...ify_arm.id_result.SimplifyArmIdentity.diff | 8 +-- ...lify_arm.id_result.SimplifyBranchSame.diff | 12 ++-- ...mplify_arm.id_try.SimplifyArmIdentity.diff | 4 +- ...implify_arm.id_try.SimplifyBranchSame.diff | 6 +- ...entity.main.SimplifyArmIdentity.32bit.diff | 8 +-- ...entity.main.SimplifyArmIdentity.64bit.diff | 8 +-- ..._locals_fixedpoint.foo.SimplifyLocals.diff | 8 +-- ...minant_reads.map.SimplifyLocals.32bit.diff | 6 +- ...minant_reads.map.SimplifyLocals.64bit.diff | 6 +- .../simplify_match.main.ConstProp.diff | 6 +- ...y.try_identity.DestinationPropagation.diff | 6 +- ..._try.try_identity.SimplifyArmIdentity.diff | 4 +- ....try_identity.SimplifyBranchSame.after.mir | 4 +- ...after-uninhabited-enum-branching.after.mir | 10 +-- ...anching.main.UninhabitedEnumBranching.diff | 20 +++--- ...after-uninhabited-enum-branching.after.mir | 16 ++--- ...nching2.main.UninhabitedEnumBranching.diff | 28 ++++----- ...oops.change_loop_body.ConstProp.32bit.diff | 2 +- ...oops.change_loop_body.ConstProp.64bit.diff | 2 +- .../borrowck/borrowck-anon-fields-variant.rs | 7 ++- .../borrowck-anon-fields-variant.stderr | 14 ++--- .../ui/borrowck/borrowck-describe-lvalue.rs | 2 +- .../borrowck/borrowck-describe-lvalue.stderr | 9 ++- .../borrowck-match-already-borrowed.rs | 4 +- .../borrowck-match-already-borrowed.stderr | 5 +- ...issue-27282-move-match-input-into-guard.rs | 2 +- ...e-27282-move-match-input-into-guard.stderr | 7 +-- ..._refers_to_static_cross_crate.32bit.stderr | 4 +- ..._refers_to_static_cross_crate.64bit.stderr | 4 +- src/test/ui/issues/issue-17385.rs | 4 +- src/test/ui/issues/issue-17385.stderr | 5 +- src/test/ui/nll/borrowed-match-issue-45045.rs | 2 +- .../ui/nll/borrowed-match-issue-45045.stderr | 8 +-- src/test/ui/nll/match-cfg-fake-edges2.rs | 4 +- src/test/ui/nll/match-cfg-fake-edges2.stderr | 8 +-- src/test/ui/nll/match-on-borrowed.rs | 9 ++- src/test/ui/nll/match-on-borrowed.stderr | 19 +++--- .../borrowck-non-exhaustive.rs | 2 +- .../borrowck-non-exhaustive.stderr | 5 +- src/test/ui/union/union-unsafe.mir.stderr | 4 +- 92 files changed, 533 insertions(+), 482 deletions(-) diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index a36af024ad8d0..7c4bdf1066a14 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -21,7 +21,7 @@ use rustc_middle::mir::*; use rustc_middle::thir::{self, *}; use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty}; use rustc_span::symbol::Symbol; -use rustc_span::Span; +use rustc_span::{BytePos, Pos, Span}; use rustc_target::abi::VariantIdx; use smallvec::{smallvec, SmallVec}; @@ -143,8 +143,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let mut candidates = arm_candidates.iter_mut().map(|(_, candidate)| candidate).collect::>(); - let fake_borrow_temps = - self.lower_match_tree(block, scrutinee_span, match_has_guard, &mut candidates); + let match_start_span = span.shrink_to_lo().to(scrutinee.span); + + let fake_borrow_temps = self.lower_match_tree( + block, + scrutinee_span, + match_start_span, + match_has_guard, + &mut candidates, + ); self.lower_match_arms( destination, @@ -224,6 +231,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { &mut self, block: BasicBlock, scrutinee_span: Span, + match_start_span: Span, match_has_guard: bool, candidates: &mut [&mut Candidate<'pat, 'tcx>], ) -> Vec<(Place<'tcx>, Local)> { @@ -236,7 +244,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // This will generate code to test scrutinee_place and // branch to the appropriate arm block - self.match_candidates(scrutinee_span, block, &mut otherwise, candidates, &mut fake_borrows); + self.match_candidates( + match_start_span, + scrutinee_span, + block, + &mut otherwise, + candidates, + &mut fake_borrows, + ); if let Some(otherwise_block) = otherwise { // See the doc comment on `match_candidates` for why we may have an @@ -339,8 +354,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // all the arm blocks will rejoin here let end_block = self.cfg.start_new_block(); + let end_brace = self.source_info( + outer_source_info.span.with_lo(outer_source_info.span.hi() - BytePos::from_usize(1)), + ); for arm_block in arm_end_blocks { - self.cfg.goto(unpack!(arm_block), outer_source_info, end_block); + let block = &self.cfg.basic_blocks[arm_block.0]; + let last_location = block.statements.last().map(|s| s.source_info); + + self.cfg.goto(unpack!(arm_block), last_location.unwrap_or(end_brace), end_block); } self.source_scope = outer_source_info.scope; @@ -533,8 +554,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { set_match_place: bool, ) -> BlockAnd<()> { let mut candidate = Candidate::new(initializer.clone(), &irrefutable_pat, false); - let fake_borrow_temps = - self.lower_match_tree(block, irrefutable_pat.span, false, &mut [&mut candidate]); + let fake_borrow_temps = self.lower_match_tree( + block, + irrefutable_pat.span, + irrefutable_pat.span, + false, + &mut [&mut candidate], + ); // For matches and function arguments, the place that is being matched // can be set when creating the variables. But the place for // let PATTERN = ... might not even exist until we do the assignment. @@ -993,6 +1019,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { fn match_candidates<'pat>( &mut self, span: Span, + scrutinee_span: Span, start_block: BasicBlock, otherwise_block: &mut Option, candidates: &mut [&mut Candidate<'pat, 'tcx>], @@ -1022,6 +1049,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } self.match_simplified_candidates( span, + scrutinee_span, start_block, otherwise_block, &mut *new_candidates, @@ -1030,6 +1058,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } else { self.match_simplified_candidates( span, + scrutinee_span, start_block, otherwise_block, candidates, @@ -1042,6 +1071,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { fn match_simplified_candidates( &mut self, span: Span, + scrutinee_span: Span, start_block: BasicBlock, otherwise_block: &mut Option, candidates: &mut [&mut Candidate<'_, 'tcx>], @@ -1087,6 +1117,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // Test for the remaining candidates. self.test_candidates_with_or( span, + scrutinee_span, unmatched_candidates, block, otherwise_block, @@ -1257,6 +1288,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { fn test_candidates_with_or( &mut self, span: Span, + scrutinee_span: Span, candidates: &mut [&mut Candidate<'_, 'tcx>], block: BasicBlock, otherwise_block: &mut Option, @@ -1269,7 +1301,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { match *first_candidate.match_pairs[0].pattern.kind { PatKind::Or { .. } => (), _ => { - self.test_candidates(span, candidates, block, otherwise_block, fake_borrows); + self.test_candidates( + span, + scrutinee_span, + candidates, + block, + otherwise_block, + fake_borrows, + ); return; } } @@ -1302,6 +1341,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { self.match_candidates( span, + scrutinee_span, remainder_start, otherwise_block, remaining_candidates, @@ -1330,6 +1370,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { otherwise }; self.match_candidates( + or_span, or_span, candidate.pre_binding_block.unwrap(), otherwise, @@ -1497,6 +1538,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { fn test_candidates<'pat, 'b, 'c>( &mut self, span: Span, + scrutinee_span: Span, mut candidates: &'b mut [&'c mut Candidate<'pat, 'tcx>], block: BasicBlock, otherwise_block: &mut Option, @@ -1591,6 +1633,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let candidate_start = this.cfg.start_new_block(); this.match_candidates( span, + scrutinee_span, candidate_start, remainder_start, &mut *candidates, @@ -1607,6 +1650,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let remainder_start = remainder_start.unwrap_or_else(|| this.cfg.start_new_block()); this.match_candidates( span, + scrutinee_span, remainder_start, otherwise_block, candidates, @@ -1617,7 +1661,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { target_blocks }; - self.perform_test(block, match_place, &test, make_target_blocks); + self.perform_test(span, scrutinee_span, block, match_place, &test, make_target_blocks); } /// Determine the fake borrows that are needed from a set of places that @@ -1713,6 +1757,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let fake_borrow_temps = self.lower_match_tree( block, pat.span, + pat.span, false, &mut [&mut guard_candidate, &mut otherwise_candidate], ); diff --git a/compiler/rustc_mir_build/src/build/matches/test.rs b/compiler/rustc_mir_build/src/build/matches/test.rs index 42d062c93e9d2..a01df2372a097 100644 --- a/compiler/rustc_mir_build/src/build/matches/test.rs +++ b/compiler/rustc_mir_build/src/build/matches/test.rs @@ -19,6 +19,7 @@ use rustc_middle::ty::util::IntTypeExt; use rustc_middle::ty::{self, adjustment::PointerCast, Ty, TyCtxt}; use rustc_span::def_id::DefId; use rustc_span::symbol::{sym, Symbol}; +use rustc_span::Span; use rustc_target::abi::VariantIdx; use std::cmp::Ordering; @@ -151,6 +152,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { pub(super) fn perform_test( &mut self, + match_start_span: Span, + scrutinee_span: Span, block: BasicBlock, place_builder: PlaceBuilder<'tcx>, test: &Test<'tcx>, @@ -206,10 +209,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { debug!("num_enum_variants: {}, variants: {:?}", num_enum_variants, variants); let discr_ty = adt_def.repr.discr_type().to_ty(tcx); let discr = self.temp(discr_ty, test.span); - self.cfg.push_assign(block, source_info, discr, Rvalue::Discriminant(place)); + self.cfg.push_assign( + block, + self.source_info(scrutinee_span), + discr, + Rvalue::Discriminant(place), + ); self.cfg.terminate( block, - source_info, + self.source_info(match_start_span), TerminatorKind::SwitchInt { discr: Operand::Move(discr), switch_ty: discr_ty, @@ -246,7 +254,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { targets: switch_targets, } }; - self.cfg.terminate(block, source_info, terminator); + self.cfg.terminate(block, self.source_info(match_start_span), terminator); } TestKind::Eq { value, ty } => { diff --git a/src/test/mir-opt/76803_regression.encode.SimplifyBranchSame.diff b/src/test/mir-opt/76803_regression.encode.SimplifyBranchSame.diff index 28b8329606c1b..1969d5e040409 100644 --- a/src/test/mir-opt/76803_regression.encode.SimplifyBranchSame.diff +++ b/src/test/mir-opt/76803_regression.encode.SimplifyBranchSame.diff @@ -7,18 +7,18 @@ let mut _2: isize; // in scope 0 at $DIR/76803_regression.rs:12:9: 12:16 bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/76803_regression.rs:12:9: 12:16 - switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/76803_regression.rs:12:9: 12:16 + _2 = discriminant(_1); // scope 0 at $DIR/76803_regression.rs:11:11: 11:12 + switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/76803_regression.rs:11:5: 11:12 } bb1: { _0 = move _1; // scope 0 at $DIR/76803_regression.rs:13:14: 13:15 - goto -> bb3; // scope 0 at $DIR/76803_regression.rs:11:5: 14:6 + goto -> bb3; // scope 0 at $DIR/76803_regression.rs:13:14: 13:15 } bb2: { discriminant(_0) = 1; // scope 0 at $DIR/76803_regression.rs:12:20: 12:27 - goto -> bb3; // scope 0 at $DIR/76803_regression.rs:11:5: 14:6 + goto -> bb3; // scope 0 at $DIR/76803_regression.rs:12:20: 12:27 } bb3: { diff --git a/src/test/mir-opt/const_goto.issue_77355_opt.ConstGoto.diff b/src/test/mir-opt/const_goto.issue_77355_opt.ConstGoto.diff index ddb9a8034e8bf..0f64f7c09ab55 100644 --- a/src/test/mir-opt/const_goto.issue_77355_opt.ConstGoto.diff +++ b/src/test/mir-opt/const_goto.issue_77355_opt.ConstGoto.diff @@ -10,10 +10,10 @@ bb0: { - StorageLive(_2); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL -- _3 = discriminant(_1); // scope 0 at $DIR/const_goto.rs:12:22: 12:28 -- switchInt(move _3) -> [1_isize: bb2, 2_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/const_goto.rs:12:22: 12:28 -+ _2 = discriminant(_1); // scope 0 at $DIR/const_goto.rs:12:22: 12:28 -+ switchInt(move _2) -> [1_isize: bb2, 2_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/const_goto.rs:12:22: 12:28 +- _3 = discriminant(_1); // scope 0 at $DIR/const_goto.rs:12:17: 12:20 +- switchInt(move _3) -> [1_isize: bb2, 2_isize: bb2, otherwise: bb1]; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL ++ _2 = discriminant(_1); // scope 0 at $DIR/const_goto.rs:12:17: 12:20 ++ switchInt(move _2) -> [1_isize: bb2, 2_isize: bb2, otherwise: bb1]; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL } bb1: { diff --git a/src/test/mir-opt/const_goto_const_eval_fail.f.ConstGoto.diff b/src/test/mir-opt/const_goto_const_eval_fail.f.ConstGoto.diff index f0103fc42025a..9ba02942b58b6 100644 --- a/src/test/mir-opt/const_goto_const_eval_fail.f.ConstGoto.diff +++ b/src/test/mir-opt/const_goto_const_eval_fail.f.ConstGoto.diff @@ -10,35 +10,35 @@ StorageLive(_1); // scope 0 at $DIR/const_goto_const_eval_fail.rs:7:11: 12:6 StorageLive(_2); // scope 0 at $DIR/const_goto_const_eval_fail.rs:8:15: 8:16 _2 = const A; // scope 0 at $DIR/const_goto_const_eval_fail.rs:8:15: 8:16 - switchInt(_2) -> [1_i32: bb2, 2_i32: bb2, 3_i32: bb2, otherwise: bb1]; // scope 0 at $DIR/const_goto_const_eval_fail.rs:9:13: 9:14 + switchInt(_2) -> [1_i32: bb2, 2_i32: bb2, 3_i32: bb2, otherwise: bb1]; // scope 0 at $DIR/const_goto_const_eval_fail.rs:8:9: 8:16 } bb1: { _1 = const true; // scope 0 at $DIR/const_goto_const_eval_fail.rs:10:18: 10:22 - goto -> bb3; // scope 0 at $DIR/const_goto_const_eval_fail.rs:8:9: 11:10 + goto -> bb3; // scope 0 at $DIR/const_goto_const_eval_fail.rs:10:18: 10:22 } bb2: { _1 = const B; // scope 0 at $DIR/const_goto_const_eval_fail.rs:9:26: 9:27 -- goto -> bb3; // scope 0 at $DIR/const_goto_const_eval_fail.rs:8:9: 11:10 -+ switchInt(_1) -> [false: bb4, otherwise: bb3]; // scope 0 at $DIR/const_goto_const_eval_fail.rs:13:9: 13:14 +- goto -> bb3; // scope 0 at $DIR/const_goto_const_eval_fail.rs:9:26: 9:27 ++ switchInt(_1) -> [false: bb4, otherwise: bb3]; // scope 0 at $DIR/const_goto_const_eval_fail.rs:7:5: 12:6 } bb3: { -- switchInt(_1) -> [false: bb5, otherwise: bb4]; // scope 0 at $DIR/const_goto_const_eval_fail.rs:13:9: 13:14 +- switchInt(_1) -> [false: bb5, otherwise: bb4]; // scope 0 at $DIR/const_goto_const_eval_fail.rs:7:5: 12:6 - } - - bb4: { _0 = const 2_u64; // scope 0 at $DIR/const_goto_const_eval_fail.rs:14:17: 14:18 -- goto -> bb6; // scope 0 at $DIR/const_goto_const_eval_fail.rs:7:5: 15:6 -+ goto -> bb5; // scope 0 at $DIR/const_goto_const_eval_fail.rs:7:5: 15:6 +- goto -> bb6; // scope 0 at $DIR/const_goto_const_eval_fail.rs:14:17: 14:18 ++ goto -> bb5; // scope 0 at $DIR/const_goto_const_eval_fail.rs:14:17: 14:18 } - bb5: { + bb4: { _0 = const 1_u64; // scope 0 at $DIR/const_goto_const_eval_fail.rs:13:18: 13:19 -- goto -> bb6; // scope 0 at $DIR/const_goto_const_eval_fail.rs:7:5: 15:6 -+ goto -> bb5; // scope 0 at $DIR/const_goto_const_eval_fail.rs:7:5: 15:6 +- goto -> bb6; // scope 0 at $DIR/const_goto_const_eval_fail.rs:13:18: 13:19 ++ goto -> bb5; // scope 0 at $DIR/const_goto_const_eval_fail.rs:13:18: 13:19 } - bb6: { diff --git a/src/test/mir-opt/const_prop/discriminant.main.ConstProp.32bit.diff b/src/test/mir-opt/const_prop/discriminant.main.ConstProp.32bit.diff index 706cd63a73f6a..bbfeb4dc392c2 100644 --- a/src/test/mir-opt/const_prop/discriminant.main.ConstProp.32bit.diff +++ b/src/test/mir-opt/const_prop/discriminant.main.ConstProp.32bit.diff @@ -29,7 +29,7 @@ } bb2: { - switchInt(((_3 as Some).0: bool)) -> [false: bb1, otherwise: bb3]; // scope 0 at $DIR/discriminant.rs:11:26: 11:30 + switchInt(((_3 as Some).0: bool)) -> [false: bb1, otherwise: bb3]; // scope 0 at $DIR/discriminant.rs:11:21: 11:31 } bb3: { diff --git a/src/test/mir-opt/const_prop/discriminant.main.ConstProp.64bit.diff b/src/test/mir-opt/const_prop/discriminant.main.ConstProp.64bit.diff index 706cd63a73f6a..bbfeb4dc392c2 100644 --- a/src/test/mir-opt/const_prop/discriminant.main.ConstProp.64bit.diff +++ b/src/test/mir-opt/const_prop/discriminant.main.ConstProp.64bit.diff @@ -29,7 +29,7 @@ } bb2: { - switchInt(((_3 as Some).0: bool)) -> [false: bb1, otherwise: bb3]; // scope 0 at $DIR/discriminant.rs:11:26: 11:30 + switchInt(((_3 as Some).0: bool)) -> [false: bb1, otherwise: bb3]; // scope 0 at $DIR/discriminant.rs:11:21: 11:31 } bb3: { diff --git a/src/test/mir-opt/const_prop/switch_int.main.ConstProp.diff b/src/test/mir-opt/const_prop/switch_int.main.ConstProp.diff index f51df7ae821ce..f031a703a9d72 100644 --- a/src/test/mir-opt/const_prop/switch_int.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/switch_int.main.ConstProp.diff @@ -8,8 +8,8 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/switch_int.rs:7:11: 7:12 _1 = const 1_i32; // scope 0 at $DIR/switch_int.rs:7:11: 7:12 -- switchInt(_1) -> [1_i32: bb2, otherwise: bb1]; // scope 0 at $DIR/switch_int.rs:8:9: 8:10 -+ switchInt(const 1_i32) -> [1_i32: bb2, otherwise: bb1]; // scope 0 at $DIR/switch_int.rs:8:9: 8:10 +- switchInt(_1) -> [1_i32: bb2, otherwise: bb1]; // scope 0 at $DIR/switch_int.rs:7:5: 7:12 ++ switchInt(const 1_i32) -> [1_i32: bb2, otherwise: bb1]; // scope 0 at $DIR/switch_int.rs:7:5: 7:12 } bb1: { diff --git a/src/test/mir-opt/const_prop/switch_int.main.SimplifyBranches-after-const-prop.diff b/src/test/mir-opt/const_prop/switch_int.main.SimplifyBranches-after-const-prop.diff index a444956ad1d0a..6a5b88c4a7f0d 100644 --- a/src/test/mir-opt/const_prop/switch_int.main.SimplifyBranches-after-const-prop.diff +++ b/src/test/mir-opt/const_prop/switch_int.main.SimplifyBranches-after-const-prop.diff @@ -8,8 +8,8 @@ bb0: { StorageLive(_1); // scope 0 at $DIR/switch_int.rs:7:11: 7:12 _1 = const 1_i32; // scope 0 at $DIR/switch_int.rs:7:11: 7:12 -- switchInt(const 1_i32) -> [1_i32: bb2, otherwise: bb1]; // scope 0 at $DIR/switch_int.rs:8:9: 8:10 -+ goto -> bb2; // scope 0 at $DIR/switch_int.rs:8:9: 8:10 +- switchInt(const 1_i32) -> [1_i32: bb2, otherwise: bb1]; // scope 0 at $DIR/switch_int.rs:7:5: 7:12 ++ goto -> bb2; // scope 0 at $DIR/switch_int.rs:7:5: 7:12 } bb1: { diff --git a/src/test/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.diff b/src/test/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.diff index b0c97f4237818..48a37a8496cb7 100644 --- a/src/test/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.diff +++ b/src/test/mir-opt/deduplicate_blocks.is_line_doc_comment_2.DeduplicateBlocks.diff @@ -31,20 +31,20 @@ } bb1: { - switchInt((*_2)[0 of 4]) -> [47_u8: bb2, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:4:10: 4:14 + switchInt((*_2)[0 of 4]) -> [47_u8: bb2, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 3:23 } bb2: { - switchInt((*_2)[1 of 4]) -> [47_u8: bb3, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:4:16: 4:20 + switchInt((*_2)[1 of 4]) -> [47_u8: bb3, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 3:23 } bb3: { - switchInt((*_2)[2 of 4]) -> [47_u8: bb4, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:4:22: 4:26 + switchInt((*_2)[2 of 4]) -> [47_u8: bb4, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 3:23 } bb4: { -- switchInt((*_2)[3 of 4]) -> [47_u8: bb10, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:4:28: 4:32 -+ switchInt((*_2)[3 of 4]) -> [47_u8: bb9, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:4:28: 4:32 +- switchInt((*_2)[3 of 4]) -> [47_u8: bb10, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 3:23 ++ switchInt((*_2)[3 of 4]) -> [47_u8: bb9, otherwise: bb5]; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 3:23 } bb5: { @@ -54,39 +54,39 @@ } bb6: { - switchInt((*_2)[0 of 3]) -> [47_u8: bb7, otherwise: bb9]; // scope 0 at $DIR/deduplicate_blocks.rs:5:10: 5:14 + switchInt((*_2)[0 of 3]) -> [47_u8: bb7, otherwise: bb9]; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 3:23 } bb7: { - switchInt((*_2)[1 of 3]) -> [47_u8: bb8, otherwise: bb9]; // scope 0 at $DIR/deduplicate_blocks.rs:5:16: 5:20 + switchInt((*_2)[1 of 3]) -> [47_u8: bb8, otherwise: bb9]; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 3:23 } bb8: { -- switchInt((*_2)[2 of 3]) -> [47_u8: bb11, 33_u8: bb12, otherwise: bb9]; // scope 0 at $DIR/deduplicate_blocks.rs:5:22: 5:26 -+ switchInt((*_2)[2 of 3]) -> [47_u8: bb10, 33_u8: bb10, otherwise: bb9]; // scope 0 at $DIR/deduplicate_blocks.rs:5:22: 5:26 +- switchInt((*_2)[2 of 3]) -> [47_u8: bb11, 33_u8: bb12, otherwise: bb9]; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 3:23 ++ switchInt((*_2)[2 of 3]) -> [47_u8: bb10, 33_u8: bb10, otherwise: bb9]; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 3:23 } bb9: { - _0 = const false; // scope 0 at $DIR/deduplicate_blocks.rs:7:14: 7:19 -- goto -> bb13; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 8:6 +- goto -> bb13; // scope 0 at $DIR/deduplicate_blocks.rs:7:14: 7:19 - } - - bb10: { _0 = const false; // scope 0 at $DIR/deduplicate_blocks.rs:4:41: 4:46 -- goto -> bb13; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 8:6 -+ goto -> bb11; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 8:6 +- goto -> bb13; // scope 0 at $DIR/deduplicate_blocks.rs:4:41: 4:46 ++ goto -> bb11; // scope 0 at $DIR/deduplicate_blocks.rs:4:41: 4:46 } - bb11: { - _0 = const true; // scope 0 at $DIR/deduplicate_blocks.rs:5:35: 5:39 -- goto -> bb13; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 8:6 +- goto -> bb13; // scope 0 at $DIR/deduplicate_blocks.rs:5:35: 5:39 - } - - bb12: { + bb10: { _0 = const true; // scope 0 at $DIR/deduplicate_blocks.rs:6:35: 6:39 -- goto -> bb13; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 8:6 -+ goto -> bb11; // scope 0 at $DIR/deduplicate_blocks.rs:3:5: 8:6 +- goto -> bb13; // scope 0 at $DIR/deduplicate_blocks.rs:6:35: 6:39 ++ goto -> bb11; // scope 0 at $DIR/deduplicate_blocks.rs:6:35: 6:39 } - bb13: { diff --git a/src/test/mir-opt/early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff index 386726bfddc74..c1591e5d72915 100644 --- a/src/test/mir-opt/early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch.opt1.EarlyOtherwiseBranch.diff @@ -29,26 +29,26 @@ (_3.1: std::option::Option) = move _5; // scope 0 at $DIR/early_otherwise_branch.rs:4:11: 4:17 StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch.rs:4:16: 4:17 StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch.rs:4:16: 4:17 - _7 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 -- switchInt(move _7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 -+ StorageLive(_10); // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 -+ _10 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 -+ StorageLive(_11); // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 -+ _11 = Ne(_10, _7); // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 -+ StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 -+ switchInt(move _11) -> [false: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:5:10: 5:17 + _7 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:4:11: 4:17 +- switchInt(move _7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 4:17 ++ StorageLive(_10); // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 4:17 ++ _10 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 4:17 ++ StorageLive(_11); // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 4:17 ++ _11 = Ne(_10, _7); // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 4:17 ++ StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 4:17 ++ switchInt(move _11) -> [false: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 4:17 } bb1: { + StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:6:14: 6:15 _0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch.rs:6:14: 6:15 -- goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 7:6 -+ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 7:6 +- goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:6:14: 6:15 ++ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:6:14: 6:15 } bb2: { -- _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:5:19: 5:26 -- switchInt(move _6) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:5:19: 5:26 +- _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:4:11: 4:17 +- switchInt(move _6) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 4:17 - } - - bb3: { @@ -59,8 +59,8 @@ _0 = const 0_u32; // scope 1 at $DIR/early_otherwise_branch.rs:5:31: 5:32 StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch.rs:5:31: 5:32 StorageDead(_8); // scope 0 at $DIR/early_otherwise_branch.rs:5:31: 5:32 -- goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 7:6 -+ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:4:5: 7:6 +- goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:5:31: 5:32 ++ goto -> bb3; // scope 0 at $DIR/early_otherwise_branch.rs:5:31: 5:32 } - bb4: { diff --git a/src/test/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff index bc5934dec84e4..b949d307e20e9 100644 --- a/src/test/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch.opt2.EarlyOtherwiseBranch.diff @@ -30,31 +30,31 @@ (_3.1: std::option::Option) = move _5; // scope 0 at $DIR/early_otherwise_branch.rs:12:11: 12:17 StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch.rs:12:16: 12:17 StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch.rs:12:16: 12:17 - _8 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 -- switchInt(move _8) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 -+ StorageLive(_11); // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 -+ _11 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 -+ StorageLive(_12); // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 -+ _12 = Ne(_11, _8); // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 -+ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 -+ switchInt(move _12) -> [false: bb5, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:13:10: 13:17 + _8 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:12:11: 12:17 +- switchInt(move _8) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 12:17 ++ StorageLive(_11); // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 12:17 ++ _11 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 12:17 ++ StorageLive(_12); // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 12:17 ++ _12 = Ne(_11, _8); // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 12:17 ++ StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 12:17 ++ switchInt(move _12) -> [false: bb5, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 12:17 } bb1: { -- _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:14:16: 14:20 -- switchInt(move _6) -> [0_isize: bb5, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:14:16: 14:20 +- _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:12:11: 12:17 +- switchInt(move _6) -> [0_isize: bb5, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 12:17 - } - - bb2: { + StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch.rs:15:14: 15:15 _0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch.rs:15:14: 15:15 -- goto -> bb6; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 -+ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 +- goto -> bb6; // scope 0 at $DIR/early_otherwise_branch.rs:15:14: 15:15 ++ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:15:14: 15:15 } - bb3: { -- _7 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:13:19: 13:26 -- switchInt(move _7) -> [1_isize: bb4, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:13:19: 13:26 +- _7 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch.rs:12:11: 12:17 +- switchInt(move _7) -> [1_isize: bb4, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 12:17 - } - - bb4: { @@ -66,15 +66,15 @@ _0 = const 0_u32; // scope 1 at $DIR/early_otherwise_branch.rs:13:31: 13:32 StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch.rs:13:31: 13:32 StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch.rs:13:31: 13:32 -- goto -> bb6; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 -+ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 +- goto -> bb6; // scope 0 at $DIR/early_otherwise_branch.rs:13:31: 13:32 ++ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:13:31: 13:32 } - bb5: { + bb3: { _0 = const 0_u32; // scope 0 at $DIR/early_otherwise_branch.rs:14:25: 14:26 -- goto -> bb6; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 -+ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:12:5: 16:6 +- goto -> bb6; // scope 0 at $DIR/early_otherwise_branch.rs:14:25: 14:26 ++ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch.rs:14:25: 14:26 } - bb6: { diff --git a/src/test/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff index b0357f1aecd61..5b9ec1e53d946 100644 --- a/src/test/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch_3_element_tuple.opt1.EarlyOtherwiseBranch.diff @@ -40,33 +40,33 @@ StorageDead(_7); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:19: 5:20 StorageDead(_6); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:19: 5:20 StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:19: 5:20 - _10 = discriminant((_4.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 -- switchInt(move _10) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 -+ StorageLive(_14); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 -+ _14 = discriminant((_4.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 -+ StorageLive(_15); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 -+ _15 = Ne(_14, _10); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 -+ StorageDead(_14); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 -+ switchInt(move _15) -> [false: bb5, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:10: 6:17 + _10 = discriminant((_4.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:11: 5:20 +- switchInt(move _10) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 ++ StorageLive(_14); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 ++ _14 = discriminant((_4.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 ++ StorageLive(_15); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 ++ _15 = Ne(_14, _10); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 ++ StorageDead(_14); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 ++ switchInt(move _15) -> [false: bb5, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 } bb1: { + StorageDead(_17); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:7:14: 7:15 + StorageDead(_15); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:7:14: 7:15 _0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:7:14: 7:15 -- goto -> bb5; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 8:6 -+ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 8:6 +- goto -> bb5; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:7:14: 7:15 ++ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:7:14: 7:15 } bb2: { -- _9 = discriminant((_4.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:19: 6:26 -- switchInt(move _9) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:19: 6:26 +- _9 = discriminant((_4.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:11: 5:20 +- switchInt(move _9) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 - } - - bb3: { - _8 = discriminant((_4.2: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:28: 6:35 -- switchInt(move _8) -> [1_isize: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:28: 6:35 -+ switchInt(move _8) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:28: 6:35 + _8 = discriminant((_4.2: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:11: 5:20 +- switchInt(move _8) -> [1_isize: bb4, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 ++ switchInt(move _8) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 5:20 } - bb4: { @@ -81,8 +81,8 @@ StorageDead(_13); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:40: 6:41 StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:40: 6:41 StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:40: 6:41 -- goto -> bb5; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 8:6 -+ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:5:5: 8:6 +- goto -> bb5; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:40: 6:41 ++ goto -> bb4; // scope 0 at $DIR/early_otherwise_branch_3_element_tuple.rs:6:40: 6:41 } - bb5: { diff --git a/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.before-SimplifyBranches-final.after.diff b/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.before-SimplifyBranches-final.after.diff index 2893ee9ac334b..f23d035545eec 100644 --- a/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.before-SimplifyBranches-final.after.diff +++ b/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.before-SimplifyBranches-final.after.diff @@ -80,19 +80,19 @@ StorageDead(_6); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:23: 21:24 - StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:23: 21:24 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:23: 21:24 - _11 = discriminant((*(_4.0: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -- switchInt(move _11) -> [0_isize: bb1, 1_isize: bb3, 2_isize: bb4, 3_isize: bb5, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ StorageLive(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ _34 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ StorageLive(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ _35 = Ne(_34, _11); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ StorageDead(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ switchInt(move _35) -> [false: bb7, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 + _11 = discriminant((*(_4.0: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _11) -> [0_isize: bb1, 1_isize: bb3, 2_isize: bb4, 3_isize: bb5, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ StorageLive(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ _34 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ StorageLive(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ _35 = Ne(_34, _11); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ StorageDead(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ switchInt(move _35) -> [false: bb7, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 } bb1: { -- _7 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:21: 22:30 -- switchInt(move _7) -> [0_isize: bb6, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:21: 22:30 +- _7 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _7) -> [0_isize: bb6, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 - } - - bb2: { @@ -126,12 +126,12 @@ + nop; // scope 1 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 + } + bb3: { -- _8 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:21: 23:30 -- switchInt(move _8) -> [1_isize: bb7, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:21: 23:30 +- _8 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _8) -> [1_isize: bb7, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 + _20 = (((*(_4.0: &ViewportPercentageLength)) as Vh).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:14: 23:17 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:24: 23:29 @@ -149,12 +149,12 @@ + nop; // scope 2 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 } bb4: { -- _9 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:23: 24:34 -- switchInt(move _9) -> [2_isize: bb8, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:23: 24:34 +- _9 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _9) -> [2_isize: bb8, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:16: 24:19 + _25 = (((*(_4.0: &ViewportPercentageLength)) as Vmin).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:16: 24:19 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:28: 24:33 @@ -172,12 +172,12 @@ + nop; // scope 3 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 } bb5: { -- _10 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:23: 25:34 -- switchInt(move _10) -> [3_isize: bb9, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:23: 25:34 +- _10 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _10) -> [3_isize: bb9, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 + _30 = (((*(_4.0: &ViewportPercentageLength)) as Vmax).0: f32); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:16: 25:19 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:28: 25:33 @@ -195,7 +195,7 @@ + nop; // scope 4 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 } bb6: { @@ -216,7 +216,7 @@ - StorageDead(_14); // scope 1 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 - StorageDead(_13); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 - StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 -- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 +- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:5: 27:7 + discriminant(_0) = 0; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:5: 27:7 + nop; // scope 0 at $DIR/early_otherwise_branch_68867.rs:27:6: 27:7 @@ -242,7 +242,7 @@ - StorageDead(_19); // scope 2 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 - StorageDead(_18); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 - StorageDead(_17); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 -- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 +- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 - } - - bb8: { @@ -263,7 +263,7 @@ - StorageDead(_24); // scope 3 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 - StorageDead(_23); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 - StorageDead(_22); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 -- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 +- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 - } - - bb9: { @@ -284,7 +284,7 @@ - StorageDead(_29); // scope 4 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 - StorageDead(_28); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 - StorageDead(_27); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 -- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 +- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 - } - - bb10: { diff --git a/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff index 9039989e0f288..af32d4d2d149c 100644 --- a/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch_68867.try_sum.EarlyOtherwiseBranch.diff @@ -66,19 +66,19 @@ (_4.1: &ViewportPercentageLength) = move _6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 StorageDead(_6); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:23: 21:24 StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:23: 21:24 - _11 = discriminant((*(_4.0: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -- switchInt(move _11) -> [0_isize: bb1, 1_isize: bb3, 2_isize: bb4, 3_isize: bb5, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ StorageLive(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ _34 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ StorageLive(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ _35 = Ne(_34, _11); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ StorageDead(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 -+ switchInt(move _35) -> [false: bb7, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:11: 22:18 + _11 = discriminant((*(_4.0: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _11) -> [0_isize: bb1, 1_isize: bb3, 2_isize: bb4, 3_isize: bb5, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ StorageLive(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ _34 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ StorageLive(_35); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ _35 = Ne(_34, _11); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ StorageDead(_34); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 ++ switchInt(move _35) -> [false: bb7, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 } bb1: { -- _7 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:21: 22:30 -- switchInt(move _7) -> [0_isize: bb6, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:21: 22:30 +- _7 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _7) -> [0_isize: bb6, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 - } - - bb2: { @@ -93,18 +93,18 @@ } - bb3: { -- _8 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:21: 23:30 -- switchInt(move _8) -> [1_isize: bb7, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:21: 23:30 +- _8 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _8) -> [1_isize: bb7, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 - } - - bb4: { -- _9 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:23: 24:34 -- switchInt(move _9) -> [2_isize: bb8, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:23: 24:34 +- _9 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _9) -> [2_isize: bb8, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 - } - - bb5: { -- _10 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:23: 25:34 -- switchInt(move _10) -> [3_isize: bb9, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:23: 25:34 +- _10 = discriminant((*(_4.1: &ViewportPercentageLength))); // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:14: 21:24 +- switchInt(move _10) -> [3_isize: bb9, otherwise: bb2]; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 21:24 - } - - bb6: { @@ -126,8 +126,8 @@ StorageDead(_14); // scope 1 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 StorageDead(_13); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 -- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 +- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:22:49: 22:50 } - bb7: { @@ -149,8 +149,8 @@ StorageDead(_19); // scope 2 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 StorageDead(_18); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 StorageDead(_17); // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 -- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 +- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:23:49: 23:50 } - bb8: { @@ -172,8 +172,8 @@ StorageDead(_24); // scope 3 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 StorageDead(_23); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 StorageDead(_22); // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 -- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 +- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:24:55: 24:56 } - bb9: { @@ -195,8 +195,8 @@ StorageDead(_29); // scope 4 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 StorageDead(_28); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 StorageDead(_27); // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 -- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 -+ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:21:8: 27:6 +- goto -> bb10; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 ++ goto -> bb6; // scope 0 at $DIR/early_otherwise_branch_68867.rs:25:55: 25:56 } - bb10: { diff --git a/src/test/mir-opt/early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff index 9a6094f12dfb1..5343f22d3da3e 100644 --- a/src/test/mir-opt/early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch_noopt.noopt1.EarlyOtherwiseBranch.diff @@ -36,23 +36,23 @@ (_3.1: std::option::Option) = move _5; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:11: 8:17 StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:16: 8:17 StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:16: 8:17 - _8 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:10: 9:17 - switchInt(move _8) -> [0_isize: bb1, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:10: 9:17 + _8 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:11: 8:17 + switchInt(move _8) -> [0_isize: bb1, otherwise: bb3]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 8:17 } bb1: { - _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:11:16: 11:23 - switchInt(move _6) -> [0_isize: bb2, otherwise: bb6]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:11:16: 11:23 + _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:11: 8:17 + switchInt(move _6) -> [0_isize: bb2, otherwise: bb6]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 8:17 } bb2: { _0 = const 3_u32; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:12:25: 12:26 - goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 13:6 + goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:12:25: 12:26 } bb3: { - _7 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:19: 9:26 - switchInt(move _7) -> [0_isize: bb5, otherwise: bb4]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:19: 9:26 + _7 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:11: 8:17 + switchInt(move _7) -> [0_isize: bb5, otherwise: bb4]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 8:17 } bb4: { @@ -63,7 +63,7 @@ _0 = const 0_u32; // scope 1 at $DIR/early_otherwise_branch_noopt.rs:9:31: 9:32 StorageDead(_10); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:31: 9:32 StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:31: 9:32 - goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 13:6 + goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:9:31: 9:32 } bb5: { @@ -71,7 +71,7 @@ _11 = (((_3.0: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:10:15: 10:16 _0 = const 1_u32; // scope 2 at $DIR/early_otherwise_branch_noopt.rs:10:28: 10:29 StorageDead(_11); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:10:28: 10:29 - goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 13:6 + goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:10:28: 10:29 } bb6: { @@ -79,7 +79,7 @@ _12 = (((_3.1: std::option::Option) as Some).0: u32); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:11:21: 11:22 _0 = const 2_u32; // scope 3 at $DIR/early_otherwise_branch_noopt.rs:11:28: 11:29 StorageDead(_12); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:11:28: 11:29 - goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:8:5: 13:6 + goto -> bb7; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:11:28: 11:29 } bb7: { diff --git a/src/test/mir-opt/early_otherwise_branch_noopt.noopt2.EarlyOtherwiseBranch.diff b/src/test/mir-opt/early_otherwise_branch_noopt.noopt2.EarlyOtherwiseBranch.diff index c3aecb4529351..66ea828bf682c 100644 --- a/src/test/mir-opt/early_otherwise_branch_noopt.noopt2.EarlyOtherwiseBranch.diff +++ b/src/test/mir-opt/early_otherwise_branch_noopt.noopt2.EarlyOtherwiseBranch.diff @@ -27,18 +27,18 @@ (_3.1: std::option::Option) = move _5; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:11: 19:17 StorageDead(_5); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:16: 19:17 StorageDead(_4); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:16: 19:17 - _7 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:10: 20:17 - switchInt(move _7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:10: 20:17 + _7 = discriminant((_3.0: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:11: 19:17 + switchInt(move _7) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:5: 19:17 } bb1: { _0 = const 1_u32; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:21:14: 21:15 - goto -> bb4; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:5: 22:6 + goto -> bb4; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:21:14: 21:15 } bb2: { - _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:19: 20:26 - switchInt(move _6) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:19: 20:26 + _6 = discriminant((_3.1: std::option::Option)); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:11: 19:17 + switchInt(move _6) -> [1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:5: 19:17 } bb3: { @@ -49,7 +49,7 @@ _0 = const 0_u32; // scope 1 at $DIR/early_otherwise_branch_noopt.rs:20:31: 20:32 StorageDead(_9); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:31: 20:32 StorageDead(_8); // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:31: 20:32 - goto -> bb4; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:19:5: 22:6 + goto -> bb4; // scope 0 at $DIR/early_otherwise_branch_noopt.rs:20:31: 20:32 } bb4: { diff --git a/src/test/mir-opt/exponential_or.match_tuple.SimplifyCfg-initial.after.mir b/src/test/mir-opt/exponential_or.match_tuple.SimplifyCfg-initial.after.mir index 93507879a6f83..6b7b3db05419e 100644 --- a/src/test/mir-opt/exponential_or.match_tuple.SimplifyCfg-initial.after.mir +++ b/src/test/mir-opt/exponential_or.match_tuple.SimplifyCfg-initial.after.mir @@ -19,21 +19,21 @@ fn match_tuple(_1: (u32, bool, Option, u32)) -> u32 { bb0: { FakeRead(ForMatchedPlace(None), _1); // scope 0 at $DIR/exponential-or.rs:5:11: 5:12 - switchInt((_1.0: u32)) -> [1_u32: bb2, 4_u32: bb2, otherwise: bb1]; // scope 0 at $DIR/exponential-or.rs:6:15: 6:16 + switchInt((_1.0: u32)) -> [1_u32: bb2, 4_u32: bb2, otherwise: bb1]; // scope 0 at $DIR/exponential-or.rs:6:15: 6:20 } bb1: { _0 = const 0_u32; // scope 0 at $DIR/exponential-or.rs:7:14: 7:15 - goto -> bb10; // scope 0 at $DIR/exponential-or.rs:5:5: 8:6 + goto -> bb10; // scope 0 at $DIR/exponential-or.rs:7:14: 7:15 } bb2: { - _2 = discriminant((_1.2: std::option::Option)); // scope 0 at $DIR/exponential-or.rs:6:37: 6:48 - switchInt(move _2) -> [0_isize: bb4, 1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/exponential-or.rs:6:37: 6:48 + _2 = discriminant((_1.2: std::option::Option)); // scope 0 at $DIR/exponential-or.rs:6:37: 6:55 + switchInt(move _2) -> [0_isize: bb4, 1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/exponential-or.rs:6:37: 6:55 } bb3: { - switchInt((((_1.2: std::option::Option) as Some).0: i32)) -> [1_i32: bb4, 8_i32: bb4, otherwise: bb1]; // scope 0 at $DIR/exponential-or.rs:6:42: 6:43 + switchInt((((_1.2: std::option::Option) as Some).0: i32)) -> [1_i32: bb4, 8_i32: bb4, otherwise: bb1]; // scope 0 at $DIR/exponential-or.rs:6:37: 6:55 } bb4: { @@ -74,7 +74,7 @@ fn match_tuple(_1: (u32, bool, Option, u32)) -> u32 { StorageDead(_9); // scope 1 at $DIR/exponential-or.rs:6:87: 6:88 StorageDead(_8); // scope 0 at $DIR/exponential-or.rs:6:87: 6:88 StorageDead(_7); // scope 0 at $DIR/exponential-or.rs:6:87: 6:88 - goto -> bb10; // scope 0 at $DIR/exponential-or.rs:5:5: 8:6 + goto -> bb10; // scope 0 at $DIR/exponential-or.rs:6:87: 6:88 } bb10: { diff --git a/src/test/mir-opt/funky_arms.float_to_exponential_common.ConstProp.diff b/src/test/mir-opt/funky_arms.float_to_exponential_common.ConstProp.diff index a7e4a131bfb72..44167ac0c4826 100644 --- a/src/test/mir-opt/funky_arms.float_to_exponential_common.ConstProp.diff +++ b/src/test/mir-opt/funky_arms.float_to_exponential_common.ConstProp.diff @@ -47,17 +47,17 @@ bb1: { StorageDead(_5); // scope 0 at $DIR/funky_arms.rs:15:36: 15:37 StorageLive(_6); // scope 1 at $DIR/funky_arms.rs:19:9: 19:13 - switchInt(_4) -> [false: bb3, otherwise: bb2]; // scope 1 at $DIR/funky_arms.rs:20:9: 20:14 + switchInt(_4) -> [false: bb3, otherwise: bb2]; // scope 1 at $DIR/funky_arms.rs:19:16: 19:32 } bb2: { discriminant(_6) = 1; // scope 1 at $DIR/funky_arms.rs:21:17: 21:41 - goto -> bb4; // scope 1 at $DIR/funky_arms.rs:19:16: 22:6 + goto -> bb4; // scope 1 at $DIR/funky_arms.rs:21:17: 21:41 } bb3: { discriminant(_6) = 0; // scope 1 at $DIR/funky_arms.rs:20:18: 20:38 - goto -> bb4; // scope 1 at $DIR/funky_arms.rs:19:16: 22:6 + goto -> bb4; // scope 1 at $DIR/funky_arms.rs:20:18: 20:38 } bb4: { diff --git a/src/test/mir-opt/if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff b/src/test/mir-opt/if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff index b590be5370f1d..fd4dcb2265e61 100644 --- a/src/test/mir-opt/if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff +++ b/src/test/mir-opt/if_condition_int.dont_remove_comparison.SimplifyComparisonIntegral.diff @@ -20,14 +20,14 @@ _3 = _1; // scope 0 at $DIR/if-condition-int.rs:44:13: 44:14 - _2 = Eq(move _3, const 17_i8); // scope 0 at $DIR/if-condition-int.rs:44:13: 44:20 - StorageDead(_3); // scope 0 at $DIR/if-condition-int.rs:44:19: 44:20 -- switchInt(_2) -> [false: bb2, otherwise: bb1]; // scope 1 at $DIR/if-condition-int.rs:46:9: 46:14 +- switchInt(_2) -> [false: bb2, otherwise: bb1]; // scope 1 at $DIR/if-condition-int.rs:45:5: 45:12 + _2 = Eq(_3, const 17_i8); // scope 0 at $DIR/if-condition-int.rs:44:13: 44:20 + nop; // scope 0 at $DIR/if-condition-int.rs:44:19: 44:20 -+ switchInt(move _3) -> [17_i8: bb1, otherwise: bb2]; // scope 1 at $DIR/if-condition-int.rs:46:9: 46:14 ++ switchInt(move _3) -> [17_i8: bb1, otherwise: bb2]; // scope 1 at $DIR/if-condition-int.rs:45:5: 45:12 } bb1: { -+ StorageDead(_3); // scope 1 at $DIR/if-condition-int.rs:46:9: 46:14 ++ StorageDead(_3); // scope 1 at $DIR/if-condition-int.rs:45:5: 45:12 StorageLive(_6); // scope 1 at $DIR/if-condition-int.rs:47:23: 47:31 StorageLive(_7); // scope 1 at $DIR/if-condition-int.rs:47:23: 47:24 _7 = _2; // scope 1 at $DIR/if-condition-int.rs:47:23: 47:24 @@ -35,11 +35,11 @@ StorageDead(_7); // scope 1 at $DIR/if-condition-int.rs:47:30: 47:31 _0 = Add(const 100_i32, move _6); // scope 1 at $DIR/if-condition-int.rs:47:17: 47:31 StorageDead(_6); // scope 1 at $DIR/if-condition-int.rs:47:30: 47:31 - goto -> bb3; // scope 1 at $DIR/if-condition-int.rs:45:5: 48:6 + goto -> bb3; // scope 1 at $DIR/if-condition-int.rs:47:30: 47:31 } bb2: { -+ StorageDead(_3); // scope 1 at $DIR/if-condition-int.rs:46:9: 46:14 ++ StorageDead(_3); // scope 1 at $DIR/if-condition-int.rs:45:5: 45:12 StorageLive(_4); // scope 1 at $DIR/if-condition-int.rs:46:23: 46:31 StorageLive(_5); // scope 1 at $DIR/if-condition-int.rs:46:23: 46:24 _5 = _2; // scope 1 at $DIR/if-condition-int.rs:46:23: 46:24 @@ -47,7 +47,7 @@ StorageDead(_5); // scope 1 at $DIR/if-condition-int.rs:46:30: 46:31 _0 = Add(const 10_i32, move _4); // scope 1 at $DIR/if-condition-int.rs:46:18: 46:31 StorageDead(_4); // scope 1 at $DIR/if-condition-int.rs:46:30: 46:31 - goto -> bb3; // scope 1 at $DIR/if-condition-int.rs:45:5: 48:6 + goto -> bb3; // scope 1 at $DIR/if-condition-int.rs:46:30: 46:31 } bb3: { diff --git a/src/test/mir-opt/issue_49232.main.mir_map.0.mir b/src/test/mir-opt/issue_49232.main.mir_map.0.mir index 06fbbda3d9e22..2f8931382a69e 100644 --- a/src/test/mir-opt/issue_49232.main.mir_map.0.mir +++ b/src/test/mir-opt/issue_49232.main.mir_map.0.mir @@ -25,7 +25,7 @@ fn main() -> () { StorageLive(_3); // scope 0 at $DIR/issue-49232.rs:8:19: 8:23 _3 = const true; // scope 0 at $DIR/issue-49232.rs:8:19: 8:23 FakeRead(ForMatchedPlace(None), _3); // scope 0 at $DIR/issue-49232.rs:8:19: 8:23 - switchInt(_3) -> [false: bb3, otherwise: bb4]; // scope 0 at $DIR/issue-49232.rs:9:17: 9:22 + switchInt(_3) -> [false: bb3, otherwise: bb4]; // scope 0 at $DIR/issue-49232.rs:8:13: 8:23 } bb3: { @@ -39,7 +39,7 @@ fn main() -> () { bb5: { _2 = const 4_i32; // scope 0 at $DIR/issue-49232.rs:9:26: 9:27 - goto -> bb8; // scope 0 at $DIR/issue-49232.rs:8:13: 11:14 + goto -> bb8; // scope 0 at $DIR/issue-49232.rs:9:26: 9:27 } bb6: { @@ -47,7 +47,7 @@ fn main() -> () { } bb7: { - goto -> bb8; // scope 0 at $DIR/issue-49232.rs:8:13: 11:14 + goto -> bb8; // scope 0 at $DIR/issue-49232.rs:11:13: 11:14 } bb8: { diff --git a/src/test/mir-opt/issue_62289.test.ElaborateDrops.before.mir b/src/test/mir-opt/issue_62289.test.ElaborateDrops.before.mir index ba17a45f984ef..95efa74289d85 100644 --- a/src/test/mir-opt/issue_62289.test.ElaborateDrops.before.mir +++ b/src/test/mir-opt/issue_62289.test.ElaborateDrops.before.mir @@ -37,8 +37,8 @@ fn test() -> Option> { bb1: { StorageDead(_4); // scope 0 at $DIR/issue-62289.rs:9:19: 9:20 - _5 = discriminant(_3); // scope 0 at $DIR/issue-62289.rs:9:19: 9:20 - switchInt(move _5) -> [0_isize: bb2, 1_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/issue-62289.rs:9:19: 9:20 + _5 = discriminant(_3); // scope 0 at $DIR/issue-62289.rs:9:15: 9:20 + switchInt(move _5) -> [0_isize: bb2, 1_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/issue-62289.rs:9:15: 9:20 } bb2: { diff --git a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff index ff8c410a7268d..a544f0f4b62a9 100644 --- a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff +++ b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.32bit.diff @@ -53,8 +53,8 @@ StorageLive(_2); // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 ((_2 as Some).0: i32) = const 1_i32; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 discriminant(_2) = 1; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 - _3 = const 1_isize; // scope 0 at $DIR/issue-73223.rs:3:9: 3:16 - goto -> bb2; // scope 0 at $DIR/issue-73223.rs:3:9: 3:16 + _3 = const 1_isize; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + goto -> bb2; // scope 0 at $DIR/issue-73223.rs:2:17: 2:30 } bb1: { diff --git a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff index ff8c410a7268d..a544f0f4b62a9 100644 --- a/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff +++ b/src/test/mir-opt/issue_73223.main.SimplifyArmIdentity.64bit.diff @@ -53,8 +53,8 @@ StorageLive(_2); // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 ((_2 as Some).0: i32) = const 1_i32; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 discriminant(_2) = 1; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 - _3 = const 1_isize; // scope 0 at $DIR/issue-73223.rs:3:9: 3:16 - goto -> bb2; // scope 0 at $DIR/issue-73223.rs:3:9: 3:16 + _3 = const 1_isize; // scope 0 at $DIR/issue-73223.rs:2:23: 2:30 + goto -> bb2; // scope 0 at $DIR/issue-73223.rs:2:17: 2:30 } bb1: { diff --git a/src/test/mir-opt/issues/issue_75439.foo.MatchBranchSimplification.diff b/src/test/mir-opt/issues/issue_75439.foo.MatchBranchSimplification.diff index 89ba5eeeef4e6..0d19b3d459eb0 100644 --- a/src/test/mir-opt/issues/issue_75439.foo.MatchBranchSimplification.diff +++ b/src/test/mir-opt/issues/issue_75439.foo.MatchBranchSimplification.diff @@ -32,15 +32,15 @@ bb1: { StorageDead(_3); // scope 2 at $DIR/issue-75439.rs:7:52: 7:53 - switchInt(_2[0 of 4]) -> [0_u32: bb2, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:9:13: 9:14 + switchInt(_2[0 of 4]) -> [0_u32: bb2, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:9:12: 9:30 } bb2: { - switchInt(_2[1 of 4]) -> [0_u32: bb3, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:9:16: 9:17 + switchInt(_2[1 of 4]) -> [0_u32: bb3, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:9:12: 9:30 } bb3: { - switchInt(_2[2 of 4]) -> [0_u32: bb6, 4294901760_u32: bb7, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:9:19: 9:20 + switchInt(_2[2 of 4]) -> [0_u32: bb6, 4294901760_u32: bb7, otherwise: bb4]; // scope 1 at $DIR/issue-75439.rs:9:12: 9:30 } bb4: { diff --git a/src/test/mir-opt/match_arm_scopes.complicated_match.SimplifyCfg-initial.after-ElaborateDrops.after.diff b/src/test/mir-opt/match_arm_scopes.complicated_match.SimplifyCfg-initial.after-ElaborateDrops.after.diff index feb25035ee0ec..f756b6bbf3d5c 100644 --- a/src/test/mir-opt/match_arm_scopes.complicated_match.SimplifyCfg-initial.after-ElaborateDrops.after.diff +++ b/src/test/mir-opt/match_arm_scopes.complicated_match.SimplifyCfg-initial.after-ElaborateDrops.after.diff @@ -32,18 +32,18 @@ bb0: { - FakeRead(ForMatchedPlace(None), _2); // scope 0 at $DIR/match-arm-scopes.rs:14:11: 14:16 -- switchInt((_2.0: bool)) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/match-arm-scopes.rs:15:10: 15:15 -+ switchInt((_2.0: bool)) -> [false: bb5, otherwise: bb1]; // scope 0 at $DIR/match-arm-scopes.rs:15:10: 15:15 +- switchInt((_2.0: bool)) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 14:16 ++ switchInt((_2.0: bool)) -> [false: bb5, otherwise: bb1]; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 14:16 } bb1: { - falseEdge -> [real: bb8, imaginary: bb3]; // scope 0 at $DIR/match-arm-scopes.rs:15:9: 15:22 -+ switchInt((_2.1: bool)) -> [false: bb10, otherwise: bb2]; // scope 0 at $DIR/match-arm-scopes.rs:15:29: 15:34 ++ switchInt((_2.1: bool)) -> [false: bb10, otherwise: bb2]; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 14:16 } bb2: { -- switchInt((_2.1: bool)) -> [false: bb3, otherwise: bb4]; // scope 0 at $DIR/match-arm-scopes.rs:15:29: 15:34 -+ switchInt((_2.0: bool)) -> [false: bb3, otherwise: bb17]; // scope 0 at $DIR/match-arm-scopes.rs:16:10: 16:14 +- switchInt((_2.1: bool)) -> [false: bb3, otherwise: bb4]; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 14:16 ++ switchInt((_2.0: bool)) -> [false: bb3, otherwise: bb17]; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 14:16 } bb3: { @@ -51,7 +51,7 @@ - } - - bb4: { -- switchInt((_2.0: bool)) -> [false: bb6, otherwise: bb5]; // scope 0 at $DIR/match-arm-scopes.rs:16:10: 16:14 +- switchInt((_2.0: bool)) -> [false: bb6, otherwise: bb5]; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 14:16 - } - - bb5: { @@ -192,8 +192,8 @@ StorageDead(_5); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 StorageDead(_8); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 StorageDead(_6); // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 -- goto -> bb22; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 -+ goto -> bb19; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 +- goto -> bb22; // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 ++ goto -> bb19; // scope 0 at $DIR/match-arm-scopes.rs:15:77: 15:78 } - bb19: { @@ -217,8 +217,8 @@ + bb18: { StorageDead(_16); // scope 0 at $DIR/match-arm-scopes.rs:16:41: 16:42 StorageDead(_15); // scope 0 at $DIR/match-arm-scopes.rs:16:41: 16:42 -- goto -> bb22; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 -+ goto -> bb19; // scope 0 at $DIR/match-arm-scopes.rs:14:5: 17:6 +- goto -> bb22; // scope 0 at $DIR/match-arm-scopes.rs:16:41: 16:42 ++ goto -> bb19; // scope 0 at $DIR/match-arm-scopes.rs:16:41: 16:42 } - bb22: { diff --git a/src/test/mir-opt/match_false_edges.full_tested_match.PromoteTemps.after.mir b/src/test/mir-opt/match_false_edges.full_tested_match.PromoteTemps.after.mir index c27ee528b80b7..a2fa39d365a0e 100644 --- a/src/test/mir-opt/match_false_edges.full_tested_match.PromoteTemps.after.mir +++ b/src/test/mir-opt/match_false_edges.full_tested_match.PromoteTemps.after.mir @@ -28,13 +28,13 @@ fn full_tested_match() -> () { StorageLive(_2); // scope 0 at $DIR/match_false_edges.rs:15:19: 15:27 _2 = Option::::Some(const 42_i32); // scope 0 at $DIR/match_false_edges.rs:15:19: 15:27 FakeRead(ForMatchedPlace(None), _2); // scope 0 at $DIR/match_false_edges.rs:15:19: 15:27 - _3 = discriminant(_2); // scope 0 at $DIR/match_false_edges.rs:16:9: 16:16 - switchInt(move _3) -> [0_isize: bb1, 1_isize: bb2, otherwise: bb4]; // scope 0 at $DIR/match_false_edges.rs:16:9: 16:16 + _3 = discriminant(_2); // scope 0 at $DIR/match_false_edges.rs:15:19: 15:27 + switchInt(move _3) -> [0_isize: bb1, 1_isize: bb2, otherwise: bb4]; // scope 0 at $DIR/match_false_edges.rs:15:13: 15:27 } bb1: { _1 = (const 3_i32, const 3_i32); // scope 0 at $DIR/match_false_edges.rs:18:17: 18:23 - goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:15:13: 19:6 + goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:18:17: 18:23 } bb2: { @@ -83,7 +83,7 @@ fn full_tested_match() -> () { StorageDead(_8); // scope 2 at $DIR/match_false_edges.rs:16:36: 16:37 StorageDead(_5); // scope 0 at $DIR/match_false_edges.rs:16:36: 16:37 StorageDead(_6); // scope 0 at $DIR/match_false_edges.rs:16:36: 16:37 - goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:15:13: 19:6 + goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:16:36: 16:37 } bb8: { @@ -100,7 +100,7 @@ fn full_tested_match() -> () { _1 = (const 2_i32, move _10); // scope 3 at $DIR/match_false_edges.rs:17:20: 17:26 StorageDead(_10); // scope 3 at $DIR/match_false_edges.rs:17:25: 17:26 StorageDead(_9); // scope 0 at $DIR/match_false_edges.rs:17:25: 17:26 - goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:15:13: 19:6 + goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:17:25: 17:26 } bb10: { diff --git a/src/test/mir-opt/match_false_edges.full_tested_match2.PromoteTemps.before.mir b/src/test/mir-opt/match_false_edges.full_tested_match2.PromoteTemps.before.mir index a4ebf8a02466a..9913d179edde6 100644 --- a/src/test/mir-opt/match_false_edges.full_tested_match2.PromoteTemps.before.mir +++ b/src/test/mir-opt/match_false_edges.full_tested_match2.PromoteTemps.before.mir @@ -27,8 +27,8 @@ fn full_tested_match2() -> () { StorageLive(_2); // scope 0 at $DIR/match_false_edges.rs:26:19: 26:27 _2 = Option::::Some(const 42_i32); // scope 0 at $DIR/match_false_edges.rs:26:19: 26:27 FakeRead(ForMatchedPlace(None), _2); // scope 0 at $DIR/match_false_edges.rs:26:19: 26:27 - _3 = discriminant(_2); // scope 0 at $DIR/match_false_edges.rs:27:9: 27:16 - switchInt(move _3) -> [0_isize: bb1, 1_isize: bb2, otherwise: bb4]; // scope 0 at $DIR/match_false_edges.rs:27:9: 27:16 + _3 = discriminant(_2); // scope 0 at $DIR/match_false_edges.rs:26:19: 26:27 + switchInt(move _3) -> [0_isize: bb1, 1_isize: bb2, otherwise: bb4]; // scope 0 at $DIR/match_false_edges.rs:26:13: 26:27 } bb1: { @@ -47,7 +47,7 @@ fn full_tested_match2() -> () { _1 = (const 2_i32, move _10); // scope 3 at $DIR/match_false_edges.rs:29:20: 29:26 StorageDead(_10); // scope 3 at $DIR/match_false_edges.rs:29:25: 29:26 StorageDead(_9); // scope 0 at $DIR/match_false_edges.rs:29:25: 29:26 - goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:26:13: 30:6 + goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:29:25: 29:26 } bb4: { @@ -81,7 +81,7 @@ fn full_tested_match2() -> () { StorageDead(_8); // scope 2 at $DIR/match_false_edges.rs:27:36: 27:37 StorageDead(_5); // scope 0 at $DIR/match_false_edges.rs:27:36: 27:37 StorageDead(_6); // scope 0 at $DIR/match_false_edges.rs:27:36: 27:37 - goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:26:13: 30:6 + goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:27:36: 27:37 } bb8: { @@ -92,7 +92,7 @@ fn full_tested_match2() -> () { bb9: { _1 = (const 3_i32, const 3_i32); // scope 0 at $DIR/match_false_edges.rs:28:17: 28:23 - goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:26:13: 30:6 + goto -> bb10; // scope 0 at $DIR/match_false_edges.rs:28:17: 28:23 } bb10: { diff --git a/src/test/mir-opt/match_false_edges.main.PromoteTemps.before.mir b/src/test/mir-opt/match_false_edges.main.PromoteTemps.before.mir index 5de52b324f43f..9113d9d318941 100644 --- a/src/test/mir-opt/match_false_edges.main.PromoteTemps.before.mir +++ b/src/test/mir-opt/match_false_edges.main.PromoteTemps.before.mir @@ -38,8 +38,8 @@ fn main() -> () { StorageLive(_2); // scope 0 at $DIR/match_false_edges.rs:35:19: 35:26 _2 = Option::::Some(const 1_i32); // scope 0 at $DIR/match_false_edges.rs:35:19: 35:26 FakeRead(ForMatchedPlace(None), _2); // scope 0 at $DIR/match_false_edges.rs:35:19: 35:26 - _4 = discriminant(_2); // scope 0 at $DIR/match_false_edges.rs:36:9: 36:17 - switchInt(move _4) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/match_false_edges.rs:36:9: 36:17 + _4 = discriminant(_2); // scope 0 at $DIR/match_false_edges.rs:35:19: 35:26 + switchInt(move _4) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/match_false_edges.rs:35:13: 35:26 } bb1: { @@ -55,7 +55,7 @@ fn main() -> () { _14 = _2; // scope 0 at $DIR/match_false_edges.rs:39:9: 39:11 _1 = const 4_i32; // scope 5 at $DIR/match_false_edges.rs:39:15: 39:16 StorageDead(_14); // scope 0 at $DIR/match_false_edges.rs:39:15: 39:16 - goto -> bb14; // scope 0 at $DIR/match_false_edges.rs:35:13: 40:6 + goto -> bb14; // scope 0 at $DIR/match_false_edges.rs:39:15: 39:16 } bb4: { @@ -86,7 +86,7 @@ fn main() -> () { _1 = const 1_i32; // scope 2 at $DIR/match_false_edges.rs:36:32: 36:33 StorageDead(_6); // scope 0 at $DIR/match_false_edges.rs:36:32: 36:33 StorageDead(_7); // scope 0 at $DIR/match_false_edges.rs:36:32: 36:33 - goto -> bb14; // scope 0 at $DIR/match_false_edges.rs:35:13: 40:6 + goto -> bb14; // scope 0 at $DIR/match_false_edges.rs:36:32: 36:33 } bb8: { @@ -100,7 +100,7 @@ fn main() -> () { _9 = _2; // scope 0 at $DIR/match_false_edges.rs:37:9: 37:11 _1 = const 2_i32; // scope 3 at $DIR/match_false_edges.rs:37:15: 37:16 StorageDead(_9); // scope 0 at $DIR/match_false_edges.rs:37:15: 37:16 - goto -> bb14; // scope 0 at $DIR/match_false_edges.rs:35:13: 40:6 + goto -> bb14; // scope 0 at $DIR/match_false_edges.rs:37:15: 37:16 } bb10: { @@ -130,7 +130,7 @@ fn main() -> () { _1 = const 3_i32; // scope 4 at $DIR/match_false_edges.rs:38:33: 38:34 StorageDead(_10); // scope 0 at $DIR/match_false_edges.rs:38:33: 38:34 StorageDead(_11); // scope 0 at $DIR/match_false_edges.rs:38:33: 38:34 - goto -> bb14; // scope 0 at $DIR/match_false_edges.rs:35:13: 40:6 + goto -> bb14; // scope 0 at $DIR/match_false_edges.rs:38:33: 38:34 } bb13: { diff --git a/src/test/mir-opt/match_test.main.SimplifyCfg-initial.after.mir b/src/test/mir-opt/match_test.main.SimplifyCfg-initial.after.mir index 5bb910947ca25..4dab5b4c1ef9e 100644 --- a/src/test/mir-opt/match_test.main.SimplifyCfg-initial.after.mir +++ b/src/test/mir-opt/match_test.main.SimplifyCfg-initial.after.mir @@ -42,7 +42,7 @@ fn main() -> () { bb3: { _3 = const 3_i32; // scope 2 at $DIR/match_test.rs:16:14: 16:15 - goto -> bb14; // scope 2 at $DIR/match_test.rs:12:5: 17:6 + goto -> bb14; // scope 2 at $DIR/match_test.rs:16:14: 16:15 } bb4: { @@ -60,7 +60,7 @@ fn main() -> () { } bb7: { - switchInt(_1) -> [-1_i32: bb8, otherwise: bb3]; // scope 2 at $DIR/match_test.rs:15:9: 15:11 + switchInt(_1) -> [-1_i32: bb8, otherwise: bb3]; // scope 2 at $DIR/match_test.rs:12:5: 12:12 } bb8: { @@ -78,7 +78,7 @@ fn main() -> () { StorageDead(_9); // scope 2 at $DIR/match_test.rs:13:23: 13:24 FakeRead(ForMatchGuard, _8); // scope 2 at $DIR/match_test.rs:13:18: 13:19 _3 = const 0_i32; // scope 2 at $DIR/match_test.rs:13:23: 13:24 - goto -> bb14; // scope 2 at $DIR/match_test.rs:12:5: 17:6 + goto -> bb14; // scope 2 at $DIR/match_test.rs:13:23: 13:24 } bb11: { @@ -88,12 +88,12 @@ fn main() -> () { bb12: { _3 = const 1_i32; // scope 2 at $DIR/match_test.rs:14:20: 14:21 - goto -> bb14; // scope 2 at $DIR/match_test.rs:12:5: 17:6 + goto -> bb14; // scope 2 at $DIR/match_test.rs:14:20: 14:21 } bb13: { _3 = const 2_i32; // scope 2 at $DIR/match_test.rs:15:15: 15:16 - goto -> bb14; // scope 2 at $DIR/match_test.rs:12:5: 17:6 + goto -> bb14; // scope 2 at $DIR/match_test.rs:15:15: 15:16 } bb14: { diff --git a/src/test/mir-opt/matches_reduce_branches.bar.MatchBranchSimplification.32bit.diff b/src/test/mir-opt/matches_reduce_branches.bar.MatchBranchSimplification.32bit.diff index a52c6ae351b2c..d164f62c580f7 100644 --- a/src/test/mir-opt/matches_reduce_branches.bar.MatchBranchSimplification.32bit.diff +++ b/src/test/mir-opt/matches_reduce_branches.bar.MatchBranchSimplification.32bit.diff @@ -10,7 +10,7 @@ let mut _8: bool; // in scope 0 at $DIR/matches_reduce_branches.rs:36:9: 36:10 let mut _9: bool; // in scope 0 at $DIR/matches_reduce_branches.rs:36:12: 36:13 let mut _10: bool; // in scope 0 at $DIR/matches_reduce_branches.rs:36:15: 36:16 -+ let mut _11: i32; // in scope 0 at $DIR/matches_reduce_branches.rs:20:9: 20:10 ++ let mut _11: i32; // in scope 0 at $DIR/matches_reduce_branches.rs:19:5: 19:12 scope 1 { debug a => _2; // in scope 1 at $DIR/matches_reduce_branches.rs:14:9: 14:10 let _3: bool; // in scope 1 at $DIR/matches_reduce_branches.rs:15:9: 15:10 @@ -33,7 +33,7 @@ StorageLive(_4); // scope 2 at $DIR/matches_reduce_branches.rs:16:9: 16:10 StorageLive(_5); // scope 3 at $DIR/matches_reduce_branches.rs:17:9: 17:10 StorageLive(_6); // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 34:6 -- switchInt(_1) -> [7_i32: bb2, otherwise: bb1]; // scope 4 at $DIR/matches_reduce_branches.rs:20:9: 20:10 +- switchInt(_1) -> [7_i32: bb2, otherwise: bb1]; // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 19:12 - } - - bb1: { @@ -41,23 +41,23 @@ - _3 = const false; // scope 4 at $DIR/matches_reduce_branches.rs:29:13: 29:22 - _4 = const false; // scope 4 at $DIR/matches_reduce_branches.rs:30:13: 30:22 - _5 = const true; // scope 4 at $DIR/matches_reduce_branches.rs:31:13: 31:21 -- goto -> bb3; // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 34:6 +- goto -> bb3; // scope 4 at $DIR/matches_reduce_branches.rs:32:13: 32:15 - } - - bb2: { - _2 = const false; // scope 4 at $DIR/matches_reduce_branches.rs:21:13: 21:22 - _3 = const true; // scope 4 at $DIR/matches_reduce_branches.rs:22:13: 22:21 -+ StorageLive(_11); // scope 4 at $DIR/matches_reduce_branches.rs:20:9: 20:10 -+ _11 = _1; // scope 4 at $DIR/matches_reduce_branches.rs:20:9: 20:10 ++ StorageLive(_11); // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 19:12 ++ _11 = _1; // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 19:12 + _2 = Ne(_11, const 7_i32); // scope 4 at $DIR/matches_reduce_branches.rs:21:13: 21:22 + _3 = Eq(_11, const 7_i32); // scope 4 at $DIR/matches_reduce_branches.rs:22:13: 22:21 _4 = const false; // scope 4 at $DIR/matches_reduce_branches.rs:23:13: 23:22 _5 = const true; // scope 4 at $DIR/matches_reduce_branches.rs:24:13: 24:21 -- goto -> bb3; // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 34:6 +- goto -> bb3; // scope 4 at $DIR/matches_reduce_branches.rs:25:13: 25:15 - } - - bb3: { -+ StorageDead(_11); // scope 4 at $DIR/matches_reduce_branches.rs:20:9: 20:10 ++ StorageDead(_11); // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 19:12 StorageDead(_6); // scope 4 at $DIR/matches_reduce_branches.rs:34:6: 34:7 StorageLive(_7); // scope 4 at $DIR/matches_reduce_branches.rs:36:6: 36:7 _7 = _2; // scope 4 at $DIR/matches_reduce_branches.rs:36:6: 36:7 diff --git a/src/test/mir-opt/matches_reduce_branches.bar.MatchBranchSimplification.64bit.diff b/src/test/mir-opt/matches_reduce_branches.bar.MatchBranchSimplification.64bit.diff index a52c6ae351b2c..d164f62c580f7 100644 --- a/src/test/mir-opt/matches_reduce_branches.bar.MatchBranchSimplification.64bit.diff +++ b/src/test/mir-opt/matches_reduce_branches.bar.MatchBranchSimplification.64bit.diff @@ -10,7 +10,7 @@ let mut _8: bool; // in scope 0 at $DIR/matches_reduce_branches.rs:36:9: 36:10 let mut _9: bool; // in scope 0 at $DIR/matches_reduce_branches.rs:36:12: 36:13 let mut _10: bool; // in scope 0 at $DIR/matches_reduce_branches.rs:36:15: 36:16 -+ let mut _11: i32; // in scope 0 at $DIR/matches_reduce_branches.rs:20:9: 20:10 ++ let mut _11: i32; // in scope 0 at $DIR/matches_reduce_branches.rs:19:5: 19:12 scope 1 { debug a => _2; // in scope 1 at $DIR/matches_reduce_branches.rs:14:9: 14:10 let _3: bool; // in scope 1 at $DIR/matches_reduce_branches.rs:15:9: 15:10 @@ -33,7 +33,7 @@ StorageLive(_4); // scope 2 at $DIR/matches_reduce_branches.rs:16:9: 16:10 StorageLive(_5); // scope 3 at $DIR/matches_reduce_branches.rs:17:9: 17:10 StorageLive(_6); // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 34:6 -- switchInt(_1) -> [7_i32: bb2, otherwise: bb1]; // scope 4 at $DIR/matches_reduce_branches.rs:20:9: 20:10 +- switchInt(_1) -> [7_i32: bb2, otherwise: bb1]; // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 19:12 - } - - bb1: { @@ -41,23 +41,23 @@ - _3 = const false; // scope 4 at $DIR/matches_reduce_branches.rs:29:13: 29:22 - _4 = const false; // scope 4 at $DIR/matches_reduce_branches.rs:30:13: 30:22 - _5 = const true; // scope 4 at $DIR/matches_reduce_branches.rs:31:13: 31:21 -- goto -> bb3; // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 34:6 +- goto -> bb3; // scope 4 at $DIR/matches_reduce_branches.rs:32:13: 32:15 - } - - bb2: { - _2 = const false; // scope 4 at $DIR/matches_reduce_branches.rs:21:13: 21:22 - _3 = const true; // scope 4 at $DIR/matches_reduce_branches.rs:22:13: 22:21 -+ StorageLive(_11); // scope 4 at $DIR/matches_reduce_branches.rs:20:9: 20:10 -+ _11 = _1; // scope 4 at $DIR/matches_reduce_branches.rs:20:9: 20:10 ++ StorageLive(_11); // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 19:12 ++ _11 = _1; // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 19:12 + _2 = Ne(_11, const 7_i32); // scope 4 at $DIR/matches_reduce_branches.rs:21:13: 21:22 + _3 = Eq(_11, const 7_i32); // scope 4 at $DIR/matches_reduce_branches.rs:22:13: 22:21 _4 = const false; // scope 4 at $DIR/matches_reduce_branches.rs:23:13: 23:22 _5 = const true; // scope 4 at $DIR/matches_reduce_branches.rs:24:13: 24:21 -- goto -> bb3; // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 34:6 +- goto -> bb3; // scope 4 at $DIR/matches_reduce_branches.rs:25:13: 25:15 - } - - bb3: { -+ StorageDead(_11); // scope 4 at $DIR/matches_reduce_branches.rs:20:9: 20:10 ++ StorageDead(_11); // scope 4 at $DIR/matches_reduce_branches.rs:19:5: 19:12 StorageDead(_6); // scope 4 at $DIR/matches_reduce_branches.rs:34:6: 34:7 StorageLive(_7); // scope 4 at $DIR/matches_reduce_branches.rs:36:6: 36:7 _7 = _2; // scope 4 at $DIR/matches_reduce_branches.rs:36:6: 36:7 diff --git a/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.32bit.diff b/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.32bit.diff index 96b03477d0108..29f66ceac981e 100644 --- a/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.32bit.diff +++ b/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.32bit.diff @@ -5,11 +5,11 @@ debug bar => _1; // in scope 0 at $DIR/matches_reduce_branches.rs:7:8: 7:11 let mut _0: (); // return place in scope 0 at $DIR/matches_reduce_branches.rs:7:25: 7:25 let mut _2: isize; // in scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 -+ let mut _3: isize; // in scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 ++ let mut _3: isize; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 -- switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 + _2 = discriminant(_1); // scope 0 at $DIR/matches_reduce_branches.rs:8:17: 8:20 +- switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL - } - - bb1: { @@ -21,9 +21,9 @@ - } - - bb3: { -+ StorageLive(_3); // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 -+ _3 = move _2; // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 -+ StorageDead(_3); // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 ++ StorageLive(_3); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL ++ _3 = move _2; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL ++ StorageDead(_3); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL return; // scope 0 at $DIR/matches_reduce_branches.rs:11:2: 11:2 } } diff --git a/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.64bit.diff b/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.64bit.diff index 96b03477d0108..29f66ceac981e 100644 --- a/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.64bit.diff +++ b/src/test/mir-opt/matches_reduce_branches.foo.MatchBranchSimplification.64bit.diff @@ -5,11 +5,11 @@ debug bar => _1; // in scope 0 at $DIR/matches_reduce_branches.rs:7:8: 7:11 let mut _0: (); // return place in scope 0 at $DIR/matches_reduce_branches.rs:7:25: 7:25 let mut _2: isize; // in scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 -+ let mut _3: isize; // in scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 ++ let mut _3: isize; // in scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 -- switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 + _2 = discriminant(_1); // scope 0 at $DIR/matches_reduce_branches.rs:8:17: 8:20 +- switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL - } - - bb1: { @@ -21,9 +21,9 @@ - } - - bb3: { -+ StorageLive(_3); // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 -+ _3 = move _2; // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 -+ StorageDead(_3); // scope 0 at $DIR/matches_reduce_branches.rs:8:22: 8:26 ++ StorageLive(_3); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL ++ _3 = move _2; // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL ++ StorageDead(_3); // scope 0 at $SRC_DIR/core/src/macros/mod.rs:LL:COL return; // scope 0 at $DIR/matches_reduce_branches.rs:11:2: 11:2 } } diff --git a/src/test/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.32bit.diff b/src/test/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.32bit.diff index 410320e643cad..4ce1b57b9a3ad 100644 --- a/src/test/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.32bit.diff +++ b/src/test/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.32bit.diff @@ -90,13 +90,13 @@ + _10 = move _3; // scope 0 at $DIR/matches_reduce_branches.rs:41:15: 45:10 StorageDead(_3); // scope 0 at $DIR/matches_reduce_branches.rs:48:9: 48:10 - _1 = const true; // scope 0 at $DIR/matches_reduce_branches.rs:47:13: 47:17 -- goto -> bb12; // scope 0 at $DIR/matches_reduce_branches.rs:40:15: 50:6 +- goto -> bb12; // scope 0 at $DIR/matches_reduce_branches.rs:47:13: 47:17 - } - - bb11: { - StorageDead(_3); // scope 0 at $DIR/matches_reduce_branches.rs:48:9: 48:10 - _1 = const false; // scope 0 at $DIR/matches_reduce_branches.rs:49:14: 49:19 -- goto -> bb12; // scope 0 at $DIR/matches_reduce_branches.rs:40:15: 50:6 +- goto -> bb12; // scope 0 at $DIR/matches_reduce_branches.rs:49:14: 49:19 - } - - bb12: { diff --git a/src/test/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.64bit.diff b/src/test/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.64bit.diff index 410320e643cad..4ce1b57b9a3ad 100644 --- a/src/test/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.64bit.diff +++ b/src/test/mir-opt/matches_reduce_branches.match_nested_if.MatchBranchSimplification.64bit.diff @@ -90,13 +90,13 @@ + _10 = move _3; // scope 0 at $DIR/matches_reduce_branches.rs:41:15: 45:10 StorageDead(_3); // scope 0 at $DIR/matches_reduce_branches.rs:48:9: 48:10 - _1 = const true; // scope 0 at $DIR/matches_reduce_branches.rs:47:13: 47:17 -- goto -> bb12; // scope 0 at $DIR/matches_reduce_branches.rs:40:15: 50:6 +- goto -> bb12; // scope 0 at $DIR/matches_reduce_branches.rs:47:13: 47:17 - } - - bb11: { - StorageDead(_3); // scope 0 at $DIR/matches_reduce_branches.rs:48:9: 48:10 - _1 = const false; // scope 0 at $DIR/matches_reduce_branches.rs:49:14: 49:19 -- goto -> bb12; // scope 0 at $DIR/matches_reduce_branches.rs:40:15: 50:6 +- goto -> bb12; // scope 0 at $DIR/matches_reduce_branches.rs:49:14: 49:19 - } - - bb12: { diff --git a/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.32bit.diff b/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.32bit.diff index 9fde4888809d1..711cc31f49f98 100644 --- a/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.32bit.diff +++ b/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.32bit.diff @@ -7,18 +7,18 @@ let mut _2: isize; // in scope 0 at $DIR/matches_u8.rs:13:9: 13:13 bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:13:9: 13:13 - switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:13:9: 13:13 + _2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:12:11: 12:12 + switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:12:5: 12:12 } bb1: { _0 = const 1_u8; // scope 0 at $DIR/matches_u8.rs:14:17: 14:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:12:5: 15:6 + goto -> bb3; // scope 0 at $DIR/matches_u8.rs:14:17: 14:18 } bb2: { _0 = const 0_u8; // scope 0 at $DIR/matches_u8.rs:13:17: 13:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:12:5: 15:6 + goto -> bb3; // scope 0 at $DIR/matches_u8.rs:13:17: 13:18 } bb3: { diff --git a/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.64bit.diff b/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.64bit.diff index 9fde4888809d1..711cc31f49f98 100644 --- a/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.64bit.diff +++ b/src/test/mir-opt/matches_u8.exhaustive_match.MatchBranchSimplification.64bit.diff @@ -7,18 +7,18 @@ let mut _2: isize; // in scope 0 at $DIR/matches_u8.rs:13:9: 13:13 bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:13:9: 13:13 - switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:13:9: 13:13 + _2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:12:11: 12:12 + switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:12:5: 12:12 } bb1: { _0 = const 1_u8; // scope 0 at $DIR/matches_u8.rs:14:17: 14:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:12:5: 15:6 + goto -> bb3; // scope 0 at $DIR/matches_u8.rs:14:17: 14:18 } bb2: { _0 = const 0_u8; // scope 0 at $DIR/matches_u8.rs:13:17: 13:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:12:5: 15:6 + goto -> bb3; // scope 0 at $DIR/matches_u8.rs:13:17: 13:18 } bb3: { diff --git a/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.32bit.diff b/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.32bit.diff index 2dd0a3edb479a..6bdeccbf913e6 100644 --- a/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.32bit.diff +++ b/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.32bit.diff @@ -7,18 +7,18 @@ let mut _2: isize; // in scope 0 at $DIR/matches_u8.rs:21:9: 21:13 bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:21:9: 21:13 - switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:21:9: 21:13 + _2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:20:11: 20:12 + switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:20:5: 20:12 } bb1: { _0 = const 1_i8; // scope 0 at $DIR/matches_u8.rs:22:17: 22:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:20:5: 23:6 + goto -> bb3; // scope 0 at $DIR/matches_u8.rs:22:17: 22:18 } bb2: { _0 = const 0_i8; // scope 0 at $DIR/matches_u8.rs:21:17: 21:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:20:5: 23:6 + goto -> bb3; // scope 0 at $DIR/matches_u8.rs:21:17: 21:18 } bb3: { diff --git a/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.64bit.diff b/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.64bit.diff index 2dd0a3edb479a..6bdeccbf913e6 100644 --- a/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.64bit.diff +++ b/src/test/mir-opt/matches_u8.exhaustive_match_i8.MatchBranchSimplification.64bit.diff @@ -7,18 +7,18 @@ let mut _2: isize; // in scope 0 at $DIR/matches_u8.rs:21:9: 21:13 bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:21:9: 21:13 - switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:21:9: 21:13 + _2 = discriminant(_1); // scope 0 at $DIR/matches_u8.rs:20:11: 20:12 + switchInt(move _2) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/matches_u8.rs:20:5: 20:12 } bb1: { _0 = const 1_i8; // scope 0 at $DIR/matches_u8.rs:22:17: 22:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:20:5: 23:6 + goto -> bb3; // scope 0 at $DIR/matches_u8.rs:22:17: 22:18 } bb2: { _0 = const 0_i8; // scope 0 at $DIR/matches_u8.rs:21:17: 21:18 - goto -> bb3; // scope 0 at $DIR/matches_u8.rs:20:5: 23:6 + goto -> bb3; // scope 0 at $DIR/matches_u8.rs:21:17: 21:18 } bb3: { diff --git a/src/test/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-elaborate-drops.after.mir b/src/test/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-elaborate-drops.after.mir index 8a1134478d6b5..cc4457cc5f3ff 100644 --- a/src/test/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-elaborate-drops.after.mir +++ b/src/test/mir-opt/no_drop_for_inactive_variant.unwrap.SimplifyCfg-elaborate-drops.after.mir @@ -14,8 +14,8 @@ fn unwrap(_1: Option) -> T { } bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/no-drop-for-inactive-variant.rs:9:9: 9:16 - switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/no-drop-for-inactive-variant.rs:9:9: 9:16 + _2 = discriminant(_1); // scope 0 at $DIR/no-drop-for-inactive-variant.rs:8:11: 8:14 + switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/no-drop-for-inactive-variant.rs:8:5: 8:14 } bb1: { diff --git a/src/test/mir-opt/remove_fake_borrows.match_guard.CleanupNonCodegenStatements.diff b/src/test/mir-opt/remove_fake_borrows.match_guard.CleanupNonCodegenStatements.diff index 4aa388fc67bd0..52b5611e905fa 100644 --- a/src/test/mir-opt/remove_fake_borrows.match_guard.CleanupNonCodegenStatements.diff +++ b/src/test/mir-opt/remove_fake_borrows.match_guard.CleanupNonCodegenStatements.diff @@ -15,17 +15,17 @@ bb0: { - FakeRead(ForMatchedPlace(None), _1); // scope 0 at $DIR/remove_fake_borrows.rs:7:11: 7:12 + nop; // scope 0 at $DIR/remove_fake_borrows.rs:7:11: 7:12 - _3 = discriminant(_1); // scope 0 at $DIR/remove_fake_borrows.rs:8:9: 8:16 - switchInt(move _3) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/remove_fake_borrows.rs:8:9: 8:16 + _3 = discriminant(_1); // scope 0 at $DIR/remove_fake_borrows.rs:7:11: 7:12 + switchInt(move _3) -> [1_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/remove_fake_borrows.rs:7:5: 7:12 } bb1: { _0 = const 1_i32; // scope 0 at $DIR/remove_fake_borrows.rs:9:14: 9:15 - goto -> bb7; // scope 0 at $DIR/remove_fake_borrows.rs:7:5: 10:6 + goto -> bb7; // scope 0 at $DIR/remove_fake_borrows.rs:9:14: 9:15 } bb2: { - switchInt((*(*((_1 as Some).0: &&i32)))) -> [0_i32: bb3, otherwise: bb1]; // scope 0 at $DIR/remove_fake_borrows.rs:8:14: 8:15 + switchInt((*(*((_1 as Some).0: &&i32)))) -> [0_i32: bb3, otherwise: bb1]; // scope 0 at $DIR/remove_fake_borrows.rs:7:5: 7:12 } bb3: { @@ -57,7 +57,7 @@ + nop; // scope 0 at $DIR/remove_fake_borrows.rs:8:20: 8:21 + nop; // scope 0 at $DIR/remove_fake_borrows.rs:8:20: 8:21 _0 = const 0_i32; // scope 0 at $DIR/remove_fake_borrows.rs:8:25: 8:26 - goto -> bb7; // scope 0 at $DIR/remove_fake_borrows.rs:7:5: 10:6 + goto -> bb7; // scope 0 at $DIR/remove_fake_borrows.rs:8:25: 8:26 } bb6: { diff --git a/src/test/mir-opt/remove_storage_markers.main.RemoveStorageMarkers.diff b/src/test/mir-opt/remove_storage_markers.main.RemoveStorageMarkers.diff index 80024124dc523..6d6c2721973f8 100644 --- a/src/test/mir-opt/remove_storage_markers.main.RemoveStorageMarkers.diff +++ b/src/test/mir-opt/remove_storage_markers.main.RemoveStorageMarkers.diff @@ -115,8 +115,8 @@ bb4: { - StorageDead(_18); // scope 7 at $DIR/remove_storage_markers.rs:8:14: 8:19 - StorageDead(_9); // scope 3 at $DIR/remove_storage_markers.rs:8:18: 8:19 - _11 = discriminant(_8); // scope 3 at $DIR/remove_storage_markers.rs:8:9: 8:10 - switchInt(move _11) -> [0_isize: bb2, otherwise: bb3]; // scope 3 at $DIR/remove_storage_markers.rs:8:9: 8:10 + _11 = discriminant(_8); // scope 3 at $DIR/remove_storage_markers.rs:8:14: 8:19 + switchInt(move _11) -> [0_isize: bb2, otherwise: bb3]; // scope 3 at $DIR/remove_storage_markers.rs:8:14: 8:19 } } diff --git a/src/test/mir-opt/separate_const_switch.identity.ConstProp.diff b/src/test/mir-opt/separate_const_switch.identity.ConstProp.diff index 57299cee7b726..d5190cdb0c7de 100644 --- a/src/test/mir-opt/separate_const_switch.identity.ConstProp.diff +++ b/src/test/mir-opt/separate_const_switch.identity.ConstProp.diff @@ -110,10 +110,10 @@ StorageDead(_13); // scope 5 at $DIR/separate_const_switch.rs:29:8: 29:10 StorageDead(_10); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 StorageDead(_4); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -- _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -- switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -+ _5 = const 1_isize; // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -+ switchInt(const 1_isize) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 +- _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 +- switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 ++ _5 = const 1_isize; // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 ++ switchInt(const 1_isize) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 } bb4: { @@ -131,10 +131,10 @@ StorageDead(_11); // scope 5 at $DIR/separate_const_switch.rs:29:8: 29:10 StorageDead(_10); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 StorageDead(_4); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -- _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -- switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -+ _5 = const 0_isize; // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -+ switchInt(const 0_isize) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 +- _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 +- switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 ++ _5 = const 0_isize; // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 ++ switchInt(const 0_isize) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 } } diff --git a/src/test/mir-opt/separate_const_switch.identity.SeparateConstSwitch.diff b/src/test/mir-opt/separate_const_switch.identity.SeparateConstSwitch.diff index 4bfd0842db084..69f3bec6fea25 100644 --- a/src/test/mir-opt/separate_const_switch.identity.SeparateConstSwitch.diff +++ b/src/test/mir-opt/separate_const_switch.identity.SeparateConstSwitch.diff @@ -64,8 +64,8 @@ bb1: { - StorageDead(_10); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 - StorageDead(_4); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -- _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -- switchInt(move _5) -> [0_isize: bb2, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 +- _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 +- switchInt(move _5) -> [0_isize: bb2, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 - } - - bb2: { @@ -121,8 +121,8 @@ - goto -> bb1; // scope 5 at $DIR/separate_const_switch.rs:29:8: 29:10 + StorageDead(_10); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 + StorageDead(_4); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -+ _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -+ switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 ++ _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 ++ switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 } - bb5: { @@ -143,8 +143,8 @@ - goto -> bb1; // scope 5 at $DIR/separate_const_switch.rs:29:8: 29:10 + StorageDead(_10); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 + StorageDead(_4); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -+ _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 -+ switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:9: 29:10 ++ _5 = discriminant(_3); // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 ++ switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/separate_const_switch.rs:29:8: 29:10 } } diff --git a/src/test/mir-opt/separate_const_switch.too_complex.ConstProp.diff b/src/test/mir-opt/separate_const_switch.too_complex.ConstProp.diff index 973b7838eca35..5316c34fb37d1 100644 --- a/src/test/mir-opt/separate_const_switch.too_complex.ConstProp.diff +++ b/src/test/mir-opt/separate_const_switch.too_complex.ConstProp.diff @@ -29,8 +29,8 @@ bb0: { StorageLive(_2); // scope 0 at $DIR/separate_const_switch.rs:14:11: 19:6 - _3 = discriminant(_1); // scope 0 at $DIR/separate_const_switch.rs:16:13: 16:18 - switchInt(move _3) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/separate_const_switch.rs:16:13: 16:18 + _3 = discriminant(_1); // scope 0 at $DIR/separate_const_switch.rs:15:15: 15:16 + switchInt(move _3) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/separate_const_switch.rs:15:9: 15:16 } bb1: { @@ -42,10 +42,10 @@ discriminant(_2) = 1; // scope 2 at $DIR/separate_const_switch.rs:17:23: 17:44 StorageDead(_7); // scope 2 at $DIR/separate_const_switch.rs:17:43: 17:44 StorageDead(_6); // scope 0 at $DIR/separate_const_switch.rs:17:43: 17:44 -- _8 = discriminant(_2); // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 -- switchInt(move _8) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 -+ _8 = const 1_isize; // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 -+ switchInt(const 1_isize) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 +- _8 = discriminant(_2); // scope 0 at $DIR/separate_const_switch.rs:14:11: 19:6 +- switchInt(move _8) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:14:5: 19:6 ++ _8 = const 1_isize; // scope 0 at $DIR/separate_const_switch.rs:14:11: 19:6 ++ switchInt(const 1_isize) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:14:5: 19:6 } bb2: { @@ -57,10 +57,10 @@ discriminant(_2) = 0; // scope 1 at $DIR/separate_const_switch.rs:16:22: 16:46 StorageDead(_5); // scope 1 at $DIR/separate_const_switch.rs:16:45: 16:46 StorageDead(_4); // scope 0 at $DIR/separate_const_switch.rs:16:45: 16:46 -- _8 = discriminant(_2); // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 -- switchInt(move _8) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 -+ _8 = const 0_isize; // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 -+ switchInt(const 0_isize) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 +- _8 = discriminant(_2); // scope 0 at $DIR/separate_const_switch.rs:14:11: 19:6 +- switchInt(move _8) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:14:5: 19:6 ++ _8 = const 0_isize; // scope 0 at $DIR/separate_const_switch.rs:14:11: 19:6 ++ switchInt(const 0_isize) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:14:5: 19:6 } bb3: { @@ -68,7 +68,7 @@ _11 = ((_2 as Break).0: usize); // scope 0 at $DIR/separate_const_switch.rs:21:28: 21:29 discriminant(_0) = 0; // scope 4 at $DIR/separate_const_switch.rs:21:34: 21:38 StorageDead(_11); // scope 0 at $DIR/separate_const_switch.rs:21:37: 21:38 - goto -> bb5; // scope 0 at $DIR/separate_const_switch.rs:14:5: 22:6 + goto -> bb5; // scope 0 at $DIR/separate_const_switch.rs:21:37: 21:38 } bb4: { @@ -80,7 +80,7 @@ discriminant(_0) = 1; // scope 3 at $DIR/separate_const_switch.rs:20:37: 20:44 StorageDead(_10); // scope 3 at $DIR/separate_const_switch.rs:20:43: 20:44 StorageDead(_9); // scope 0 at $DIR/separate_const_switch.rs:20:43: 20:44 - goto -> bb5; // scope 0 at $DIR/separate_const_switch.rs:14:5: 22:6 + goto -> bb5; // scope 0 at $DIR/separate_const_switch.rs:20:43: 20:44 } bb5: { diff --git a/src/test/mir-opt/separate_const_switch.too_complex.PreCodegen.after.mir b/src/test/mir-opt/separate_const_switch.too_complex.PreCodegen.after.mir index cc941f251cea5..38ad12157e279 100644 --- a/src/test/mir-opt/separate_const_switch.too_complex.PreCodegen.after.mir +++ b/src/test/mir-opt/separate_const_switch.too_complex.PreCodegen.after.mir @@ -27,8 +27,8 @@ fn too_complex(_1: Result) -> Option { bb0: { StorageLive(_2); // scope 0 at $DIR/separate_const_switch.rs:14:11: 19:6 - _3 = discriminant(_1); // scope 0 at $DIR/separate_const_switch.rs:16:13: 16:18 - switchInt(move _3) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/separate_const_switch.rs:16:13: 16:18 + _3 = discriminant(_1); // scope 0 at $DIR/separate_const_switch.rs:15:15: 15:16 + switchInt(move _3) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/separate_const_switch.rs:15:9: 15:16 } bb1: { @@ -44,7 +44,7 @@ fn too_complex(_1: Result) -> Option { _10 = ((_2 as Break).0: usize); // scope 0 at $DIR/separate_const_switch.rs:21:28: 21:29 discriminant(_0) = 0; // scope 4 at $DIR/separate_const_switch.rs:21:34: 21:38 StorageDead(_10); // scope 0 at $DIR/separate_const_switch.rs:21:37: 21:38 - goto -> bb3; // scope 0 at $DIR/separate_const_switch.rs:14:5: 22:6 + goto -> bb3; // scope 0 at $DIR/separate_const_switch.rs:21:37: 21:38 } bb2: { @@ -64,7 +64,7 @@ fn too_complex(_1: Result) -> Option { discriminant(_0) = 1; // scope 3 at $DIR/separate_const_switch.rs:20:37: 20:44 StorageDead(_9); // scope 3 at $DIR/separate_const_switch.rs:20:43: 20:44 StorageDead(_8); // scope 0 at $DIR/separate_const_switch.rs:20:43: 20:44 - goto -> bb3; // scope 0 at $DIR/separate_const_switch.rs:14:5: 22:6 + goto -> bb3; // scope 0 at $DIR/separate_const_switch.rs:20:43: 20:44 } bb3: { diff --git a/src/test/mir-opt/separate_const_switch.too_complex.SeparateConstSwitch.diff b/src/test/mir-opt/separate_const_switch.too_complex.SeparateConstSwitch.diff index ce32227ed653b..0b5b9a490c62b 100644 --- a/src/test/mir-opt/separate_const_switch.too_complex.SeparateConstSwitch.diff +++ b/src/test/mir-opt/separate_const_switch.too_complex.SeparateConstSwitch.diff @@ -29,8 +29,8 @@ bb0: { StorageLive(_2); // scope 0 at $DIR/separate_const_switch.rs:14:11: 19:6 - _3 = discriminant(_1); // scope 0 at $DIR/separate_const_switch.rs:16:13: 16:18 - switchInt(move _3) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/separate_const_switch.rs:16:13: 16:18 + _3 = discriminant(_1); // scope 0 at $DIR/separate_const_switch.rs:15:15: 15:16 + switchInt(move _3) -> [0_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/separate_const_switch.rs:15:9: 15:16 } bb1: { @@ -42,9 +42,9 @@ discriminant(_2) = 1; // scope 2 at $DIR/separate_const_switch.rs:17:23: 17:44 StorageDead(_7); // scope 2 at $DIR/separate_const_switch.rs:17:43: 17:44 StorageDead(_6); // scope 0 at $DIR/separate_const_switch.rs:17:43: 17:44 -- goto -> bb3; // scope 0 at $DIR/separate_const_switch.rs:15:9: 18:10 -+ _8 = discriminant(_2); // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 -+ switchInt(move _8) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 +- goto -> bb3; // scope 0 at $DIR/separate_const_switch.rs:17:43: 17:44 ++ _8 = discriminant(_2); // scope 0 at $DIR/separate_const_switch.rs:14:11: 19:6 ++ switchInt(move _8) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:14:5: 19:6 } bb2: { @@ -56,13 +56,13 @@ discriminant(_2) = 0; // scope 1 at $DIR/separate_const_switch.rs:16:22: 16:46 StorageDead(_5); // scope 1 at $DIR/separate_const_switch.rs:16:45: 16:46 StorageDead(_4); // scope 0 at $DIR/separate_const_switch.rs:16:45: 16:46 -- goto -> bb3; // scope 0 at $DIR/separate_const_switch.rs:15:9: 18:10 +- goto -> bb3; // scope 0 at $DIR/separate_const_switch.rs:16:45: 16:46 - } - - bb3: { - _8 = discriminant(_2); // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 -- switchInt(move _8) -> [0_isize: bb5, otherwise: bb4]; // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 -+ switchInt(move _8) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:20:9: 20:33 + _8 = discriminant(_2); // scope 0 at $DIR/separate_const_switch.rs:14:11: 19:6 +- switchInt(move _8) -> [0_isize: bb5, otherwise: bb4]; // scope 0 at $DIR/separate_const_switch.rs:14:5: 19:6 ++ switchInt(move _8) -> [0_isize: bb4, otherwise: bb3]; // scope 0 at $DIR/separate_const_switch.rs:14:5: 19:6 } - bb4: { @@ -71,8 +71,8 @@ _11 = ((_2 as Break).0: usize); // scope 0 at $DIR/separate_const_switch.rs:21:28: 21:29 discriminant(_0) = 0; // scope 4 at $DIR/separate_const_switch.rs:21:34: 21:38 StorageDead(_11); // scope 0 at $DIR/separate_const_switch.rs:21:37: 21:38 -- goto -> bb6; // scope 0 at $DIR/separate_const_switch.rs:14:5: 22:6 -+ goto -> bb5; // scope 0 at $DIR/separate_const_switch.rs:14:5: 22:6 +- goto -> bb6; // scope 0 at $DIR/separate_const_switch.rs:21:37: 21:38 ++ goto -> bb5; // scope 0 at $DIR/separate_const_switch.rs:21:37: 21:38 } - bb5: { @@ -85,8 +85,8 @@ discriminant(_0) = 1; // scope 3 at $DIR/separate_const_switch.rs:20:37: 20:44 StorageDead(_10); // scope 3 at $DIR/separate_const_switch.rs:20:43: 20:44 StorageDead(_9); // scope 0 at $DIR/separate_const_switch.rs:20:43: 20:44 -- goto -> bb6; // scope 0 at $DIR/separate_const_switch.rs:14:5: 22:6 -+ goto -> bb5; // scope 0 at $DIR/separate_const_switch.rs:14:5: 22:6 +- goto -> bb6; // scope 0 at $DIR/separate_const_switch.rs:20:43: 20:44 ++ goto -> bb5; // scope 0 at $DIR/separate_const_switch.rs:20:43: 20:44 } - bb6: { diff --git a/src/test/mir-opt/simple_match.match_bool.mir_map.0.32bit.mir b/src/test/mir-opt/simple_match.match_bool.mir_map.0.32bit.mir index 841cca7c381f7..c189c18d2d0e7 100644 --- a/src/test/mir-opt/simple_match.match_bool.mir_map.0.32bit.mir +++ b/src/test/mir-opt/simple_match.match_bool.mir_map.0.32bit.mir @@ -6,7 +6,7 @@ fn match_bool(_1: bool) -> usize { bb0: { FakeRead(ForMatchedPlace(None), _1); // scope 0 at $DIR/simple-match.rs:6:11: 6:12 - switchInt(_1) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/simple-match.rs:7:9: 7:13 + switchInt(_1) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/simple-match.rs:6:5: 6:12 } bb1: { @@ -15,12 +15,12 @@ fn match_bool(_1: bool) -> usize { bb2: { _0 = const 20_usize; // scope 0 at $DIR/simple-match.rs:8:14: 8:16 - goto -> bb4; // scope 0 at $DIR/simple-match.rs:6:5: 9:6 + goto -> bb4; // scope 0 at $DIR/simple-match.rs:8:14: 8:16 } bb3: { _0 = const 10_usize; // scope 0 at $DIR/simple-match.rs:7:17: 7:19 - goto -> bb4; // scope 0 at $DIR/simple-match.rs:6:5: 9:6 + goto -> bb4; // scope 0 at $DIR/simple-match.rs:7:17: 7:19 } bb4: { diff --git a/src/test/mir-opt/simple_match.match_bool.mir_map.0.64bit.mir b/src/test/mir-opt/simple_match.match_bool.mir_map.0.64bit.mir index 841cca7c381f7..c189c18d2d0e7 100644 --- a/src/test/mir-opt/simple_match.match_bool.mir_map.0.64bit.mir +++ b/src/test/mir-opt/simple_match.match_bool.mir_map.0.64bit.mir @@ -6,7 +6,7 @@ fn match_bool(_1: bool) -> usize { bb0: { FakeRead(ForMatchedPlace(None), _1); // scope 0 at $DIR/simple-match.rs:6:11: 6:12 - switchInt(_1) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/simple-match.rs:7:9: 7:13 + switchInt(_1) -> [false: bb2, otherwise: bb1]; // scope 0 at $DIR/simple-match.rs:6:5: 6:12 } bb1: { @@ -15,12 +15,12 @@ fn match_bool(_1: bool) -> usize { bb2: { _0 = const 20_usize; // scope 0 at $DIR/simple-match.rs:8:14: 8:16 - goto -> bb4; // scope 0 at $DIR/simple-match.rs:6:5: 9:6 + goto -> bb4; // scope 0 at $DIR/simple-match.rs:8:14: 8:16 } bb3: { _0 = const 10_usize; // scope 0 at $DIR/simple-match.rs:7:17: 7:19 - goto -> bb4; // scope 0 at $DIR/simple-match.rs:6:5: 9:6 + goto -> bb4; // scope 0 at $DIR/simple-match.rs:7:17: 7:19 } bb4: { diff --git a/src/test/mir-opt/simplify_arm.id.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_arm.id.SimplifyArmIdentity.diff index e390662307e04..ad47891294a08 100644 --- a/src/test/mir-opt/simplify_arm.id.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_arm.id.SimplifyArmIdentity.diff @@ -13,13 +13,13 @@ } bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 - switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 + _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:10:11: 10:12 + switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:10:5: 10:12 } bb1: { discriminant(_0) = 0; // scope 0 at $DIR/simplify-arm.rs:12:17: 12:21 - goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 + goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:12:17: 12:21 } bb2: { @@ -36,7 +36,7 @@ - StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:11:26: 11:27 - StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:11:26: 11:27 + _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27 - goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 + goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:11:26: 11:27 } bb4: { diff --git a/src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff b/src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff index 81a0e6ba0b4ee..52c036a77007c 100644 --- a/src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify_arm.id.SimplifyBranchSame.diff @@ -12,14 +12,14 @@ } bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 -- switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 -+ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:11:9: 11:16 + _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:10:11: 10:12 +- switchInt(move _2) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:10:5: 10:12 ++ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:10:5: 10:12 } bb1: { - discriminant(_0) = 0; // scope 0 at $DIR/simplify-arm.rs:12:17: 12:21 -- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 +- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:12:17: 12:21 - } - - bb2: { @@ -28,8 +28,8 @@ - - bb3: { _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:11:20: 11:27 -- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 -+ goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:10:5: 13:6 +- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:11:26: 11:27 ++ goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:11:26: 11:27 } - bb4: { diff --git a/src/test/mir-opt/simplify_arm.id_result.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_arm.id_result.SimplifyArmIdentity.diff index 40c18fb7282ec..b24bdea9b715d 100644 --- a/src/test/mir-opt/simplify_arm.id_result.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_arm.id_result.SimplifyArmIdentity.diff @@ -19,8 +19,8 @@ } bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 - switchInt(move _2) -> [0_isize: bb3, 1_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 + _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:17:11: 17:12 + switchInt(move _2) -> [0_isize: bb3, 1_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:17:5: 17:12 } bb1: { @@ -33,7 +33,7 @@ - StorageDead(_6); // scope 2 at $DIR/simplify-arm.rs:19:24: 19:25 - StorageDead(_5); // scope 0 at $DIR/simplify-arm.rs:19:24: 19:25 + _0 = move _1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25 - goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 + goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:19:24: 19:25 } bb2: { @@ -50,7 +50,7 @@ - StorageDead(_4); // scope 1 at $DIR/simplify-arm.rs:18:22: 18:23 - StorageDead(_3); // scope 0 at $DIR/simplify-arm.rs:18:22: 18:23 + _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23 - goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 + goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:18:22: 18:23 } bb4: { diff --git a/src/test/mir-opt/simplify_arm.id_result.SimplifyBranchSame.diff b/src/test/mir-opt/simplify_arm.id_result.SimplifyBranchSame.diff index 596dbabead0bf..4d6a4edb08ae5 100644 --- a/src/test/mir-opt/simplify_arm.id_result.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify_arm.id_result.SimplifyBranchSame.diff @@ -17,14 +17,14 @@ } bb0: { - _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 -- switchInt(move _2) -> [0_isize: bb3, 1_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 -+ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:18:9: 18:14 + _2 = discriminant(_1); // scope 0 at $DIR/simplify-arm.rs:17:11: 17:12 +- switchInt(move _2) -> [0_isize: bb3, 1_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:17:5: 17:12 ++ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:17:5: 17:12 } bb1: { - _0 = move _1; // scope 2 at $DIR/simplify-arm.rs:19:19: 19:25 -- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 +- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:19:24: 19:25 - } - - bb2: { @@ -33,8 +33,8 @@ - - bb3: { _0 = move _1; // scope 1 at $DIR/simplify-arm.rs:18:18: 18:23 -- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 -+ goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:17:5: 20:6 +- goto -> bb4; // scope 0 at $DIR/simplify-arm.rs:18:22: 18:23 ++ goto -> bb2; // scope 0 at $DIR/simplify-arm.rs:18:22: 18:23 } - bb4: { diff --git a/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff index a3bad4f0c623d..272a6756f39f2 100644 --- a/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_arm.id_try.SimplifyArmIdentity.diff @@ -45,8 +45,8 @@ _4 = _1; // scope 0 at $DIR/simplify-arm.rs:36:31: 36:32 _3 = move _4; // scope 4 at $DIR/simplify-arm.rs:36:19: 36:33 StorageDead(_4); // scope 0 at $DIR/simplify-arm.rs:36:32: 36:33 - _5 = discriminant(_3); // scope 0 at $DIR/simplify-arm.rs:37:9: 37:15 - switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:37:9: 37:15 + _5 = discriminant(_3); // scope 0 at $DIR/simplify-arm.rs:36:19: 36:33 + switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:36:13: 36:33 } bb1: { diff --git a/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff b/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff index b6b7511b3f597..651a37f5a9722 100644 --- a/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff +++ b/src/test/mir-opt/simplify_arm.id_try.SimplifyBranchSame.diff @@ -40,9 +40,9 @@ _4 = _1; // scope 0 at $DIR/simplify-arm.rs:36:31: 36:32 _3 = move _4; // scope 4 at $DIR/simplify-arm.rs:36:19: 36:33 StorageDead(_4); // scope 0 at $DIR/simplify-arm.rs:36:32: 36:33 - _5 = discriminant(_3); // scope 0 at $DIR/simplify-arm.rs:37:9: 37:15 -- switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:37:9: 37:15 -+ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:37:9: 37:15 + _5 = discriminant(_3); // scope 0 at $DIR/simplify-arm.rs:36:19: 36:33 +- switchInt(move _5) -> [0_isize: bb1, 1_isize: bb3, otherwise: bb2]; // scope 0 at $DIR/simplify-arm.rs:36:13: 36:33 ++ goto -> bb1; // scope 0 at $DIR/simplify-arm.rs:36:13: 36:33 } bb1: { diff --git a/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.32bit.diff b/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.32bit.diff index 7495b0d407d2c..512d9fe172b9f 100644 --- a/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.32bit.diff +++ b/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.32bit.diff @@ -22,14 +22,14 @@ ((_1 as Foo).0: u8) = const 0_u8; // scope 0 at $DIR/simplify-arm-identity.rs:18:18: 18:29 discriminant(_1) = 0; // scope 0 at $DIR/simplify-arm-identity.rs:18:18: 18:29 StorageLive(_2); // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 - _3 = const 0_isize; // scope 1 at $DIR/simplify-arm-identity.rs:20:9: 20:20 - goto -> bb3; // scope 1 at $DIR/simplify-arm-identity.rs:20:9: 20:20 + _3 = const 0_isize; // scope 1 at $DIR/simplify-arm-identity.rs:19:24: 19:25 + goto -> bb3; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 19:25 } bb1: { ((_2 as Foo).0: u8) = const 0_u8; // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 discriminant(_2) = 0; // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 - goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 + goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 } bb2: { @@ -45,7 +45,7 @@ discriminant(_2) = 0; // scope 3 at $DIR/simplify-arm-identity.rs:20:24: 20:35 StorageDead(_5); // scope 3 at $DIR/simplify-arm-identity.rs:20:34: 20:35 StorageDead(_4); // scope 1 at $DIR/simplify-arm-identity.rs:20:34: 20:35 - goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 + goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:20:34: 20:35 } bb4: { diff --git a/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.64bit.diff b/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.64bit.diff index 7495b0d407d2c..512d9fe172b9f 100644 --- a/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.64bit.diff +++ b/src/test/mir-opt/simplify_arm_identity.main.SimplifyArmIdentity.64bit.diff @@ -22,14 +22,14 @@ ((_1 as Foo).0: u8) = const 0_u8; // scope 0 at $DIR/simplify-arm-identity.rs:18:18: 18:29 discriminant(_1) = 0; // scope 0 at $DIR/simplify-arm-identity.rs:18:18: 18:29 StorageLive(_2); // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 - _3 = const 0_isize; // scope 1 at $DIR/simplify-arm-identity.rs:20:9: 20:20 - goto -> bb3; // scope 1 at $DIR/simplify-arm-identity.rs:20:9: 20:20 + _3 = const 0_isize; // scope 1 at $DIR/simplify-arm-identity.rs:19:24: 19:25 + goto -> bb3; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 19:25 } bb1: { ((_2 as Foo).0: u8) = const 0_u8; // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 discriminant(_2) = 0; // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 - goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 + goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:21:21: 21:32 } bb2: { @@ -45,7 +45,7 @@ discriminant(_2) = 0; // scope 3 at $DIR/simplify-arm-identity.rs:20:24: 20:35 StorageDead(_5); // scope 3 at $DIR/simplify-arm-identity.rs:20:34: 20:35 StorageDead(_4); // scope 1 at $DIR/simplify-arm-identity.rs:20:34: 20:35 - goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:19:18: 22:6 + goto -> bb4; // scope 1 at $DIR/simplify-arm-identity.rs:20:34: 20:35 } bb4: { diff --git a/src/test/mir-opt/simplify_locals_fixedpoint.foo.SimplifyLocals.diff b/src/test/mir-opt/simplify_locals_fixedpoint.foo.SimplifyLocals.diff index 41a6fe30412d0..381f4056cc87d 100644 --- a/src/test/mir-opt/simplify_locals_fixedpoint.foo.SimplifyLocals.diff +++ b/src/test/mir-opt/simplify_locals_fixedpoint.foo.SimplifyLocals.diff @@ -25,13 +25,13 @@ (_1.1: std::option::Option) = move _3; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:30: 4:69 StorageDead(_3); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:68: 4:69 StorageDead(_2); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:68: 4:69 - _5 = discriminant((_1.0: std::option::Option)); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:13: 4:20 - switchInt(move _5) -> [1_isize: bb1, otherwise: bb3]; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:13: 4:20 + _5 = discriminant((_1.0: std::option::Option)); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:12: 4:27 + switchInt(move _5) -> [1_isize: bb1, otherwise: bb3]; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:12: 4:27 } bb1: { - _4 = discriminant((_1.1: std::option::Option)); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:22: 4:26 - switchInt(move _4) -> [0_isize: bb2, otherwise: bb3]; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:22: 4:26 + _4 = discriminant((_1.1: std::option::Option)); // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:12: 4:27 + switchInt(move _4) -> [0_isize: bb2, otherwise: bb3]; // scope 0 at $DIR/simplify-locals-fixedpoint.rs:4:12: 4:27 } bb2: { diff --git a/src/test/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals.32bit.diff b/src/test/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals.32bit.diff index 760fb747f7229..e139eedf3a0d6 100644 --- a/src/test/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals.32bit.diff +++ b/src/test/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals.32bit.diff @@ -15,9 +15,9 @@ } bb0: { -- _5 = const false; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13 -- _5 = const true; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13 -- _2 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13 +- _5 = const false; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:11: 4:12 +- _5 = const true; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:11: 4:12 +- _2 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:11: 4:12 _0 = move _1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:20: 6:27 - _6 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:1: 8:2 return; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:2: 8:2 diff --git a/src/test/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals.64bit.diff b/src/test/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals.64bit.diff index 760fb747f7229..e139eedf3a0d6 100644 --- a/src/test/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals.64bit.diff +++ b/src/test/mir-opt/simplify_locals_removes_unused_discriminant_reads.map.SimplifyLocals.64bit.diff @@ -15,9 +15,9 @@ } bb0: { -- _5 = const false; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13 -- _5 = const true; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13 -- _2 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:5:9: 5:13 +- _5 = const false; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:11: 4:12 +- _5 = const true; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:11: 4:12 +- _2 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:4:11: 4:12 _0 = move _1; // scope 1 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:6:20: 6:27 - _6 = discriminant(_1); // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:1: 8:2 return; // scope 0 at $DIR/simplify-locals-removes-unused-discriminant-reads.rs:8:2: 8:2 diff --git a/src/test/mir-opt/simplify_match.main.ConstProp.diff b/src/test/mir-opt/simplify_match.main.ConstProp.diff index 3f5efcffc1995..1c8d043a6030c 100644 --- a/src/test/mir-opt/simplify_match.main.ConstProp.diff +++ b/src/test/mir-opt/simplify_match.main.ConstProp.diff @@ -16,13 +16,13 @@ - _1 = _2; // scope 1 at $DIR/simplify_match.rs:6:28: 6:29 + _1 = const false; // scope 1 at $DIR/simplify_match.rs:6:28: 6:29 StorageDead(_2); // scope 0 at $DIR/simplify_match.rs:6:30: 6:31 -- switchInt(_1) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_match.rs:7:9: 7:13 -+ switchInt(const false) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_match.rs:7:9: 7:13 +- switchInt(_1) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_match.rs:6:5: 6:31 ++ switchInt(const false) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_match.rs:6:5: 6:31 } bb1: { nop; // scope 0 at $DIR/simplify_match.rs:8:18: 8:20 - goto -> bb3; // scope 0 at $DIR/simplify_match.rs:6:5: 9:6 + goto -> bb3; // scope 0 at $DIR/simplify_match.rs:8:18: 8:20 } bb2: { diff --git a/src/test/mir-opt/simplify_try.try_identity.DestinationPropagation.diff b/src/test/mir-opt/simplify_try.try_identity.DestinationPropagation.diff index e09b8cb39bd51..a6ea8cacfd2c5 100644 --- a/src/test/mir-opt/simplify_try.try_identity.DestinationPropagation.diff +++ b/src/test/mir-opt/simplify_try.try_identity.DestinationPropagation.diff @@ -41,14 +41,14 @@ - _4 = _1; // scope 0 at $DIR/simplify_try.rs:21:31: 21:32 - _3 = move _4; // scope 4 at $DIR/simplify_try.rs:21:19: 21:33 - StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:21:32: 21:33 -- _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:22:9: 22:15 +- _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:21:19: 21:33 + nop; // scope 0 at $DIR/simplify_try.rs:21:19: 21:33 + nop; // scope 0 at $DIR/simplify_try.rs:21:31: 21:32 + _0 = _1; // scope 0 at $DIR/simplify_try.rs:21:31: 21:32 + nop; // scope 4 at $DIR/simplify_try.rs:21:19: 21:33 + nop; // scope 0 at $DIR/simplify_try.rs:21:32: 21:33 -+ _5 = discriminant(_0); // scope 0 at $DIR/simplify_try.rs:22:9: 22:15 - goto -> bb1; // scope 0 at $DIR/simplify_try.rs:22:9: 22:15 ++ _5 = discriminant(_0); // scope 0 at $DIR/simplify_try.rs:21:19: 21:33 + goto -> bb1; // scope 0 at $DIR/simplify_try.rs:21:13: 21:33 } bb1: { diff --git a/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff b/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff index 488ad33f80a2d..bef57548005ce 100644 --- a/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/simplify_try.try_identity.SimplifyArmIdentity.diff @@ -45,8 +45,8 @@ _4 = _1; // scope 0 at $DIR/simplify_try.rs:21:31: 21:32 _3 = move _4; // scope 4 at $DIR/simplify_try.rs:21:19: 21:33 StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:21:32: 21:33 - _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:22:9: 22:15 - switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:22:9: 22:15 + _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:21:19: 21:33 + switchInt(move _5) -> [0_isize: bb1, otherwise: bb2]; // scope 0 at $DIR/simplify_try.rs:21:13: 21:33 } bb1: { diff --git a/src/test/mir-opt/simplify_try.try_identity.SimplifyBranchSame.after.mir b/src/test/mir-opt/simplify_try.try_identity.SimplifyBranchSame.after.mir index 5d829f859e9d9..aa19c479881aa 100644 --- a/src/test/mir-opt/simplify_try.try_identity.SimplifyBranchSame.after.mir +++ b/src/test/mir-opt/simplify_try.try_identity.SimplifyBranchSame.after.mir @@ -39,8 +39,8 @@ fn try_identity(_1: Result) -> Result { _4 = _1; // scope 0 at $DIR/simplify_try.rs:21:31: 21:32 _3 = move _4; // scope 4 at $DIR/simplify_try.rs:21:19: 21:33 StorageDead(_4); // scope 0 at $DIR/simplify_try.rs:21:32: 21:33 - _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:22:9: 22:15 - goto -> bb1; // scope 0 at $DIR/simplify_try.rs:22:9: 22:15 + _5 = discriminant(_3); // scope 0 at $DIR/simplify_try.rs:21:19: 21:33 + goto -> bb1; // scope 0 at $DIR/simplify_try.rs:21:13: 21:33 } bb1: { diff --git a/src/test/mir-opt/uninhabited_enum_branching.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir b/src/test/mir-opt/uninhabited_enum_branching.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir index 17dcc99bc0c6f..bdcb9357308ec 100644 --- a/src/test/mir-opt/uninhabited_enum_branching.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir +++ b/src/test/mir-opt/uninhabited_enum_branching.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir @@ -16,7 +16,7 @@ fn main() -> () { StorageLive(_1); // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 24:6 StorageLive(_2); // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 discriminant(_2) = 2; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 - _3 = discriminant(_2); // scope 0 at $DIR/uninhabited_enum_branching.rs:21:9: 21:20 + _3 = discriminant(_2); // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 StorageLive(_5); // scope 0 at $DIR/uninhabited_enum_branching.rs:23:21: 23:24 _5 = const "C"; // scope 0 at $DIR/uninhabited_enum_branching.rs:23:21: 23:24 // ty::Const @@ -32,8 +32,8 @@ fn main() -> () { StorageLive(_6); // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 StorageLive(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 discriminant(_7) = 0; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 - _8 = discriminant(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 - switchInt(move _8) -> [4_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 + _8 = discriminant(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 + switchInt(move _8) -> [4_isize: bb2, otherwise: bb1]; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 26:19 } bb1: { @@ -47,7 +47,7 @@ fn main() -> () { // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [69], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _6 = &(*_9); // scope 0 at $DIR/uninhabited_enum_branching.rs:28:21: 28:24 StorageDead(_9); // scope 0 at $DIR/uninhabited_enum_branching.rs:28:23: 28:24 - goto -> bb3; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 + goto -> bb3; // scope 0 at $DIR/uninhabited_enum_branching.rs:28:23: 28:24 } bb2: { @@ -58,7 +58,7 @@ fn main() -> () { // mir::Constant // + span: $DIR/uninhabited_enum_branching.rs:27:21: 27:24 // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [68], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } - goto -> bb3; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 + goto -> bb3; // scope 0 at $DIR/uninhabited_enum_branching.rs:27:21: 27:24 } bb3: { diff --git a/src/test/mir-opt/uninhabited_enum_branching.main.UninhabitedEnumBranching.diff b/src/test/mir-opt/uninhabited_enum_branching.main.UninhabitedEnumBranching.diff index 9ae7a9d7384c1..d8410caa7cd56 100644 --- a/src/test/mir-opt/uninhabited_enum_branching.main.UninhabitedEnumBranching.diff +++ b/src/test/mir-opt/uninhabited_enum_branching.main.UninhabitedEnumBranching.diff @@ -17,9 +17,9 @@ StorageLive(_1); // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 24:6 StorageLive(_2); // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 discriminant(_2) = 2; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 - _3 = discriminant(_2); // scope 0 at $DIR/uninhabited_enum_branching.rs:21:9: 21:20 -- switchInt(move _3) -> [0_isize: bb2, 1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/uninhabited_enum_branching.rs:21:9: 21:20 -+ switchInt(move _3) -> bb1; // scope 0 at $DIR/uninhabited_enum_branching.rs:21:9: 21:20 + _3 = discriminant(_2); // scope 0 at $DIR/uninhabited_enum_branching.rs:20:11: 20:19 +- switchInt(move _3) -> [0_isize: bb2, 1_isize: bb3, otherwise: bb1]; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 20:19 ++ switchInt(move _3) -> bb1; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 20:19 } bb1: { @@ -33,7 +33,7 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [67], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _1 = &(*_5); // scope 0 at $DIR/uninhabited_enum_branching.rs:23:21: 23:24 StorageDead(_5); // scope 0 at $DIR/uninhabited_enum_branching.rs:23:23: 23:24 - goto -> bb4; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 24:6 + goto -> bb4; // scope 0 at $DIR/uninhabited_enum_branching.rs:23:23: 23:24 } bb2: { @@ -44,7 +44,7 @@ // mir::Constant // + span: $DIR/uninhabited_enum_branching.rs:21:24: 21:34 // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [65, 40, 69, 109, 112, 116, 121, 41], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [255], len: Size { raw: 8 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 8 }) } - goto -> bb4; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 24:6 + goto -> bb4; // scope 0 at $DIR/uninhabited_enum_branching.rs:21:24: 21:34 } bb3: { @@ -58,7 +58,7 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [66, 40, 69, 109, 112, 116, 121, 41], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [255], len: Size { raw: 8 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 8 }) } _1 = &(*_4); // scope 0 at $DIR/uninhabited_enum_branching.rs:22:24: 22:34 StorageDead(_4); // scope 0 at $DIR/uninhabited_enum_branching.rs:22:33: 22:34 - goto -> bb4; // scope 0 at $DIR/uninhabited_enum_branching.rs:20:5: 24:6 + goto -> bb4; // scope 0 at $DIR/uninhabited_enum_branching.rs:22:33: 22:34 } bb4: { @@ -67,8 +67,8 @@ StorageLive(_6); // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 StorageLive(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 discriminant(_7) = 0; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 - _8 = discriminant(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 - switchInt(move _8) -> [4_isize: bb6, otherwise: bb5]; // scope 0 at $DIR/uninhabited_enum_branching.rs:27:9: 27:17 + _8 = discriminant(_7); // scope 0 at $DIR/uninhabited_enum_branching.rs:26:11: 26:19 + switchInt(move _8) -> [4_isize: bb6, otherwise: bb5]; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 26:19 } bb5: { @@ -82,7 +82,7 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [69], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _6 = &(*_9); // scope 0 at $DIR/uninhabited_enum_branching.rs:28:21: 28:24 StorageDead(_9); // scope 0 at $DIR/uninhabited_enum_branching.rs:28:23: 28:24 - goto -> bb7; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 + goto -> bb7; // scope 0 at $DIR/uninhabited_enum_branching.rs:28:23: 28:24 } bb6: { @@ -93,7 +93,7 @@ // mir::Constant // + span: $DIR/uninhabited_enum_branching.rs:27:21: 27:24 // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [68], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } - goto -> bb7; // scope 0 at $DIR/uninhabited_enum_branching.rs:26:5: 29:6 + goto -> bb7; // scope 0 at $DIR/uninhabited_enum_branching.rs:27:21: 27:24 } bb7: { diff --git a/src/test/mir-opt/uninhabited_enum_branching2.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir b/src/test/mir-opt/uninhabited_enum_branching2.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir index 373be9f174b2d..e20faa5247499 100644 --- a/src/test/mir-opt/uninhabited_enum_branching2.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir +++ b/src/test/mir-opt/uninhabited_enum_branching2.main.SimplifyCfg-after-uninhabited-enum-branching.after.mir @@ -29,8 +29,8 @@ fn main() -> () { StorageLive(_3); // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 26:6 StorageLive(_4); // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:11: 21:22 _4 = &(_1.1: Test1); // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:11: 21:22 - _5 = discriminant((*_4)); // scope 1 at $DIR/uninhabited_enum_branching2.rs:22:9: 22:20 - switchInt(move _5) -> [2_isize: bb2, otherwise: bb1]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:22:9: 22:20 + _5 = discriminant((*_4)); // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:11: 21:22 + switchInt(move _5) -> [2_isize: bb2, otherwise: bb1]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 21:22 } bb1: { @@ -44,7 +44,7 @@ fn main() -> () { // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [68], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _3 = &(*_8); // scope 1 at $DIR/uninhabited_enum_branching2.rs:25:21: 25:24 StorageDead(_8); // scope 1 at $DIR/uninhabited_enum_branching2.rs:25:23: 25:24 - goto -> bb3; // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 26:6 + goto -> bb3; // scope 1 at $DIR/uninhabited_enum_branching2.rs:25:23: 25:24 } bb2: { @@ -58,15 +58,15 @@ fn main() -> () { // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [67], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _3 = &(*_7); // scope 1 at $DIR/uninhabited_enum_branching2.rs:24:21: 24:24 StorageDead(_7); // scope 1 at $DIR/uninhabited_enum_branching2.rs:24:23: 24:24 - goto -> bb3; // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 26:6 + goto -> bb3; // scope 1 at $DIR/uninhabited_enum_branching2.rs:24:23: 24:24 } bb3: { StorageDead(_4); // scope 1 at $DIR/uninhabited_enum_branching2.rs:26:6: 26:7 StorageDead(_3); // scope 1 at $DIR/uninhabited_enum_branching2.rs:26:6: 26:7 StorageLive(_9); // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 33:6 - _10 = discriminant((_1.1: Test1)); // scope 1 at $DIR/uninhabited_enum_branching2.rs:29:9: 29:20 - switchInt(move _10) -> [2_isize: bb5, otherwise: bb4]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:29:9: 29:20 + _10 = discriminant((_1.1: Test1)); // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:11: 28:21 + switchInt(move _10) -> [2_isize: bb5, otherwise: bb4]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 28:21 } bb4: { @@ -80,7 +80,7 @@ fn main() -> () { // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [68], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _9 = &(*_13); // scope 1 at $DIR/uninhabited_enum_branching2.rs:32:21: 32:24 StorageDead(_13); // scope 1 at $DIR/uninhabited_enum_branching2.rs:32:23: 32:24 - goto -> bb6; // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 33:6 + goto -> bb6; // scope 1 at $DIR/uninhabited_enum_branching2.rs:32:23: 32:24 } bb5: { @@ -94,7 +94,7 @@ fn main() -> () { // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [67], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _9 = &(*_12); // scope 1 at $DIR/uninhabited_enum_branching2.rs:31:21: 31:24 StorageDead(_12); // scope 1 at $DIR/uninhabited_enum_branching2.rs:31:23: 31:24 - goto -> bb6; // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 33:6 + goto -> bb6; // scope 1 at $DIR/uninhabited_enum_branching2.rs:31:23: 31:24 } bb6: { diff --git a/src/test/mir-opt/uninhabited_enum_branching2.main.UninhabitedEnumBranching.diff b/src/test/mir-opt/uninhabited_enum_branching2.main.UninhabitedEnumBranching.diff index f9488bae4c836..77507ef1ee02d 100644 --- a/src/test/mir-opt/uninhabited_enum_branching2.main.UninhabitedEnumBranching.diff +++ b/src/test/mir-opt/uninhabited_enum_branching2.main.UninhabitedEnumBranching.diff @@ -30,9 +30,9 @@ StorageLive(_3); // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 26:6 StorageLive(_4); // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:11: 21:22 _4 = &(_1.1: Test1); // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:11: 21:22 - _5 = discriminant((*_4)); // scope 1 at $DIR/uninhabited_enum_branching2.rs:22:9: 22:20 -- switchInt(move _5) -> [0_isize: bb2, 1_isize: bb3, 2_isize: bb4, otherwise: bb1]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:22:9: 22:20 -+ switchInt(move _5) -> [2_isize: bb4, otherwise: bb1]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:22:9: 22:20 + _5 = discriminant((*_4)); // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:11: 21:22 +- switchInt(move _5) -> [0_isize: bb2, 1_isize: bb3, 2_isize: bb4, otherwise: bb1]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 21:22 ++ switchInt(move _5) -> [2_isize: bb4, otherwise: bb1]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 21:22 } bb1: { @@ -46,7 +46,7 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [68], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _3 = &(*_8); // scope 1 at $DIR/uninhabited_enum_branching2.rs:25:21: 25:24 StorageDead(_8); // scope 1 at $DIR/uninhabited_enum_branching2.rs:25:23: 25:24 - goto -> bb5; // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 26:6 + goto -> bb5; // scope 1 at $DIR/uninhabited_enum_branching2.rs:25:23: 25:24 } bb2: { @@ -57,7 +57,7 @@ // mir::Constant // + span: $DIR/uninhabited_enum_branching2.rs:22:24: 22:34 // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [65, 40, 69, 109, 112, 116, 121, 41], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [255], len: Size { raw: 8 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 8 }) } - goto -> bb5; // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 26:6 + goto -> bb5; // scope 1 at $DIR/uninhabited_enum_branching2.rs:22:24: 22:34 } bb3: { @@ -71,7 +71,7 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [66, 40, 69, 109, 112, 116, 121, 41], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [255], len: Size { raw: 8 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 8 }) } _3 = &(*_6); // scope 1 at $DIR/uninhabited_enum_branching2.rs:23:24: 23:34 StorageDead(_6); // scope 1 at $DIR/uninhabited_enum_branching2.rs:23:33: 23:34 - goto -> bb5; // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 26:6 + goto -> bb5; // scope 1 at $DIR/uninhabited_enum_branching2.rs:23:33: 23:34 } bb4: { @@ -85,16 +85,16 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [67], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _3 = &(*_7); // scope 1 at $DIR/uninhabited_enum_branching2.rs:24:21: 24:24 StorageDead(_7); // scope 1 at $DIR/uninhabited_enum_branching2.rs:24:23: 24:24 - goto -> bb5; // scope 1 at $DIR/uninhabited_enum_branching2.rs:21:5: 26:6 + goto -> bb5; // scope 1 at $DIR/uninhabited_enum_branching2.rs:24:23: 24:24 } bb5: { StorageDead(_4); // scope 1 at $DIR/uninhabited_enum_branching2.rs:26:6: 26:7 StorageDead(_3); // scope 1 at $DIR/uninhabited_enum_branching2.rs:26:6: 26:7 StorageLive(_9); // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 33:6 - _10 = discriminant((_1.1: Test1)); // scope 1 at $DIR/uninhabited_enum_branching2.rs:29:9: 29:20 -- switchInt(move _10) -> [0_isize: bb7, 1_isize: bb8, 2_isize: bb9, otherwise: bb6]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:29:9: 29:20 -+ switchInt(move _10) -> [2_isize: bb9, otherwise: bb6]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:29:9: 29:20 + _10 = discriminant((_1.1: Test1)); // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:11: 28:21 +- switchInt(move _10) -> [0_isize: bb7, 1_isize: bb8, 2_isize: bb9, otherwise: bb6]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 28:21 ++ switchInt(move _10) -> [2_isize: bb9, otherwise: bb6]; // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 28:21 } bb6: { @@ -108,7 +108,7 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [68], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _9 = &(*_13); // scope 1 at $DIR/uninhabited_enum_branching2.rs:32:21: 32:24 StorageDead(_13); // scope 1 at $DIR/uninhabited_enum_branching2.rs:32:23: 32:24 - goto -> bb10; // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 33:6 + goto -> bb10; // scope 1 at $DIR/uninhabited_enum_branching2.rs:32:23: 32:24 } bb7: { @@ -119,7 +119,7 @@ // mir::Constant // + span: $DIR/uninhabited_enum_branching2.rs:29:24: 29:34 // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [65, 40, 69, 109, 112, 116, 121, 41], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [255], len: Size { raw: 8 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 8 }) } - goto -> bb10; // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 33:6 + goto -> bb10; // scope 1 at $DIR/uninhabited_enum_branching2.rs:29:24: 29:34 } bb8: { @@ -133,7 +133,7 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [66, 40, 69, 109, 112, 116, 121, 41], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [255], len: Size { raw: 8 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 8 }) } _9 = &(*_11); // scope 1 at $DIR/uninhabited_enum_branching2.rs:30:24: 30:34 StorageDead(_11); // scope 1 at $DIR/uninhabited_enum_branching2.rs:30:33: 30:34 - goto -> bb10; // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 33:6 + goto -> bb10; // scope 1 at $DIR/uninhabited_enum_branching2.rs:30:33: 30:34 } bb9: { @@ -147,7 +147,7 @@ // + literal: Const { ty: &str, val: Value(Slice { data: Allocation { bytes: [67], relocations: Relocations(SortedMap { data: [] }), init_mask: InitMask { blocks: [1], len: Size { raw: 1 } }, align: Align { pow2: 0 }, mutability: Not, extra: () }, start: 0, end: 1 }) } _9 = &(*_12); // scope 1 at $DIR/uninhabited_enum_branching2.rs:31:21: 31:24 StorageDead(_12); // scope 1 at $DIR/uninhabited_enum_branching2.rs:31:23: 31:24 - goto -> bb10; // scope 1 at $DIR/uninhabited_enum_branching2.rs:28:5: 33:6 + goto -> bb10; // scope 1 at $DIR/uninhabited_enum_branching2.rs:31:23: 31:24 } bb10: { diff --git a/src/test/mir-opt/while_let_loops.change_loop_body.ConstProp.32bit.diff b/src/test/mir-opt/while_let_loops.change_loop_body.ConstProp.32bit.diff index 91927dc7f1676..c5a100fe3e500 100644 --- a/src/test/mir-opt/while_let_loops.change_loop_body.ConstProp.32bit.diff +++ b/src/test/mir-opt/while_let_loops.change_loop_body.ConstProp.32bit.diff @@ -34,7 +34,7 @@ } bb2: { - switchInt(((_3 as Some).0: u32)) -> [0_u32: bb3, otherwise: bb1]; // scope 1 at $DIR/while_let_loops.rs:7:20: 7:24 + switchInt(((_3 as Some).0: u32)) -> [0_u32: bb3, otherwise: bb1]; // scope 1 at $DIR/while_let_loops.rs:7:15: 7:25 } bb3: { diff --git a/src/test/mir-opt/while_let_loops.change_loop_body.ConstProp.64bit.diff b/src/test/mir-opt/while_let_loops.change_loop_body.ConstProp.64bit.diff index 91927dc7f1676..c5a100fe3e500 100644 --- a/src/test/mir-opt/while_let_loops.change_loop_body.ConstProp.64bit.diff +++ b/src/test/mir-opt/while_let_loops.change_loop_body.ConstProp.64bit.diff @@ -34,7 +34,7 @@ } bb2: { - switchInt(((_3 as Some).0: u32)) -> [0_u32: bb3, otherwise: bb1]; // scope 1 at $DIR/while_let_loops.rs:7:20: 7:24 + switchInt(((_3 as Some).0: u32)) -> [0_u32: bb3, otherwise: bb1]; // scope 1 at $DIR/while_let_loops.rs:7:15: 7:25 } bb3: { diff --git a/src/test/ui/borrowck/borrowck-anon-fields-variant.rs b/src/test/ui/borrowck/borrowck-anon-fields-variant.rs index cecc278e1931c..6e63de9136cb1 100644 --- a/src/test/ui/borrowck/borrowck-anon-fields-variant.rs +++ b/src/test/ui/borrowck/borrowck-anon-fields-variant.rs @@ -14,8 +14,8 @@ fn distinct_variant() { // also used for the discriminant of `Foo`, which it would be if `a` was a // reference. let b = match y { - Foo::Y(_, ref mut b) => b, //~^ ERROR cannot use `y` + Foo::Y(_, ref mut b) => b, Foo::X => panic!() }; @@ -32,8 +32,9 @@ fn same_variant() { }; let b = match y { - Foo::Y(ref mut b, _) => b, //~ ERROR cannot use `y` - //~| ERROR cannot borrow `y.0` as mutable + //~^ ERROR cannot use `y` + Foo::Y(ref mut b, _) => b, + //~^ ERROR cannot borrow `y.0` as mutable Foo::X => panic!() }; diff --git a/src/test/ui/borrowck/borrowck-anon-fields-variant.stderr b/src/test/ui/borrowck/borrowck-anon-fields-variant.stderr index 2caeed1bd44ea..98f6f00a7d48b 100644 --- a/src/test/ui/borrowck/borrowck-anon-fields-variant.stderr +++ b/src/test/ui/borrowck/borrowck-anon-fields-variant.stderr @@ -1,29 +1,29 @@ error[E0503]: cannot use `y` because it was mutably borrowed - --> $DIR/borrowck-anon-fields-variant.rs:17:7 + --> $DIR/borrowck-anon-fields-variant.rs:16:19 | LL | Foo::Y(ref mut a, _) => a, | --------- borrow of `y.0` occurs here ... -LL | Foo::Y(_, ref mut b) => b, - | ^^^^^^^^^^^^^^^^^^^^ use of borrowed `y.0` +LL | let b = match y { + | ^ use of borrowed `y.0` ... LL | *a += 1; | ------- borrow later used here error[E0503]: cannot use `y` because it was mutably borrowed - --> $DIR/borrowck-anon-fields-variant.rs:35:7 + --> $DIR/borrowck-anon-fields-variant.rs:34:19 | LL | Foo::Y(ref mut a, _) => a, | --------- borrow of `y.0` occurs here ... -LL | Foo::Y(ref mut b, _) => b, - | ^^^^^^^^^^^^^^^^^^^^ use of borrowed `y.0` +LL | let b = match y { + | ^ use of borrowed `y.0` ... LL | *a += 1; | ------- borrow later used here error[E0499]: cannot borrow `y.0` as mutable more than once at a time - --> $DIR/borrowck-anon-fields-variant.rs:35:14 + --> $DIR/borrowck-anon-fields-variant.rs:36:14 | LL | Foo::Y(ref mut a, _) => a, | --------- first mutable borrow occurs here diff --git a/src/test/ui/borrowck/borrowck-describe-lvalue.rs b/src/test/ui/borrowck/borrowck-describe-lvalue.rs index 0e6c0635adb45..cdcff69d6e529 100644 --- a/src/test/ui/borrowck/borrowck-describe-lvalue.rs +++ b/src/test/ui/borrowck/borrowck-describe-lvalue.rs @@ -164,9 +164,9 @@ fn main() { let mut e = E::A(3); let x = &mut e; match e { + //~^ ERROR cannot use `e` because it was mutably borrowed E::A(ref ax) => //~^ ERROR cannot borrow `e.0` as immutable because it is also borrowed as mutable - //~| ERROR cannot use `e` because it was mutably borrowed println!("e.ax: {:?}", ax), E::B { x: ref bx } => //~^ ERROR cannot borrow `e.x` as immutable because it is also borrowed as mutable diff --git a/src/test/ui/borrowck/borrowck-describe-lvalue.stderr b/src/test/ui/borrowck/borrowck-describe-lvalue.stderr index 0f2ebbcbf3cdb..4b9c5a2a98ff6 100644 --- a/src/test/ui/borrowck/borrowck-describe-lvalue.stderr +++ b/src/test/ui/borrowck/borrowck-describe-lvalue.stderr @@ -238,23 +238,22 @@ LL | drop(x); | - borrow later used here error[E0503]: cannot use `e` because it was mutably borrowed - --> $DIR/borrowck-describe-lvalue.rs:167:13 + --> $DIR/borrowck-describe-lvalue.rs:166:15 | LL | let x = &mut e; | ------ borrow of `e` occurs here LL | match e { -LL | E::A(ref ax) => - | ^^^^^^^^^^^^ use of borrowed `e` + | ^ use of borrowed `e` ... LL | drop(x); | - borrow later used here error[E0502]: cannot borrow `e.0` as immutable because it is also borrowed as mutable - --> $DIR/borrowck-describe-lvalue.rs:167:18 + --> $DIR/borrowck-describe-lvalue.rs:168:18 | LL | let x = &mut e; | ------ mutable borrow occurs here -LL | match e { +... LL | E::A(ref ax) => | ^^^^^^ immutable borrow occurs here ... diff --git a/src/test/ui/borrowck/borrowck-match-already-borrowed.rs b/src/test/ui/borrowck/borrowck-match-already-borrowed.rs index c766e6c108086..a925cbbf57b6d 100644 --- a/src/test/ui/borrowck/borrowck-match-already-borrowed.rs +++ b/src/test/ui/borrowck/borrowck-match-already-borrowed.rs @@ -6,8 +6,8 @@ enum Foo { fn match_enum() { let mut foo = Foo::B; let p = &mut foo; - let _ = match foo { - Foo::B => 1, //~ ERROR [E0503] + let _ = match foo { //~ ERROR [E0503] + Foo::B => 1, _ => 2, Foo::A(x) => x //~ ERROR [E0503] }; diff --git a/src/test/ui/borrowck/borrowck-match-already-borrowed.stderr b/src/test/ui/borrowck/borrowck-match-already-borrowed.stderr index 286a925bb7f6c..39047be9de670 100644 --- a/src/test/ui/borrowck/borrowck-match-already-borrowed.stderr +++ b/src/test/ui/borrowck/borrowck-match-already-borrowed.stderr @@ -1,11 +1,10 @@ error[E0503]: cannot use `foo` because it was mutably borrowed - --> $DIR/borrowck-match-already-borrowed.rs:10:9 + --> $DIR/borrowck-match-already-borrowed.rs:9:19 | LL | let p = &mut foo; | -------- borrow of `foo` occurs here LL | let _ = match foo { -LL | Foo::B => 1, - | ^^^^^^ use of borrowed `foo` + | ^^^ use of borrowed `foo` ... LL | drop(p); | - borrow later used here diff --git a/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.rs b/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.rs index 71f1f15654b55..4109c10e2e46b 100644 --- a/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.rs +++ b/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.rs @@ -10,11 +10,11 @@ fn main() { let b = &mut true; match b { + //~^ ERROR use of moved value: `b` [E0382] &mut false => {}, _ if { (|| { let bar = b; *bar = false; })(); false } => { }, &mut true => { println!("You might think we should get here"); }, - //~^ ERROR use of moved value: `b` [E0382] _ => panic!("surely we could never get here, since rustc warns it is unreachable."), } } diff --git a/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.stderr b/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.stderr index 51f9b464d7660..9be1a9279992b 100644 --- a/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.stderr +++ b/src/test/ui/borrowck/issue-27282-move-match-input-into-guard.stderr @@ -1,16 +1,15 @@ error[E0382]: use of moved value: `b` - --> $DIR/issue-27282-move-match-input-into-guard.rs:16:14 + --> $DIR/issue-27282-move-match-input-into-guard.rs:12:5 | LL | let b = &mut true; | - move occurs because `b` has type `&mut bool`, which does not implement the `Copy` trait +LL | match b { + | ^^^^^^^ value used here after move ... LL | _ if { (|| { let bar = b; *bar = false; })(); | -- - variable moved due to use in closure | | | value moved into closure here -LL | false } => { }, -LL | &mut true => { println!("You might think we should get here"); }, - | ^^^^ value used here after move error: aborting due to previous error diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr index 64a1214e8bf1b..64d8540878ec2 100644 --- a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr +++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.32bit.stderr @@ -65,11 +65,11 @@ LL | U8_MUT2 => true, | ^^^^^^^ warning: any use of this value will cause an error - --> $DIR/const_refers_to_static_cross_crate.rs:32:51 + --> $DIR/const_refers_to_static_cross_crate.rs:32:20 | LL | / const U8_MUT3: &u8 = { LL | | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } } - | | ^^^^^^^^^^^ constant accesses static + | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static LL | | LL | | LL | | diff --git a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr index 66fe4ec076005..8e793ab3f0d91 100644 --- a/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr +++ b/src/test/ui/consts/miri_unleashed/const_refers_to_static_cross_crate.64bit.stderr @@ -65,11 +65,11 @@ LL | U8_MUT2 => true, | ^^^^^^^ warning: any use of this value will cause an error - --> $DIR/const_refers_to_static_cross_crate.rs:32:51 + --> $DIR/const_refers_to_static_cross_crate.rs:32:20 | LL | / const U8_MUT3: &u8 = { LL | | unsafe { match static_cross_crate::OPT_ZERO { Some(ref u) => u, None => panic!() } } - | | ^^^^^^^^^^^ constant accesses static + | | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant accesses static LL | | LL | | LL | | diff --git a/src/test/ui/issues/issue-17385.rs b/src/test/ui/issues/issue-17385.rs index 93364d2f6259e..7400aadb059f7 100644 --- a/src/test/ui/issues/issue-17385.rs +++ b/src/test/ui/issues/issue-17385.rs @@ -15,8 +15,8 @@ impl Drop for Enum { fn main() { let foo = X(1); drop(foo); - match foo { - X(1) => (), //~ ERROR use of moved value + match foo { //~ ERROR use of moved value + X(1) => (), _ => unreachable!() } diff --git a/src/test/ui/issues/issue-17385.stderr b/src/test/ui/issues/issue-17385.stderr index 28c22260c3888..77aa201b33564 100644 --- a/src/test/ui/issues/issue-17385.stderr +++ b/src/test/ui/issues/issue-17385.stderr @@ -1,13 +1,12 @@ error[E0382]: use of moved value: `foo` - --> $DIR/issue-17385.rs:19:11 + --> $DIR/issue-17385.rs:18:5 | LL | let foo = X(1); | --- move occurs because `foo` has type `X`, which does not implement the `Copy` trait LL | drop(foo); | --- value moved here LL | match foo { -LL | X(1) => (), - | ^ value used here after move + | ^^^^^^^^^ value used here after move error[E0382]: use of moved value: `e` --> $DIR/issue-17385.rs:25:11 diff --git a/src/test/ui/nll/borrowed-match-issue-45045.rs b/src/test/ui/nll/borrowed-match-issue-45045.rs index 0cd8e956d309f..978eeb868edc0 100644 --- a/src/test/ui/nll/borrowed-match-issue-45045.rs +++ b/src/test/ui/nll/borrowed-match-issue-45045.rs @@ -10,8 +10,8 @@ fn main() { let f = &mut e; let g = f; match e { - Xyz::A => println!("a"), //~^ cannot use `e` because it was mutably borrowed [E0503] + Xyz::A => println!("a"), Xyz::B => println!("b"), }; *g = Xyz::B; diff --git a/src/test/ui/nll/borrowed-match-issue-45045.stderr b/src/test/ui/nll/borrowed-match-issue-45045.stderr index 1607304e6716b..9d4682667dddd 100644 --- a/src/test/ui/nll/borrowed-match-issue-45045.stderr +++ b/src/test/ui/nll/borrowed-match-issue-45045.stderr @@ -1,11 +1,11 @@ error[E0503]: cannot use `e` because it was mutably borrowed - --> $DIR/borrowed-match-issue-45045.rs:13:9 + --> $DIR/borrowed-match-issue-45045.rs:12:11 | LL | let f = &mut e; | ------ borrow of `e` occurs here -... -LL | Xyz::A => println!("a"), - | ^^^^^^ use of borrowed `e` +LL | let g = f; +LL | match e { + | ^ use of borrowed `e` ... LL | *g = Xyz::B; | ----------- borrow later used here diff --git a/src/test/ui/nll/match-cfg-fake-edges2.rs b/src/test/ui/nll/match-cfg-fake-edges2.rs index 84c0dec2fe5cd..e61db71220e85 100644 --- a/src/test/ui/nll/match-cfg-fake-edges2.rs +++ b/src/test/ui/nll/match-cfg-fake-edges2.rs @@ -7,8 +7,8 @@ fn all_previous_tests_may_be_done(y: &mut (bool, bool)) { let r = &mut y.1; // We don't actually test y.1 to select the second arm, but we don't want // borrowck results to be based on the order we match patterns. - match y { - (false, true) => 1, //~ ERROR cannot use `y.1` because it was mutably borrowed + match y { //~ ERROR cannot use `y.1` because it was mutably borrowed + (false, true) => 1, (true, _) => { r; 2 diff --git a/src/test/ui/nll/match-cfg-fake-edges2.stderr b/src/test/ui/nll/match-cfg-fake-edges2.stderr index eab89658e79be..0ce83849b9f94 100644 --- a/src/test/ui/nll/match-cfg-fake-edges2.stderr +++ b/src/test/ui/nll/match-cfg-fake-edges2.stderr @@ -1,12 +1,12 @@ error[E0503]: cannot use `y.1` because it was mutably borrowed - --> $DIR/match-cfg-fake-edges2.rs:11:17 + --> $DIR/match-cfg-fake-edges2.rs:10:5 | LL | let r = &mut y.1; | -------- borrow of `y.1` occurs here ... -LL | (false, true) => 1, - | ^^^^ use of borrowed `y.1` -LL | (true, _) => { +LL | match y { + | ^^^^^^^ use of borrowed `y.1` +... LL | r; | - borrow later used here diff --git a/src/test/ui/nll/match-on-borrowed.rs b/src/test/ui/nll/match-on-borrowed.rs index aba0a7f71f5c1..447dabeb47e59 100644 --- a/src/test/ui/nll/match-on-borrowed.rs +++ b/src/test/ui/nll/match-on-borrowed.rs @@ -45,8 +45,9 @@ fn enum_example(mut e: E) { E::W => panic!(), }; match e { // Don't know that E uses a tag for its discriminant + //~^ ERROR _ if false => (), - E::V(_, r) => (), //~ ERROR + E::V(_, r) => (), E::W => (), } x; @@ -58,8 +59,9 @@ fn indirect_enum_example(mut f: &mut E) { E::W => panic!(), }; match f { // Don't know that E uses a tag for its discriminant + //~^ ERROR _ if false => (), - E::V(_, r) => (), //~ ERROR + E::V(_, r) => (), E::W => (), } x; @@ -77,7 +79,8 @@ fn match_on_muatbly_borrowed_ref(mut p: &bool) { fn match_on_borrowed(mut t: bool) { let x = &mut t; match t { - true => (), //~ ERROR + //~^ ERROR + true => (), false => (), } x; diff --git a/src/test/ui/nll/match-on-borrowed.stderr b/src/test/ui/nll/match-on-borrowed.stderr index f9c9a84632212..2121b59b02da3 100644 --- a/src/test/ui/nll/match-on-borrowed.stderr +++ b/src/test/ui/nll/match-on-borrowed.stderr @@ -1,41 +1,40 @@ error[E0503]: cannot use `e` because it was mutably borrowed - --> $DIR/match-on-borrowed.rs:49:9 + --> $DIR/match-on-borrowed.rs:47:11 | LL | E::V(ref mut x, _) => x, | --------- borrow of `e.0` occurs here ... -LL | E::V(_, r) => (), - | ^^^^^^^^^^ use of borrowed `e.0` +LL | match e { // Don't know that E uses a tag for its discriminant + | ^ use of borrowed `e.0` ... LL | x; | - borrow later used here error[E0503]: cannot use `*f` because it was mutably borrowed - --> $DIR/match-on-borrowed.rs:62:9 + --> $DIR/match-on-borrowed.rs:61:11 | LL | E::V(ref mut x, _) => x, | --------- borrow of `f.0` occurs here ... -LL | E::V(_, r) => (), - | ^^^^^^^^^^ use of borrowed `f.0` +LL | match f { // Don't know that E uses a tag for its discriminant + | ^ use of borrowed `f.0` ... LL | x; | - borrow later used here error[E0503]: cannot use `t` because it was mutably borrowed - --> $DIR/match-on-borrowed.rs:80:9 + --> $DIR/match-on-borrowed.rs:81:5 | LL | let x = &mut t; | ------ borrow of `t` occurs here LL | match t { -LL | true => (), - | ^^^^ use of borrowed `t` + | ^^^^^^^ use of borrowed `t` ... LL | x; | - borrow later used here error[E0381]: use of possibly-uninitialized variable: `n` - --> $DIR/match-on-borrowed.rs:90:11 + --> $DIR/match-on-borrowed.rs:93:11 | LL | match n {} | ^ use of possibly-uninitialized `n` diff --git a/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.rs b/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.rs index 00dcf89c7aa67..2ad92b7944492 100644 --- a/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.rs +++ b/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.rs @@ -10,8 +10,8 @@ fn main() { let mut x = NonExhaustiveMonovariant::Variant(1); let y = &mut x; match x { - NonExhaustiveMonovariant::Variant(_) => {}, //~^ ERROR cannot use `x` because it was mutably borrowed + NonExhaustiveMonovariant::Variant(_) => {}, _ => {}, } drop(y); diff --git a/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.stderr b/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.stderr index 9edfa84cbc085..de730ce1030f2 100644 --- a/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.stderr +++ b/src/test/ui/rfc-2008-non-exhaustive/borrowck-non-exhaustive.stderr @@ -1,11 +1,10 @@ error[E0503]: cannot use `x` because it was mutably borrowed - --> $DIR/borrowck-non-exhaustive.rs:13:9 + --> $DIR/borrowck-non-exhaustive.rs:12:11 | LL | let y = &mut x; | ------ borrow of `x` occurs here LL | match x { -LL | NonExhaustiveMonovariant::Variant(_) => {}, - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ use of borrowed `x` + | ^ use of borrowed `x` ... LL | drop(y); | - borrow later used here diff --git a/src/test/ui/union/union-unsafe.mir.stderr b/src/test/ui/union/union-unsafe.mir.stderr index 84a7eb2ef2e72..318b00ddea94e 100644 --- a/src/test/ui/union/union-unsafe.mir.stderr +++ b/src/test/ui/union/union-unsafe.mir.stderr @@ -55,10 +55,10 @@ LL | let U1 { a } = u1; = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior error[E0133]: access to union field is unsafe and requires unsafe function or block - --> $DIR/union-unsafe.rs:65:20 + --> $DIR/union-unsafe.rs:65:12 | LL | if let U1 { a: 12 } = u1 {} - | ^^ access to union field + | ^^^^^^^^^^^^ access to union field | = note: the field may not be properly initialized: using uninitialized data will cause undefined behavior From 8a6501d28831d864a3af6adf2e0bd83a773062ed Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Wed, 25 Aug 2021 14:40:06 -0700 Subject: [PATCH 31/36] Adjust spans * Highlight the whole pattern if it has no fields * Highlight the whole definition if it has no fields * Only highlight the pattern name if the pattern is multi-line * Determine whether a pattern is multi-line based on distance from name to last field, rather than first field --- compiler/rustc_typeck/src/check/pat.rs | 10 +- .../tuple_struct_destructure_fail.stderr | 8 +- src/test/ui/error-codes/E0023.stderr | 12 +- src/test/ui/issues/issue-72574-2.stderr | 2 +- .../match/match-pattern-field-mismatch.stderr | 2 +- ...7-pat-tup-scrut-ty-diff-less-fields.stderr | 4 +- src/test/ui/pattern/issue-74539.stderr | 2 +- .../pat-tuple-field-count-cross.stderr | 54 ++++----- src/test/ui/pattern/pat-tuple-overfield.rs | 16 +++ .../ui/pattern/pat-tuple-overfield.stderr | 108 ++++++++++++++---- src/test/ui/pattern/pat-tuple-underfield.rs | 12 ++ .../ui/pattern/pat-tuple-underfield.stderr | 64 ++++++++--- .../ui/pattern/pattern-error-continue.stderr | 2 +- 13 files changed, 211 insertions(+), 85 deletions(-) diff --git a/compiler/rustc_typeck/src/check/pat.rs b/compiler/rustc_typeck/src/check/pat.rs index 341385731e7d2..e1f0d3c436366 100644 --- a/compiler/rustc_typeck/src/check/pat.rs +++ b/compiler/rustc_typeck/src/check/pat.rs @@ -992,7 +992,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let fields_ending = pluralize!(fields.len()); let subpat_spans = if subpats.is_empty() { - vec![pat_span.trim_start(qpath.span()).unwrap_or(pat_span)] + vec![pat_span] } else { subpats.iter().map(|p| p.span).collect() }; @@ -1000,7 +1000,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let res_span = self.tcx.def_span(res.def_id()); let def_ident_span = self.tcx.def_ident_span(res.def_id()).unwrap_or(res_span); let field_def_spans = if fields.is_empty() { - vec![res_span.trim_start(def_ident_span).unwrap_or(res_span)] + vec![res_span] } else { fields.iter().map(|f| f.ident.span).collect() }; @@ -1021,8 +1021,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { last_subpat_span, &format!("expected {} field{}, found {}", fields.len(), fields_ending, subpats.len()), ); - err.span_label(qpath.span(), ""); - if self.tcx.sess.source_map().is_multiline(def_ident_span.between(field_def_spans[0])) { + if self.tcx.sess.source_map().is_multiline(qpath.span().between(last_subpat_span)) { + err.span_label(qpath.span(), ""); + } + if self.tcx.sess.source_map().is_multiline(def_ident_span.between(last_field_def_span)) { err.span_label(def_ident_span, format!("{} defined here", res.descr())); } for span in &field_def_spans[..field_def_spans.len() - 1] { diff --git a/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr b/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr index 9a47ddf047991..9aae4b0a3faed 100644 --- a/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr +++ b/src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr @@ -21,7 +21,7 @@ LL | struct TupleStruct(S, T); | - - tuple struct has 2 fields ... LL | TupleStruct(a, a, b) = TupleStruct(1, 2); - | ----------- ^ ^ ^ expected 2 fields, found 3 + | ^ ^ ^ expected 2 fields, found 3 error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 2 fields --> $DIR/tuple_struct_destructure_fail.rs:32:17 @@ -30,7 +30,7 @@ LL | struct TupleStruct(S, T); | - - tuple struct has 2 fields ... LL | TupleStruct(_) = TupleStruct(1, 2); - | ----------- ^ expected 2 fields, found 1 + | ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -48,7 +48,7 @@ LL | SingleVariant(S, T) | - - tuple variant has 2 fields ... LL | Enum::SingleVariant(a, a, b) = Enum::SingleVariant(1, 2); - | ------------------- ^ ^ ^ expected 2 fields, found 3 + | ^ ^ ^ expected 2 fields, found 3 error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields --> $DIR/tuple_struct_destructure_fail.rs:36:25 @@ -57,7 +57,7 @@ LL | SingleVariant(S, T) | - - tuple variant has 2 fields ... LL | Enum::SingleVariant(_) = Enum::SingleVariant(1, 2); - | ------------------- ^ expected 2 fields, found 1 + | ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/error-codes/E0023.stderr b/src/test/ui/error-codes/E0023.stderr index 85e1b2cb4ceef..3e321b037b2b2 100644 --- a/src/test/ui/error-codes/E0023.stderr +++ b/src/test/ui/error-codes/E0023.stderr @@ -5,7 +5,7 @@ LL | Apple(String, String), | ------ ------ tuple variant has 2 fields ... LL | Fruit::Apple(a) => {}, - | ------------ ^ expected 2 fields, found 1 + | ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -19,7 +19,7 @@ LL | Apple(String, String), | ------ ------ tuple variant has 2 fields ... LL | Fruit::Apple(a, b, c) => {}, - | ------------ ^ ^ ^ expected 2 fields, found 3 + | ^ ^ ^ expected 2 fields, found 3 error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 1 field --> $DIR/E0023.rs:13:21 @@ -28,7 +28,7 @@ LL | Pear(u32), | --- tuple variant has 1 field ... LL | Fruit::Pear(1, 2) => {}, - | ----------- ^ ^ expected 1 field, found 2 + | ^ ^ expected 1 field, found 2 error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 1 field --> $DIR/E0023.rs:14:23 @@ -37,7 +37,7 @@ LL | Orange((String, String)), | ---------------- tuple variant has 1 field ... LL | Fruit::Orange(a, b) => {}, - | ------------- ^ ^ expected 1 field, found 2 + | ^ ^ expected 1 field, found 2 | help: missing parentheses | @@ -45,13 +45,13 @@ LL | Fruit::Orange((a, b)) => {}, | + + error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 1 field - --> $DIR/E0023.rs:15:22 + --> $DIR/E0023.rs:15:9 | LL | Banana(()), | -- tuple variant has 1 field ... LL | Fruit::Banana() => {}, - | -------------^^ expected 1 field, found 0 + | ^^^^^^^^^^^^^^^ expected 1 field, found 0 | help: missing parentheses | diff --git a/src/test/ui/issues/issue-72574-2.stderr b/src/test/ui/issues/issue-72574-2.stderr index 3f8ff4f0bacd5..05650f05cbf5b 100644 --- a/src/test/ui/issues/issue-72574-2.stderr +++ b/src/test/ui/issues/issue-72574-2.stderr @@ -25,7 +25,7 @@ LL | struct Binder(i32, i32, i32); | --- --- --- tuple struct has 3 fields ... LL | Binder(_a, _x @ ..) => {} - | ------ ^^ ^^^^^^^ expected 3 fields, found 2 + | ^^ ^^^^^^^ expected 3 fields, found 2 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/match/match-pattern-field-mismatch.stderr b/src/test/ui/match/match-pattern-field-mismatch.stderr index 01d7cf0d054c9..c994ee4f6d4ff 100644 --- a/src/test/ui/match/match-pattern-field-mismatch.stderr +++ b/src/test/ui/match/match-pattern-field-mismatch.stderr @@ -5,7 +5,7 @@ LL | Rgb(usize, usize, usize), | ----- ----- ----- tuple variant has 3 fields ... LL | Color::Rgb(_, _) => { } - | ---------- ^ ^ expected 3 fields, found 2 + | ^ ^ expected 3 fields, found 2 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr b/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr index c87b70625b40e..75a231f6b4ba3 100644 --- a/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr +++ b/src/test/ui/pattern/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr @@ -10,13 +10,13 @@ LL | let P() = U {}; found struct `P<_>` error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 1 field - --> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:10 + --> $DIR/issue-67037-pat-tup-scrut-ty-diff-less-fields.rs:19:9 | LL | struct P(T); // 1 type parameter wanted | - tuple struct has 1 field ... LL | let P() = U {}; - | -^^ expected 1 field, found 0 + | ^^^ expected 1 field, found 0 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/issue-74539.stderr b/src/test/ui/pattern/issue-74539.stderr index d7cbcf2cfa109..7443946c013f7 100644 --- a/src/test/ui/pattern/issue-74539.stderr +++ b/src/test/ui/pattern/issue-74539.stderr @@ -25,7 +25,7 @@ LL | A(u8, u8), | -- -- tuple variant has 2 fields ... LL | E::A(x @ ..) => { - | ---- ^^^^^^ expected 2 fields, found 1 + | ^^^^^^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | diff --git a/src/test/ui/pattern/pat-tuple-field-count-cross.stderr b/src/test/ui/pattern/pat-tuple-field-count-cross.stderr index 570bf0cbc0810..cab8d4759df64 100644 --- a/src/test/ui/pattern/pat-tuple-field-count-cross.stderr +++ b/src/test/ui/pattern/pat-tuple-field-count-cross.stderr @@ -121,7 +121,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 0 --> $DIR/pat-tuple-field-count-cross.rs:14:12 | LL | Z1(x) => {} - | -- ^ expected 0 fields, found 1 + | ^ expected 0 fields, found 1 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:2:1 | @@ -129,10 +129,10 @@ LL | pub struct Z1(); | ---------------- tuple struct has 0 fields error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-field-count-cross.rs:18:10 + --> $DIR/pat-tuple-field-count-cross.rs:18:9 | LL | S() => {} - | -^^ expected 3 fields, found 0 + | ^^^ expected 3 fields, found 0 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14 | @@ -152,7 +152,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 3 --> $DIR/pat-tuple-field-count-cross.rs:19:11 | LL | S(1) => {} - | - ^ expected 3 fields, found 1 + | ^ expected 3 fields, found 1 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14 | @@ -172,7 +172,7 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has --> $DIR/pat-tuple-field-count-cross.rs:20:11 | LL | S(xyz, abc) => {} - | - ^^^ ^^^ expected 3 fields, found 2 + | ^^^ ^^^ expected 3 fields, found 2 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14 | @@ -188,7 +188,7 @@ error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has --> $DIR/pat-tuple-field-count-cross.rs:21:11 | LL | S(1, 2, 3, 4) => {} - | - ^ ^ ^ ^ expected 3 fields, found 4 + | ^ ^ ^ ^ expected 3 fields, found 4 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:4:14 | @@ -196,10 +196,10 @@ LL | pub struct S(pub u8, pub u8, pub u8); | ------ ------ ------ tuple struct has 3 fields error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 3 fields - --> $DIR/pat-tuple-field-count-cross.rs:24:10 + --> $DIR/pat-tuple-field-count-cross.rs:24:9 | LL | M() => {} - | -^^ expected 3 fields, found 0 + | ^^^ expected 3 fields, found 0 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1 | @@ -226,7 +226,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 3 --> $DIR/pat-tuple-field-count-cross.rs:25:11 | LL | M(1) => {} - | - ^ expected 3 fields, found 1 + | ^ expected 3 fields, found 1 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1 | @@ -253,7 +253,7 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has --> $DIR/pat-tuple-field-count-cross.rs:26:11 | LL | M(xyz, abc) => {} - | - ^^^ ^^^ expected 3 fields, found 2 + | ^^^ ^^^ expected 3 fields, found 2 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1 | @@ -276,7 +276,7 @@ error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has --> $DIR/pat-tuple-field-count-cross.rs:27:11 | LL | M(1, 2, 3, 4) => {} - | - ^ ^ ^ ^ expected 3 fields, found 4 + | ^ ^ ^ ^ expected 3 fields, found 4 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:5:1 | @@ -294,7 +294,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:36:16 | LL | E1::Z1(x) => {} - | ------ ^ expected 0 fields, found 1 + | ^ expected 0 fields, found 1 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:19 | @@ -302,10 +302,10 @@ LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } | ---- tuple variant has 0 fields error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 3 fields - --> $DIR/pat-tuple-field-count-cross.rs:39:14 + --> $DIR/pat-tuple-field-count-cross.rs:39:9 | LL | E1::S() => {} - | -----^^ expected 3 fields, found 0 + | ^^^^^^^ expected 3 fields, found 0 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27 | @@ -325,7 +325,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:40:15 | LL | E1::S(1) => {} - | ----- ^ expected 3 fields, found 1 + | ^ expected 3 fields, found 1 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27 | @@ -345,7 +345,7 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:41:15 | LL | E1::S(xyz, abc) => {} - | ----- ^^^ ^^^ expected 3 fields, found 2 + | ^^^ ^^^ expected 3 fields, found 2 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27 | @@ -361,7 +361,7 @@ error[E0023]: this pattern has 4 fields, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:42:15 | LL | E1::S(1, 2, 3, 4) => {} - | ----- ^ ^ ^ ^ expected 3 fields, found 4 + | ^ ^ ^ ^ expected 3 fields, found 4 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:11:27 | @@ -369,10 +369,10 @@ LL | pub enum E1 { Z0, Z1(), S(u8, u8, u8) } | -- -- -- tuple variant has 3 fields error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 3 fields - --> $DIR/pat-tuple-field-count-cross.rs:46:14 + --> $DIR/pat-tuple-field-count-cross.rs:46:9 | LL | E2::S() => {} - | -----^^ expected 3 fields, found 0 + | ^^^^^^^ expected 3 fields, found 0 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7 | @@ -392,7 +392,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:47:15 | LL | E2::S(1) => {} - | ----- ^ expected 3 fields, found 1 + | ^ expected 3 fields, found 1 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7 | @@ -412,7 +412,7 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:48:15 | LL | E2::S(xyz, abc) => {} - | ----- ^^^ ^^^ expected 3 fields, found 2 + | ^^^ ^^^ expected 3 fields, found 2 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7 | @@ -428,7 +428,7 @@ error[E0023]: this pattern has 4 fields, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:49:15 | LL | E2::S(1, 2, 3, 4) => {} - | ----- ^ ^ ^ ^ expected 3 fields, found 4 + | ^ ^ ^ ^ expected 3 fields, found 4 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:14:7 | @@ -436,10 +436,10 @@ LL | S(u8, u8, u8), | -- -- -- tuple variant has 3 fields error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 3 fields - --> $DIR/pat-tuple-field-count-cross.rs:52:14 + --> $DIR/pat-tuple-field-count-cross.rs:52:9 | LL | E2::M() => {} - | -----^^ expected 3 fields, found 0 + | ^^^^^^^ expected 3 fields, found 0 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5 | @@ -466,7 +466,7 @@ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:53:15 | LL | E2::M(1) => {} - | ----- ^ expected 3 fields, found 1 + | ^ expected 3 fields, found 1 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5 | @@ -493,7 +493,7 @@ error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:54:15 | LL | E2::M(xyz, abc) => {} - | ----- ^^^ ^^^ expected 3 fields, found 2 + | ^^^ ^^^ expected 3 fields, found 2 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5 | @@ -516,7 +516,7 @@ error[E0023]: this pattern has 4 fields, but the corresponding tuple variant has --> $DIR/pat-tuple-field-count-cross.rs:55:15 | LL | E2::M(1, 2, 3, 4) => {} - | ----- ^ ^ ^ ^ expected 3 fields, found 4 + | ^ ^ ^ ^ expected 3 fields, found 4 | ::: $DIR/auxiliary/declarations-for-tuple-field-count-errors.rs:15:5 | diff --git a/src/test/ui/pattern/pat-tuple-overfield.rs b/src/test/ui/pattern/pat-tuple-overfield.rs index dd0548a088c72..c863c657514f3 100644 --- a/src/test/ui/pattern/pat-tuple-overfield.rs +++ b/src/test/ui/pattern/pat-tuple-overfield.rs @@ -30,6 +30,22 @@ fn main() { match M(1, 2, 3, 4, 5) { M(1, 2, 3, 4, 5, 6) => {} //~^ ERROR this pattern has 6 fields, but the corresponding tuple struct has 5 fields + M(1, + 2, + 3, + 4, + 5, + 6) => {} + //~^ ERROR this pattern has 6 fields, but the corresponding tuple struct has 5 fields + M( + 1, + 2, + 3, + 4, + 5, + 6, + ) => {} + //~^^ ERROR this pattern has 6 fields, but the corresponding tuple struct has 5 fields } match Z0 { Z0 => {} diff --git a/src/test/ui/pattern/pat-tuple-overfield.stderr b/src/test/ui/pattern/pat-tuple-overfield.stderr index 646ac4e661897..1c44f7e5f6f1f 100644 --- a/src/test/ui/pattern/pat-tuple-overfield.stderr +++ b/src/test/ui/pattern/pat-tuple-overfield.stderr @@ -1,5 +1,5 @@ error[E0530]: match bindings cannot shadow tuple structs - --> $DIR/pat-tuple-overfield.rs:41:9 + --> $DIR/pat-tuple-overfield.rs:57:9 | LL | struct Z1(); | ------------ the tuple struct `Z1` is defined here @@ -8,7 +8,7 @@ LL | Z1 => {} | ^^ cannot be named the same as a tuple struct error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` - --> $DIR/pat-tuple-overfield.rs:36:9 + --> $DIR/pat-tuple-overfield.rs:52:9 | LL | struct Z0; | ---------- `Z0` defined here @@ -28,7 +28,7 @@ LL | Z1() => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` - --> $DIR/pat-tuple-overfield.rs:37:9 + --> $DIR/pat-tuple-overfield.rs:53:9 | LL | struct Z0; | ---------- `Z0` defined here @@ -48,7 +48,7 @@ LL | Z1(_) => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit struct `Z0` - --> $DIR/pat-tuple-overfield.rs:38:9 + --> $DIR/pat-tuple-overfield.rs:54:9 | LL | struct Z0; | ---------- `Z0` defined here @@ -68,7 +68,7 @@ LL | Z1(_, _) => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` - --> $DIR/pat-tuple-overfield.rs:48:9 + --> $DIR/pat-tuple-overfield.rs:64:9 | LL | Z0, | -- `E1::Z0` defined here @@ -88,7 +88,7 @@ LL | E1::Z1() => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` - --> $DIR/pat-tuple-overfield.rs:49:9 + --> $DIR/pat-tuple-overfield.rs:65:9 | LL | Z0, | -- `E1::Z0` defined here @@ -108,7 +108,7 @@ LL | E1::Z1(_) => {} | ~~ error[E0532]: expected tuple struct or tuple variant, found unit variant `E1::Z0` - --> $DIR/pat-tuple-overfield.rs:50:9 + --> $DIR/pat-tuple-overfield.rs:66:9 | LL | Z0, | -- `E1::Z0` defined here @@ -128,7 +128,7 @@ LL | E1::Z1(_, _) => {} | ~~ error[E0532]: expected unit struct, unit variant or constant, found tuple variant `E1::Z1` - --> $DIR/pat-tuple-overfield.rs:53:9 + --> $DIR/pat-tuple-overfield.rs:69:9 | LL | Z0, | -- similarly named unit variant `Z0` defined here @@ -177,7 +177,7 @@ LL | struct S(u8, u8, u8); | -- -- -- tuple struct has 3 fields ... LL | S(1, 2, 3, 4) => {} - | - ^ ^ ^ ^ expected 3 fields, found 4 + | ^ ^ ^ ^ expected 3 fields, found 4 error[E0023]: this pattern has 4 fields, but the corresponding tuple struct has 3 fields --> $DIR/pat-tuple-overfield.rs:26:11 @@ -186,7 +186,7 @@ LL | struct S(u8, u8, u8); | -- -- -- tuple struct has 3 fields ... LL | S(1, 2, .., 3, 4) => {} - | - ^ ^ ^ ^ expected 3 fields, found 4 + | ^ ^ ^ ^ expected 3 fields, found 4 error[E0023]: this pattern has 6 fields, but the corresponding tuple struct has 5 fields --> $DIR/pat-tuple-overfield.rs:31:11 @@ -205,45 +205,105 @@ LL | u8, | -- tuple struct has 5 fields ... LL | M(1, 2, 3, 4, 5, 6) => {} - | - ^ ^ ^ ^ ^ ^ expected 5 fields, found 6 + | ^ ^ ^ ^ ^ ^ expected 5 fields, found 6 + +error[E0023]: this pattern has 6 fields, but the corresponding tuple struct has 5 fields + --> $DIR/pat-tuple-overfield.rs:33:11 + | +LL | struct M( + | - tuple struct defined here +LL | u8, + | -- +LL | u8, + | -- +LL | u8, + | -- +LL | u8, + | -- +LL | u8, + | -- tuple struct has 5 fields +... +LL | M(1, + | - ^ +LL | 2, + | ^ +LL | 3, + | ^ +LL | 4, + | ^ +LL | 5, + | ^ +LL | 6) => {} + | ^ expected 5 fields, found 6 + +error[E0023]: this pattern has 6 fields, but the corresponding tuple struct has 5 fields + --> $DIR/pat-tuple-overfield.rs:41:13 + | +LL | struct M( + | - tuple struct defined here +LL | u8, + | -- +LL | u8, + | -- +LL | u8, + | -- +LL | u8, + | -- +LL | u8, + | -- tuple struct has 5 fields +... +LL | M( + | - +LL | 1, + | ^ +LL | 2, + | ^ +LL | 3, + | ^ +LL | 4, + | ^ +LL | 5, + | ^ +LL | 6, + | ^ expected 5 fields, found 6 error[E0023]: this pattern has 1 field, but the corresponding tuple struct has 0 fields - --> $DIR/pat-tuple-overfield.rs:43:12 + --> $DIR/pat-tuple-overfield.rs:59:12 | LL | struct Z1(); - | --- tuple struct has 0 fields + | ------------ tuple struct has 0 fields ... LL | Z1(_) => {} - | -- ^ expected 0 fields, found 1 + | ^ expected 0 fields, found 1 error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 0 fields - --> $DIR/pat-tuple-overfield.rs:44:12 + --> $DIR/pat-tuple-overfield.rs:60:12 | LL | struct Z1(); - | --- tuple struct has 0 fields + | ------------ tuple struct has 0 fields ... LL | Z1(_, _) => {} - | -- ^ ^ expected 0 fields, found 2 + | ^ ^ expected 0 fields, found 2 error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 0 fields - --> $DIR/pat-tuple-overfield.rs:55:16 + --> $DIR/pat-tuple-overfield.rs:71:16 | LL | Z1(), - | -- tuple variant has 0 fields + | ---- tuple variant has 0 fields ... LL | E1::Z1(_) => {} - | ------ ^ expected 0 fields, found 1 + | ^ expected 0 fields, found 1 error[E0023]: this pattern has 2 fields, but the corresponding tuple variant has 0 fields - --> $DIR/pat-tuple-overfield.rs:56:16 + --> $DIR/pat-tuple-overfield.rs:72:16 | LL | Z1(), - | -- tuple variant has 0 fields + | ---- tuple variant has 0 fields ... LL | E1::Z1(_, _) => {} - | ------ ^ ^ expected 0 fields, found 2 + | ^ ^ expected 0 fields, found 2 -error: aborting due to 17 previous errors +error: aborting due to 19 previous errors Some errors have detailed explanations: E0023, E0308, E0530, E0532. For more information about an error, try `rustc --explain E0023`. diff --git a/src/test/ui/pattern/pat-tuple-underfield.rs b/src/test/ui/pattern/pat-tuple-underfield.rs index ed852a47bb4ee..dac60e3fab2c0 100644 --- a/src/test/ui/pattern/pat-tuple-underfield.rs +++ b/src/test/ui/pattern/pat-tuple-underfield.rs @@ -21,6 +21,12 @@ fn main() { //~^ ERROR this pattern has 0 fields, but the corresponding tuple struct has 2 fields //~| HELP use `_` to explicitly ignore each field //~| HELP use `..` to ignore all fields + + // Test non-standard formatting + S () => {} + //~^ ERROR this pattern has 0 fields, but the corresponding tuple struct has 2 fields + //~| HELP use `_` to explicitly ignore each field + //~| HELP use `..` to ignore all fields } match E::S(0, 1.0) { @@ -39,6 +45,12 @@ fn main() { //~^ ERROR this pattern has 0 fields, but the corresponding tuple variant has 2 fields //~| HELP use `_` to explicitly ignore each field //~| HELP use `..` to ignore all fields + + // Test non-standard formatting + E::S () => {} + //~^ ERROR this pattern has 0 fields, but the corresponding tuple variant has 2 fields + //~| HELP use `_` to explicitly ignore each field + //~| HELP use `..` to ignore all fields } match E::S(0, 1.0) { E::S => {} diff --git a/src/test/ui/pattern/pat-tuple-underfield.stderr b/src/test/ui/pattern/pat-tuple-underfield.stderr index 4c21ad0be3eb4..e75f9b38da566 100644 --- a/src/test/ui/pattern/pat-tuple-underfield.stderr +++ b/src/test/ui/pattern/pat-tuple-underfield.stderr @@ -1,5 +1,5 @@ error[E0532]: expected unit struct, unit variant or constant, found tuple variant `E::S` - --> $DIR/pat-tuple-underfield.rs:44:9 + --> $DIR/pat-tuple-underfield.rs:56:9 | LL | S(i32, f32), | ----------- `E::S` defined here @@ -14,7 +14,7 @@ LL | struct S(i32, f32); | --- --- tuple struct has 2 fields ... LL | S(x) => {} - | - ^ expected 2 fields, found 1 + | ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -28,7 +28,7 @@ LL | struct S(i32, f32); | --- --- tuple struct has 2 fields ... LL | S(_) => {} - | - ^ expected 2 fields, found 1 + | ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -40,13 +40,13 @@ LL | S(..) => {} | ~~ error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 2 fields - --> $DIR/pat-tuple-underfield.rs:20:10 + --> $DIR/pat-tuple-underfield.rs:20:9 | LL | struct S(i32, f32); | --- --- tuple struct has 2 fields ... LL | S() => {} - | -^^ expected 2 fields, found 0 + | ^^^ expected 2 fields, found 0 | help: use `_` to explicitly ignore each field | @@ -57,14 +57,32 @@ help: use `..` to ignore all fields LL | S(..) => {} | ++ +error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 2 fields + --> $DIR/pat-tuple-underfield.rs:26:9 + | +LL | struct S(i32, f32); + | --- --- tuple struct has 2 fields +... +LL | S () => {} + | ^^^^ expected 2 fields, found 0 + | +help: use `_` to explicitly ignore each field + | +LL | S (_, _) => {} + | ++++ +help: use `..` to ignore all fields + | +LL | S (..) => {} + | ++ + error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/pat-tuple-underfield.rs:27:14 + --> $DIR/pat-tuple-underfield.rs:33:14 | LL | S(i32, f32), | --- --- tuple variant has 2 fields ... LL | E::S(x) => {} - | ---- ^ expected 2 fields, found 1 + | ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -72,13 +90,13 @@ LL | E::S(x, _) => {} | +++ error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields - --> $DIR/pat-tuple-underfield.rs:32:14 + --> $DIR/pat-tuple-underfield.rs:38:14 | LL | S(i32, f32), | --- --- tuple variant has 2 fields ... LL | E::S(_) => {} - | ---- ^ expected 2 fields, found 1 + | ^ expected 2 fields, found 1 | help: use `_` to explicitly ignore each field | @@ -90,13 +108,13 @@ LL | E::S(..) => {} | ~~ error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 2 fields - --> $DIR/pat-tuple-underfield.rs:38:13 + --> $DIR/pat-tuple-underfield.rs:44:9 | LL | S(i32, f32), | --- --- tuple variant has 2 fields ... LL | E::S() => {} - | ----^^ expected 2 fields, found 0 + | ^^^^^^ expected 2 fields, found 0 | help: use `_` to explicitly ignore each field | @@ -107,14 +125,32 @@ help: use `..` to ignore all fields LL | E::S(..) => {} | ++ +error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 2 fields + --> $DIR/pat-tuple-underfield.rs:50:9 + | +LL | S(i32, f32), + | --- --- tuple variant has 2 fields +... +LL | E::S () => {} + | ^^^^^^^ expected 2 fields, found 0 + | +help: use `_` to explicitly ignore each field + | +LL | E::S (_, _) => {} + | ++++ +help: use `..` to ignore all fields + | +LL | E::S (..) => {} + | ++ + error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 4 fields - --> $DIR/pat-tuple-underfield.rs:50:19 + --> $DIR/pat-tuple-underfield.rs:62:19 | LL | struct Point4(i32, i32, i32, i32); | --- --- --- --- tuple struct has 4 fields ... LL | Point4( a , _ ) => {} - | ------ ^ ^ expected 4 fields, found 2 + | ^ ^ expected 4 fields, found 2 | help: use `_` to explicitly ignore each field | @@ -125,7 +161,7 @@ help: use `..` to ignore the rest of the fields LL | Point4( a, ..) => {} | ~~~~ -error: aborting due to 8 previous errors +error: aborting due to 10 previous errors Some errors have detailed explanations: E0023, E0532. For more information about an error, try `rustc --explain E0023`. diff --git a/src/test/ui/pattern/pattern-error-continue.stderr b/src/test/ui/pattern/pattern-error-continue.stderr index efc6723e9ef8e..c800afdae2afb 100644 --- a/src/test/ui/pattern/pattern-error-continue.stderr +++ b/src/test/ui/pattern/pattern-error-continue.stderr @@ -32,7 +32,7 @@ LL | B(isize, isize), | ----- ----- tuple variant has 2 fields ... LL | A::B(_, _, _) => (), - | ---- ^ ^ ^ expected 2 fields, found 3 + | ^ ^ ^ expected 2 fields, found 3 error[E0308]: mismatched types --> $DIR/pattern-error-continue.rs:22:9 From 5df5659a6b96436ae55fd6bd8e9a7dbe7e22b37d Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 25 Aug 2021 19:14:50 -0300 Subject: [PATCH 32/36] Revert "Add type of a let tait test impl trait straight in let" This reverts commit dbadab54df148b55b2e884440bfaeaa38517e6e8. This is not part of TAITs, so, if tested should probably be done elsewhere. --- .../type-alias-impl-trait/type_of_a_let2.rs | 25 ------------------- .../type_of_a_let2.stderr | 21 ---------------- 2 files changed, 46 deletions(-) delete mode 100644 src/test/ui/type-alias-impl-trait/type_of_a_let2.rs delete mode 100644 src/test/ui/type-alias-impl-trait/type_of_a_let2.stderr diff --git a/src/test/ui/type-alias-impl-trait/type_of_a_let2.rs b/src/test/ui/type-alias-impl-trait/type_of_a_let2.rs deleted file mode 100644 index 33d3f164ce15e..0000000000000 --- a/src/test/ui/type-alias-impl-trait/type_of_a_let2.rs +++ /dev/null @@ -1,25 +0,0 @@ -#![feature(type_alias_impl_trait)] -#![allow(dead_code)] - -// FIXME This should be under a feature flag - -use std::fmt::Debug; - -fn foo1() -> u32 { - let x: impl Debug = 22_u32; - //~^ ERROR: `impl Trait` not allowed outside of function and method return types [E0562] - x // ERROR: we only know x: Debug, we don't know x = u32 -} - -fn foo2() -> u32 { - let x: impl Debug = 22_u32; - //~^ ERROR: `impl Trait` not allowed outside of function and method return types [E0562] - let y: impl Debug = x; - //~^ ERROR: `impl Trait` not allowed outside of function and method return types [E0562] - same_type((x, y)); // ERROR - x -} - -fn same_type(x: (T, T)) {} - -fn main() {} diff --git a/src/test/ui/type-alias-impl-trait/type_of_a_let2.stderr b/src/test/ui/type-alias-impl-trait/type_of_a_let2.stderr deleted file mode 100644 index 7a1825a8e2d9a..0000000000000 --- a/src/test/ui/type-alias-impl-trait/type_of_a_let2.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0562]: `impl Trait` not allowed outside of function and method return types - --> $DIR/type_of_a_let2.rs:9:12 - | -LL | let x: impl Debug = 22_u32; - | ^^^^^^^^^^ - -error[E0562]: `impl Trait` not allowed outside of function and method return types - --> $DIR/type_of_a_let2.rs:15:12 - | -LL | let x: impl Debug = 22_u32; - | ^^^^^^^^^^ - -error[E0562]: `impl Trait` not allowed outside of function and method return types - --> $DIR/type_of_a_let2.rs:17:12 - | -LL | let y: impl Debug = x; - | ^^^^^^^^^^ - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0562`. From 84a266149bb212109baa94de98457edddff1bae1 Mon Sep 17 00:00:00 2001 From: Wesley Wiser Date: Fri, 6 Aug 2021 14:13:10 -0400 Subject: [PATCH 33/36] Add test for stepping though `match` expressions --- src/test/debuginfo/step-into-match.rs | 383 ++++++++++++++++++++++++++ 1 file changed, 383 insertions(+) create mode 100644 src/test/debuginfo/step-into-match.rs diff --git a/src/test/debuginfo/step-into-match.rs b/src/test/debuginfo/step-into-match.rs new file mode 100644 index 0000000000000..4a5f7857097a1 --- /dev/null +++ b/src/test/debuginfo/step-into-match.rs @@ -0,0 +1,383 @@ +// compile-flags: -g +// ignore-android: FIXME(#10381) + +// === GDB TESTS ============================================================== + +// gdb-command: r + +// gdb-command: s +// gdb-check:[...]match x { + +// gdb-command: s +// gdb-check:[...] Some(42) => 1, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_enum(Some(12)); + +// gdb-command: s +// gdb-check:[...]match x { + +// gdb-command: s +// gdb-check:[...]Some(_) => 2, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_enum(None); + +// gdb-command: s +// gdb-check:[...]match x { + +// gdb-command: s +// gdb-check:[...]None => 3, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_int(1); + +// gdb-command: s +// gdb-check:[...]match y { + +// gdb-command: s +// gdb-check:[...]1 => 3, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_int(2); + +// gdb-command: s +// gdb-check:[...]match y { + +// gdb-command: s +// gdb-check:[...]_ => 4, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_int(0); + +// gdb-command: s +// gdb-check:[...]match y { + +// gdb-command: s +// gdb-check:[...]0 => 2, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_int(-1); + +// gdb-command: s +// gdb-check:[...]match y { + +// gdb-command: s +// gdb-check:[...]-1 => 1, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_tuple(5, 12); + +// gdb-command: s +// gdb-check:[...]match (a, b) { + +// gdb-command: s +// gdb-check:[...](5, 12) => 3, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_tuple(29, 1); + +// gdb-command: s +// gdb-check:[...]match (a, b) { + +// gdb-command: s +// gdb-check:[...](29, _) => 2, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_tuple(12, 12); + +// gdb-command: s +// gdb-check:[...]match (a, b) { + +// gdb-command: s +// gdb-check:[...](_, _) => 5 + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_tuple(42, 12); + +// gdb-command: s +// gdb-check:[...]match (a, b) { + +// gdb-command: s +// gdb-check:[...](42, 12) => 1, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]match_tuple(1, 9); + +// gdb-command: s +// gdb-check:[...]match (a, b) { + +// gdb-command: s +// gdb-check:[...](_, 9) => 4, + +// gdb-command: s +// gdb-check:[...]} + +// gdb-command: s +// gdb-check:[...]} + +// === CDB TESTS ============================================================== + +// Enable line-based debugging and print lines after stepping. +// cdb-command: .lines -e +// cdb-command: l+s +// cdb-command: l+t + +// cdb-command: g + +// cdb-command: t +// cdb-check: [...]: fn match_enum(x: Option) -> u8 { + +// cdb-command: t +// cdb-check: [...]: match x { + +// cdb-command: t +// cdb-check: [...]: Some(42) => 1, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_enum(Some(12)); + +// cdb-command: t +// cdb-check: [...]: fn match_enum(x: Option) -> u8 { + +// cdb-command: t +// cdb-check: [...]: match x { + +// cdb-command: t +// cdb-check: [...]: Some(_) => 2, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_enum(None); + +// cdb-command: t +// cdb-check: [...]: fn match_enum(x: Option) -> u8 { + +// cdb-command: t +// cdb-check: [...]: match x { + +// cdb-command: t +// cdb-check: [...]: None => 3, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_int(1); + +// cdb-command: t +// cdb-check: [...]: fn match_int(y: i32) -> u16 { + +// cdb-command: t +// cdb-check: [...]: match y { + +// cdb-command: t +// cdb-check: [...]: 1 => 3, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_int(2); + +// cdb-command: t +// cdb-check: [...]: fn match_int(y: i32) -> u16 { + +// cdb-command: t +// cdb-check: [...]: match y { + +// cdb-command: t +// cdb-check: [...]: _ => 4, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_int(0); + +// cdb-command: t +// cdb-check: [...]: fn match_int(y: i32) -> u16 { + +// cdb-command: t +// cdb-check: [...]: match y { + +// cdb-command: t +// cdb-check: [...]: 0 => 2, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_int(-1); + +// cdb-command: t +// cdb-check: [...]: fn match_int(y: i32) -> u16 { + +// cdb-command: t +// cdb-check: [...]: match y { + +// cdb-command: t +// cdb-check: [...]: -1 => 1, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_tuple(5, 12); + +// cdb-command: t +// cdb-check: [...]: fn match_tuple(a: u8, b: i8) -> u32 { + +// cdb-command: t +// cdb-check: [...]: match (a, b) { + +// cdb-command: t +// cdb-check: [...]: (5, 12) => 3, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_tuple(29, 1); + +// cdb-command: t +// cdb-check: [...]: fn match_tuple(a: u8, b: i8) -> u32 { + +// cdb-command: t +// cdb-check: [...]: match (a, b) { + +// cdb-command: t +// cdb-check: [...]: (29, _) => 2, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_tuple(12, 12); + +// cdb-command: t +// cdb-check: [...]: fn match_tuple(a: u8, b: i8) -> u32 { + +// cdb-command: t +// cdb-check: [...]: match (a, b) { + +// cdb-command: t +// cdb-check: [...]: (_, _) => 5 + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_tuple(42, 12); + +// cdb-command: t +// cdb-check: [...]: fn match_tuple(a: u8, b: i8) -> u32 { + +// cdb-command: t +// cdb-check: [...]: match (a, b) { + +// cdb-command: t +// cdb-check: [...]: (42, 12) => 1, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: match_tuple(1, 9); + +// cdb-command: t +// cdb-check: [...]: fn match_tuple(a: u8, b: i8) -> u32 { + +// cdb-command: t +// cdb-check: [...]: match (a, b) { + +// cdb-command: t +// cdb-check: [...]: (_, 9) => 4, + +// cdb-command: t +// cdb-check: [...]: } + +// cdb-command: t +// cdb-check: [...]: } + +fn main() { + match_enum(Some(42)); // #break + match_enum(Some(12)); + match_enum(None); + + match_int(1); + match_int(2); + match_int(0); + match_int(-1); + + match_tuple(5, 12); + match_tuple(29, 1); + match_tuple(12, 12); + match_tuple(42, 12); + match_tuple(1, 9); +} + +fn match_enum(x: Option) -> u8 { + match x { + Some(42) => 1, + Some(_) => 2, + None => 3, + } +} + +fn match_int(y: i32) -> u16 { + match y { + -1 => 1, + 0 => 2, + 1 => 3, + _ => 4, + } +} + +fn match_tuple(a: u8, b: i8) -> u32 { + match (a, b) { + (42, 12) => 1, + (29, _) => 2, + (5, 12) => 3, + (_, 9) => 4, + (_, _) => 5 + } +} From 118df1cd6bca455498f6ef0a55133d99dfe99f0d Mon Sep 17 00:00:00 2001 From: 12101111 Date: Sun, 22 Aug 2021 15:54:03 +0800 Subject: [PATCH 34/36] Adjust linking order of static nobundle libraries Link the static libraries with "-bundle" modifier from upstream rust crate right after linking this rust crate. Some linker such as GNU linker `ld.bdf` treat order of linking as order of dependency. After this change, static libraries with "-bundle" modifier is linked in the same order as "+bundle" modifier. So we can change the value of "bundle" modifier without causing linking error. --- compiler/rustc_codegen_ssa/src/back/link.rs | 69 ++++++++++----------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index f3eb1e04d07dc..e51d6fff78847 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -1803,15 +1803,16 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>( add_local_native_libraries(cmd, sess, codegen_results); } - // Rust libraries. + // Upstream rust libraries and their nobundle static libraries add_upstream_rust_crates::(cmd, sess, codegen_results, crate_type, tmpdir); - // Native libraries linked with `#[link]` attributes at and `-l` command line options. + // Upstream dymamic native libraries linked with `#[link]` attributes at and `-l` + // command line options. // If -Zlink-native-libraries=false is set, then the assumption is that an // external build system already has the native dependencies defined, and it // will provide them to the linker itself. if sess.opts.debugging_opts.link_native_libraries { - add_upstream_native_libraries(cmd, sess, codegen_results, crate_type); + add_upstream_native_libraries(cmd, sess, codegen_results); } // Library linking above uses some global state for things like `-Bstatic`/`-Bdynamic` to make @@ -2033,7 +2034,7 @@ fn add_local_native_libraries( } } -/// # Rust Crate linking +/// # Linking Rust crates and their nobundle static libraries /// /// Rust crates are not considered at all when creating an rlib output. All dependencies will be /// linked when producing the final output (instead of the intermediate rlib version). @@ -2138,6 +2139,29 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>( Linkage::NotLinked | Linkage::IncludedFromDylib => {} Linkage::Static => { add_static_crate::(cmd, sess, codegen_results, tmpdir, crate_type, cnum); + + // Link static native libs with "-bundle" modifier only if the crate they originate from + // is being linked statically to the current crate. If it's linked dynamically + // or is an rlib already included via some other dylib crate, the symbols from + // native libs will have already been included in that dylib. + // + // If -Zlink-native-libraries=false is set, then the assumption is that an + // external build system already has the native dependencies defined, and it + // will provide them to the linker itself. + if sess.opts.debugging_opts.link_native_libraries { + // Skip if this library is the same as the last. + let mut last = None; + for lib in &codegen_results.crate_info.native_libraries[&cnum] { + if lib.name.is_some() + && relevant_lib(sess, lib) + && matches!(lib.kind, NativeLibKind::Static { bundle: Some(false), .. }) + && last != lib.name + { + cmd.link_staticlib(lib.name.unwrap(), lib.verbatim.unwrap_or(false)); + last = lib.name; + } + } + } } Linkage::Dynamic => add_dynamic_crate(cmd, sess, &src.dylib.as_ref().unwrap().0), } @@ -2310,27 +2334,9 @@ fn add_upstream_native_libraries( cmd: &mut dyn Linker, sess: &Session, codegen_results: &CodegenResults, - crate_type: CrateType, ) { - // Be sure to use a topological sorting of crates because there may be - // interdependencies between native libraries. When passing -nodefaultlibs, - // for example, almost all native libraries depend on libc, so we have to - // make sure that's all the way at the right (liblibc is near the base of - // the dependency chain). - // - // This passes RequireStatic, but the actual requirement doesn't matter, - // we're just getting an ordering of crate numbers, we're not worried about - // the paths. - let (_, data) = codegen_results - .crate_info - .dependency_formats - .iter() - .find(|(ty, _)| *ty == crate_type) - .expect("failed to find crate type in dependency format list"); - - let crates = &codegen_results.crate_info.used_crates; let mut last = (NativeLibKind::Unspecified, None); - for &cnum in crates { + for &cnum in &codegen_results.crate_info.used_crates { for lib in codegen_results.crate_info.native_libraries[&cnum].iter() { let name = match lib.name { Some(l) => l, @@ -2352,19 +2358,10 @@ fn add_upstream_native_libraries( NativeLibKind::Framework { as_needed } => { cmd.link_framework(name, as_needed.unwrap_or(true)) } - NativeLibKind::Static { bundle: Some(false), .. } => { - // Link "static-nobundle" native libs only if the crate they originate from - // is being linked statically to the current crate. If it's linked dynamically - // or is an rlib already included via some other dylib crate, the symbols from - // native libs will have already been included in that dylib. - if data[cnum.as_usize() - 1] == Linkage::Static { - cmd.link_staticlib(name, verbatim) - } - } - // ignore statically included native libraries here as we've - // already included them when we included the rust library - // previously - NativeLibKind::Static { bundle: None | Some(true), .. } => {} + // ignore static native libraries here as we've + // already included them in add_local_native_libraries and + // add_upstream_rust_crates + NativeLibKind::Static { .. } => {} NativeLibKind::RawDylib => {} } } From 4924e34526cc8098d36ad60ed974dbe6484ac519 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Wed, 25 Aug 2021 12:49:39 -0300 Subject: [PATCH 35/36] Add argument types tait tests --- .../type-alias-impl-trait/argument-types.rs | 28 +++++++++++++++++++ .../argument-types.stderr | 15 ++++++++++ 2 files changed, 43 insertions(+) create mode 100644 src/test/ui/type-alias-impl-trait/argument-types.rs create mode 100644 src/test/ui/type-alias-impl-trait/argument-types.stderr diff --git a/src/test/ui/type-alias-impl-trait/argument-types.rs b/src/test/ui/type-alias-impl-trait/argument-types.rs new file mode 100644 index 0000000000000..8427b5b1fe854 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/argument-types.rs @@ -0,0 +1,28 @@ +#![feature(type_alias_impl_trait)] +#![allow(dead_code)] + +use std::fmt::Debug; + +type Foo = impl Debug; + +// FIXME: This should compile, but it currently doesn't +fn foo1(mut x: Foo) { + x = 22_u32; + //~^ ERROR: mismatched types [E0308] +} + +fn foo2(mut x: Foo) { + // no constraint on x +} + +fn foo3(x: Foo) { + println!("{:?}", x); +} + +fn foo_value() -> Foo { + 11_u32 +} + +fn main() { + foo3(foo_value()); +} diff --git a/src/test/ui/type-alias-impl-trait/argument-types.stderr b/src/test/ui/type-alias-impl-trait/argument-types.stderr new file mode 100644 index 0000000000000..1cbf9c95d3148 --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/argument-types.stderr @@ -0,0 +1,15 @@ +error[E0308]: mismatched types + --> $DIR/argument-types.rs:10:9 + | +LL | type Foo = impl Debug; + | ---------- the expected opaque type +... +LL | x = 22_u32; + | ^^^^^^ expected opaque type, found `u32` + | + = note: expected opaque type `impl Debug` + found type `u32` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. From 027db5d036768ba8b0e36cb1b9f3f0ed1e3da000 Mon Sep 17 00:00:00 2001 From: Augie Fackler Date: Tue, 24 Aug 2021 09:44:17 -0400 Subject: [PATCH 36/36] RustWrapper: adapt to LLVM change 0f45c16f2caa The above-mentioned commit (part of the LLVM 14 development cycle) removes a method that rustc uses somewhat extensively. We mostly switch to lower-level methods that exist in all versions of LLVM we use, so no new ifdef logic is required in most cases. --- .../rustc_llvm/llvm-wrapper/RustWrapper.cpp | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index 4edfed0340187..4f07a0c67c13f 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -270,34 +270,30 @@ extern "C" void LLVMRustAddFunctionAttribute(LLVMValueRef Fn, unsigned Index, LLVMRustAttribute RustAttr) { Function *A = unwrap(Fn); Attribute Attr = Attribute::get(A->getContext(), fromRust(RustAttr)); - AttrBuilder B(Attr); - A->addAttributes(Index, B); + A->addAttribute(Index, Attr); } extern "C" void LLVMRustAddAlignmentAttr(LLVMValueRef Fn, unsigned Index, uint32_t Bytes) { Function *A = unwrap(Fn); - AttrBuilder B; - B.addAlignmentAttr(Bytes); - A->addAttributes(Index, B); + A->addAttribute(Index, Attribute::getWithAlignment( + A->getContext(), llvm::Align(Bytes))); } extern "C" void LLVMRustAddDereferenceableAttr(LLVMValueRef Fn, unsigned Index, uint64_t Bytes) { Function *A = unwrap(Fn); - AttrBuilder B; - B.addDereferenceableAttr(Bytes); - A->addAttributes(Index, B); + A->addAttribute(Index, Attribute::getWithDereferenceableBytes(A->getContext(), + Bytes)); } extern "C" void LLVMRustAddDereferenceableOrNullAttr(LLVMValueRef Fn, unsigned Index, uint64_t Bytes) { Function *A = unwrap(Fn); - AttrBuilder B; - B.addDereferenceableOrNullAttr(Bytes); - A->addAttributes(Index, B); + A->addAttribute(Index, Attribute::getWithDereferenceableOrNullBytes( + A->getContext(), Bytes)); } extern "C" void LLVMRustAddByValAttr(LLVMValueRef Fn, unsigned Index, @@ -323,9 +319,8 @@ extern "C" void LLVMRustAddFunctionAttrStringValue(LLVMValueRef Fn, const char *Name, const char *Value) { Function *F = unwrap(Fn); - AttrBuilder B; - B.addAttribute(Name, Value); - F->addAttributes(Index, B); + F->addAttribute(Index, Attribute::get( + F->getContext(), StringRef(Name), StringRef(Value))); } extern "C" void LLVMRustRemoveFunctionAttributes(LLVMValueRef Fn,