Skip to content

Commit 361367c

Browse files
authored
Merge pull request #964 from Havvy/turbofish
Define turbofish in the glossary
2 parents 6017cc6 + 6b4826e commit 361367c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/glossary.md

+17
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,22 @@ It allows a type to make certain promises about its behavior.
234234

235235
Generic functions and generic structs can use traits to constrain, or bound, the types they accept.
236236

237+
### Turbofish
238+
239+
Paths with generic parameters in expressions must prefix the opening brackets with a `::`.
240+
Combined with the angular brackets for generics, this looks like a fish `::<>`.
241+
As such, this syntax is colloquially referred to as turbofish syntax.
242+
243+
Examples:
244+
245+
```rust
246+
let ok_num = Ok::<_, ()>(5);
247+
let vec = [1, 2, 3].iter().map(|n| n * 2).collect::<Vec<_>>();
248+
```
249+
250+
This `::` prefix is required to disambiguate generic paths with multiple comparisons in a comma-separate list.
251+
See [the bastion of the turbofish][turbofish test] for an example.
252+
237253
### Uncovered type
238254

239255
A type which does not appear as an argument to another type. For example,
@@ -286,6 +302,7 @@ example of an uninhabited type is the [never type] `!`, or an enum with no varia
286302
[structs]: items/structs.md
287303
[trait objects]: types/trait-object.md
288304
[traits]: items/traits.md
305+
[turbofish test]: https://github.com/rust-lang/rust/blob/master/src/test/ui/bastion-of-the-turbofish.rs
289306
[types]: types.md
290307
[undefined-behavior]: behavior-considered-undefined.md
291308
[unions]: items/unions.md

0 commit comments

Comments
 (0)