Skip to content

Commit f865300

Browse files
committed
ufcs with annot in position 1 and 2
1 parent 05c1b89 commit f865300

File tree

4 files changed

+240
-0
lines changed

4 files changed

+240
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
// Unit test for the "user substitutions" that are annotated on each
12+
// node.
13+
14+
#![feature(nll)]
15+
16+
trait Bazoom<T>: Sized {
17+
fn method<U>(self, arg: T, arg2: U) { }
18+
}
19+
20+
impl<T, U> Bazoom<U> for T {
21+
}
22+
23+
fn annot_underscore() {
24+
let a = 22;
25+
let b = 44;
26+
let c = 66;
27+
<_ as Bazoom<_>>::method::<_>(&a, b, c); // OK
28+
}
29+
30+
fn annot_reference_any_lifetime() {
31+
let a = 22;
32+
let b = 44;
33+
let c = 66;
34+
<&u32 as Bazoom<_>>::method(&a, b, c); // OK
35+
}
36+
37+
fn annot_reference_static_lifetime() {
38+
let a = 22;
39+
let b = 44;
40+
let c = 66;
41+
let x = <&'static u32 as Bazoom<_>>::method;
42+
x(&a, b, c); //~ ERROR
43+
}
44+
45+
fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
46+
let a = 22;
47+
let b = 44;
48+
let c = 66;
49+
<&'a u32 as Bazoom<_>>::method(&a, b, c); //~ ERROR
50+
}
51+
52+
fn annot_reference_named_lifetime_ok<'a>(a: &'a u32) {
53+
let b = 44;
54+
let c = 66;
55+
<&'a u32 as Bazoom<_>>::method(&a, b, c);
56+
}
57+
58+
fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
59+
let a = 22;
60+
let b = 44;
61+
let _closure = || {
62+
let c = 66;
63+
<&'a u32 as Bazoom<_>>::method(&a, b, c); //~ ERROR
64+
};
65+
}
66+
67+
fn annot_reference_named_lifetime_in_closure_ok<'a>(a: &'a u32) {
68+
let b = 44;
69+
let c = 66;
70+
let _closure = || {
71+
<&'a u32 as Bazoom<_>>::method(&a, b, c);
72+
};
73+
}
74+
75+
fn main() { }
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
error[E0597]: `a` does not live long enough
2+
--> $DIR/method-ufcs-1.rs:42:7
3+
|
4+
LL | x(&a, b, c); //~ ERROR
5+
| ^^ borrowed value does not live long enough
6+
LL | }
7+
| - `a` dropped here while still borrowed
8+
|
9+
= note: borrowed value must be valid for the static lifetime...
10+
11+
error[E0597]: `a` does not live long enough
12+
--> $DIR/method-ufcs-1.rs:49:36
13+
|
14+
LL | <&'a u32 as Bazoom<_>>::method(&a, b, c); //~ ERROR
15+
| ^^ borrowed value does not live long enough
16+
LL | }
17+
| - `a` dropped here while still borrowed
18+
|
19+
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 45:35...
20+
--> $DIR/method-ufcs-1.rs:45:35
21+
|
22+
LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
23+
| ^^
24+
25+
error[E0597]: `a` does not live long enough
26+
--> $DIR/method-ufcs-1.rs:63:41
27+
|
28+
LL | let _closure = || {
29+
| -- value captured here
30+
LL | let c = 66;
31+
LL | <&'a u32 as Bazoom<_>>::method(&a, b, c); //~ ERROR
32+
| ^ borrowed value does not live long enough
33+
LL | };
34+
LL | }
35+
| - `a` dropped here while still borrowed
36+
|
37+
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 58:46...
38+
--> $DIR/method-ufcs-1.rs:58:46
39+
|
40+
LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
41+
| ^^
42+
43+
error: aborting due to 3 previous errors
44+
45+
For more information about this error, try `rustc --explain E0597`.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
// Unit test for the "user substitutions" that are annotated on each
12+
// node.
13+
14+
#![feature(nll)]
15+
16+
trait Bazoom<T>: Sized {
17+
fn method<U>(self, arg: T, arg2: U) { }
18+
}
19+
20+
impl<T, U> Bazoom<U> for T {
21+
}
22+
23+
fn annot_underscore() {
24+
let a = 22;
25+
let b = 44;
26+
let c = 66;
27+
<_ as Bazoom<_>>::method(a, &b, c); // OK
28+
}
29+
30+
fn annot_reference_any_lifetime() {
31+
let a = 22;
32+
let b = 44;
33+
let c = 66;
34+
<_ as Bazoom<&u32>>::method(a, &b, c); // OK
35+
}
36+
37+
fn annot_reference_static_lifetime() {
38+
let a = 22;
39+
let b = 44;
40+
let c = 66;
41+
let x = <&'static u32 as Bazoom<_>>::method;
42+
x(&a, b, c); //~ ERROR
43+
}
44+
45+
fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
46+
let a = 22;
47+
let b = 44;
48+
let c = 66;
49+
<_ as Bazoom<&'a u32>>::method(a, &b, c); //~ ERROR
50+
}
51+
52+
fn annot_reference_named_lifetime_ok<'a>(b: &'a u32) {
53+
let a = 44;
54+
let c = 66;
55+
<_ as Bazoom<&'a u32>>::method(a, &b, c);
56+
}
57+
58+
fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
59+
let a = 22;
60+
let b = 44;
61+
let _closure = || {
62+
let c = 66;
63+
<_ as Bazoom<&'a u32>>::method(a, &b, c); //~ ERROR
64+
};
65+
}
66+
67+
fn annot_reference_named_lifetime_in_closure_ok<'a>(b: &'a u32) {
68+
let a = 44;
69+
let c = 66;
70+
let _closure = || {
71+
<_ as Bazoom<&'a u32>>::method(a, &b, c);
72+
};
73+
}
74+
75+
fn main() { }
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
error[E0597]: `a` does not live long enough
2+
--> $DIR/method-ufcs-2.rs:42:7
3+
|
4+
LL | x(&a, b, c); //~ ERROR
5+
| ^^ borrowed value does not live long enough
6+
LL | }
7+
| - `a` dropped here while still borrowed
8+
|
9+
= note: borrowed value must be valid for the static lifetime...
10+
11+
error[E0597]: `b` does not live long enough
12+
--> $DIR/method-ufcs-2.rs:49:39
13+
|
14+
LL | <_ as Bazoom<&'a u32>>::method(a, &b, c); //~ ERROR
15+
| ^^ borrowed value does not live long enough
16+
LL | }
17+
| - `b` dropped here while still borrowed
18+
|
19+
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 45:35...
20+
--> $DIR/method-ufcs-2.rs:45:35
21+
|
22+
LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
23+
| ^^
24+
25+
error[E0597]: `b` does not live long enough
26+
--> $DIR/method-ufcs-2.rs:63:44
27+
|
28+
LL | let _closure = || {
29+
| -- value captured here
30+
LL | let c = 66;
31+
LL | <_ as Bazoom<&'a u32>>::method(a, &b, c); //~ ERROR
32+
| ^ borrowed value does not live long enough
33+
LL | };
34+
LL | }
35+
| - `b` dropped here while still borrowed
36+
|
37+
note: borrowed value must be valid for the lifetime 'a as defined on the function body at 58:46...
38+
--> $DIR/method-ufcs-2.rs:58:46
39+
|
40+
LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
41+
| ^^
42+
43+
error: aborting due to 3 previous errors
44+
45+
For more information about this error, try `rustc --explain E0597`.

0 commit comments

Comments
 (0)