Skip to content

Commit 5ff13ac

Browse files
committed
Move where clause to the bounds chapter
Organizationally I think it makes more sense, since this chapter is all about defining bounds.
1 parent 5a52502 commit 5ff13ac

7 files changed

Lines changed: 40 additions & 39 deletions

File tree

book.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ use-boolean-and = true
5151
"/glossary.html#object-safe-traits" = "glossary.html#dyn-compatible-traits"
5252
"/items/extern-crates.html#extern-prelude" = "../names/preludes.html#extern-prelude"
5353
"/items/generics.html" = "../types/generics.html"
54+
"/items/generics.html#where-clauses" = "../trait-bounds.html#where-clauses"
5455
"/items/modules.html#prelude-items" = "../names/preludes.html"
5556
"/items/traits.html#object-safety" = "traits.html#dyn-compatibility"
5657
"/lifetime-elision.html#static-lifetime-elision" = "lifetime-elision.html#const-and-static-elision"

src/crates-and-source-files.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,4 @@ The crate name must not be empty, and must only contain [Unicode alphanumeric] o
139139
[panic-docs]: panic.md#unwinding-across-ffi-boundaries
140140
[shebang]: input-format.md#shebang-removal
141141
[trait or lifetime bounds]: trait-bounds.md
142-
[where clauses]: types/generics.md#where-clauses
142+
[where clauses]: bound.where

src/items/associated-items.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,5 +510,5 @@ fn main() {
510510
[path]: ../paths.md
511511
[regular function parameters]: functions.md#attributes-on-function-parameters
512512
[generic parameters]: ../types/generics.md
513-
[where clauses]: ../types/generics.md#where-clauses
513+
[where clauses]: bound.where
514514
[constant evaluation]: ../const_eval.md

src/items/traits.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ fn main() {
374374
[supertraits]: #supertraits
375375
[implementations]: implementations.md
376376
[generics]: ../types/generics.md
377-
[where clauses]: ../types/generics.md#where-clauses
377+
[where clauses]: bound.where
378378
[generic functions]: functions.md#generic-functions
379379
[unsafe]: ../unsafety.md
380380
[trait implementation]: implementations.md#trait-implementations

src/syntax-index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,6 @@ This appendix provides an index of tokens and common forms with links to where t
450450
[use items]: items.use
451451
[variadic functions]: items.extern.variadic
452452
[visibility]: vis
453-
[where clauses]: generics.where
453+
[where clauses]: bound.where
454454
[while let]: expr.loop.while.let
455455
[wildcard pattern]: patterns.wildcard

src/trait-bounds.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,40 @@ struct UsesA<'a, T>(A<'a, T>);
9595
r[bound.trait-object]
9696
Trait and lifetime bounds are also used to name [trait objects].
9797

98+
r[bound.where]
99+
## Where clauses
100+
101+
r[bound.where.intro]
102+
*Where clauses* provide another way to specify bounds on type and lifetime parameters as well as a way to specify bounds on types that aren't type parameters.
103+
104+
r[bound.where.syntax]
105+
```grammar,items
106+
WhereClause -> `where` ( WhereClauseItem `,` )* WhereClauseItem?
107+
108+
WhereClauseItem ->
109+
LifetimeWhereClauseItem
110+
| TypeBoundWhereClauseItem
111+
112+
LifetimeWhereClauseItem -> Lifetime `:` LifetimeBounds
113+
114+
TypeBoundWhereClauseItem -> ForLifetimes? Type `:` TypeParamBounds?
115+
```
116+
117+
r[bound.where.higher-ranked-lifetimes]
118+
The `for` keyword can be used to introduce [higher-ranked lifetimes]. It only allows [LifetimeParam] parameters.
119+
120+
```rust
121+
struct A<T>
122+
where
123+
T: Iterator, // Could use A<T: Iterator> instead
124+
T::Item: Copy, // Bound on an associated type
125+
String: PartialEq<T>, // Bound on `String`, using the type parameter
126+
i32: Default, // Allowed, but not useful
127+
{
128+
f: T,
129+
}
130+
```
131+
98132
r[bound.sized]
99133
## `?Sized`
100134

@@ -251,4 +285,4 @@ Certain bounds lists may include a `use<..>` bound to control which generic para
251285
[trait object]: types/trait-object.md
252286
[trait objects]: types/trait-object.md
253287
[type parameters]: types/parameters.md
254-
[where clause]: types/generics.md#where-clauses
288+
[where clause]: bound.where

src/types/generics.md

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -225,40 +225,6 @@ fn generic<const B: bool>() {
225225
}
226226
```
227227

228-
r[generics.where]
229-
## Where clauses
230-
231-
r[generics.where.syntax]
232-
```grammar,items
233-
WhereClause -> `where` ( WhereClauseItem `,` )* WhereClauseItem?
234-
235-
WhereClauseItem ->
236-
LifetimeWhereClauseItem
237-
| TypeBoundWhereClauseItem
238-
239-
LifetimeWhereClauseItem -> Lifetime `:` LifetimeBounds
240-
241-
TypeBoundWhereClauseItem -> ForLifetimes? Type `:` TypeParamBounds?
242-
```
243-
244-
r[generics.where.intro]
245-
*Where clauses* provide another way to specify bounds on type and lifetime parameters as well as a way to specify bounds on types that aren't type parameters.
246-
247-
r[generics.where.higher-ranked-lifetimes]
248-
The `for` keyword can be used to introduce [higher-ranked lifetimes]. It only allows [LifetimeParam] parameters.
249-
250-
```rust
251-
struct A<T>
252-
where
253-
T: Iterator, // Could use A<T: Iterator> instead
254-
T::Item: Copy, // Bound on an associated type
255-
String: PartialEq<T>, // Bound on `String`, using the type parameter
256-
i32: Default, // Allowed, but not useful
257-
{
258-
f: T,
259-
}
260-
```
261-
262228
r[generics.parameters.attributes]
263229
## Attributes
264230

0 commit comments

Comments
 (0)