Skip to content

Commit bb04c68

Browse files
committedSep 20, 2024
Auto merge of #124895 - obeis:static-mut-hidden-ref, r=compiler-errors
Disallow hidden references to mutable static Closes #123060 Tracking: - rust-lang/rust#123758
2 parents 4f31900 + cd99729 commit bb04c68

12 files changed

+122
-92
lines changed
 

‎tests/ui/checked_unwrap/simple_conditionals.stderr

+12-1
Original file line numberDiff line numberDiff line change
@@ -236,5 +236,16 @@ LL | if result.is_ok() {
236236
LL | result.as_mut().unwrap();
237237
| ^^^^^^^^^^^^^^^^^^^^^^^^
238238

239-
error: aborting due to 25 previous errors
239+
error: creating a shared reference to mutable static is discouraged
240+
--> tests/ui/checked_unwrap/simple_conditionals.rs:174:12
241+
|
242+
LL | if X.is_some() {
243+
| ^^^^^^^^^^^ shared reference to mutable static
244+
|
245+
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2024/static-mut-references.html>
246+
= note: shared references to mutable statics are dangerous; it's undefined behavior if the static is mutated or if a mutable reference is created for it while the shared reference lives
247+
= note: `-D static-mut-refs` implied by `-D warnings`
248+
= help: to override `-D warnings` add `#[allow(static_mut_refs)]`
249+
250+
error: aborting due to 26 previous errors
240251

‎tests/ui/multiple_unsafe_ops_per_block.rs

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#![allow(deref_nullptr)]
55
#![allow(clippy::unnecessary_operation)]
66
#![allow(dropping_copy_types)]
7+
#![allow(clippy::assign_op_pattern)]
78
#![warn(clippy::multiple_unsafe_ops_per_block)]
89

910
extern crate proc_macros;

‎tests/ui/multiple_unsafe_ops_per_block.stderr

+29-29
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this `unsafe` block contains 2 unsafe operations, expected only one
2-
--> tests/ui/multiple_unsafe_ops_per_block.rs:37:5
2+
--> tests/ui/multiple_unsafe_ops_per_block.rs:38:5
33
|
44
LL | / unsafe {
55
LL | | STATIC += 1;
@@ -8,20 +8,20 @@ LL | | }
88
| |_____^
99
|
1010
note: modification of a mutable static occurs here
11-
--> tests/ui/multiple_unsafe_ops_per_block.rs:38:9
11+
--> tests/ui/multiple_unsafe_ops_per_block.rs:39:9
1212
|
1313
LL | STATIC += 1;
1414
| ^^^^^^^^^^^
1515
note: unsafe function call occurs here
16-
--> tests/ui/multiple_unsafe_ops_per_block.rs:39:9
16+
--> tests/ui/multiple_unsafe_ops_per_block.rs:40:9
1717
|
1818
LL | not_very_safe();
1919
| ^^^^^^^^^^^^^^^
2020
= note: `-D clippy::multiple-unsafe-ops-per-block` implied by `-D warnings`
2121
= help: to override `-D warnings` add `#[allow(clippy::multiple_unsafe_ops_per_block)]`
2222

2323
error: this `unsafe` block contains 2 unsafe operations, expected only one
24-
--> tests/ui/multiple_unsafe_ops_per_block.rs:46:5
24+
--> tests/ui/multiple_unsafe_ops_per_block.rs:47:5
2525
|
2626
LL | / unsafe {
2727
LL | | drop(u.u);
@@ -30,18 +30,18 @@ LL | | }
3030
| |_____^
3131
|
3232
note: union field access occurs here
33-
--> tests/ui/multiple_unsafe_ops_per_block.rs:47:14
33+
--> tests/ui/multiple_unsafe_ops_per_block.rs:48:14
3434
|
3535
LL | drop(u.u);
3636
| ^^^
3737
note: raw pointer dereference occurs here
38-
--> tests/ui/multiple_unsafe_ops_per_block.rs:48:9
38+
--> tests/ui/multiple_unsafe_ops_per_block.rs:49:9
3939
|
4040
LL | *raw_ptr();
4141
| ^^^^^^^^^^
4242

4343
error: this `unsafe` block contains 3 unsafe operations, expected only one
44-
--> tests/ui/multiple_unsafe_ops_per_block.rs:53:5
44+
--> tests/ui/multiple_unsafe_ops_per_block.rs:54:5
4545
|
4646
LL | / unsafe {
4747
LL | | asm!("nop");
@@ -51,23 +51,23 @@ LL | | }
5151
| |_____^
5252
|
5353
note: inline assembly used here
54-
--> tests/ui/multiple_unsafe_ops_per_block.rs:54:9
54+
--> tests/ui/multiple_unsafe_ops_per_block.rs:55:9
5555
|
5656
LL | asm!("nop");
5757
| ^^^^^^^^^^^
5858
note: unsafe method call occurs here
59-
--> tests/ui/multiple_unsafe_ops_per_block.rs:55:9
59+
--> tests/ui/multiple_unsafe_ops_per_block.rs:56:9
6060
|
6161
LL | sample.not_very_safe();
6262
| ^^^^^^^^^^^^^^^^^^^^^^
6363
note: modification of a mutable static occurs here
64-
--> tests/ui/multiple_unsafe_ops_per_block.rs:56:9
64+
--> tests/ui/multiple_unsafe_ops_per_block.rs:57:9
6565
|
6666
LL | STATIC = 0;
6767
| ^^^^^^^^^^
6868

6969
error: this `unsafe` block contains 6 unsafe operations, expected only one
70-
--> tests/ui/multiple_unsafe_ops_per_block.rs:62:5
70+
--> tests/ui/multiple_unsafe_ops_per_block.rs:63:5
7171
|
7272
LL | / unsafe {
7373
LL | | drop(u.u);
@@ -79,55 +79,55 @@ LL | | }
7979
| |_____^
8080
|
8181
note: union field access occurs here
82-
--> tests/ui/multiple_unsafe_ops_per_block.rs:63:14
82+
--> tests/ui/multiple_unsafe_ops_per_block.rs:64:14
8383
|
8484
LL | drop(u.u);
8585
| ^^^
8686
note: access of a mutable static occurs here
87-
--> tests/ui/multiple_unsafe_ops_per_block.rs:64:14
87+
--> tests/ui/multiple_unsafe_ops_per_block.rs:65:14
8888
|
8989
LL | drop(STATIC);
9090
| ^^^^^^
9191
note: unsafe method call occurs here
92-
--> tests/ui/multiple_unsafe_ops_per_block.rs:65:9
92+
--> tests/ui/multiple_unsafe_ops_per_block.rs:66:9
9393
|
9494
LL | sample.not_very_safe();
9595
| ^^^^^^^^^^^^^^^^^^^^^^
9696
note: unsafe function call occurs here
97-
--> tests/ui/multiple_unsafe_ops_per_block.rs:66:9
97+
--> tests/ui/multiple_unsafe_ops_per_block.rs:67:9
9898
|
9999
LL | not_very_safe();
100100
| ^^^^^^^^^^^^^^^
101101
note: raw pointer dereference occurs here
102-
--> tests/ui/multiple_unsafe_ops_per_block.rs:67:9
102+
--> tests/ui/multiple_unsafe_ops_per_block.rs:68:9
103103
|
104104
LL | *raw_ptr();
105105
| ^^^^^^^^^^
106106
note: inline assembly used here
107-
--> tests/ui/multiple_unsafe_ops_per_block.rs:68:9
107+
--> tests/ui/multiple_unsafe_ops_per_block.rs:69:9
108108
|
109109
LL | asm!("nop");
110110
| ^^^^^^^^^^^
111111

112112
error: this `unsafe` block contains 2 unsafe operations, expected only one
113-
--> tests/ui/multiple_unsafe_ops_per_block.rs:106:5
113+
--> tests/ui/multiple_unsafe_ops_per_block.rs:107:5
114114
|
115115
LL | unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
116116
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
117117
|
118118
note: unsafe function call occurs here
119-
--> tests/ui/multiple_unsafe_ops_per_block.rs:106:14
119+
--> tests/ui/multiple_unsafe_ops_per_block.rs:107:14
120120
|
121121
LL | unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
122122
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
123123
note: raw pointer dereference occurs here
124-
--> tests/ui/multiple_unsafe_ops_per_block.rs:106:39
124+
--> tests/ui/multiple_unsafe_ops_per_block.rs:107:39
125125
|
126126
LL | unsafe { char::from_u32_unchecked(*ptr.cast::<u32>()) }
127127
| ^^^^^^^^^^^^^^^^^^
128128

129129
error: this `unsafe` block contains 2 unsafe operations, expected only one
130-
--> tests/ui/multiple_unsafe_ops_per_block.rs:124:5
130+
--> tests/ui/multiple_unsafe_ops_per_block.rs:125:5
131131
|
132132
LL | / unsafe {
133133
LL | | x();
@@ -136,18 +136,18 @@ LL | | }
136136
| |_____^
137137
|
138138
note: unsafe function call occurs here
139-
--> tests/ui/multiple_unsafe_ops_per_block.rs:125:9
139+
--> tests/ui/multiple_unsafe_ops_per_block.rs:126:9
140140
|
141141
LL | x();
142142
| ^^^
143143
note: unsafe function call occurs here
144-
--> tests/ui/multiple_unsafe_ops_per_block.rs:126:9
144+
--> tests/ui/multiple_unsafe_ops_per_block.rs:127:9
145145
|
146146
LL | x();
147147
| ^^^
148148

149149
error: this `unsafe` block contains 2 unsafe operations, expected only one
150-
--> tests/ui/multiple_unsafe_ops_per_block.rs:135:9
150+
--> tests/ui/multiple_unsafe_ops_per_block.rs:136:9
151151
|
152152
LL | / unsafe {
153153
LL | | T::X();
@@ -156,18 +156,18 @@ LL | | }
156156
| |_________^
157157
|
158158
note: unsafe function call occurs here
159-
--> tests/ui/multiple_unsafe_ops_per_block.rs:136:13
159+
--> tests/ui/multiple_unsafe_ops_per_block.rs:137:13
160160
|
161161
LL | T::X();
162162
| ^^^^^^
163163
note: unsafe function call occurs here
164-
--> tests/ui/multiple_unsafe_ops_per_block.rs:137:13
164+
--> tests/ui/multiple_unsafe_ops_per_block.rs:138:13
165165
|
166166
LL | T::X();
167167
| ^^^^^^
168168

169169
error: this `unsafe` block contains 2 unsafe operations, expected only one
170-
--> tests/ui/multiple_unsafe_ops_per_block.rs:145:5
170+
--> tests/ui/multiple_unsafe_ops_per_block.rs:146:5
171171
|
172172
LL | / unsafe {
173173
LL | | x.0();
@@ -176,12 +176,12 @@ LL | | }
176176
| |_____^
177177
|
178178
note: unsafe function call occurs here
179-
--> tests/ui/multiple_unsafe_ops_per_block.rs:146:9
179+
--> tests/ui/multiple_unsafe_ops_per_block.rs:147:9
180180
|
181181
LL | x.0();
182182
| ^^^^^
183183
note: unsafe function call occurs here
184-
--> tests/ui/multiple_unsafe_ops_per_block.rs:147:9
184+
--> tests/ui/multiple_unsafe_ops_per_block.rs:148:9
185185
|
186186
LL | x.0();
187187
| ^^^^^

‎tests/ui/must_use_candidates.fixed

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#![feature(never_type)]
2-
#![allow(unused_mut, clippy::redundant_allocation, clippy::needless_pass_by_ref_mut)]
2+
#![allow(
3+
unused_mut,
4+
clippy::redundant_allocation,
5+
clippy::needless_pass_by_ref_mut,
6+
static_mut_refs
7+
)]
38
#![warn(clippy::must_use_candidate)]
49
use std::rc::Rc;
510
use std::sync::atomic::{AtomicBool, Ordering};

‎tests/ui/must_use_candidates.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
#![feature(never_type)]
2-
#![allow(unused_mut, clippy::redundant_allocation, clippy::needless_pass_by_ref_mut)]
2+
#![allow(
3+
unused_mut,
4+
clippy::redundant_allocation,
5+
clippy::needless_pass_by_ref_mut,
6+
static_mut_refs
7+
)]
38
#![warn(clippy::must_use_candidate)]
49
use std::rc::Rc;
510
use std::sync::atomic::{AtomicBool, Ordering};

‎tests/ui/must_use_candidates.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: this function could have a `#[must_use]` attribute
2-
--> tests/ui/must_use_candidates.rs:11:1
2+
--> tests/ui/must_use_candidates.rs:16:1
33
|
44
LL | pub fn pure(i: u8) -> u8 {
55
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn pure(i: u8) -> u8`
@@ -8,25 +8,25 @@ LL | pub fn pure(i: u8) -> u8 {
88
= help: to override `-D warnings` add `#[allow(clippy::must_use_candidate)]`
99

1010
error: this method could have a `#[must_use]` attribute
11-
--> tests/ui/must_use_candidates.rs:16:5
11+
--> tests/ui/must_use_candidates.rs:21:5
1212
|
1313
LL | pub fn inherent_pure(&self) -> u8 {
1414
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn inherent_pure(&self) -> u8`
1515

1616
error: this function could have a `#[must_use]` attribute
17-
--> tests/ui/must_use_candidates.rs:47:1
17+
--> tests/ui/must_use_candidates.rs:52:1
1818
|
1919
LL | pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool {
2020
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn with_marker(_d: std::marker::PhantomData<&mut u32>) -> bool`
2121

2222
error: this function could have a `#[must_use]` attribute
23-
--> tests/ui/must_use_candidates.rs:59:1
23+
--> tests/ui/must_use_candidates.rs:64:1
2424
|
2525
LL | pub fn rcd(_x: Rc<u32>) -> bool {
2626
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn rcd(_x: Rc<u32>) -> bool`
2727

2828
error: this function could have a `#[must_use]` attribute
29-
--> tests/ui/must_use_candidates.rs:67:1
29+
--> tests/ui/must_use_candidates.rs:72:1
3030
|
3131
LL | pub fn arcd(_x: Arc<u32>) -> bool {
3232
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn arcd(_x: Arc<u32>) -> bool`

‎tests/ui/redundant_static_lifetimes.fixed

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#![allow(unused)]
2+
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
3+
#![allow(static_mut_refs)]
24

35
#[derive(Debug)]
46
struct Foo;

‎tests/ui/redundant_static_lifetimes.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#![allow(unused)]
2+
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
3+
#![allow(static_mut_refs)]
24

35
#[derive(Debug)]
46
struct Foo;

‎tests/ui/redundant_static_lifetimes.stderr

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: constants have by default a `'static` lifetime
2-
--> tests/ui/redundant_static_lifetimes.rs:6:17
2+
--> tests/ui/redundant_static_lifetimes.rs:8:17
33
|
44
LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR: Consider removing 'static.
55
| -^^^^^^^---- help: consider removing `'static`: `&str`
@@ -8,103 +8,103 @@ LL | const VAR_ONE: &'static str = "Test constant #1"; // ERROR: Consider removi
88
= help: to override `-D warnings` add `#[allow(clippy::redundant_static_lifetimes)]`
99

1010
error: constants have by default a `'static` lifetime
11-
--> tests/ui/redundant_static_lifetimes.rs:10:21
11+
--> tests/ui/redundant_static_lifetimes.rs:12:21
1212
|
1313
LL | const VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR: Consider removing 'static
1414
| -^^^^^^^---- help: consider removing `'static`: `&str`
1515

1616
error: constants have by default a `'static` lifetime
17-
--> tests/ui/redundant_static_lifetimes.rs:12:32
17+
--> tests/ui/redundant_static_lifetimes.rs:14:32
1818
|
1919
LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static
2020
| -^^^^^^^---- help: consider removing `'static`: `&str`
2121

2222
error: constants have by default a `'static` lifetime
23-
--> tests/ui/redundant_static_lifetimes.rs:12:47
23+
--> tests/ui/redundant_static_lifetimes.rs:14:47
2424
|
2525
LL | const VAR_FOUR: (&str, (&str, &'static str), &'static str) = ("on", ("th", "th"), "on"); // ERROR: Consider removing 'static
2626
| -^^^^^^^---- help: consider removing `'static`: `&str`
2727

2828
error: constants have by default a `'static` lifetime
29-
--> tests/ui/redundant_static_lifetimes.rs:14:17
29+
--> tests/ui/redundant_static_lifetimes.rs:16:17
3030
|
3131
LL | const VAR_SIX: &'static u8 = &5;
3232
| -^^^^^^^--- help: consider removing `'static`: `&u8`
3333

3434
error: constants have by default a `'static` lifetime
35-
--> tests/ui/redundant_static_lifetimes.rs:16:20
35+
--> tests/ui/redundant_static_lifetimes.rs:18:20
3636
|
3737
LL | const VAR_HEIGHT: &'static Foo = &Foo {};
3838
| -^^^^^^^---- help: consider removing `'static`: `&Foo`
3939

4040
error: constants have by default a `'static` lifetime
41-
--> tests/ui/redundant_static_lifetimes.rs:18:19
41+
--> tests/ui/redundant_static_lifetimes.rs:20:19
4242
|
4343
LL | const VAR_SLICE: &'static [u8] = b"Test constant #1"; // ERROR: Consider removing 'static.
4444
| -^^^^^^^----- help: consider removing `'static`: `&[u8]`
4545

4646
error: constants have by default a `'static` lifetime
47-
--> tests/ui/redundant_static_lifetimes.rs:20:19
47+
--> tests/ui/redundant_static_lifetimes.rs:22:19
4848
|
4949
LL | const VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR: Consider removing 'static.
5050
| -^^^^^^^--------- help: consider removing `'static`: `&(u8, u8)`
5151

5252
error: constants have by default a `'static` lifetime
53-
--> tests/ui/redundant_static_lifetimes.rs:22:19
53+
--> tests/ui/redundant_static_lifetimes.rs:24:19
5454
|
5555
LL | const VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR: Consider removing 'static.
5656
| -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]`
5757

5858
error: statics have by default a `'static` lifetime
59-
--> tests/ui/redundant_static_lifetimes.rs:24:25
59+
--> tests/ui/redundant_static_lifetimes.rs:26:25
6060
|
6161
LL | static STATIC_VAR_ONE: &'static str = "Test static #1"; // ERROR: Consider removing 'static.
6262
| -^^^^^^^---- help: consider removing `'static`: `&str`
6363

6464
error: statics have by default a `'static` lifetime
65-
--> tests/ui/redundant_static_lifetimes.rs:28:29
65+
--> tests/ui/redundant_static_lifetimes.rs:30:29
6666
|
6767
LL | static STATIC_VAR_THREE: &[&'static str] = &["one", "two"]; // ERROR: Consider removing 'static
6868
| -^^^^^^^---- help: consider removing `'static`: `&str`
6969

7070
error: statics have by default a `'static` lifetime
71-
--> tests/ui/redundant_static_lifetimes.rs:30:25
71+
--> tests/ui/redundant_static_lifetimes.rs:32:25
7272
|
7373
LL | static STATIC_VAR_SIX: &'static u8 = &5;
7474
| -^^^^^^^--- help: consider removing `'static`: `&u8`
7575

7676
error: statics have by default a `'static` lifetime
77-
--> tests/ui/redundant_static_lifetimes.rs:32:28
77+
--> tests/ui/redundant_static_lifetimes.rs:34:28
7878
|
7979
LL | static STATIC_VAR_HEIGHT: &'static Foo = &Foo {};
8080
| -^^^^^^^---- help: consider removing `'static`: `&Foo`
8181

8282
error: statics have by default a `'static` lifetime
83-
--> tests/ui/redundant_static_lifetimes.rs:34:27
83+
--> tests/ui/redundant_static_lifetimes.rs:36:27
8484
|
8585
LL | static STATIC_VAR_SLICE: &'static [u8] = b"Test static #3"; // ERROR: Consider removing 'static.
8686
| -^^^^^^^----- help: consider removing `'static`: `&[u8]`
8787

8888
error: statics have by default a `'static` lifetime
89-
--> tests/ui/redundant_static_lifetimes.rs:36:27
89+
--> tests/ui/redundant_static_lifetimes.rs:38:27
9090
|
9191
LL | static STATIC_VAR_TUPLE: &'static (u8, u8) = &(1, 2); // ERROR: Consider removing 'static.
9292
| -^^^^^^^--------- help: consider removing `'static`: `&(u8, u8)`
9393

9494
error: statics have by default a `'static` lifetime
95-
--> tests/ui/redundant_static_lifetimes.rs:38:27
95+
--> tests/ui/redundant_static_lifetimes.rs:40:27
9696
|
9797
LL | static STATIC_VAR_ARRAY: &'static [u8; 1] = b"T"; // ERROR: Consider removing 'static.
9898
| -^^^^^^^-------- help: consider removing `'static`: `&[u8; 1]`
9999

100100
error: statics have by default a `'static` lifetime
101-
--> tests/ui/redundant_static_lifetimes.rs:40:31
101+
--> tests/ui/redundant_static_lifetimes.rs:42:31
102102
|
103103
LL | static mut STATIC_MUT_SLICE: &'static mut [u32] = &mut [0];
104104
| -^^^^^^^---------- help: consider removing `'static`: `&mut [u32]`
105105

106106
error: statics have by default a `'static` lifetime
107-
--> tests/ui/redundant_static_lifetimes.rs:69:16
107+
--> tests/ui/redundant_static_lifetimes.rs:71:16
108108
|
109109
LL | static V: &'static u8 = &17;
110110
| -^^^^^^^--- help: consider removing `'static`: `&u8`

‎tests/ui/useless_conversion.fixed

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![deny(clippy::useless_conversion)]
22
#![allow(clippy::needless_if, clippy::unnecessary_wraps)]
3+
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
4+
#![allow(static_mut_refs)]
35

46
fn test_generic<T: Copy>(val: T) -> T {
57
let _ = val;

‎tests/ui/useless_conversion.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![deny(clippy::useless_conversion)]
22
#![allow(clippy::needless_if, clippy::unnecessary_wraps)]
3+
// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint
4+
#![allow(static_mut_refs)]
35

46
fn test_generic<T: Copy>(val: T) -> T {
57
let _ = T::from(val);

‎tests/ui/useless_conversion.stderr

+37-37
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: useless conversion to the same type: `T`
2-
--> tests/ui/useless_conversion.rs:5:13
2+
--> tests/ui/useless_conversion.rs:7:13
33
|
44
LL | let _ = T::from(val);
55
| ^^^^^^^^^^^^ help: consider removing `T::from()`: `val`
@@ -11,217 +11,217 @@ LL | #![deny(clippy::useless_conversion)]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error: useless conversion to the same type: `T`
14-
--> tests/ui/useless_conversion.rs:6:5
14+
--> tests/ui/useless_conversion.rs:8:5
1515
|
1616
LL | val.into()
1717
| ^^^^^^^^^^ help: consider removing `.into()`: `val`
1818

1919
error: useless conversion to the same type: `i32`
20-
--> tests/ui/useless_conversion.rs:18:22
20+
--> tests/ui/useless_conversion.rs:20:22
2121
|
2222
LL | let _: i32 = 0i32.into();
2323
| ^^^^^^^^^^^ help: consider removing `.into()`: `0i32`
2424

2525
error: useless conversion to the same type: `std::str::Lines<'_>`
26-
--> tests/ui/useless_conversion.rs:48:22
26+
--> tests/ui/useless_conversion.rs:50:22
2727
|
2828
LL | if Some("ok") == lines.into_iter().next() {}
2929
| ^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `lines`
3030

3131
error: useless conversion to the same type: `std::str::Lines<'_>`
32-
--> tests/ui/useless_conversion.rs:53:21
32+
--> tests/ui/useless_conversion.rs:55:21
3333
|
3434
LL | let mut lines = text.lines().into_iter();
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `text.lines()`
3636

3737
error: useless conversion to the same type: `std::str::Lines<'_>`
38-
--> tests/ui/useless_conversion.rs:59:22
38+
--> tests/ui/useless_conversion.rs:61:22
3939
|
4040
LL | if Some("ok") == text.lines().into_iter().next() {}
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `text.lines()`
4242

4343
error: useless conversion to the same type: `std::ops::Range<i32>`
44-
--> tests/ui/useless_conversion.rs:65:13
44+
--> tests/ui/useless_conversion.rs:67:13
4545
|
4646
LL | let _ = NUMBERS.into_iter().next();
4747
| ^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `NUMBERS`
4848

4949
error: useless conversion to the same type: `std::ops::Range<i32>`
50-
--> tests/ui/useless_conversion.rs:70:17
50+
--> tests/ui/useless_conversion.rs:72:17
5151
|
5252
LL | let mut n = NUMBERS.into_iter();
5353
| ^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `NUMBERS`
5454

5555
error: useless conversion to the same type: `std::string::String`
56-
--> tests/ui/useless_conversion.rs:132:21
56+
--> tests/ui/useless_conversion.rs:134:21
5757
|
5858
LL | let _: String = "foo".to_string().into();
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `"foo".to_string()`
6060

6161
error: useless conversion to the same type: `std::string::String`
62-
--> tests/ui/useless_conversion.rs:133:21
62+
--> tests/ui/useless_conversion.rs:135:21
6363
|
6464
LL | let _: String = From::from("foo".to_string());
6565
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `From::from()`: `"foo".to_string()`
6666

6767
error: useless conversion to the same type: `std::string::String`
68-
--> tests/ui/useless_conversion.rs:134:13
68+
--> tests/ui/useless_conversion.rs:136:13
6969
|
7070
LL | let _ = String::from("foo".to_string());
7171
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `"foo".to_string()`
7272

7373
error: useless conversion to the same type: `std::string::String`
74-
--> tests/ui/useless_conversion.rs:135:13
74+
--> tests/ui/useless_conversion.rs:137:13
7575
|
7676
LL | let _ = String::from(format!("A: {:04}", 123));
7777
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `String::from()`: `format!("A: {:04}", 123)`
7878

7979
error: useless conversion to the same type: `std::str::Lines<'_>`
80-
--> tests/ui/useless_conversion.rs:136:13
80+
--> tests/ui/useless_conversion.rs:138:13
8181
|
8282
LL | let _ = "".lines().into_iter();
8383
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `"".lines()`
8484

8585
error: useless conversion to the same type: `std::vec::IntoIter<i32>`
86-
--> tests/ui/useless_conversion.rs:137:13
86+
--> tests/ui/useless_conversion.rs:139:13
8787
|
8888
LL | let _ = vec![1, 2, 3].into_iter().into_iter();
8989
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![1, 2, 3].into_iter()`
9090

9191
error: useless conversion to the same type: `std::string::String`
92-
--> tests/ui/useless_conversion.rs:138:21
92+
--> tests/ui/useless_conversion.rs:140:21
9393
|
9494
LL | let _: String = format!("Hello {}", "world").into();
9595
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into()`: `format!("Hello {}", "world")`
9696

9797
error: useless conversion to the same type: `i32`
98-
--> tests/ui/useless_conversion.rs:143:13
98+
--> tests/ui/useless_conversion.rs:145:13
9999
|
100100
LL | let _ = i32::from(a + b) * 3;
101101
| ^^^^^^^^^^^^^^^^ help: consider removing `i32::from()`: `(a + b)`
102102

103103
error: useless conversion to the same type: `Foo<'a'>`
104-
--> tests/ui/useless_conversion.rs:149:23
104+
--> tests/ui/useless_conversion.rs:151:23
105105
|
106106
LL | let _: Foo<'a'> = s2.into();
107107
| ^^^^^^^^^ help: consider removing `.into()`: `s2`
108108

109109
error: useless conversion to the same type: `Foo<'a'>`
110-
--> tests/ui/useless_conversion.rs:151:13
110+
--> tests/ui/useless_conversion.rs:153:13
111111
|
112112
LL | let _ = Foo::<'a'>::from(s3);
113113
| ^^^^^^^^^^^^^^^^^^^^ help: consider removing `Foo::<'a'>::from()`: `s3`
114114

115115
error: useless conversion to the same type: `std::vec::IntoIter<Foo<'a'>>`
116-
--> tests/ui/useless_conversion.rs:153:13
116+
--> tests/ui/useless_conversion.rs:155:13
117117
|
118118
LL | let _ = vec![s4, s4, s4].into_iter().into_iter();
119119
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing `.into_iter()`: `vec![s4, s4, s4].into_iter()`
120120

121121
error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
122-
--> tests/ui/useless_conversion.rs:185:7
122+
--> tests/ui/useless_conversion.rs:187:7
123123
|
124124
LL | b(vec![1, 2].into_iter());
125125
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]`
126126
|
127127
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
128-
--> tests/ui/useless_conversion.rs:175:13
128+
--> tests/ui/useless_conversion.rs:177:13
129129
|
130130
LL | fn b<T: IntoIterator<Item = i32>>(_: T) {}
131131
| ^^^^^^^^^^^^^^^^^^^^^^^^
132132

133133
error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
134-
--> tests/ui/useless_conversion.rs:186:7
134+
--> tests/ui/useless_conversion.rs:188:7
135135
|
136136
LL | c(vec![1, 2].into_iter());
137137
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]`
138138
|
139139
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
140-
--> tests/ui/useless_conversion.rs:176:18
140+
--> tests/ui/useless_conversion.rs:178:18
141141
|
142142
LL | fn c(_: impl IntoIterator<Item = i32>) {}
143143
| ^^^^^^^^^^^^^^^^^^^^^^^^
144144

145145
error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
146-
--> tests/ui/useless_conversion.rs:187:7
146+
--> tests/ui/useless_conversion.rs:189:7
147147
|
148148
LL | d(vec![1, 2].into_iter());
149149
| ^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `vec![1, 2]`
150150
|
151151
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
152-
--> tests/ui/useless_conversion.rs:179:12
152+
--> tests/ui/useless_conversion.rs:181:12
153153
|
154154
LL | T: IntoIterator<Item = i32>,
155155
| ^^^^^^^^^^^^^^^^^^^^^^^^
156156

157157
error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
158-
--> tests/ui/useless_conversion.rs:190:7
158+
--> tests/ui/useless_conversion.rs:192:7
159159
|
160160
LL | b(vec![1, 2].into_iter().into_iter());
161161
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`s: `vec![1, 2]`
162162
|
163163
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
164-
--> tests/ui/useless_conversion.rs:175:13
164+
--> tests/ui/useless_conversion.rs:177:13
165165
|
166166
LL | fn b<T: IntoIterator<Item = i32>>(_: T) {}
167167
| ^^^^^^^^^^^^^^^^^^^^^^^^
168168

169169
error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
170-
--> tests/ui/useless_conversion.rs:191:7
170+
--> tests/ui/useless_conversion.rs:193:7
171171
|
172172
LL | b(vec![1, 2].into_iter().into_iter().into_iter());
173173
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`s: `vec![1, 2]`
174174
|
175175
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
176-
--> tests/ui/useless_conversion.rs:175:13
176+
--> tests/ui/useless_conversion.rs:177:13
177177
|
178178
LL | fn b<T: IntoIterator<Item = i32>>(_: T) {}
179179
| ^^^^^^^^^^^^^^^^^^^^^^^^
180180

181181
error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
182-
--> tests/ui/useless_conversion.rs:237:24
182+
--> tests/ui/useless_conversion.rs:239:24
183183
|
184184
LL | foo2::<i32, _>([1, 2, 3].into_iter());
185185
| ^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `[1, 2, 3]`
186186
|
187187
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
188-
--> tests/ui/useless_conversion.rs:216:12
188+
--> tests/ui/useless_conversion.rs:218:12
189189
|
190190
LL | I: IntoIterator<Item = i32> + Helper<X>,
191191
| ^^^^^^^^^^^^^^^^^^^^^^^^
192192

193193
error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
194-
--> tests/ui/useless_conversion.rs:245:14
194+
--> tests/ui/useless_conversion.rs:247:14
195195
|
196196
LL | foo3([1, 2, 3].into_iter());
197197
| ^^^^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `[1, 2, 3]`
198198
|
199199
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
200-
--> tests/ui/useless_conversion.rs:225:12
200+
--> tests/ui/useless_conversion.rs:227:12
201201
|
202202
LL | I: IntoIterator<Item = i32>,
203203
| ^^^^^^^^^^^^^^^^^^^^^^^^
204204

205205
error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
206-
--> tests/ui/useless_conversion.rs:254:16
206+
--> tests/ui/useless_conversion.rs:256:16
207207
|
208208
LL | S1.foo([1, 2].into_iter());
209209
| ^^^^^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `[1, 2]`
210210
|
211211
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
212-
--> tests/ui/useless_conversion.rs:251:27
212+
--> tests/ui/useless_conversion.rs:253:27
213213
|
214214
LL | pub fn foo<I: IntoIterator>(&self, _: I) {}
215215
| ^^^^^^^^^^^^
216216

217217
error: explicit call to `.into_iter()` in function argument accepting `IntoIterator`
218-
--> tests/ui/useless_conversion.rs:273:44
218+
--> tests/ui/useless_conversion.rs:275:44
219219
|
220220
LL | v0.into_iter().interleave_shortest(v1.into_iter());
221221
| ^^^^^^^^^^^^^^ help: consider removing the `.into_iter()`: `v1`
222222
|
223223
note: this parameter accepts any `IntoIterator`, so you don't need to call `.into_iter()`
224-
--> tests/ui/useless_conversion.rs:260:20
224+
--> tests/ui/useless_conversion.rs:262:20
225225
|
226226
LL | J: IntoIterator,
227227
| ^^^^^^^^^^^^

0 commit comments

Comments
 (0)
Please sign in to comment.