Skip to content

Commit 74a04c2

Browse files
committed
---
yaml --- r: 232377 b: refs/heads/try c: 7ed39c6 h: refs/heads/master i: 232375: 6f20862 v: v3
1 parent 5741e12 commit 74a04c2

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
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: edeb4f1c86cbf6af8ef9874d4b3af50f721ea1b8
33
refs/heads/snap-stage3: 1af31d4974e33027a68126fa5a5a3c2c6491824f
4-
refs/heads/try: dee8b54b71e6cb8145fc00b64f35c736a70c6bcf
4+
refs/heads/try: 7ed39c6d9bddb6f11b4681574cc0375446eb594e
55
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
66
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
77
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
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/try/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)