Skip to content

Commit 0606234

Browse files
committed
auto merge of #17836 : typelist/rust/guide-tuples, r=steveklabnik
Currently, the Guide says tuples "are only equivalent if the arity, types, and values are all identical", before presenting an example that uses `==` to compare two tuples whose arity and contained types match. This is misleading, because it implies that `==` can dynamically check whether two tuples have the same arity and contained types, whereas trying to do this would lead to a compiler error. I tried to avoid destroying the flow of this section, but I'm not sure if I've been successful.
2 parents 3b945dc + c211d13 commit 0606234

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/doc/guide.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -914,12 +914,23 @@ or 'breaks up,' the tuple, and assigns the bits to three bindings.
914914

915915
This pattern is very powerful, and we'll see it repeated more later.
916916

917-
The last thing to say about tuples is that they are only equivalent if
918-
the arity, types, and values are all identical.
917+
There also a few things you can do with a tuple as a whole, without
918+
destructuring. You can assign one tuple into another, if they have the same
919+
arity and contained types.
920+
921+
```rust
922+
let mut x = (1i, 2i);
923+
let y = (2i, 3i);
924+
925+
x = y;
926+
```
927+
928+
You can also check for equality with `==`. Again, this will only compile if the
929+
tuples have the same type.
919930

920931
```rust
921932
let x = (1i, 2i, 3i);
922-
let y = (2i, 3i, 4i);
933+
let y = (2i, 2i, 4i);
923934

924935
if x == y {
925936
println!("yes");
@@ -928,7 +939,7 @@ if x == y {
928939
}
929940
```
930941

931-
This will print `no`, as the values aren't equal.
942+
This will print `no`, because some of the values aren't equal.
932943

933944
One other use of tuples is to return multiple values from a function:
934945

0 commit comments

Comments
 (0)