Skip to content

Commit df37678

Browse files
committed
add FIXME related to ref x bindings
1 parent 2b6f966 commit df37678

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

src/librustc_mir/build/matches/mod.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
475475
pub fn visit_bindings(
476476
&mut self,
477477
pattern: &Pattern<'tcx>,
478-
pattern_user_ty: Option<CanonicalTy<'tcx>>,
478+
mut pattern_user_ty: Option<CanonicalTy<'tcx>>,
479479
f: &mut impl FnMut(
480480
&mut Self,
481481
Mutability,
@@ -497,6 +497,19 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
497497
ref subpattern,
498498
..
499499
} => {
500+
match mode {
501+
BindingMode::ByValue => { }
502+
BindingMode::ByRef(..) => {
503+
// If this is a `ref` binding (e.g., `let ref
504+
// x: T = ..`), then the type of `x` is not
505+
// `T` but rather `&T`, so ignore
506+
// `pattern_user_ty` for now.
507+
//
508+
// FIXME(#47184): extract or handle `pattern_user_ty` somehow
509+
pattern_user_ty = None;
510+
}
511+
}
512+
500513
f(self, mutability, name, mode, var, pattern.span, ty, pattern_user_ty);
501514
if let Some(subpattern) = subpattern.as_ref() {
502515
self.visit_bindings(subpattern, pattern_user_ty, f);

src/test/ui/nll/user-annotations/patterns.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn ref_with_ascribed_static_type() -> u32 {
2020
// Check the behavior in some wacky cases.
2121
let x = 22;
2222
let y = &x; //~ ERROR
23-
let ref z: &'static u32 = y; //~ ERROR
23+
let ref z: &'static u32 = y;
2424
**z
2525
}
2626

src/test/ui/nll/user-annotations/patterns.stderr

+1-12
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,6 @@ LL | }
1919
|
2020
= note: borrowed value must be valid for the static lifetime...
2121

22-
error[E0597]: `y` does not live long enough
23-
--> $DIR/patterns.rs:23:9
24-
|
25-
LL | let ref z: &'static u32 = y; //~ ERROR
26-
| ^^^^^ borrowed value does not live long enough
27-
LL | **z
28-
LL | }
29-
| - `y` dropped here while still borrowed
30-
|
31-
= note: borrowed value must be valid for the static lifetime...
32-
3322
error[E0597]: `x` does not live long enough
3423
--> $DIR/patterns.rs:46:27
3524
|
@@ -149,6 +138,6 @@ LL | fn a_to_static_then_static<'a>(x: &'a u32) -> &'static u32 {
149138
LL | let (y, _z): (&'static u32, u32) = (x, 44); //~ ERROR
150139
| ^^^^^^^ requires that `'a` must outlive `'static`
151140

152-
error: aborting due to 15 previous errors
141+
error: aborting due to 14 previous errors
153142

154143
For more information about this error, try `rustc --explain E0597`.

0 commit comments

Comments
 (0)