Use better spans for dummy accesses used in matches

This commit is contained in:
Matthew Jasper 2018-07-22 21:13:18 +01:00
parent 45b48b9b6d
commit 71637c2937
10 changed files with 85 additions and 134 deletions

View File

@ -63,13 +63,13 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
// injects a borrow of the matched input, which should have the same effect
// as eddyb's hack. Once NLL is the default, we can remove the hack.
let dummy_source_info = self.source_info(span);
let dummy_source_info = self.source_info(discriminant_span);
let dummy_access = Rvalue::Discriminant(discriminant_place.clone());
let dummy_ty = dummy_access.ty(&self.local_decls, tcx);
let dummy_temp = self.temp(dummy_ty, dummy_source_info.span);
self.cfg.push_assign(block, dummy_source_info, &dummy_temp, dummy_access);
let source_info = self.source_info(span);
let source_info = self.source_info(discriminant_span);
let borrowed_input_temp = if tcx.generate_borrow_of_any_match_input() {
// The region is unknown at this point; we rely on NLL
// inference to find an appropriate one. Therefore you can
@ -134,9 +134,9 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
// This should ensure that you cannot change
// the variant for an enum while you are in
// the midst of matching on it.
let pattern_source_info = self.source_info(pattern.span);
self.cfg.push(*pre_binding_block, Statement {
source_info,
source_info: pattern_source_info,
kind: StatementKind::ReadForMatch(borrow_temp.clone()),
});
}

View File

@ -17,26 +17,22 @@ LL | if let Some(thing) = maybe {
= note: move occurs because the value has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `maybe` (Mir)
--> $DIR/issue-41962.rs:17:9
--> $DIR/issue-41962.rs:17:30
|
LL | if let Some(thing) = maybe {
| ^ ----- value moved here
| _________|
| |
LL | | }
| |_________^ value used here after move
LL | if let Some(thing) = maybe {
| ----- ^^^^^ value used here after move
| |
| value moved here
|
= note: move occurs because value has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `maybe` (Mir)
--> $DIR/issue-41962.rs:17:9
--> $DIR/issue-41962.rs:17:30
|
LL | if let Some(thing) = maybe {
| ^ ----- value moved here
| _________|
| |
LL | | }
| |_________^ value borrowed here after move
LL | if let Some(thing) = maybe {
| ----- ^^^^^ value borrowed here after move
| |
| value moved here
|
= note: move occurs because value has type `std::vec::Vec<bool>`, which does not implement the `Copy` trait

View File

@ -1,26 +1,20 @@
error[E0382]: use of moved value: `foo`
--> $DIR/issue-17385.rs:28:5
--> $DIR/issue-17385.rs:28:11
|
LL | drop(foo);
| --- value moved here
LL | / match foo { //~ ERROR use of moved value
LL | | X(1) => (),
LL | | _ => unreachable!()
LL | | }
| |_____^ value used here after move
LL | drop(foo);
| --- value moved here
LL | match foo { //~ ERROR use of moved value
| ^^^ value used here after move
|
= note: move occurs because `foo` has type `X`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `foo`
--> $DIR/issue-17385.rs:28:5
--> $DIR/issue-17385.rs:28:11
|
LL | drop(foo);
| --- value moved here
LL | / match foo { //~ ERROR use of moved value
LL | | X(1) => (),
LL | | _ => unreachable!()
LL | | }
| |_____^ value borrowed here after move
LL | drop(foo);
| --- value moved here
LL | match foo { //~ ERROR use of moved value
| ^^^ value borrowed here after move
|
= note: move occurs because `foo` has type `X`, which does not implement the `Copy` trait
@ -36,28 +30,22 @@ LL | X(1) => (),
= note: move occurs because `foo` has type `X`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `e`
--> $DIR/issue-17385.rs:35:5
--> $DIR/issue-17385.rs:35:11
|
LL | drop(e);
| - value moved here
LL | / match e { //~ ERROR use of moved value
LL | | Enum::Variant1 => unreachable!(),
LL | | Enum::Variant2 => ()
LL | | }
| |_____^ value used here after move
LL | drop(e);
| - value moved here
LL | match e { //~ ERROR use of moved value
| ^ value used here after move
|
= note: move occurs because `e` has type `Enum`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `e`
--> $DIR/issue-17385.rs:35:5
--> $DIR/issue-17385.rs:35:11
|
LL | drop(e);
| - value moved here
LL | / match e { //~ ERROR use of moved value
LL | | Enum::Variant1 => unreachable!(),
LL | | Enum::Variant2 => ()
LL | | }
| |_____^ value borrowed here after move
LL | drop(e);
| - value moved here
LL | match e { //~ ERROR use of moved value
| ^ value borrowed here after move
|
= note: move occurs because `e` has type `Enum`, which does not implement the `Copy` trait

View File

@ -1,21 +1,14 @@
error[E0505]: cannot move out of `b` because it is borrowed
--> $DIR/issue-27282-move-match-input-into-guard.rs:26:16
|
LL | match b {
| _____-
| |_____|
| ||
LL | || &mut false => {},
LL | || _ if { (|| { let bar = b; *bar = false; })();
| || ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ move out of `b` occurs here
LL | || //~^ ERROR cannot move out of `b` because it is borrowed [E0505]
... ||
LL | || _ => panic!("surely we could never get here, since rustc warns it is unreachable."),
LL | || }
| || -
| ||_____|
| |______borrow of `b` occurs here
| borrow later used here
LL | match b {
| - borrow of `b` occurs here
LL | &mut false => {},
LL | _ if { (|| { let bar = b; *bar = false; })();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ move out of `b` occurs here
...
LL | &mut true => { println!("You might think we should get here"); },
| --------- borrow later used here
error[E0382]: use of moved value: `*b`
--> $DIR/issue-27282-move-match-input-into-guard.rs:29:14

View File

@ -1,24 +1,16 @@
error[E0500]: closure requires unique access to `x` but it is already borrowed
--> $DIR/issue-27282-mutate-before-diverging-arm-1.rs:33:14
|
LL | match x {
| _____-
| |_____|
| ||
LL | || &mut None => panic!("unreachable"),
LL | || &mut Some(&_) if {
LL | || // ForceFnOnce needed to exploit #27282
LL | || (|| { *x = None; drop(force_fn_once); })();
| || ^^ - borrow occurs due to use of `x` in closure
| || |
| || closure construction occurs here
... ||
LL | || _ => panic!("unreachable"),
LL | || }
| || -
| ||_____|
| |______borrow occurs here
| borrow later used here
LL | match x {
| - borrow occurs here
...
LL | (|| { *x = None; drop(force_fn_once); })();
| ^^ - borrow occurs due to use of `x` in closure
| |
| closure construction occurs here
...
LL | &mut Some(&a) if { // this binds to garbage if we've corrupted discriminant
| ------------- borrow later used here
error: aborting due to previous error

View File

@ -1,25 +1,16 @@
error[E0500]: closure requires unique access to `x` but it is already borrowed
--> $DIR/issue-27282-mutate-before-diverging-arm-2.rs:38:18
|
LL | match x {
| _____-
| |_____|
| ||
LL | || &mut None => panic!("unreachable"),
LL | || &mut Some(&_)
LL | || if {
LL | || // ForceFnOnce needed to exploit #27282
LL | || (|| { *x = None; drop(force_fn_once); })();
| || ^^ - borrow occurs due to use of `x` in closure
| || |
| || closure construction occurs here
... ||
LL | || _ => panic!("unreachable"),
LL | || }
| || -
| ||_____|
| |______borrow occurs here
| borrow later used here
LL | match x {
| - borrow occurs here
...
LL | (|| { *x = None; drop(force_fn_once); })();
| ^^ - borrow occurs due to use of `x` in closure
| |
| closure construction occurs here
...
LL | &mut Some(&2)
| ------------- borrow later used here
error: aborting due to previous error

View File

@ -1,16 +1,16 @@
error[E0133]: access to union field is unsafe and requires unsafe function or block
--> $DIR/issue-47412.rs:21:5
--> $DIR/issue-47412.rs:21:11
|
LL | match u.void {}
| ^^^^^^^^^^^^^^^ access to union field
| ^^^^^^ access to union field
|
= note: the field may not be properly initialized: using uninitialized data will cause undefined behavior
error[E0133]: dereference of raw pointer is unsafe and requires unsafe function or block
--> $DIR/issue-47412.rs:27:5
--> $DIR/issue-47412.rs:27:11
|
LL | match *ptr {}
| ^^^^^^^^^^^^^ dereference of raw pointer
| ^^^^ dereference of raw pointer
|
= note: raw pointers may be NULL, dangling or unaligned; they can violate aliasing rules and cause data races: all of these are undefined behavior

View File

@ -5,18 +5,12 @@ LL | other //~ ERROR explicit lifetime
| ^^^^^
error[E0621]: explicit lifetime required in the type of `other`
--> $DIR/ex1-return-one-existing-name-early-bound-in-struct.rs:18:9
--> $DIR/ex1-return-one-existing-name-early-bound-in-struct.rs:18:15
|
LL | fn bar(&self, other: Foo) -> Foo<'a> {
| ----- consider changing the type of `other` to `Foo<'a>`
LL | / match *self {
LL | | Foo::Bar(s) => {
LL | | if s == "test" {
LL | | other //~ ERROR explicit lifetime
... |
LL | | }
LL | | }
| |_________^ lifetime `'a` required
LL | fn bar(&self, other: Foo) -> Foo<'a> {
| ----- consider changing the type of `other` to `Foo<'a>`
LL | match *self {
| ^^^^^ lifetime `'a` required
error: aborting due to previous error

View File

@ -1,17 +1,14 @@
error[E0503]: cannot use `e` because it was mutably borrowed
--> $DIR/borrowed-match-issue-45045.rs:24:5
--> $DIR/borrowed-match-issue-45045.rs:24:11
|
LL | let f = &mut e;
| ------ borrow of `e` occurs here
LL | let g = f;
LL | / match e { //~ cannot use `e` because it was mutably borrowed [E0503]
LL | | Xyz::A => println!("a"),
LL | | //~^ cannot use `e` because it was mutably borrowed [E0503]
LL | | Xyz::B => println!("b"),
LL | | };
| |_____^ use of borrowed `e`
LL | *g = Xyz::B;
| ----------- borrow later used here
LL | let f = &mut e;
| ------ borrow of `e` occurs here
LL | let g = f;
LL | match e { //~ cannot use `e` because it was mutably borrowed [E0503]
| ^ use of borrowed `e`
...
LL | *g = Xyz::B;
| ----------- borrow later used here
error[E0503]: cannot use `e` because it was mutably borrowed
--> $DIR/borrowed-match-issue-45045.rs:25:9

View File

@ -2,11 +2,11 @@ error[E0597]: `foo` does not live long enough
--> $DIR/issue-40157.rs:12:53
|
LL | {println!("{:?}", match { let foo = vec![1, 2]; foo.get(1) } { x => x });}
| ------------------------------^^^--------------------
| | | |
| | | `foo` dropped here while still borrowed
| | borrowed value does not live long enough
| borrow later used here
| ------------------------^^^---------
| | | |
| | | `foo` dropped here while still borrowed
| | borrowed value does not live long enough
| borrow later used here
error: aborting due to previous error