File tree 6 files changed +199
-0
lines changed
6 files changed +199
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright 2015 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
+ // Regression test for #48132. This was failing due to problems around
12
+ // the projection caching and dropck type enumeration.
13
+
14
+ // run-pass
15
+
16
+ #![ feature( nll) ]
17
+ #![ allow( warnings) ]
18
+
19
+ struct Inner < I , V > {
20
+ iterator : I ,
21
+ item : V ,
22
+ }
23
+
24
+ struct Outer < I : Iterator > {
25
+ inner : Inner < I , I :: Item > ,
26
+ }
27
+
28
+ fn outer < I > ( iterator : I ) -> Outer < I >
29
+ where I : Iterator ,
30
+ I :: Item : Default ,
31
+ {
32
+ Outer {
33
+ inner : Inner {
34
+ iterator : iterator,
35
+ item : Default :: default ( ) ,
36
+ }
37
+ }
38
+ }
39
+
40
+ fn main ( ) {
41
+ outer ( std:: iter:: once ( & 1 ) . cloned ( ) ) ;
42
+ }
Original file line number Diff line number Diff line change
1
+ // Copyright 2015 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
+ // Regression test for #48132. This was failing due to problems around
12
+ // the projection caching and dropck type enumeration.
13
+
14
+ // run-pass
15
+
16
+ #![ feature( nll) ]
17
+ #![ allow( warnings) ]
18
+
19
+ pub struct Container < T : Iterator > {
20
+ value : Option < T :: Item > ,
21
+ }
22
+
23
+ impl < T : Iterator > Container < T > {
24
+ pub fn new ( iter : T ) -> Self {
25
+ panic ! ( )
26
+ }
27
+ }
28
+
29
+ pub struct Wrapper < ' a > {
30
+ content : & ' a Content ,
31
+ }
32
+
33
+ impl < ' a , ' de > Wrapper < ' a > {
34
+ pub fn new ( content : & ' a Content ) -> Self {
35
+ Wrapper {
36
+ content : content,
37
+ }
38
+ }
39
+ }
40
+
41
+ pub struct Content ;
42
+
43
+ fn crash_it ( content : Content ) {
44
+ let items = vec ! [ content] ;
45
+ let map = items. iter ( ) . map ( |ref o| Wrapper :: new ( o) ) ;
46
+
47
+ let mut map_visitor = Container :: new ( map) ;
48
+
49
+ }
50
+
51
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ // Copyright 2017 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
+ // Regression test for #31567: cached results of projections were
12
+ // causing region relations not to be enforced at all the places where
13
+ // they have to be enforced.
14
+
15
+ #![ feature( nll) ]
16
+
17
+ struct VecWrapper < ' a > ( & ' a mut S ) ;
18
+
19
+ struct S ( Box < u32 > ) ;
20
+
21
+ fn get_dangling < ' a > ( v : VecWrapper < ' a > ) -> & ' a u32 {
22
+ let s_inner: & ' a S = & * v. 0 ; //~ ERROR `*v.0` does not live long enough
23
+ & s_inner. 0
24
+ }
25
+
26
+ impl < ' a > Drop for VecWrapper < ' a > {
27
+ fn drop ( & mut self ) {
28
+ * self . 0 = S ( Box :: new ( 0 ) ) ;
29
+ }
30
+ }
31
+
32
+ fn main ( ) {
33
+ let mut s = S ( Box :: new ( 11 ) ) ;
34
+ let vw = VecWrapper ( & mut s) ;
35
+ let dangling = get_dangling ( vw) ;
36
+ println ! ( "{}" , dangling) ;
37
+ }
Original file line number Diff line number Diff line change
1
+ error[E0597]: `*v.0` does not live long enough
2
+ --> $DIR/issue-31567.rs:22:26
3
+ |
4
+ LL | let s_inner: &'a S = &*v.0; //~ ERROR `*v.0` does not live long enough
5
+ | ^^^^^ borrowed value does not live long enough
6
+ LL | &s_inner.0
7
+ LL | }
8
+ | - borrowed value only lives until here
9
+ |
10
+ note: borrowed value must be valid for the lifetime 'a as defined on the function body at 21:1...
11
+ --> $DIR/issue-31567.rs:21:1
12
+ |
13
+ LL | fn get_dangling<'a>(v: VecWrapper<'a>) -> &'a u32 {
14
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15
+
16
+ error: aborting due to previous error
17
+
18
+ If you want more information on this error, try using "rustc --explain E0597"
Original file line number Diff line number Diff line change
1
+ // Copyright 2017 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
+ // Regression test for #47470: cached results of projections were
12
+ // causing region relations not to be enforced at all the places where
13
+ // they have to be enforced.
14
+
15
+ #![ feature( nll) ]
16
+
17
+ struct Foo < ' a > ( & ' a ( ) ) ;
18
+ trait Bar {
19
+ type Assoc ;
20
+ fn get ( self ) -> Self :: Assoc ;
21
+ }
22
+
23
+ impl < ' a > Bar for Foo < ' a > {
24
+ type Assoc = & ' a u32 ;
25
+ fn get ( self ) -> Self :: Assoc {
26
+ let local = 42 ;
27
+ & local //~ ERROR `local` does not live long enough
28
+ }
29
+ }
30
+
31
+ fn main ( ) {
32
+ let f = Foo ( & ( ) ) . get ( ) ;
33
+ println ! ( "{}" , f) ;
34
+ }
Original file line number Diff line number Diff line change
1
+ error[E0597]: `local` does not live long enough
2
+ --> $DIR/issue-47470.rs:27:9
3
+ |
4
+ LL | &local //~ ERROR `local` does not live long enough
5
+ | ^^^^^^ borrowed value does not live long enough
6
+ LL | }
7
+ | - borrowed value only lives until here
8
+ |
9
+ note: borrowed value must be valid for the lifetime 'a as defined on the impl at 23:1...
10
+ --> $DIR/issue-47470.rs:23:1
11
+ |
12
+ LL | impl<'a> Bar for Foo<'a> {
13
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
14
+
15
+ error: aborting due to previous error
16
+
17
+ If you want more information on this error, try using "rustc --explain E0597"
You can’t perform that action at this time.
0 commit comments