Skip to content

Commit e84db9b

Browse files
committed
add test for method ufcs notation
1 parent 56506cf commit e84db9b

File tree

2 files changed

+122
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)