Skip to content

Commit

Permalink
Use // revisions in the dropck-eyepatch tests instead of relying on…
Browse files Browse the repository at this point in the history
… compare-mode=nll.

NLL has increased precision in its analysis of drop order, and we want
the test annotations to deliberately reflect this by having fewer
ERROR annotations for NLL than for AST-borrowck. The best way to get
this effect is via `// revisions`.

As a drive-by, also added uses of all the borrows just to make it
clear that NLL isn't somehow sidestepping things by using shorter
borrows than you might have otherwise expected. (Of course, the added
uses do not make all that much difference since the relevant types all
declare `impl Drop` and thus those drops have implicit uses anyway.)
  • Loading branch information
pnkfelix committed Nov 5, 2018
1 parent c25319f commit cf71582
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 51 deletions.
Expand Up @@ -32,7 +32,7 @@ LL | }
= note: values in a scope are dropped in the opposite order they are created

error[E0597]: `c_shortest` does not live long enough
--> $DIR/dropck-eyepatch-extern-crate.rs:49:20
--> $DIR/dropck-eyepatch-extern-crate.rs:50:20
|
LL | dr = Dr("dr", &c_shortest);
| ^^^^^^^^^^ borrowed value does not live long enough
Expand Down
35 changes: 19 additions & 16 deletions src/test/ui/dropck/dropck-eyepatch-extern-crate.rs
@@ -1,12 +1,12 @@
// Copyright 2016 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.
// The behavior of AST-borrowck and NLL explcitly differ here due to
// NLL's increased precision; so we use revisions and do not worry
// about the --compare-mode=nll on this test.

// revisions: ast nll
//[ast]compile-flags: -Z borrowck=ast
//[nll]compile-flags: -Z borrowck=migrate -Z two-phase-borrows

// ignore-compare-mode-nll

// aux-build:dropck_eyepatch_extern_crate.rs

Expand Down Expand Up @@ -39,29 +39,32 @@ fn main() { #![rustc_error] // rust-lang/rust#49855

// Error: destructor order imprecisely modelled
dt = Dt("dt", &c);
//~^ ERROR `c` does not live long enough
//[ast]~^ ERROR `c` does not live long enough
dr = Dr("dr", &c);
//~^ ERROR `c` does not live long enough
//[ast]~^ ERROR `c` does not live long enough

// Error: `c_shortest` dies too soon for the references in dtors to be valid.
dt = Dt("dt", &c_shortest);
//~^ ERROR `c_shortest` does not live long enough
//[ast]~^ ERROR `c_shortest` does not live long enough
//[nll]~^^ ERROR `c_shortest` does not live long enough
dr = Dr("dr", &c_shortest);
//~^ ERROR `c_shortest` does not live long enough

//[ast]~^ ERROR `c_shortest` does not live long enough
// No error: Drop impl asserts .1 (A and &'a _) are not accessed
pt = Pt("pt", &c_shortest, &c_long);
pr = Pr("pr", &c_shortest, &c_long);

// Error: Drop impl's assertion does not apply to `B` nor `&'b _`
pt = Pt("pt", &c_long, &c_shortest);
//~^ ERROR `c_shortest` does not live long enough
//[ast]~^ ERROR `c_shortest` does not live long enough
pr = Pr("pr", &c_long, &c_shortest);
//~^ ERROR `c_shortest` does not live long enough
//[ast]~^ ERROR `c_shortest` does not live long enough

// No error: St and Sr have no destructor.
st = St("st", &c_shortest);
sr = Sr("sr", &c_shortest);

println!("{:?}", (dt.0, dr.0, pt.0, pr.0, st.0, sr.0));
use_imm(sr.1); use_imm(st.1); use_imm(pr.1); use_imm(pt.1); use_imm(dr.1); use_imm(dt.1);
}

fn use_imm<T>(_: &T) { }
Expand Up @@ -32,7 +32,7 @@ LL | }
= note: values in a scope are dropped in the opposite order they are created

error[E0597]: `c_shortest` does not live long enough
--> $DIR/dropck-eyepatch-reorder.rs:66:20
--> $DIR/dropck-eyepatch-reorder.rs:67:20
|
LL | dr = Dr("dr", &c_shortest);
| ^^^^^^^^^^ borrowed value does not live long enough
Expand Down
35 changes: 19 additions & 16 deletions src/test/ui/dropck/dropck-eyepatch-reorder.rs
@@ -1,12 +1,12 @@
// Copyright 2016 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.
// The behavior of AST-borrowck and NLL explcitly differ here due to
// NLL's increased precision; so we use revisions and do not worry
// about the --compare-mode=nll on this test.

// revisions: ast nll
//[ast]compile-flags: -Z borrowck=ast
//[nll]compile-flags: -Z borrowck=migrate -Z two-phase-borrows

// ignore-compare-mode-nll

#![feature(dropck_eyepatch, rustc_attrs)]

Expand Down Expand Up @@ -56,29 +56,32 @@ fn main() { #![rustc_error] // rust-lang/rust#49855

// Error: destructor order imprecisely modelled
dt = Dt("dt", &c);
//~^ ERROR `c` does not live long enough
//[ast]~^ ERROR `c` does not live long enough
dr = Dr("dr", &c);
//~^ ERROR `c` does not live long enough
//[ast]~^ ERROR `c` does not live long enough

// Error: `c_shortest` dies too soon for the references in dtors to be valid.
dt = Dt("dt", &c_shortest);
//~^ ERROR `c_shortest` does not live long enough
//[ast]~^ ERROR `c_shortest` does not live long enough
//[nll]~^^ ERROR `c_shortest` does not live long enough
dr = Dr("dr", &c_shortest);
//~^ ERROR `c_shortest` does not live long enough

//[ast]~^ ERROR `c_shortest` does not live long enough
// No error: Drop impl asserts .1 (A and &'a _) are not accessed
pt = Pt("pt", &c_shortest, &c_long);
pr = Pr("pr", &c_shortest, &c_long);

// Error: Drop impl's assertion does not apply to `B` nor `&'b _`
pt = Pt("pt", &c_long, &c_shortest);
//~^ ERROR `c_shortest` does not live long enough
//[ast]~^ ERROR `c_shortest` does not live long enough
pr = Pr("pr", &c_long, &c_shortest);
//~^ ERROR `c_shortest` does not live long enough
//[ast]~^ ERROR `c_shortest` does not live long enough

// No error: St and Sr have no destructor.
st = St("st", &c_shortest);
sr = Sr("sr", &c_shortest);

println!("{:?}", (dt.0, dr.0, pt.0, pr.0, st.0, sr.0));
use_imm(sr.1); use_imm(st.1); use_imm(pr.1); use_imm(pt.1); use_imm(dr.1); use_imm(dt.1);
}

fn use_imm<T>(_: &T) { }
Expand Up @@ -32,7 +32,7 @@ LL | }
= note: values in a scope are dropped in the opposite order they are created

error[E0597]: `c_shortest` does not live long enough
--> $DIR/dropck-eyepatch.rs:89:20
--> $DIR/dropck-eyepatch.rs:90:20
|
LL | dr = Dr("dr", &c_shortest);
| ^^^^^^^^^^ borrowed value does not live long enough
Expand Down
35 changes: 19 additions & 16 deletions src/test/ui/dropck/dropck-eyepatch.rs
@@ -1,12 +1,12 @@
// Copyright 2016 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.
// The behavior of AST-borrowck and NLL explcitly differ here due to
// NLL's increased precision; so we use revisions and do not worry
// about the --compare-mode=nll on this test.

// revisions: ast nll
//[ast]compile-flags: -Z borrowck=ast
//[nll]compile-flags: -Z borrowck=migrate -Z two-phase-borrows

// ignore-compare-mode-nll

#![feature(dropck_eyepatch, rustc_attrs)]

Expand Down Expand Up @@ -79,30 +79,33 @@ fn main() { #![rustc_error] // rust-lang/rust#49855

// Error: destructor order imprecisely modelled
dt = Dt("dt", &c);
//~^ ERROR `c` does not live long enough
//[ast]~^ ERROR `c` does not live long enough
dr = Dr("dr", &c);
//~^ ERROR `c` does not live long enough
//[ast]~^ ERROR `c` does not live long enough

// Error: `c_shortest` dies too soon for the references in dtors to be valid.
dt = Dt("dt", &c_shortest);
//~^ ERROR `c_shortest` does not live long enough
//[ast]~^ ERROR `c_shortest` does not live long enough
//[nll]~^^ ERROR `c_shortest` does not live long enough
dr = Dr("dr", &c_shortest);
//~^ ERROR `c_shortest` does not live long enough

//[ast]~^ ERROR `c_shortest` does not live long enough

// No error: Drop impl asserts .1 (A and &'a _) are not accessed
pt = Pt("pt", &c_shortest, &c_long);
pr = Pr("pr", &c_shortest, &c_long);

// Error: Drop impl's assertion does not apply to `B` nor `&'b _`
pt = Pt("pt", &c_long, &c_shortest);
//~^ ERROR `c_shortest` does not live long enough
//[ast]~^ ERROR `c_shortest` does not live long enough
pr = Pr("pr", &c_long, &c_shortest);
//~^ ERROR `c_shortest` does not live long enough
//[ast]~^ ERROR `c_shortest` does not live long enough

// No error: St and Sr have no destructor.
st = St("st", &c_shortest);
sr = Sr("sr", &c_shortest);

println!("{:?}", (dt.0, dr.0, pt.0, pr.0, st.0, sr.0));
use_imm(sr.1); use_imm(st.1); use_imm(pr.1); use_imm(pt.1); use_imm(dr.1); use_imm(dt.1);
}

fn use_imm<T>(_: &T) { }

0 comments on commit cf71582

Please sign in to comment.