Skip to content

Commit ab09710

Browse files
committed
Add ntoes for test examples.
1 parent ce1800d commit ab09710

File tree

2 files changed

+28
-16
lines changed

2 files changed

+28
-16
lines changed

tests/ui/lifetimes.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,21 @@ fn fn_bound_2<'a, F, I>(_m: Lt<'a, I>, _f: F) -> Lt<'a, I>
5353
where for<'x> F: Fn(Lt<'x, I>) -> Lt<'x, I>
5454
{ unreachable!() }
5555

56-
fn fn_bound_3<'a, F: FnOnce(&'a ())>(x: &'a (), f: F) {} // no error, referenced
56+
fn fn_bound_3<'a, F: FnOnce(&'a i32)>(x: &'a i32, f: F) { // no error, see below
57+
f(x);
58+
}
59+
60+
fn fn_bound_3_cannot_elide() {
61+
let x = 42;
62+
let p = &x;
63+
let mut q = &x;
64+
fn_bound_3(p, |y| q = y); // this will fail if we elides lifetimes of `fn_bound_3`
65+
}
5766

58-
fn fn_bound_4<'a, F: FnOnce() -> &'a ()>(x: &'a (), f: F) {} // no error, referenced
67+
// no error, multiple input refs
68+
fn fn_bound_4<'a, F: FnOnce() -> &'a ()>(cond: bool, x: &'a (), f: F) -> &'a () {
69+
if cond { x } else { f() }
70+
}
5971

6072
struct X {
6173
x: u8,

tests/ui/lifetimes.stderr

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,45 +45,45 @@ error: explicit lifetimes given in parameter types where they could be elided
4545
| |__________________^
4646

4747
error: explicit lifetimes given in parameter types where they could be elided
48-
--> $DIR/lifetimes.rs:65:5
48+
--> $DIR/lifetimes.rs:77:5
4949
|
50-
65 | fn self_and_out<'s>(&'s self) -> &'s u8 { &self.x }
50+
77 | fn self_and_out<'s>(&'s self) -> &'s u8 { &self.x }
5151
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5252

5353
error: explicit lifetimes given in parameter types where they could be elided
54-
--> $DIR/lifetimes.rs:69:5
54+
--> $DIR/lifetimes.rs:81:5
5555
|
56-
69 | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) { }
56+
81 | fn distinct_self_and_in<'s, 't>(&'s self, _x: &'t u8) { }
5757
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5858

5959
error: explicit lifetimes given in parameter types where they could be elided
60-
--> $DIR/lifetimes.rs:85:1
60+
--> $DIR/lifetimes.rs:97:1
6161
|
62-
85 | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { unimplemented!() }
62+
97 | fn struct_with_lt<'a>(_foo: Foo<'a>) -> &'a str { unimplemented!() }
6363
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6464

6565
error: explicit lifetimes given in parameter types where they could be elided
66-
--> $DIR/lifetimes.rs:105:1
66+
--> $DIR/lifetimes.rs:117:1
6767
|
68-
105 | fn trait_obj_elided2<'a>(_arg: &'a Drop) -> &'a str { unimplemented!() }
68+
117 | fn trait_obj_elided2<'a>(_arg: &'a Drop) -> &'a str { unimplemented!() }
6969
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7070

7171
error: explicit lifetimes given in parameter types where they could be elided
72-
--> $DIR/lifetimes.rs:109:1
72+
--> $DIR/lifetimes.rs:121:1
7373
|
74-
109 | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { unimplemented!() }
74+
121 | fn alias_with_lt<'a>(_foo: FooAlias<'a>) -> &'a str { unimplemented!() }
7575
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7676

7777
error: explicit lifetimes given in parameter types where they could be elided
78-
--> $DIR/lifetimes.rs:120:1
78+
--> $DIR/lifetimes.rs:132:1
7979
|
80-
120 | fn named_input_elided_output<'a>(_arg: &'a str) -> &str { unimplemented!() }
80+
132 | fn named_input_elided_output<'a>(_arg: &'a str) -> &str { unimplemented!() }
8181
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8282

8383
error: explicit lifetimes given in parameter types where they could be elided
84-
--> $DIR/lifetimes.rs:124:1
84+
--> $DIR/lifetimes.rs:136:1
8585
|
86-
124 | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { unimplemented!() }
86+
136 | fn trait_bound_ok<'a, T: WithLifetime<'static>>(_: &'a u8, _: T) { unimplemented!() }
8787
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8888

8989
error: aborting due to 14 previous errors

0 commit comments

Comments
 (0)