Skip to content

Commit

Permalink
Move Inferred Types and Type Parameters to their own pages.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Nov 5, 2018
1 parent 18f1418 commit eb02dd5
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 48 deletions.
2 changes: 2 additions & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
- [Function pointer types](types/function-pointer.md)
- [Trait object types](types/trait-object.md)
- [Impl trait type](types/impl-trait.md)
- [Type parameters](types/parameters.md)
- [Inferred type](types/inferred.md)
- [Dynamically Sized Types](dynamically-sized-types.md)
- [Type layout](type-layout.md)
- [Interior mutability](interior-mutability.md)
Expand Down
2 changes: 1 addition & 1 deletion src/keywords.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ is possible to declare a variable or method with the name `union`.
[items]: items.html
[Variables]: variables.html
[Type parameters]: types.html#type-parameters
[Type parameters]: types/parameters.html
[loop labels]: expressions/loop-expr.html#loop-labels
[Macros]: macros.html
[attributes]: attributes.html
Expand Down
2 changes: 1 addition & 1 deletion src/special-types-and-traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,6 @@ compiler, not by [implementation items].
[the standard library]: ../std/index.html
[trait object]: types/trait-object.html
[Tuples]: types/tuple.html
[Type parameters]: types.html#type-parameters
[Type parameters]: types/parameters.html
[variance]: subtyping.html#variance
[`!`]: types/never.html
2 changes: 1 addition & 1 deletion src/tokens.md
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ them are referred to as "token trees" in [macros]. The three types of brackets
| `(` `)` | Parentheses |


[Inferred types]: types.html#inferred-type
[Inferred types]: types/inferred.html
[Operator expressions]: expressions/operator-expr.html
[Range patterns]: patterns.html#range-patterns
[Reference patterns]: patterns.html#reference-patterns
Expand Down
4 changes: 3 additions & 1 deletion src/types-redirect.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
"#impl-trait": "types/impl-trait.html",
"#anonymous-type-parameters": "types/impl-trait.html#anonymous-type-parameters",
"#abstract-return-types": "types/impl-trait.html#abstract-return-types",
"#self-types": "paths.html#self-1"
"#self-types": "paths.html#self-1",
"#inferred-type": "types/inferred.html",
"#type-parameters": "types/parameters.html",
};
var target = fragments[window.location.hash];
if (target) {
Expand Down
47 changes: 3 additions & 44 deletions src/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ for referring to a type. It may refer to:
* The [never] type.
* [Macros] which expand to a type expression.


### Parenthesized types

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

### Inferred type
> **<sup>Syntax</sup>**\
> _InferredType_ : `_`
The inferred type asks the compiler to infer the type if possible based on the
surrounding information available. It cannot be used in item signatures. It is
often used in generic arguments:

```rust
let x: Vec<_> = (0..10).collect();
```

<!--
What else should be said here?
The only documentation I am aware of is https://rust-lang-nursery.github.io/rustc-guide/type-inference.html
There should be a broader discussion of type inference somewhere.
-->


### Type parameters

Within the body of an item that has type parameter declarations, the names of
its type parameters are types:

```rust
fn to_vec<A: Clone>(xs: &[A]) -> Vec<A> {
if xs.is_empty() {
return vec![];
}
let first: A = xs[0].clone();
let mut rest: Vec<A> = to_vec(&xs[1..]);
rest.insert(0, first);
rest
}
```

Here, `first` has type `A`, referring to `to_vec`'s `A` type parameter; and
`rest` has type `Vec<A>`, a vector with element type `A`.


## Recursive types

Nominal types &mdash; [structs], [enumerations] and [unions] &mdash; may be
Expand Down Expand Up @@ -164,7 +123,7 @@ let a: List<i32> = List::Cons(7, Box::new(List::Cons(13, Box::new(List::Nil))));
[_BareFunctionType_]: types/function-pointer.html
[_ImplTraitTypeOneBound_]: types/impl-trait.html
[_ImplTraitType_]: types/impl-trait.html
[_InferredType_]: types.html#inferred-type
[_InferredType_]: types/inferred.html
[_MacroInvocation_]: macros.html#macro-invocation
[_NeverType_]: types/never.html
[_ParenthesizedType_]: types.html#parenthesized-types
Expand Down Expand Up @@ -202,7 +161,7 @@ let a: List<i32> = List::Cons(7, Box::new(List::Cons(13, Box::new(List::Nil))));
[arrays]: types/array.html
[enumerations]: types/enum.html
[function pointer]: types/function-pointer.html
[inferred type]: types.html#inferred-type
[inferred type]: types/inferred.html
[item]: items.html
[never]: types/never.html
[pointer types]: types/pointer.html
Expand All @@ -215,5 +174,5 @@ let a: List<i32> = List::Cons(7, Box::new(List::Cons(13, Box::new(List::Nil))));
[type alias]: items/type-aliases.html
[type aliases]: items/type-aliases.html
[type boundaries]: trait-bounds.html
[type parameters]: #type-parameters
[type parameters]: types/parameters.html
[unions]: types/union.html
18 changes: 18 additions & 0 deletions src/types/inferred.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Inferred type

> **<sup>Syntax</sup>**\
> _InferredType_ : `_`
The inferred type asks the compiler to infer the type if possible based on the
surrounding information available. It cannot be used in item signatures. It is
often used in generic arguments:

```rust
let x: Vec<_> = (0..10).collect();
```

<!--
What else should be said here?
The only documentation I am aware of is https://rust-lang-nursery.github.io/rustc-guide/type-inference.html
There should be a broader discussion of type inference somewhere.
-->
19 changes: 19 additions & 0 deletions src/types/parameters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Type parameters

Within the body of an item that has type parameter declarations, the names of
its type parameters are types:

```rust
fn to_vec<A: Clone>(xs: &[A]) -> Vec<A> {
if xs.is_empty() {
return vec![];
}
let first: A = xs[0].clone();
let mut rest: Vec<A> = to_vec(&xs[1..]);
rest.insert(0, first);
rest
}
```

Here, `first` has type `A`, referring to `to_vec`'s `A` type parameter; and
`rest` has type `Vec<A>`, a vector with element type `A`.

0 comments on commit eb02dd5

Please sign in to comment.