Skip to content

Commit 128fa2b

Browse files
authored
Rollup merge of rust-lang#72071 - PankajChaudhary5:ErrorCode-E0687, r=davidtwco
Added detailed error code explanation for issue E0687 in Rust compiler. Added proper error explanation for issue E0687 in the Rust compiler. Error Code E0687 Sub Part of Issue rust-lang#61137 r? @GuillaumeGomez
2 parents 1505c12 + 46bfc48 commit 128fa2b

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

src/librustc_error_codes/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ E0668: include_str!("./error_codes/E0668.md"),
382382
E0669: include_str!("./error_codes/E0669.md"),
383383
E0670: include_str!("./error_codes/E0670.md"),
384384
E0671: include_str!("./error_codes/E0671.md"),
385+
E0687: include_str!("./error_codes/E0687.md"),
385386
E0689: include_str!("./error_codes/E0689.md"),
386387
E0690: include_str!("./error_codes/E0690.md"),
387388
E0691: include_str!("./error_codes/E0691.md"),
@@ -613,7 +614,6 @@ E0766: include_str!("./error_codes/E0766.md"),
613614
E0640, // infer outlives requirements
614615
// E0645, // trait aliases not finished
615616
E0667, // `impl Trait` in projections
616-
E0687, // in-band lifetimes cannot be used in `fn`/`Fn` syntax
617617
E0688, // in-band lifetimes cannot be mixed with explicit lifetime binders
618618
// E0694, // an unknown tool name found in scoped attributes
619619
// E0702, // replaced with a generic attribute input check
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
In-band lifetimes cannot be used in `fn`/`Fn` syntax.
2+
3+
Erroneous code examples:
4+
5+
```compile_fail,E0687
6+
#![feature(in_band_lifetimes)]
7+
8+
fn foo(x: fn(&'a u32)) {} // error!
9+
10+
fn bar(x: &Fn(&'a u32)) {} // error!
11+
12+
fn baz(x: fn(&'a u32), y: &'a u32) {} // error!
13+
14+
struct Foo<'a> { x: &'a u32 }
15+
16+
impl Foo<'a> {
17+
fn bar(&self, x: fn(&'a u32)) {} // error!
18+
}
19+
```
20+
21+
Lifetimes used in `fn` or `Fn` syntax must be explicitly
22+
declared using `<...>` binders. For example:
23+
24+
```
25+
fn foo<'a>(x: fn(&'a u32)) {} // ok!
26+
27+
fn bar<'a>(x: &Fn(&'a u32)) {} // ok!
28+
29+
fn baz<'a>(x: fn(&'a u32), y: &'a u32) {} // ok!
30+
31+
struct Foo<'a> { x: &'a u32 }
32+
33+
impl<'a> Foo<'a> {
34+
fn bar(&self, x: fn(&'a u32)) {} // ok!
35+
}
36+
```

src/test/ui/in-band-lifetimes/E0687.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ LL | fn bar(&self, x: fn(&'a u32)) {}
2424

2525
error: aborting due to 4 previous errors
2626

27+
For more information about this error, try `rustc --explain E0687`.

src/test/ui/in-band-lifetimes/E0687_where.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ LL | fn baz(x: &impl Fn(&'a u32)) {}
1212

1313
error: aborting due to 2 previous errors
1414

15+
For more information about this error, try `rustc --explain E0687`.

0 commit comments

Comments
 (0)