Skip to content

Commit e7044cc

Browse files
committed
---
yaml --- r: 227315 b: refs/heads/auto c: 7ed39c6 h: refs/heads/master i: 227313: 86f006c 227311: fd9357c v: v3
1 parent c1a8273 commit e7044cc

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: dee8b54b71e6cb8145fc00b64f35c736a70c6bcf
11+
refs/heads/auto: 7ed39c6d9bddb6f11b4681574cc0375446eb594e
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2014 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+
// This test used to be part of a run-pass test, but revised outlives
12+
// rule means that it no longer compiles.
13+
14+
#![allow(unused_variables)]
15+
16+
trait Trait<'a> {
17+
fn long(&'a self) -> isize;
18+
fn short<'b>(&'b self) -> isize;
19+
}
20+
21+
fn object_invoke1<'d>(x: &'d Trait<'d>) -> (isize, isize) { loop { } }
22+
23+
trait MakerTrait {
24+
fn mk() -> Self;
25+
}
26+
27+
fn make_val<T:MakerTrait>() -> T {
28+
MakerTrait::mk()
29+
}
30+
31+
impl<'t> MakerTrait for Box<Trait<'t>+'static> {
32+
fn mk() -> Box<Trait<'t>+'static> { loop { } }
33+
}
34+
35+
pub fn main() {
36+
let m : Box<Trait+'static> = make_val();
37+
assert_eq!(object_invoke1(&*m), (4,5));
38+
//~^ ERROR `*m` does not live long enough
39+
40+
// the problem here is that the full type of `m` is
41+
//
42+
// Box<Trait<'m>+'static>
43+
//
44+
// Here `'m` must be exactly the lifetime of the variable `m`.
45+
// This is because of two requirements:
46+
// 1. First, the basic type rules require that the
47+
// type of `m`'s value outlives the lifetime of `m`. This puts a lower
48+
// bound `'m`.
49+
//
50+
// 2. Meanwhile, the signature of `object_invoke1` requires that
51+
// we create a reference of type `&'d Trait<'d>` for some `'d`.
52+
// `'d` cannot outlive `'m`, so that forces the lifetime to be `'m`.
53+
//
54+
// This then conflicts with the dropck rules, which require that
55+
// the type of `m` *strictly outlives* `'m`. Hence we get an
56+
// error.
57+
}

branches/auto/src/test/run-pass/regions-early-bound-trait-param.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn field_invoke1<'f, 'g>(x: &'g Struct1<'f>) -> (isize,isize) {
4242
(l,s)
4343
}
4444

45-
struct Struct2<'h, 'i> {
45+
struct Struct2<'h, 'i:'h> {
4646
f: &'h (Trait<'i>+'h)
4747
}
4848

@@ -126,7 +126,10 @@ pub fn main() {
126126
assert_eq!(field_invoke2(&s2), 3);
127127

128128
let m : Box<Trait> = make_val();
129-
assert_eq!(object_invoke1(&*m), (4,5));
129+
// assert_eq!(object_invoke1(&*m), (4,5));
130+
// ~~~~~~~~~~~~~~~~~~~
131+
// this call yields a compilation error; see compile-fail/dropck-object-cycle.rs
132+
// for details.
130133
assert_eq!(object_invoke2(&*m), 5);
131134

132135
// The RefMakerTrait above is pretty strange (i.e. it is strange

0 commit comments

Comments
 (0)