about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2018-08-15 12:02:00 +0000
committerbors <bors@rust-lang.org>2018-08-15 12:02:00 +0000
commit5db71dbae8c9cd0e6ac0558c54f2e2a6b1147d17 (patch)
tree2be921b4b994c820a382ab5dec1bbfbfb7eecda4
parent18a4c38a1df5bf79b427ed7d68609dec12bd7c0e (diff)
parent401af7994d26747c21e58dcbffa45bc3cd423696 (diff)
Auto merge of #53133 - Zoxc:gen-int, r=eddyb
Record adjustments and original type for expressions in the generator interior

Fixes https://github.com/rust-lang/rust/issues/50878 and https://github.com/rust-lang/rust/issues/52398.

r? @eddyb
-rw-r--r--src/librustc_typeck/check/generator_interior.rs8
-rw-r--r--src/test/run-pass/generator/issue-52398.rs35
2 files changed, 42 insertions, 1 deletions
diff --git a/src/librustc_typeck/check/generator_interior.rs b/src/librustc_typeck/check/generator_interior.rs
index e2090493079..6e0c0bac186 100644
--- a/src/librustc_typeck/check/generator_interior.rs
+++ b/src/librustc_typeck/check/generator_interior.rs
@@ -167,7 +167,13 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'gcx, 'tcx> {
 
         let scope = self.region_scope_tree.temporary_scope(expr.hir_id.local_id);
 
-        let ty = self.fcx.tables.borrow().expr_ty_adjusted(expr);
+        // Record the unadjusted type
+        let ty = self.fcx.tables.borrow().expr_ty(expr);
         self.record(ty, scope, Some(expr), expr.span);
+
+        // Also include the adjusted types, since these can result in MIR locals
+        for adjustment in self.fcx.tables.borrow().expr_adjustments(expr) {
+            self.record(adjustment.target, scope, Some(expr), expr.span);
+        }
     }
 }
diff --git a/src/test/run-pass/generator/issue-52398.rs b/src/test/run-pass/generator/issue-52398.rs
new file mode 100644
index 00000000000..0fb8f277ea9
--- /dev/null
+++ b/src/test/run-pass/generator/issue-52398.rs
@@ -0,0 +1,35 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![feature(generators)]
+
+use std::cell::RefCell;
+
+struct A;
+
+impl A {
+    fn test(&self, a: ()) {}
+}
+
+fn main() {
+    // Test that the MIR local with type &A created for the auto-borrow adjustment
+    // is caught by typeck
+    move || {
+        A.test(yield);
+    };
+
+    // Test that the std::cell::Ref temporary returned from the `borrow` call
+    // is caught by typeck
+    let y = RefCell::new(true);
+    static move || {
+        yield *y.borrow();
+        return "Done";
+    };
+}