Skip to content

Commit eb02dd5

Browse files
committed
Move Inferred Types and Type Parameters to their own pages.
1 parent 18f1418 commit eb02dd5

8 files changed

+48
-48
lines changed

src/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
- [Function pointer types](types/function-pointer.md)
8484
- [Trait object types](types/trait-object.md)
8585
- [Impl trait type](types/impl-trait.md)
86+
- [Type parameters](types/parameters.md)
87+
- [Inferred type](types/inferred.md)
8688
- [Dynamically Sized Types](dynamically-sized-types.md)
8789
- [Type layout](type-layout.md)
8890
- [Interior mutability](interior-mutability.md)

src/keywords.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ is possible to declare a variable or method with the name `union`.
118118
119119
[items]: items.html
120120
[Variables]: variables.html
121-
[Type parameters]: types.html#type-parameters
121+
[Type parameters]: types/parameters.html
122122
[loop labels]: expressions/loop-expr.html#loop-labels
123123
[Macros]: macros.html
124124
[attributes]: attributes.html

src/special-types-and-traits.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,6 @@ compiler, not by [implementation items].
162162
[the standard library]: ../std/index.html
163163
[trait object]: types/trait-object.html
164164
[Tuples]: types/tuple.html
165-
[Type parameters]: types.html#type-parameters
165+
[Type parameters]: types/parameters.html
166166
[variance]: subtyping.html#variance
167167
[`!`]: types/never.html

src/tokens.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ them are referred to as "token trees" in [macros]. The three types of brackets
576576
| `(` `)` | Parentheses |
577577

578578

579-
[Inferred types]: types.html#inferred-type
579+
[Inferred types]: types/inferred.html
580580
[Operator expressions]: expressions/operator-expr.html
581581
[Range patterns]: patterns.html#range-patterns
582582
[Reference patterns]: patterns.html#reference-patterns

src/types-redirect.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
"#impl-trait": "types/impl-trait.html",
3030
"#anonymous-type-parameters": "types/impl-trait.html#anonymous-type-parameters",
3131
"#abstract-return-types": "types/impl-trait.html#abstract-return-types",
32-
"#self-types": "paths.html#self-1"
32+
"#self-types": "paths.html#self-1",
33+
"#inferred-type": "types/inferred.html",
34+
"#type-parameters": "types/parameters.html",
3335
};
3436
var target = fragments[window.location.hash];
3537
if (target) {

src/types.md

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ for referring to a type. It may refer to:
7575
* The [never] type.
7676
* [Macros] which expand to a type expression.
7777

78-
7978
### Parenthesized types
8079

8180
> _ParenthesizedType_ :\
@@ -93,46 +92,6 @@ require this disambiguation use the [_TypeNoBounds_] rule instead of
9392
type T<'a> = &'a (dyn Any + Send);
9493
```
9594

96-
### Inferred type
97-
> **<sup>Syntax</sup>**\
98-
> _InferredType_ : `_`
99-
100-
The inferred type asks the compiler to infer the type if possible based on the
101-
surrounding information available. It cannot be used in item signatures. It is
102-
often used in generic arguments:
103-
104-
```rust
105-
let x: Vec<_> = (0..10).collect();
106-
```
107-
108-
<!--
109-
What else should be said here?
110-
The only documentation I am aware of is https://rust-lang-nursery.github.io/rustc-guide/type-inference.html
111-
There should be a broader discussion of type inference somewhere.
112-
-->
113-
114-
115-
### Type parameters
116-
117-
Within the body of an item that has type parameter declarations, the names of
118-
its type parameters are types:
119-
120-
```rust
121-
fn to_vec<A: Clone>(xs: &[A]) -> Vec<A> {
122-
if xs.is_empty() {
123-
return vec![];
124-
}
125-
let first: A = xs[0].clone();
126-
let mut rest: Vec<A> = to_vec(&xs[1..]);
127-
rest.insert(0, first);
128-
rest
129-
}
130-
```
131-
132-
Here, `first` has type `A`, referring to `to_vec`'s `A` type parameter; and
133-
`rest` has type `Vec<A>`, a vector with element type `A`.
134-
135-
13695
## Recursive types
13796

13897
Nominal types &mdash; [structs], [enumerations] and [unions] &mdash; may be
@@ -164,7 +123,7 @@ let a: List<i32> = List::Cons(7, Box::new(List::Cons(13, Box::new(List::Nil))));
164123
[_BareFunctionType_]: types/function-pointer.html
165124
[_ImplTraitTypeOneBound_]: types/impl-trait.html
166125
[_ImplTraitType_]: types/impl-trait.html
167-
[_InferredType_]: types.html#inferred-type
126+
[_InferredType_]: types/inferred.html
168127
[_MacroInvocation_]: macros.html#macro-invocation
169128
[_NeverType_]: types/never.html
170129
[_ParenthesizedType_]: types.html#parenthesized-types
@@ -202,7 +161,7 @@ let a: List<i32> = List::Cons(7, Box::new(List::Cons(13, Box::new(List::Nil))));
202161
[arrays]: types/array.html
203162
[enumerations]: types/enum.html
204163
[function pointer]: types/function-pointer.html
205-
[inferred type]: types.html#inferred-type
164+
[inferred type]: types/inferred.html
206165
[item]: items.html
207166
[never]: types/never.html
208167
[pointer types]: types/pointer.html
@@ -215,5 +174,5 @@ let a: List<i32> = List::Cons(7, Box::new(List::Cons(13, Box::new(List::Nil))));
215174
[type alias]: items/type-aliases.html
216175
[type aliases]: items/type-aliases.html
217176
[type boundaries]: trait-bounds.html
218-
[type parameters]: #type-parameters
177+
[type parameters]: types/parameters.html
219178
[unions]: types/union.html

src/types/inferred.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Inferred type
2+
3+
> **<sup>Syntax</sup>**\
4+
> _InferredType_ : `_`
5+
6+
The inferred type asks the compiler to infer the type if possible based on the
7+
surrounding information available. It cannot be used in item signatures. It is
8+
often used in generic arguments:
9+
10+
```rust
11+
let x: Vec<_> = (0..10).collect();
12+
```
13+
14+
<!--
15+
What else should be said here?
16+
The only documentation I am aware of is https://rust-lang-nursery.github.io/rustc-guide/type-inference.html
17+
There should be a broader discussion of type inference somewhere.
18+
-->

src/types/parameters.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Type parameters
2+
3+
Within the body of an item that has type parameter declarations, the names of
4+
its type parameters are types:
5+
6+
```rust
7+
fn to_vec<A: Clone>(xs: &[A]) -> Vec<A> {
8+
if xs.is_empty() {
9+
return vec![];
10+
}
11+
let first: A = xs[0].clone();
12+
let mut rest: Vec<A> = to_vec(&xs[1..]);
13+
rest.insert(0, first);
14+
rest
15+
}
16+
```
17+
18+
Here, `first` has type `A`, referring to `to_vec`'s `A` type parameter; and
19+
`rest` has type `Vec<A>`, a vector with element type `A`.

0 commit comments

Comments
 (0)