Skip to content

Shrink span for bindings with subpatterns. #101399

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1036,7 +1036,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
VarBindingForm {
binding_mode,
opt_ty_info,
opt_match_place: Some((Some(place), span)),
opt_match_place: Some((None, span)),
pat_span: span,
},
)))))
Expand Down
7 changes: 6 additions & 1 deletion compiler/rustc_mir_build/src/thir/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {

fn lower_pattern_unadjusted(&mut self, pat: &'tcx hir::Pat<'tcx>) -> Box<Pat<'tcx>> {
let mut ty = self.typeck_results.node_type(pat.hir_id);
let mut span = pat.span;

let kind = match pat.kind {
hir::PatKind::Wild => PatKind::Wild,
Expand Down Expand Up @@ -262,6 +263,10 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
}

hir::PatKind::Binding(_, id, ident, ref sub) => {
if let Some(ident_span) = ident.span.find_ancestor_inside(span) {
span = span.with_hi(ident_span.hi());
}

let bm = *self
.typeck_results
.pat_binding_modes()
Expand Down Expand Up @@ -326,7 +331,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
hir::PatKind::Or(ref pats) => PatKind::Or { pats: self.lower_patterns(pats) },
};

Box::new(Pat { span: pat.span, ty, kind })
Box::new(Pat { span, ty, kind })
}

fn lower_tuple_subpats(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ fn match_tuple(_1: (u32, bool, Option<i32>, u32)) -> u32 {
let mut _4: bool; // in scope 0 at $DIR/exponential-or.rs:+2:70: +2:77
let mut _5: bool; // in scope 0 at $DIR/exponential-or.rs:+2:62: +2:67
let mut _6: bool; // in scope 0 at $DIR/exponential-or.rs:+2:62: +2:67
let _7: u32; // in scope 0 at $DIR/exponential-or.rs:+2:10: +2:21
let _8: u32; // in scope 0 at $DIR/exponential-or.rs:+2:57: +2:78
let _7: u32; // in scope 0 at $DIR/exponential-or.rs:+2:10: +2:11
let _8: u32; // in scope 0 at $DIR/exponential-or.rs:+2:57: +2:58
let mut _9: u32; // in scope 0 at $DIR/exponential-or.rs:+2:83: +2:84
let mut _10: u32; // in scope 0 at $DIR/exponential-or.rs:+2:87: +2:88
scope 1 {
debug y => _7; // in scope 1 at $DIR/exponential-or.rs:+2:10: +2:21
debug z => _8; // in scope 1 at $DIR/exponential-or.rs:+2:57: +2:78
debug y => _7; // in scope 1 at $DIR/exponential-or.rs:+2:10: +2:11
debug z => _8; // in scope 1 at $DIR/exponential-or.rs:+2:57: +2:58
}

bb0: {
Expand Down Expand Up @@ -61,10 +61,10 @@ fn match_tuple(_1: (u32, bool, Option<i32>, u32)) -> u32 {
}

bb9: {
StorageLive(_7); // scope 0 at $DIR/exponential-or.rs:+2:10: +2:21
_7 = (_1.0: u32); // scope 0 at $DIR/exponential-or.rs:+2:10: +2:21
StorageLive(_8); // scope 0 at $DIR/exponential-or.rs:+2:57: +2:78
_8 = (_1.3: u32); // scope 0 at $DIR/exponential-or.rs:+2:57: +2:78
StorageLive(_7); // scope 0 at $DIR/exponential-or.rs:+2:10: +2:11
_7 = (_1.0: u32); // scope 0 at $DIR/exponential-or.rs:+2:10: +2:11
StorageLive(_8); // scope 0 at $DIR/exponential-or.rs:+2:57: +2:58
_8 = (_1.3: u32); // scope 0 at $DIR/exponential-or.rs:+2:57: +2:58
StorageLive(_9); // scope 1 at $DIR/exponential-or.rs:+2:83: +2:84
_9 = _7; // scope 1 at $DIR/exponential-or.rs:+2:83: +2:84
StorageLive(_10); // scope 1 at $DIR/exponential-or.rs:+2:87: +2:88
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ fn move_out_by_subslice() -> () {
let mut _11: std::boxed::Box<i32>; // in scope 0 at $DIR/uniform_array_move_out.rs:+1:21: +1:26
scope 1 {
debug a => _1; // in scope 1 at $DIR/uniform_array_move_out.rs:+1:9: +1:10
let _12: [std::boxed::Box<i32>; 2]; // in scope 1 at $DIR/uniform_array_move_out.rs:+2:10: +2:17
let _12: [std::boxed::Box<i32>; 2]; // in scope 1 at $DIR/uniform_array_move_out.rs:+2:10: +2:12
scope 4 {
debug _y => _12; // in scope 4 at $DIR/uniform_array_move_out.rs:+2:10: +2:17
debug _y => _12; // in scope 4 at $DIR/uniform_array_move_out.rs:+2:10: +2:12
}
}
scope 2 {
Expand Down Expand Up @@ -77,8 +77,8 @@ fn move_out_by_subslice() -> () {
bb6: {
StorageDead(_2); // scope 0 at $DIR/uniform_array_move_out.rs:+1:26: +1:27
FakeRead(ForLet(None), _1); // scope 0 at $DIR/uniform_array_move_out.rs:+1:9: +1:10
StorageLive(_12); // scope 1 at $DIR/uniform_array_move_out.rs:+2:10: +2:17
_12 = move _1[0..2]; // scope 1 at $DIR/uniform_array_move_out.rs:+2:10: +2:17
StorageLive(_12); // scope 1 at $DIR/uniform_array_move_out.rs:+2:10: +2:12
_12 = move _1[0..2]; // scope 1 at $DIR/uniform_array_move_out.rs:+2:10: +2:12
_0 = const (); // scope 0 at $DIR/uniform_array_move_out.rs:+0:27: +3:2
drop(_12) -> [return: bb7, unwind: bb9]; // scope 1 at $DIR/uniform_array_move_out.rs:+3:1: +3:2
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ LL | fn bindings_after_at_slice_patterns_move_binding(x: [String; 4]) {
| - move occurs because `x` has type `[String; 4]`, which does not implement the `Copy` trait
LL | match x {
LL | a @ [.., _] => (),
| ----------- value moved here
| - value moved here
...
LL | &x;
| ^^ value borrowed here after move
Expand All @@ -32,7 +32,7 @@ error[E0502]: cannot borrow `x` as immutable because it is also borrowed as muta
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:28:5
|
LL | ref mut foo @ [.., _] => Some(foo),
| --------------------- mutable borrow occurs here
| ----------- mutable borrow occurs here
...
LL | &x;
| ^^ immutable borrow occurs here
Expand All @@ -44,7 +44,7 @@ error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immuta
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:50:5
|
LL | [ref foo @ .., ref bar] => Some(foo),
| ------------ immutable borrow occurs here
| ------- immutable borrow occurs here
...
LL | &mut x;
| ^^^^^^ mutable borrow occurs here
Expand All @@ -56,7 +56,7 @@ error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immuta
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:62:5
|
LL | ref foo @ [.., ref bar] => Some(foo),
| ----------------------- immutable borrow occurs here
| ------- immutable borrow occurs here
...
LL | &mut x;
| ^^^^^^ mutable borrow occurs here
Expand All @@ -71,7 +71,7 @@ LL | fn bindings_after_at_or_patterns_move(x: Option<Test>) {
| - move occurs because `x` has type `Option<Test>`, which does not implement the `Copy` trait
LL | match x {
LL | foo @ Some(Test::Foo | Test::Bar) => (),
| ---------------------------------
| ---
| |
| value moved here
| value moved here
Expand All @@ -83,7 +83,7 @@ error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immuta
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:86:5
|
LL | ref foo @ Some(Test::Foo | Test::Bar) => Some(foo),
| ------------------------------------- immutable borrow occurs here
| ------- immutable borrow occurs here
...
LL | &mut x;
| ^^^^^^ mutable borrow occurs here
Expand All @@ -95,7 +95,7 @@ error[E0502]: cannot borrow `x` as immutable because it is also borrowed as muta
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:98:5
|
LL | ref mut foo @ Some(Test::Foo | Test::Bar) => Some(foo),
| ----------------------------------------- mutable borrow occurs here
| ----------- mutable borrow occurs here
...
LL | &x;
| ^^ immutable borrow occurs here
Expand All @@ -107,7 +107,7 @@ error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immuta
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:112:5
|
LL | ref foo @ Some(box ref s) => Some(foo),
| ------------------------- immutable borrow occurs here
| ------- immutable borrow occurs here
...
LL | &mut x;
| ^^^^^^ mutable borrow occurs here
Expand All @@ -122,7 +122,7 @@ LL | fn bindings_after_at_slice_patterns_or_patterns_moves(x: [Option<Test>; 4])
| - move occurs because `x` has type `[Option<Test>; 4]`, which does not implement the `Copy` trait
LL | match x {
LL | a @ [.., Some(Test::Foo | Test::Bar)] => (),
| -------------------------------------
| -
| |
| value moved here
| value moved here
Expand All @@ -134,7 +134,7 @@ error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immuta
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:144:5
|
LL | ref a @ [ref b @ .., Some(Test::Foo | Test::Bar)] => Some(a),
| ------------------------------------------------- immutable borrow occurs here
| ----- immutable borrow occurs here
...
LL | &mut x;
| ^^^^^^ mutable borrow occurs here
Expand All @@ -146,7 +146,7 @@ error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immuta
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:156:5
|
LL | ref a @ [ref b @ .., Some(Test::Foo | Test::Bar)] => Some(b),
| ---------- immutable borrow occurs here
| ----- immutable borrow occurs here
...
LL | &mut x;
| ^^^^^^ mutable borrow occurs here
Expand All @@ -158,7 +158,7 @@ error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immuta
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:170:5
|
LL | [_, ref a @ Some(box ref b), ..] => Some(a),
| ----------------------- immutable borrow occurs here
| ----- immutable borrow occurs here
...
LL | &mut x;
| ^^^^^^ mutable borrow occurs here
Expand All @@ -170,7 +170,7 @@ error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immuta
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:186:5
|
LL | [_, ref a @ Some(box Test::Foo | box Test::Bar), ..] => Some(a),
| ------------------------------------------- immutable borrow occurs here
| ----- immutable borrow occurs here
...
LL | &mut x;
| ^^^^^^ mutable borrow occurs here
Expand All @@ -182,7 +182,7 @@ error[E0502]: cannot borrow `x` as immutable because it is also borrowed as muta
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:200:5
|
LL | [_, ref mut a @ Some(box Test::Foo | box Test::Bar), ..] => Some(a),
| ----------------------------------------------- mutable borrow occurs here
| --------- mutable borrow occurs here
...
LL | &x;
| ^^ immutable borrow occurs here
Expand All @@ -194,7 +194,7 @@ error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immuta
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:214:5
|
LL | ref a @ [_, ref b @ Some(box Test::Foo | box Test::Bar), ..] => Some(a),
| ------------------------------------------------------------ immutable borrow occurs here
| ----- immutable borrow occurs here
...
LL | &mut x;
| ^^^^^^ mutable borrow occurs here
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/borrowck/borrowck-describe-lvalue.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ LL | let x = &mut v;
| ------ borrow of `v` occurs here
LL | match v {
LL | &[x @ ..] => println!("{:?}", x),
| ^^^^^^ use of borrowed `v`
| ^ use of borrowed `v`
...
LL | drop(x);
| - borrow later used here
Expand All @@ -212,7 +212,7 @@ LL | let x = &mut v;
| ------ borrow of `v` occurs here
...
LL | &[_, x @ ..] => println!("{:?}", x),
| ^^^^^^ use of borrowed `v`
| ^ use of borrowed `v`
...
LL | drop(x);
| - borrow later used here
Expand All @@ -224,7 +224,7 @@ LL | let x = &mut v;
| ------ borrow of `v` occurs here
...
LL | &[x @ .., _] => println!("{:?}", x),
| ^^^^^^ use of borrowed `v`
| ^ use of borrowed `v`
...
LL | drop(x);
| - borrow later used here
Expand All @@ -236,7 +236,7 @@ LL | let x = &mut v;
| ------ borrow of `v` occurs here
...
LL | &[_, x @ .., _] => println!("{:?}", x),
| ^^^^^^ use of borrowed `v`
| ^ use of borrowed `v`
...
LL | drop(x);
| - borrow later used here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ error[E0382]: use of moved value: `a[..].0`
--> $DIR/borrowck-move-out-from-array-match.rs:89:11
|
LL | [_y @ .., _, _] => {}
| ------- value moved here
| -- value moved here
...
LL | [(_x, _), _, _] => {}
| ^^ value used here after move
Expand All @@ -90,7 +90,7 @@ error[E0382]: use of moved value: `a[..].0`
--> $DIR/borrowck-move-out-from-array-match.rs:99:15
|
LL | [_, _, _y @ ..] => {}
| ------- value moved here
| -- value moved here
...
LL | [.., (_x, _)] => {}
| ^^ value used here after move
Expand All @@ -101,7 +101,7 @@ error[E0382]: use of partially moved value: `a`
--> $DIR/borrowck-move-out-from-array-match.rs:110:11
|
LL | [x @ .., _] => {}
| ------ value partially moved here
| - value partially moved here
LL | }
LL | match a {
| ^ value used here after partial move
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ error[E0382]: use of partially moved value: `a`
--> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:85:11
|
LL | [_, _y @ ..] => {}
| ------- value partially moved here
| -- value partially moved here
LL | }
LL | match a {
| ^ value used here after partial move
Expand All @@ -79,7 +79,7 @@ error[E0382]: use of partially moved value: `a`
--> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:96:11
|
LL | [_y @ .., _] => {}
| ------- value partially moved here
| -- value partially moved here
LL | }
LL | match a {
| ^ value used here after partial move
Expand All @@ -90,7 +90,7 @@ error[E0382]: use of partially moved value: `a`
--> $DIR/borrowck-move-out-from-array-no-overlap-match.rs:109:11
|
LL | [x @ .., _, _] => {}
| ------ value partially moved here
| - value partially moved here
LL | }
LL | match a {
| ^ value used here after partial move
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ error[E0382]: borrow of moved value: `a[..]`
--> $DIR/borrowck-move-out-from-array-use-match.rs:89:11
|
LL | [_y @ .., _, _] => {}
| ------- value moved here
| -- value moved here
...
LL | [(ref _x, _), _, _] => {}
| ^^^^^^ value borrowed here after move
Expand All @@ -90,7 +90,7 @@ error[E0382]: borrow of moved value: `a[..]`
--> $DIR/borrowck-move-out-from-array-use-match.rs:99:15
|
LL | [_, _, _y @ ..] => {}
| ------- value moved here
| -- value moved here
...
LL | [.., (ref _x, _)] => {}
| ^^^^^^ value borrowed here after move
Expand All @@ -101,7 +101,7 @@ error[E0382]: use of partially moved value: `a`
--> $DIR/borrowck-move-out-from-array-use-match.rs:110:11
|
LL | [x @ .., _] => {}
| ------ value partially moved here
| - value partially moved here
LL | }
LL | match a {
| ^ value used here after partial move
Expand Down Expand Up @@ -134,7 +134,7 @@ error[E0382]: use of partially moved value: `a`
--> $DIR/borrowck-move-out-from-array-use-match.rs:139:5
|
LL | [_, _, _x @ ..] => {}
| ------- value partially moved here
| -- value partially moved here
LL | }
LL | a[0] = Default::default();
| ^^^^ value used here after partial move
Expand All @@ -145,7 +145,7 @@ error[E0382]: use of partially moved value: `a`
--> $DIR/borrowck-move-out-from-array-use-match.rs:147:5
|
LL | [_, _, _x @ ..] => {}
| ------- value partially moved here
| -- value partially moved here
LL | }
LL | a[0].1 = Default::default();
| ^^^^ value used here after partial move
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ error[E0382]: use of partially moved value: `a`
--> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:85:11
|
LL | [_, _y @ ..] => {}
| ------- value partially moved here
| -- value partially moved here
LL | }
LL | match a {
| ^ value used here after partial move
Expand All @@ -79,7 +79,7 @@ error[E0382]: use of partially moved value: `a`
--> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:96:11
|
LL | [_y @ .., _] => {}
| ------- value partially moved here
| -- value partially moved here
LL | }
LL | match a {
| ^ value used here after partial move
Expand All @@ -90,7 +90,7 @@ error[E0382]: use of partially moved value: `a`
--> $DIR/borrowck-move-out-from-array-use-no-overlap-match.rs:109:11
|
LL | [x @ .., _, _] => {}
| ------ value partially moved here
| - value partially moved here
LL | }
LL | match a {
| ^ value used here after partial move
Expand Down
Loading