]> git.lizzy.rs Git - rust.git/commitdiff
Add nll feature and make nll imply nll_dump_cause
authorSantiago Pastorino <spastorino@gmail.com>
Tue, 19 Dec 2017 18:10:07 +0000 (15:10 -0300)
committerNiko Matsakis <niko@alum.mit.edu>
Wed, 20 Dec 2017 19:38:12 +0000 (14:38 -0500)
src/librustc/infer/error_reporting/mod.rs
src/librustc/session/mod.rs
src/librustc_mir/borrow_check/mod.rs
src/libsyntax/feature_gate.rs
src/test/ui/feature-gate-nll.rs [new file with mode: 0644]
src/test/ui/feature-gate-nll.stderr [new file with mode: 0644]
src/test/ui/nll/capture-ref-in-struct.rs
src/test/ui/nll/capture-ref-in-struct.stderr

index 67746dfa330c6c2e6de8d89640d791b18d0deddb..38bbddfd825a00b0107702340993369261f5cbf0 100644 (file)
@@ -261,7 +261,7 @@ pub fn report_region_errors(&self,
                                 errors: &Vec<RegionResolutionError<'tcx>>) {
         debug!("report_region_errors(): {} errors to start", errors.len());
 
-        if self.tcx.sess.opts.debugging_opts.nll {
+        if self.tcx.sess.nll() {
             for error in errors {
                 match *error {
                     RegionResolutionError::ConcreteFailure(ref origin, ..) |
index 8f41a2d623277b57a59025c6252b978b7b9e9dfd..43ed9f02157341332f130602422b21e53a4d7aa4 100644 (file)
@@ -437,6 +437,9 @@ pub fn borrowck_stats(&self) -> bool { self.opts.debugging_opts.borrowck_stats }
     pub fn print_llvm_passes(&self) -> bool {
         self.opts.debugging_opts.print_llvm_passes
     }
+    pub fn nll(&self) -> bool {
+        self.features.borrow().nll || self.opts.debugging_opts.nll
+    }
     pub fn nll_dump_cause(&self) -> bool {
         self.opts.debugging_opts.nll_dump_cause
     }
index 46e97d95f493ff351b9d6133d6c8bccee540ebe3..34c91b84f28004e9784149acad79a8c4208361de 100644 (file)
@@ -74,7 +74,7 @@ fn mir_borrowck<'a, 'tcx>(
 
     if {
         !tcx.has_attr(def_id, "rustc_mir_borrowck") && !tcx.sess.opts.borrowck_mode.use_mir()
-            && !tcx.sess.opts.debugging_opts.nll
+            && !tcx.sess.nll()
     } {
         return None;
     }
@@ -104,7 +104,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
     // contain non-lexical lifetimes. It will have a lifetime tied
     // to the inference context.
     let mut mir: Mir<'tcx> = input_mir.clone();
-    let free_regions = if !tcx.sess.opts.debugging_opts.nll {
+    let free_regions = if !tcx.sess.nll() {
         None
     } else {
         let mir = &mut mir;
@@ -207,7 +207,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
         );
         (Some(Rc::new(regioncx)), opt_closure_req)
     } else {
-        assert!(!tcx.sess.opts.debugging_opts.nll);
+        assert!(!tcx.sess.nll());
         (None, None)
     };
     let flow_inits = flow_inits; // remove mut
index ba534676324a97fa2ba8e9b47e26379a8203dbb1..379881302eef70918b4b964faf8c430858c38957 100644 (file)
@@ -186,6 +186,9 @@ pub fn new() -> Features {
     // Allows the use of rustc_* attributes; RFC 572
     (active, rustc_attrs, "1.0.0", Some(29642)),
 
+    // Allows the use of non lexical lifetimes; RFC 2094
+    (active, nll, "1.0.0", Some(44928)),
+
     // Allows the use of #[allow_internal_unstable]. This is an
     // attribute on macro_rules! and can't use the attribute handling
     // below (it has to be checked before expansion possibly makes
@@ -798,6 +801,12 @@ pub fn is_builtin_attr(attr: &ast::Attribute) -> bool {
                                                           libcore functions that are inlined \
                                                           across crates and will never be stable",
                                                           cfg_fn!(rustc_attrs))),
+
+    // RFC #2094
+    ("nll", Whitelisted, Gated(Stability::Unstable,
+                               "nll",
+                               "Non lexical lifetimes",
+                               cfg_fn!(nll))),
     ("compiler_builtins", Whitelisted, Gated(Stability::Unstable,
                                              "compiler_builtins",
                                              "the `#[compiler_builtins]` attribute is used to \
diff --git a/src/test/ui/feature-gate-nll.rs b/src/test/ui/feature-gate-nll.rs
new file mode 100644 (file)
index 0000000..f34a9cd
--- /dev/null
@@ -0,0 +1,18 @@
+// Copyright 2015 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.
+
+#![allow(dead_code)]
+
+fn main() {
+    let mut x = 33;
+
+    let p = &x;
+    x = 22; //~ ERROR cannot assign to `x` because it is borrowed [E0506]
+}
diff --git a/src/test/ui/feature-gate-nll.stderr b/src/test/ui/feature-gate-nll.stderr
new file mode 100644 (file)
index 0000000..4135462
--- /dev/null
@@ -0,0 +1,10 @@
+error[E0506]: cannot assign to `x` because it is borrowed
+  --> $DIR/feature-gate-nll.rs:17:5
+   |
+16 |     let p = &x;
+   |              - borrow of `x` occurs here
+17 |     x = 22; //~ ERROR cannot assign to `x` because it is borrowed [E0506]
+   |     ^^^^^^ assignment to borrowed `x` occurs here
+
+error: aborting due to previous error
+
index 6e234a966d14a66525d8d5c55dac87808299cf85..2d208c8855273307e89bbca6f816feb9d37f069a 100644 (file)
@@ -8,12 +8,13 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-// compile-flags:-Znll -Zborrowck=mir -Znll-dump-cause
+// compile-flags:-Zborrowck=mir -Znll-dump-cause
 
 // Test that a structure which tries to store a pointer to `y` into
 // `p` (indirectly) fails to compile.
 
 #![feature(rustc_attrs)]
+#![feature(nll)]
 
 struct SomeStruct<'a, 'b: 'a> {
     p: &'a mut &'b i32,
index 7b3f7d25dd037c5fc1f47316cd8259f2c8fdfa8b..7e7487daa67a377d3647c22b32aab4d50f378e2b 100644 (file)
@@ -1,13 +1,13 @@
 error[E0597]: `y` does not live long enough
-  --> $DIR/capture-ref-in-struct.rs:32:16
+  --> $DIR/capture-ref-in-struct.rs:33:16
    |
-32 |             y: &y,
+33 |             y: &y,
    |                ^^ borrowed value does not live long enough
 ...
-37 |     }
+38 |     }
    |      - borrowed value only lives until here
-38 | 
-39 |     deref(p);
+39 | 
+40 |     deref(p);
    |           - borrow later used here
    |
    = note: borrowed value must be valid for lifetime '_#5r...