fork/rust

git clone https://git.julia.blue/fork/rust

borsAuto merge of #103046 - JanBeh:PR_clarify_cmp_terminology, r=workingjubilee3bcad65fbf6

master
2.3 KiB49 linesraw
1error[E0308]: mismatched types
2  --> $DIR/chain-method-call-mutation-in-place.rs:2:23
3   |
4LL |     let x: Vec<i32> = vec![1, 2, 3].into_iter().collect::<Vec<i32>>().sort_by_key(|i| i);
5   |            --------   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `Vec<i32>`, found `()`
6   |            |
7   |            expected due to this
8   |
9   = note: expected struct `Vec<i32>`
10           found unit type `()`
11note: method `sort_by_key` modifies its receiver in-place, it is not meant to be used in method chains.
12  --> $DIR/chain-method-call-mutation-in-place.rs:2:71
13   |
14LL |     let x: Vec<i32> = vec![1, 2, 3].into_iter().collect::<Vec<i32>>().sort_by_key(|i| i);
15   |                                                                       ^^^^^^^^^^^ this call modifies its receiver in-place
16
17error[E0599]: no method named `sort` found for unit type `()` in the current scope
18  --> $DIR/chain-method-call-mutation-in-place.rs:3:72
19   |
20LL |     vec![1, 2, 3].into_iter().collect::<Vec<i32>>().sort_by_key(|i| i).sort();
21   |                                                                        ^^^^ method not found in `()`
22   |
23note: method `sort_by_key` modifies its receiver in-place, it is not meant to be used in method chains.
24  --> $DIR/chain-method-call-mutation-in-place.rs:3:53
25   |
26LL |     vec![1, 2, 3].into_iter().collect::<Vec<i32>>().sort_by_key(|i| i).sort();
27   |                                                     ^^^^^^^^^^^ this call modifies its receiver in-place
28
29error[E0308]: mismatched types
30  --> $DIR/chain-method-call-mutation-in-place.rs:7:5
31   |
32LL | fn foo(mut s: String) -> String {
33   |                          ------ expected `String` because of return type
34LL |     s.push_str("asdf")
35   |     ^^^^^^^^^^^^^^^^^^ expected `String`, found `()`
36   |
37note: method `push_str` modifies its receiver in-place
38  --> $DIR/chain-method-call-mutation-in-place.rs:7:7
39   |
40LL |     s.push_str("asdf")
41   |     - ^^^^^^^^ this call modifies `s` in-place
42   |     |
43   |     you probably want to use this value after calling the method...
44   = note: ...instead of the `()` output of method `push_str`
45
46error: aborting due to 3 previous errors
47
48Some errors have detailed explanations: E0308, E0599.
49For more information about an error, try `rustc --explain E0308`.