Skip to content

Commit 28746e5

Browse files
committed
docs formatted | nested-ty-params.rs
1 parent bf175bb commit 28746e5

File tree

2 files changed

+28
-19
lines changed

2 files changed

+28
-19
lines changed
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
1-
fn hd<U>(v: Vec<U> ) -> U {
2-
fn hd1(w: [U]) -> U { return w[0]; }
3-
//~^ ERROR can't use generic parameters from outer item
4-
//~| ERROR can't use generic parameters from outer item
1+
//! Test that generic parameters from an outer function are not accessible
2+
//! in nested functions. This checks that generic parameter scope is properly
3+
//! limited to the function where they are declared.
4+
//!
5+
//! The generic parameter `U` from the outer function `head` should not be
6+
//! available in the nested function `head_inner`, resulting in a compilation error.
57
6-
return hd1(v);
8+
fn head<U>(v: Vec<U>) -> U {
9+
fn head_inner(w: [U]) -> U {
10+
//~^ ERROR can't use generic parameters from outer item
11+
//~| ERROR can't use generic parameters from outer item
12+
return w[0];
13+
}
14+
15+
return head_inner(v);
716
}
817

918
fn main() {}

tests/ui/generics/generic-params-nested-fn-scope-error.stderr

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
error[E0401]: can't use generic parameters from outer item
2-
--> $DIR/nested-ty-params.rs:2:16
2+
--> $DIR/generic-params-nested-fn-scope-error.rs:9:23
33
|
4-
LL | fn hd<U>(v: Vec<U> ) -> U {
5-
| - type parameter from outer item
6-
LL | fn hd1(w: [U]) -> U { return w[0]; }
7-
| - ^ use of generic parameter from outer item
8-
| |
9-
| help: try introducing a local generic parameter here: `<U>`
4+
LL | fn head<U>(v: Vec<U>) -> U {
5+
| - type parameter from outer item
6+
LL | fn head_inner(w: [U]) -> U {
7+
| - ^ use of generic parameter from outer item
8+
| |
9+
| help: try introducing a local generic parameter here: `<U>`
1010

1111
error[E0401]: can't use generic parameters from outer item
12-
--> $DIR/nested-ty-params.rs:2:23
12+
--> $DIR/generic-params-nested-fn-scope-error.rs:9:30
1313
|
14-
LL | fn hd<U>(v: Vec<U> ) -> U {
15-
| - type parameter from outer item
16-
LL | fn hd1(w: [U]) -> U { return w[0]; }
17-
| - ^ use of generic parameter from outer item
18-
| |
19-
| help: try introducing a local generic parameter here: `<U>`
14+
LL | fn head<U>(v: Vec<U>) -> U {
15+
| - type parameter from outer item
16+
LL | fn head_inner(w: [U]) -> U {
17+
| - ^ use of generic parameter from outer item
18+
| |
19+
| help: try introducing a local generic parameter here: `<U>`
2020

2121
error: aborting due to 2 previous errors
2222

0 commit comments

Comments
 (0)