From 5e54a7323dc3cc8b121de313b9af2d16424b086e Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 29 Oct 2013 06:14:59 -0400 Subject: [PATCH] Update various tests and libraries that were incorrectly annotated. --- Makefile.in | 1 + src/libextra/arc.rs | 28 +++++++++---------- src/librustc/driver/driver.rs | 5 +--- src/librustc/metadata/tydecode.rs | 22 +++++++-------- src/librustc/middle/trans/type_of.rs | 19 +++++++++++-- .../compile-fail/bad-mid-path-type-params.rs | 7 +++-- .../compile-fail/core-tls-store-pointer.rs | 2 +- src/test/compile-fail/issue-4335.rs | 2 +- src/test/compile-fail/issue-5216.rs | 8 +++--- .../kindck-owned-trait-contains.rs | 25 +++++++---------- src/test/compile-fail/regions-addr-of-arg.rs | 9 +++++- src/test/compile-fail/regions-addr-of-self.rs | 4 +-- .../regions-addr-of-upvar-self.rs | 2 +- src/test/compile-fail/regions-fn-subtyping.rs | 8 +++--- .../regions-free-region-ordering-callee.rs | 2 +- .../regions-free-region-ordering-caller.rs | 6 ---- .../regions-free-region-ordering-caller1.rs | 24 ++++++++++++++++ src/test/compile-fail/regions-in-consts.rs | 3 +- ...type-items.rs => regions-in-enums-anon.rs} | 12 ++------ src/test/compile-fail/regions-in-enums.rs | 14 +++++++--- ...ions-blk.rs => regions-in-structs-anon.rs} | 16 +++-------- src/test/compile-fail/regions-in-structs.rs | 14 ++++++---- ...regions-infer-region-in-fn-but-not-type.rs | 2 +- .../compile-fail/regions-ret-borrowed-1.rs | 2 +- src/test/compile-fail/regions-undeclared.rs | 23 +++++++++++++++ .../trait-impl-different-num-params.rs | 2 +- ...ddr-of.rs => regions-dependent-addr-of.rs} | 0 ...-autofn.rs => regions-dependent-autofn.rs} | 0 ...lice.rs => regions-dependent-autoslice.rs} | 0 src/test/run-pass/regions-mock-trans.rs | 2 +- ...s => regions-return-interior-of-option.rs} | 0 31 files changed, 156 insertions(+), 108 deletions(-) create mode 100644 src/test/compile-fail/regions-free-region-ordering-caller1.rs rename src/test/compile-fail/{regions-in-type-items.rs => regions-in-enums-anon.rs} (73%) rename src/test/compile-fail/{regions-blk.rs => regions-in-structs-anon.rs} (62%) create mode 100644 src/test/compile-fail/regions-undeclared.rs rename src/test/run-pass/{region-dependent-addr-of.rs => regions-dependent-addr-of.rs} (100%) rename src/test/run-pass/{region-dependent-autofn.rs => regions-dependent-autofn.rs} (100%) rename src/test/run-pass/{region-dependent-autoslice.rs => regions-dependent-autoslice.rs} (100%) rename src/test/run-pass/{region-return-interior-of-option.rs => regions-return-interior-of-option.rs} (100%) diff --git a/Makefile.in b/Makefile.in index b927c805220..f5bb3cb2ed0 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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 diff --git a/src/libextra/arc.rs b/src/libextra/arc.rs index df67b1c9cc1..b3da9b4f16b 100644 --- a/src/libextra/arc.rs +++ b/src/libextra/arc.rs @@ -233,10 +233,10 @@ impl MutexArc { /// 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(&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); @@ -290,10 +290,10 @@ impl MutexArc { /// 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(&self, + blk: &fn(x: &mut T, + c: &Condvar) -> U) + -> U { unsafe { self.unsafe_access_cond(blk) } } } @@ -402,9 +402,9 @@ impl RWArc { /// 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(&self, + blk: &fn(x: &mut T, c: &Condvar) -> U) + -> U { unsafe { let state = self.x.get(); do (*borrow_rwlock(state)).write_cond |cond| { @@ -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(&mut self, + blk: &fn(x: &mut T, c: &Condvar) -> U) + -> U { match *self { RWWriteMode { data: &ref mut data, diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 38099126682..6346e4856f2 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -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); diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 1636205c76d..6e06cef55ee 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -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)); @@ -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' => { @@ -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; } @@ -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, diff --git a/src/librustc/middle/trans/type_of.rs b/src/librustc/middle/trans/type_of.rs index 604321a0492..36af13d34e6 100644 --- a/src/librustc/middle/trans/type_of.rs +++ b/src/librustc/middle/trans/type_of.rs @@ -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; @@ -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 @@ -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; } @@ -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. diff --git a/src/test/compile-fail/bad-mid-path-type-params.rs b/src/test/compile-fail/bad-mid-path-type-params.rs index f9f4ccf0f07..90d6147f0ed 100644 --- a/src/test/compile-fail/bad-mid-path-type-params.rs +++ b/src/test/compile-fail/bad-mid-path-type-params.rs @@ -28,10 +28,11 @@ impl Trait for S2 { } } -fn main() { +fn foo<'a>() { let _ = S::new::(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::(1, 1.0); //~ ERROR this impl has no lifetime parameter + let _ = S::<'a,int>::new::(1, 1.0); //~ ERROR expected 0 lifetime parameter(s) let _: S2 = Trait::new::(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::(1, 1.0); //~ ERROR this trait has no lifetime parameter + let _: S2 = Trait::<'a,int>::new::(1, 1.0); //~ ERROR expected 0 lifetime parameter(s) } +fn main() {} diff --git a/src/test/compile-fail/core-tls-store-pointer.rs b/src/test/compile-fail/core-tls-store-pointer.rs index 4f60391892d..70573ca4f18 100644 --- a/src/test/compile-fail/core-tls-store-pointer.rs +++ b/src/test/compile-fail/core-tls-store-pointer.rs @@ -13,6 +13,6 @@ use std::local_data; local_data_key!(key: @&int) -//~^ ERROR only 'static is allowed +//~^ ERROR missing lifetime specifier fn main() {} diff --git a/src/test/compile-fail/issue-4335.rs b/src/test/compile-fail/issue-4335.rs index 5b6240d8ac8..032b2564f4f 100644 --- a/src/test/compile-fail/issue-4335.rs +++ b/src/test/compile-fail/issue-4335.rs @@ -10,7 +10,7 @@ fn id(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; diff --git a/src/test/compile-fail/issue-5216.rs b/src/test/compile-fail/issue-5216.rs index 9f88ba72f05..8205a6dae64 100644 --- a/src/test/compile-fail/issue-5216.rs +++ b/src/test/compile-fail/issue-5216.rs @@ -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() {} diff --git a/src/test/compile-fail/kindck-owned-trait-contains.rs b/src/test/compile-fail/kindck-owned-trait-contains.rs index fb85edf699a..5fe9b13f83b 100644 --- a/src/test/compile-fail/kindck-owned-trait-contains.rs +++ b/src/test/compile-fail/kindck-owned-trait-contains.rs @@ -8,29 +8,24 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[feature(managed_boxes)]; +trait Repeat { fn get(&self) -> A; } -trait repeat { fn get(&self) -> A; } - -impl repeat for @A { - fn get(&self) -> A { **self } +impl Repeat for A { + fn get(&self) -> A { self.clone() } } -fn repeater(v: @A) -> @repeat { - // Note: owned kind is not necessary as A appears in the trait type - @v as @repeat // No +fn repeater(v: A) -> ~Repeat: { + ~v as ~Repeat: // 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 } diff --git a/src/test/compile-fail/regions-addr-of-arg.rs b/src/test/compile-fail/regions-addr-of-arg.rs index 4fff5a6f87c..ff13548b494 100644 --- a/src/test/compile-fail/regions-addr-of-arg.rs +++ b/src/test/compile-fail/regions-addr-of-arg.rs @@ -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() { diff --git a/src/test/compile-fail/regions-addr-of-self.rs b/src/test/compile-fail/regions-addr-of-self.rs index 3a480a7e963..b7be0dd7b9b 100644 --- a/src/test/compile-fail/regions-addr-of-self.rs +++ b/src/test/compile-fail/regions-addr-of-self.rs @@ -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; } } diff --git a/src/test/compile-fail/regions-addr-of-upvar-self.rs b/src/test/compile-fail/regions-addr-of-upvar-self.rs index 9cedf86f350..2f60898cfee 100644 --- a/src/test/compile-fail/regions-addr-of-upvar-self.rs +++ b/src/test/compile-fail/regions-addr-of-upvar-self.rs @@ -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; }; } diff --git a/src/test/compile-fail/regions-fn-subtyping.rs b/src/test/compile-fail/regions-fn-subtyping.rs index 5928d31a668..cad73daa46b 100644 --- a/src/test/compile-fail/regions-fn-subtyping.rs +++ b/src/test/compile-fail/regions-fn-subtyping.rs @@ -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)>( @@ -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 } diff --git a/src/test/compile-fail/regions-free-region-ordering-callee.rs b/src/test/compile-fail/regions-free-region-ordering-callee.rs index 66ab4b77054..fb31e477ba2 100644 --- a/src/test/compile-fail/regions-free-region-ordering-callee.rs +++ b/src/test/compile-fail/regions-free-region-ordering-callee.rs @@ -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!(); } diff --git a/src/test/compile-fail/regions-free-region-ordering-caller.rs b/src/test/compile-fail/regions-free-region-ordering-caller.rs index c9859899ea4..58fa437a6a3 100644 --- a/src/test/compile-fail/regions-free-region-ordering-caller.rs +++ b/src/test/compile-fail/regions-free-region-ordering-caller.rs @@ -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 diff --git a/src/test/compile-fail/regions-free-region-ordering-caller1.rs b/src/test/compile-fail/regions-free-region-ordering-caller1.rs new file mode 100644 index 00000000000..1408f75be89 --- /dev/null +++ b/src/test/compile-fail/regions-free-region-ordering-caller1.rs @@ -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 or the MIT license +// , 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() {} diff --git a/src/test/compile-fail/regions-in-consts.rs b/src/test/compile-fail/regions-in-consts.rs index c34e5fb29de..9f2facf4e1f 100644 --- a/src/test/compile-fail/regions-in-consts.rs +++ b/src/test/compile-fail/regions-in-consts.rs @@ -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() { diff --git a/src/test/compile-fail/regions-in-type-items.rs b/src/test/compile-fail/regions-in-enums-anon.rs similarity index 73% rename from src/test/compile-fail/regions-in-type-items.rs rename to src/test/compile-fail/regions-in-enums-anon.rs index a30a6772bfd..5c7a37d0359 100644 --- a/src/test/compile-fail/regions-in-type-items.rs +++ b/src/test/compile-fail/regions-in-enums-anon.rs @@ -8,16 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct item_ty_yes0<'self> { - x: &'self uint -} +// Test that anonymous lifetimes are not permitted in enum declarations -struct item_ty_yes1<'self> { - x: &'self uint -} - -struct item_ty_yes2 { - x: &'a uint //~ ERROR only 'self is allowed +enum Foo { + Bar(&int) //~ ERROR missing lifetime specifier } fn main() {} diff --git a/src/test/compile-fail/regions-in-enums.rs b/src/test/compile-fail/regions-in-enums.rs index f189deef32e..0a221b9a533 100644 --- a/src/test/compile-fail/regions-in-enums.rs +++ b/src/test/compile-fail/regions-in-enums.rs @@ -8,17 +8,23 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// Test that lifetimes must be declared for use on enums. +// See also regions-undeclared.rs + enum yes0<'lt> { - // This will eventually be legal (and in fact the only way): - X3(&'lt uint) //~ ERROR Illegal lifetime 'lt: only 'self is allowed + X3(&'lt uint) } enum yes1<'self> { X4(&'self uint) } -enum yes2 { - X5(&'foo uint) //~ ERROR Illegal lifetime 'foo: only 'self is allowed +enum no0 { + X5(&'foo uint) //~ ERROR use of undeclared lifetime name `'foo` +} + +enum no1 { + X6(&'self uint) //~ ERROR use of undeclared lifetime name `'self` } fn main() {} diff --git a/src/test/compile-fail/regions-blk.rs b/src/test/compile-fail/regions-in-structs-anon.rs similarity index 62% rename from src/test/compile-fail/regions-blk.rs rename to src/test/compile-fail/regions-in-structs-anon.rs index 893e4c41178..0f2036a56cd 100644 --- a/src/test/compile-fail/regions-blk.rs +++ b/src/test/compile-fail/regions-in-structs-anon.rs @@ -8,18 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo(cond: bool) { - let x = 5; - let mut y: &'blk int = &x; +// Test that anonymous lifetimes are not permitted in struct declarations - let mut z: &'blk int; - if cond { - z = &x; //~ ERROR cannot infer an appropriate lifetime due to conflicting requirements - } else { - let w: &'blk int = &x; - z = w; - } +struct Foo { + x: &int //~ ERROR missing lifetime specifier } -fn main() { -} +fn main() {} diff --git a/src/test/compile-fail/regions-in-structs.rs b/src/test/compile-fail/regions-in-structs.rs index c4f1a8ae465..1e74fa4adb9 100644 --- a/src/test/compile-fail/regions-in-structs.rs +++ b/src/test/compile-fail/regions-in-structs.rs @@ -8,16 +8,18 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -struct yes0<'self> { - x: &uint, //~ ERROR Illegal anonymous lifetime: anonymous lifetimes are not permitted here -} - struct yes1<'self> { x: &'self uint, } -struct yes2<'self> { - x: &'foo uint, //~ ERROR Illegal lifetime 'foo: only 'self is allowed +struct yes2<'a> { + x: &'a uint, } +struct StructDecl { + a: &'a int, //~ ERROR use of undeclared lifetime name `'a` + b: &'self int, //~ ERROR use of undeclared lifetime name `'self` +} + + fn main() {} diff --git a/src/test/compile-fail/regions-infer-region-in-fn-but-not-type.rs b/src/test/compile-fail/regions-infer-region-in-fn-but-not-type.rs index 4c3338d2e1d..5c979955ec9 100644 --- a/src/test/compile-fail/regions-infer-region-in-fn-but-not-type.rs +++ b/src/test/compile-fail/regions-infer-region-in-fn-but-not-type.rs @@ -13,7 +13,7 @@ // contains region pointers struct foo(~fn(x: &int)); -fn take_foo(x: foo<'static>) {} //~ ERROR no region bound is allowed on `foo` +fn take_foo(x: foo<'static>) {} //~ ERROR wrong number of lifetime parameters fn main() { } diff --git a/src/test/compile-fail/regions-ret-borrowed-1.rs b/src/test/compile-fail/regions-ret-borrowed-1.rs index df7831e9050..ee6ed3b0d76 100644 --- a/src/test/compile-fail/regions-ret-borrowed-1.rs +++ b/src/test/compile-fail/regions-ret-borrowed-1.rs @@ -12,7 +12,7 @@ // some point regions-ret-borrowed reported an error but this file did // not, due to special hardcoding around the anonymous region. -fn with<'a, R>(f: &fn(x: &'a int) -> R) -> R { +fn with(f: &fn<'a>(x: &'a int) -> R) -> R { f(&3) } diff --git a/src/test/compile-fail/regions-undeclared.rs b/src/test/compile-fail/regions-undeclared.rs new file mode 100644 index 00000000000..fcf3a73b19f --- /dev/null +++ b/src/test/compile-fail/regions-undeclared.rs @@ -0,0 +1,23 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +static c_x: &'blk int = &22; //~ ERROR use of undeclared lifetime name `'blk` + +enum EnumDecl { + Foo(&'a int), //~ ERROR use of undeclared lifetime name `'a` + Bar(&'self int), //~ ERROR use of undeclared lifetime name `'self` +} + +fn fnDecl(x: &'a int, //~ ERROR use of undeclared lifetime name `'a` + y: &'self int) //~ ERROR use of undeclared lifetime name `'self` +{} + +fn main() { +} diff --git a/src/test/compile-fail/trait-impl-different-num-params.rs b/src/test/compile-fail/trait-impl-different-num-params.rs index 7039e050199..940c1b3a237 100644 --- a/src/test/compile-fail/trait-impl-different-num-params.rs +++ b/src/test/compile-fail/trait-impl-different-num-params.rs @@ -13,7 +13,7 @@ trait foo { } impl foo for int { fn bar(&self) -> int { - //~^ ERROR method `bar` has 0 parameters but the trait has 1 + //~^ ERROR method `bar` has 0 parameter(s) but the trait has 1 *self } } diff --git a/src/test/run-pass/region-dependent-addr-of.rs b/src/test/run-pass/regions-dependent-addr-of.rs similarity index 100% rename from src/test/run-pass/region-dependent-addr-of.rs rename to src/test/run-pass/regions-dependent-addr-of.rs diff --git a/src/test/run-pass/region-dependent-autofn.rs b/src/test/run-pass/regions-dependent-autofn.rs similarity index 100% rename from src/test/run-pass/region-dependent-autofn.rs rename to src/test/run-pass/regions-dependent-autofn.rs diff --git a/src/test/run-pass/region-dependent-autoslice.rs b/src/test/run-pass/regions-dependent-autoslice.rs similarity index 100% rename from src/test/run-pass/region-dependent-autoslice.rs rename to src/test/run-pass/regions-dependent-autoslice.rs diff --git a/src/test/run-pass/regions-mock-trans.rs b/src/test/run-pass/regions-mock-trans.rs index e66a34b47bc..6740230728c 100644 --- a/src/test/run-pass/regions-mock-trans.rs +++ b/src/test/run-pass/regions-mock-trans.rs @@ -30,7 +30,7 @@ struct Ccx { #[fixed_stack_segment] #[inline(never)] fn alloc<'a>(_bcx : &'a arena) -> &'a Bcx<'a> { unsafe { - cast::transmute(libc::malloc(mem::size_of::>() + cast::transmute(libc::malloc(mem::size_of::>() as libc::size_t)) } } diff --git a/src/test/run-pass/region-return-interior-of-option.rs b/src/test/run-pass/regions-return-interior-of-option.rs similarity index 100% rename from src/test/run-pass/region-return-interior-of-option.rs rename to src/test/run-pass/regions-return-interior-of-option.rs