about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2018-09-10 14:06:50 -0400
committerNiko Matsakis <niko@alum.mit.edu>2018-09-10 14:12:20 -0400
commitdf37678b768a6329e6aa418e59bfe07d32580ca5 (patch)
treed2a2ca9645e05472e6479d5edce67072b55f34ae
parent2b6f9664ed7b648c0cccb04f6c67629b167ff11c (diff)
downloadrust-df37678b768a6329e6aa418e59bfe07d32580ca5.tar.gz
rust-df37678b768a6329e6aa418e59bfe07d32580ca5.zip
add FIXME related to `ref x` bindings
-rw-r--r--src/librustc_mir/build/matches/mod.rs15
-rw-r--r--src/test/ui/nll/user-annotations/patterns.rs2
-rw-r--r--src/test/ui/nll/user-annotations/patterns.stderr13
3 files changed, 16 insertions, 14 deletions
diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs
index 42510f5d71c..cef1fb77e5c 100644
--- a/src/librustc_mir/build/matches/mod.rs
+++ b/src/librustc_mir/build/matches/mod.rs
@@ -475,7 +475,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
     pub fn visit_bindings(
         &mut self,
         pattern: &Pattern<'tcx>,
-        pattern_user_ty: Option<CanonicalTy<'tcx>>,
+        mut pattern_user_ty: Option<CanonicalTy<'tcx>>,
         f: &mut impl FnMut(
             &mut Self,
             Mutability,
@@ -497,6 +497,19 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
                 ref subpattern,
                 ..
             } => {
+                match mode {
+                    BindingMode::ByValue => { }
+                    BindingMode::ByRef(..) => {
+                        // If this is a `ref` binding (e.g., `let ref
+                        // x: T = ..`), then the type of `x` is not
+                        // `T` but rather `&T`, so ignore
+                        // `pattern_user_ty` for now.
+                        //
+                        // FIXME(#47184): extract or handle `pattern_user_ty` somehow
+                        pattern_user_ty = None;
+                    }
+                }
+
                 f(self, mutability, name, mode, var, pattern.span, ty, pattern_user_ty);
                 if let Some(subpattern) = subpattern.as_ref() {
                     self.visit_bindings(subpattern, pattern_user_ty, f);
diff --git a/src/test/ui/nll/user-annotations/patterns.rs b/src/test/ui/nll/user-annotations/patterns.rs
index 94ac455c257..53d97360c86 100644
--- a/src/test/ui/nll/user-annotations/patterns.rs
+++ b/src/test/ui/nll/user-annotations/patterns.rs
@@ -20,7 +20,7 @@ fn ref_with_ascribed_static_type() -> u32 {
     // Check the behavior in some wacky cases.
     let x = 22;
     let y = &x; //~ ERROR
-    let ref z: &'static u32 = y; //~ ERROR
+    let ref z: &'static u32 = y;
     **z
 }
 
diff --git a/src/test/ui/nll/user-annotations/patterns.stderr b/src/test/ui/nll/user-annotations/patterns.stderr
index c7c3df83d46..563de1a9e02 100644
--- a/src/test/ui/nll/user-annotations/patterns.stderr
+++ b/src/test/ui/nll/user-annotations/patterns.stderr
@@ -19,17 +19,6 @@ LL | }
    |
    = note: borrowed value must be valid for the static lifetime...
 
-error[E0597]: `y` does not live long enough
-  --> $DIR/patterns.rs:23:9
-   |
-LL |     let ref z: &'static u32 = y; //~ ERROR
-   |         ^^^^^ borrowed value does not live long enough
-LL |     **z
-LL | }
-   | - `y` dropped here while still borrowed
-   |
-   = note: borrowed value must be valid for the static lifetime...
-
 error[E0597]: `x` does not live long enough
   --> $DIR/patterns.rs:46:27
    |
@@ -149,6 +138,6 @@ LL | fn a_to_static_then_static<'a>(x: &'a u32) -> &'static u32 {
 LL |     let (y, _z): (&'static u32, u32) = (x, 44); //~ ERROR
    |                                        ^^^^^^^ requires that `'a` must outlive `'static`
 
-error: aborting due to 15 previous errors
+error: aborting due to 14 previous errors
 
 For more information about this error, try `rustc --explain E0597`.