Skip to content

Commit

Permalink
Update various tests and libraries that were incorrectly
Browse files Browse the repository at this point in the history
annotated.
  • Loading branch information
nikomatsakis committed Nov 9, 2013
1 parent f57a28b commit 5e54a73
Show file tree
Hide file tree
Showing 31 changed files with 156 additions and 108 deletions.
1 change: 1 addition & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ ifdef TRACE
CFG_RUSTC_FLAGS += -Z trace
endif
ifndef DEBUG_BORROWS
RUSTFLAGS_STAGE0 += -Z no-debug-borrows
RUSTFLAGS_STAGE1 += -Z no-debug-borrows
RUSTFLAGS_STAGE2 += -Z no-debug-borrows
endif
Expand Down
28 changes: 14 additions & 14 deletions src/libextra/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,10 @@ impl<T:Send> MutexArc<T> {

/// As unsafe_access(), but with a condvar, as sync::mutex.lock_cond().
#[inline]
pub unsafe fn unsafe_access_cond<'x, 'c, U>(&self,
blk: &fn(x: &'x mut T,
c: &'c Condvar) -> U)
-> U {
pub unsafe fn unsafe_access_cond<U>(&self,
blk: &fn(x: &mut T,
c: &Condvar) -> U)
-> U {
let state = self.x.get();
do (&(*state).lock).lock_cond |cond| {
check_poison(true, (*state).failed);
Expand Down Expand Up @@ -290,10 +290,10 @@ impl<T:Freeze + Send> MutexArc<T> {

/// As unsafe_access_cond but safe and Freeze.
#[inline]
pub fn access_cond<'x, 'c, U>(&self,
blk: &fn(x: &'x mut T,
c: &'c Condvar) -> U)
-> U {
pub fn access_cond<U>(&self,
blk: &fn(x: &mut T,
c: &Condvar) -> U)
-> U {
unsafe { self.unsafe_access_cond(blk) }
}
}
Expand Down Expand Up @@ -402,9 +402,9 @@ impl<T:Freeze + Send> RWArc<T> {

/// As write(), but with a condvar, as sync::rwlock.write_cond().
#[inline]
pub fn write_cond<'x, 'c, U>(&self,
blk: &fn(x: &'x mut T, c: &'c Condvar) -> U)
-> U {
pub fn write_cond<U>(&self,
blk: &fn(x: &mut T, c: &Condvar) -> U)
-> U {
unsafe {
let state = self.x.get();
do (*borrow_rwlock(state)).write_cond |cond| {
Expand Down Expand Up @@ -554,9 +554,9 @@ impl<'self, T:Freeze + Send> RWWriteMode<'self, T> {
}

/// Access the pre-downgrade RWArc in write mode with a condvar.
pub fn write_cond<'x, 'c, U>(&mut self,
blk: &fn(x: &'x mut T, c: &'c Condvar) -> U)
-> U {
pub fn write_cond<U>(&mut self,
blk: &fn(x: &mut T, c: &Condvar) -> U)
-> U {
match *self {
RWWriteMode {
data: &ref mut data,
Expand Down
5 changes: 1 addition & 4 deletions src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,7 @@ pub fn phase_3_run_analysis_passes(sess: Session,
freevars::annotate_freevars(def_map, crate));

let region_map = time(time_passes, "region resolution", (), |_|
middle::region::resolve_crate(sess, def_map, crate));

let rp_set = time(time_passes, "region parameterization inference", (), |_|
middle::region::determine_rp_in_crate(sess, ast_map, def_map, crate));
middle::region::resolve_crate(sess, crate));

let ty_cx = ty::mk_ctxt(sess, def_map, named_region_map, ast_map, freevars,
region_map, lang_items);
Expand Down
22 changes: 11 additions & 11 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,18 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
return ty::mk_param(st.tcx, parse_uint(st), did);
}
's' => {
let did = parse_def(st, TypeParameter, conv);
let did = parse_def(st, TypeParameter, |x,y| conv(x,y));
return ty::mk_self(st.tcx, did);
}
'@' => return ty::mk_box(st.tcx, parse_mt(st, conv)),
'~' => return ty::mk_uniq(st.tcx, parse_mt(st, conv)),
'*' => return ty::mk_ptr(st.tcx, parse_mt(st, conv)),
'@' => return ty::mk_box(st.tcx, parse_mt(st, |x,y| conv(x,y))),
'~' => return ty::mk_uniq(st.tcx, parse_mt(st, |x,y| conv(x,y))),
'*' => return ty::mk_ptr(st.tcx, parse_mt(st, |x,y| conv(x,y))),
'&' => {
let r = parse_region(st);
let mt = parse_mt(st, conv);
let r = parse_region(st, |x,y| conv(x,y));
let mt = parse_mt(st, |x,y| conv(x,y));
return ty::mk_rptr(st.tcx, r, mt);
}
'U' => return ty::mk_unboxed_vec(st.tcx, parse_mt(st, conv)),
'U' => return ty::mk_unboxed_vec(st.tcx, parse_mt(st, |x,y| conv(x,y))),
'V' => {
let mt = parse_mt(st, |x,y| conv(x,y));
let v = parse_vstore(st, |x,y| conv(x,y));
Expand All @@ -392,10 +392,10 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
return ty::mk_tup(st.tcx, params);
}
'f' => {
return ty::mk_closure(st.tcx, parse_closure_ty(st, conv));
return ty::mk_closure(st.tcx, parse_closure_ty(st, |x,y| conv(x,y)));
}
'F' => {
return ty::mk_bare_fn(st.tcx, parse_bare_fn_ty(st, conv));
return ty::mk_bare_fn(st.tcx, parse_bare_fn_ty(st, |x,y| conv(x,y)));
}
'Y' => return ty::mk_type(st.tcx),
'C' => {
Expand All @@ -417,7 +417,7 @@ fn parse_ty(st: &mut PState, conv: conv_did) -> ty::t {
pos: pos,
.. *st
};
let tt = parse_ty(&mut ps, conv);
let tt = parse_ty(&mut ps, |x,y| conv(x,y));
st.tcx.rcache.insert(key, tt);
return tt;
}
Expand Down Expand Up @@ -449,7 +449,7 @@ fn parse_mutability(st: &mut PState) -> ast::Mutability {

fn parse_mt(st: &mut PState, conv: conv_did) -> ty::mt {
let m = parse_mutability(st);
ty::mt { ty: parse_ty(st, conv), mutbl: m }
ty::mt { ty: parse_ty(st, |x,y| conv(x,y)), mutbl: m }
}

fn parse_def(st: &mut PState, source: DefIdSource,
Expand Down
19 changes: 16 additions & 3 deletions src/librustc/middle/trans/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use middle::trans::common::*;
use middle::trans::foreign;
use middle::ty;
use util::ppaux;
use util::ppaux::Repr;

use middle::trans::type_::Type;

Expand Down Expand Up @@ -172,14 +173,16 @@ pub fn sizing_type_of(cx: &mut CrateContext, t: ty::t) -> Type {

// NB: If you update this, be sure to update `sizing_type_of()` as well.
pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type {
debug!("type_of {:?}: {:?}", t, ty::get(t));

// Check the cache.
match cx.lltypes.find(&t) {
Some(&t) => return t,
Some(&llty) => {
return llty;
}
None => ()
}

debug!("type_of {} {:?}", t.repr(cx.tcx), t);

// Replace any typedef'd types with their equivalent non-typedef
// type. This ensures that all LLVM nominal types that contain
// Rust types are defined as the same LLVM types. If we don't do
Expand All @@ -189,6 +192,12 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type {

if t != t_norm {
let llty = type_of(cx, t_norm);
debug!("--> normalized {} {:?} to {} {:?} llty={}",
t.repr(cx.tcx),
t,
t_norm.repr(cx.tcx),
t_norm,
cx.tn.type_to_str(llty));
cx.lltypes.insert(t, llty);
return llty;
}
Expand Down Expand Up @@ -299,6 +308,10 @@ pub fn type_of(cx: &mut CrateContext, t: ty::t) -> Type {
ty::ty_err(*) => cx.tcx.sess.bug("type_of with ty_err")
};

debug!("--> mapped t={} {:?} to llty={}",
t.repr(cx.tcx),
t,
cx.tn.type_to_str(llty));
cx.lltypes.insert(t, llty);

// If this was an enum or struct, fill in the type now.
Expand Down
7 changes: 4 additions & 3 deletions src/test/compile-fail/bad-mid-path-type-params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ impl Trait<int> for S2 {
}
}

fn main() {
fn foo<'a>() {
let _ = S::new::<int,f64>(1, 1.0); //~ ERROR the impl referenced by this path has 1 type parameter, but 0 type parameters were supplied
let _ = S::<'self,int>::new::<f64>(1, 1.0); //~ ERROR this impl has no lifetime parameter
let _ = S::<'a,int>::new::<f64>(1, 1.0); //~ ERROR expected 0 lifetime parameter(s)
let _: S2 = Trait::new::<int,f64>(1, 1.0); //~ ERROR the trait referenced by this path has 1 type parameter, but 0 type parameters were supplied
let _: S2 = Trait::<'self,int>::new::<f64>(1, 1.0); //~ ERROR this trait has no lifetime parameter
let _: S2 = Trait::<'a,int>::new::<f64>(1, 1.0); //~ ERROR expected 0 lifetime parameter(s)
}

fn main() {}
2 changes: 1 addition & 1 deletion src/test/compile-fail/core-tls-store-pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
use std::local_data;

local_data_key!(key: @&int)
//~^ ERROR only 'static is allowed
//~^ ERROR missing lifetime specifier

fn main() {}
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-4335.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

fn id<T>(t: T) -> T { t }

fn f<'r, T>(v: &'r T) -> &'r fn()->T { id::<&'r fn()->T>(|| *v) } //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements
fn f<'r, T>(v: &'r T) -> &'r fn()->T { id::<&'r fn()->T>(|| *v) } //~ ERROR cannot infer an appropriate lifetime

fn main() {
let v = &5;
Expand Down
8 changes: 4 additions & 4 deletions src/test/compile-fail/issue-5216.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
// except according to those terms.

fn f() { }
struct S(&fn()); //~ ERROR Illegal anonymous lifetime
pub static C: S = S(f); //~ ERROR Illegal anonymous lifetime
struct S(&fn()); //~ ERROR missing lifetime specifier
pub static C: S = S(f);


fn g() { }
type T = &fn(); //~ ERROR Illegal anonymous lifetime
pub static D: T = g; //~ ERROR Illegal anonymous lifetime
type T = &fn(); //~ ERROR missing lifetime specifier
pub static D: T = g;

fn main() {}
25 changes: 10 additions & 15 deletions src/test/compile-fail/kindck-owned-trait-contains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,24 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#[feature(managed_boxes)];
trait Repeat<A> { fn get(&self) -> A; }

trait repeat<A> { fn get(&self) -> A; }

impl<A:Clone> repeat<A> for @A {
fn get(&self) -> A { **self }
impl<A:Clone> Repeat<A> for A {
fn get(&self) -> A { self.clone() }
}

fn repeater<A:Clone>(v: @A) -> @repeat<A> {
// Note: owned kind is not necessary as A appears in the trait type
@v as @repeat<A> // No
fn repeater<A:Clone>(v: A) -> ~Repeat:<A> {
~v as ~Repeat:<A> // No
}

fn main() {
// Error results because the type of is inferred to be
// @repeat<&'blk int> where blk is the lifetime of the block below.
// ~Repeat<&'blk int> where blk is the lifetime of the block below.

let y = { //~ ERROR lifetime of variable does not enclose its declaration
let x: &'blk int = &3;
repeater(@x)
let y = {
let tmp0 = 3;
let tmp1 = &tmp0; //~ ERROR borrowed value does not live long enough
repeater(tmp1)
};
assert!(3 == *(y.get()));
//~^ ERROR dereference of reference outside its lifetime
//~^^ ERROR automatically borrowed pointer is not valid at the time of borrow
//~^^^ ERROR lifetime of return value does not outlive the function call
}
9 changes: 8 additions & 1 deletion src/test/compile-fail/regions-addr-of-arg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Check that taking the address of an argument yields a lifetime
// bounded by the current function call.

fn foo(a: int) {
let _p: &'static int = &a; //~ ERROR borrowed value does not live long enough
}

fn bar(a: int) {
let _q: &'blk int = &a;
let _q: &int = &a;
}

fn zed<'a>(a: int) -> &'a int {
&a //~ ERROR borrowed value does not live long enough
}

fn main() {
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/regions-addr-of-self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ struct dog {

impl dog {
pub fn chase_cat(&mut self) {
let p: &'static mut uint = &mut self.cats_chased; //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements
let p: &'static mut uint = &mut self.cats_chased; //~ ERROR cannot infer an appropriate lifetime
*p += 1u;
}

pub fn chase_cat_2(&mut self) {
let p: &'blk mut uint = &mut self.cats_chased;
let p: &mut uint = &mut self.cats_chased;
*p += 1u;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/regions-addr-of-upvar-self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct dog {
impl dog {
pub fn chase_cat(&mut self) {
let _f = || {
let p: &'static mut uint = &mut self.food; //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements
let p: &'static mut uint = &mut self.food; //~ ERROR cannot infer an appropriate lifetime
*p = 3u;
};
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/compile-fail/regions-fn-subtyping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ fn test_fn<'x,'y,'z,T>(_x: &'x T, _y: &'y T, _z: &'z T) {
of::<&fn<'b>(&'b T)>());

subtype::<&fn<'b>(&'b T)>(
of::<&fn<'x>(&'x T)>());
of::<&fn(&'x T)>());

subtype::<&fn<'x>(&'x T)>(
subtype::<&fn(&'x T)>(
of::<&fn<'b>(&'b T)>()); //~ ERROR mismatched types

subtype::<&fn<'a,'b>(&'a T, &'b T)>(
Expand All @@ -36,9 +36,9 @@ fn test_fn<'x,'y,'z,T>(_x: &'x T, _y: &'y T, _z: &'z T) {
of::<&fn<'a,'b>(&'a T, &'b T)>()); //~ ERROR mismatched types

subtype::<&fn<'a,'b>(&'a T, &'b T)>(
of::<&fn<'x,'y>(&'x T, &'y T)>());
of::<&fn(&'x T, &'y T)>());

subtype::<&fn<'x,'y>(&'x T, &'y T)>(
subtype::<&fn(&'x T, &'y T)>(
of::<&fn<'a,'b>(&'a T, &'b T)>()); //~ ERROR mismatched types
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn ordering2<'a, 'b>(x: &'a &'b uint, y: &'a uint) -> &'b uint {
fn ordering3<'a, 'b>(x: &'a uint, y: &'b uint) -> &'a &'b uint {
// Do not infer an ordering from the return value.
let z: &'b uint = &*x;
//~^ ERROR cannot infer an appropriate lifetime due to conflicting requirements
//~^ ERROR cannot infer an appropriate lifetime
fail!();
}

Expand Down
6 changes: 0 additions & 6 deletions src/test/compile-fail/regions-free-region-ordering-caller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@

struct Paramd<'self> { x: &'self uint }

fn call1<'a>(x: &'a uint) {
let y: uint = 3;
let z: &'a &'blk uint = &(&y);
//~^ ERROR pointer has a longer lifetime than the data it references
}

fn call2<'a, 'b>(a: &'a uint, b: &'b uint) {
let z: Option<&'b &'a uint> = None;
//~^ ERROR pointer has a longer lifetime than the data it references
Expand Down
24 changes: 24 additions & 0 deletions src/test/compile-fail/regions-free-region-ordering-caller1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2012 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.

// Test various ways to construct a pointer with a longer lifetime
// than the thing it points at and ensure that they result in
// errors. See also regions-free-region-ordering-callee.rs

fn call1<'a>(x: &'a uint) {
// Test that creating a pointer like
// &'a &'z uint requires that 'a <= 'z:
let y: uint = 3;
let z: &'a & uint = &(&y);
//~^ ERROR borrowed value does not live long enough
//~^^ ERROR borrowed value does not live long enough
}

fn main() {}
3 changes: 1 addition & 2 deletions src/test/compile-fail/regions-in-consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

static c_x: &'blk int = &22; //~ ERROR Illegal lifetime 'blk: only 'static is allowed here
static c_y: &int = &22; //~ ERROR Illegal anonymous lifetime: only 'static is allowed here
static c_y: &int = &22; //~ ERROR missing lifetime specifier
static c_z: &'static int = &22;

fn main() {
Expand Down
Loading

0 comments on commit 5e54a73

Please sign in to comment.