Skip to content

Commit 0b2db1e

Browse files
spastorinonikomatsakis
authored andcommitted
Add nll feature and make nll imply nll_dump_cause
1 parent 95b6148 commit 0b2db1e

File tree

8 files changed

+51
-10
lines changed

8 files changed

+51
-10
lines changed

src/librustc/infer/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
261261
errors: &Vec<RegionResolutionError<'tcx>>) {
262262
debug!("report_region_errors(): {} errors to start", errors.len());
263263

264-
if self.tcx.sess.opts.debugging_opts.nll {
264+
if self.tcx.sess.nll() {
265265
for error in errors {
266266
match *error {
267267
RegionResolutionError::ConcreteFailure(ref origin, ..) |

src/librustc/session/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,9 @@ impl Session {
437437
pub fn print_llvm_passes(&self) -> bool {
438438
self.opts.debugging_opts.print_llvm_passes
439439
}
440+
pub fn nll(&self) -> bool {
441+
self.features.borrow().nll || self.opts.debugging_opts.nll
442+
}
440443
pub fn nll_dump_cause(&self) -> bool {
441444
self.opts.debugging_opts.nll_dump_cause
442445
}

src/librustc_mir/borrow_check/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn mir_borrowck<'a, 'tcx>(
7474

7575
if {
7676
!tcx.has_attr(def_id, "rustc_mir_borrowck") && !tcx.sess.opts.borrowck_mode.use_mir()
77-
&& !tcx.sess.opts.debugging_opts.nll
77+
&& !tcx.sess.nll()
7878
} {
7979
return None;
8080
}
@@ -104,7 +104,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
104104
// contain non-lexical lifetimes. It will have a lifetime tied
105105
// to the inference context.
106106
let mut mir: Mir<'tcx> = input_mir.clone();
107-
let free_regions = if !tcx.sess.opts.debugging_opts.nll {
107+
let free_regions = if !tcx.sess.nll() {
108108
None
109109
} else {
110110
let mir = &mut mir;
@@ -207,7 +207,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
207207
);
208208
(Some(Rc::new(regioncx)), opt_closure_req)
209209
} else {
210-
assert!(!tcx.sess.opts.debugging_opts.nll);
210+
assert!(!tcx.sess.nll());
211211
(None, None)
212212
};
213213
let flow_inits = flow_inits; // remove mut

src/libsyntax/feature_gate.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ declare_features! (
186186
// Allows the use of rustc_* attributes; RFC 572
187187
(active, rustc_attrs, "1.0.0", Some(29642)),
188188

189+
// Allows the use of non lexical lifetimes; RFC 2094
190+
(active, nll, "1.0.0", Some(44928)),
191+
189192
// Allows the use of #[allow_internal_unstable]. This is an
190193
// attribute on macro_rules! and can't use the attribute handling
191194
// below (it has to be checked before expansion possibly makes
@@ -798,6 +801,12 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG
798801
libcore functions that are inlined \
799802
across crates and will never be stable",
800803
cfg_fn!(rustc_attrs))),
804+
805+
// RFC #2094
806+
("nll", Whitelisted, Gated(Stability::Unstable,
807+
"nll",
808+
"Non lexical lifetimes",
809+
cfg_fn!(nll))),
801810
("compiler_builtins", Whitelisted, Gated(Stability::Unstable,
802811
"compiler_builtins",
803812
"the `#[compiler_builtins]` attribute is used to \

src/test/ui/feature-gate-nll.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![allow(dead_code)]
12+
13+
fn main() {
14+
let mut x = 33;
15+
16+
let p = &x;
17+
x = 22; //~ ERROR cannot assign to `x` because it is borrowed [E0506]
18+
}

src/test/ui/feature-gate-nll.stderr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error[E0506]: cannot assign to `x` because it is borrowed
2+
--> $DIR/feature-gate-nll.rs:17:5
3+
|
4+
16 | let p = &x;
5+
| - borrow of `x` occurs here
6+
17 | x = 22; //~ ERROR cannot assign to `x` because it is borrowed [E0506]
7+
| ^^^^^^ assignment to borrowed `x` occurs here
8+
9+
error: aborting due to previous error
10+

src/test/ui/nll/capture-ref-in-struct.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// compile-flags:-Znll -Zborrowck=mir -Znll-dump-cause
11+
// compile-flags:-Zborrowck=mir -Znll-dump-cause
1212

1313
// Test that a structure which tries to store a pointer to `y` into
1414
// `p` (indirectly) fails to compile.
1515

1616
#![feature(rustc_attrs)]
17+
#![feature(nll)]
1718

1819
struct SomeStruct<'a, 'b: 'a> {
1920
p: &'a mut &'b i32,

src/test/ui/nll/capture-ref-in-struct.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0597]: `y` does not live long enough
2-
--> $DIR/capture-ref-in-struct.rs:32:16
2+
--> $DIR/capture-ref-in-struct.rs:33:16
33
|
4-
32 | y: &y,
4+
33 | y: &y,
55
| ^^ borrowed value does not live long enough
66
...
7-
37 | }
7+
38 | }
88
| - borrowed value only lives until here
9-
38 |
10-
39 | deref(p);
9+
39 |
10+
40 | deref(p);
1111
| - borrow later used here
1212
|
1313
= note: borrowed value must be valid for lifetime '_#5r...

0 commit comments

Comments
 (0)