Skip to content

Commit 4a2116b

Browse files
committed
Auto merge of #3711 - rust-lang:rustup, r=oli-obk
Rustup fixes #3709 I'm currently in the process of making rustc's deprecation lint emit the `AtomicFoo::new(0)` suggestion
2 parents 62f40e2 + 6033294 commit 4a2116b

File tree

8 files changed

+48
-171
lines changed

8 files changed

+48
-171
lines changed

clippy_lints/src/consts.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc::{bug, span_bug};
1010
use rustc_data_structures::sync::Lrc;
1111
use std::cmp::Ordering::{self, Equal};
1212
use std::cmp::PartialOrd;
13+
use std::convert::TryFrom;
1314
use std::convert::TryInto;
1415
use std::hash::{Hash, Hasher};
1516
use syntax::ast::{FloatTy, LitKind};
@@ -441,12 +442,12 @@ pub fn miri_to_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, result: &ty::Const<'
441442
// FIXME: implement other conversion
442443
_ => None,
443444
},
444-
ConstValue::ScalarPair(Scalar::Ptr(ptr), Scalar::Bits { bits: n, .. }) => match result.ty.sty {
445+
ConstValue::Slice(Scalar::Ptr(ptr), n) => match result.ty.sty {
445446
ty::Ref(_, tam, _) => match tam.sty {
446447
ty::Str => {
447448
let alloc = tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id);
448449
let offset = ptr.offset.bytes().try_into().expect("too-large pointer offset");
449-
let n = n as usize;
450+
let n = usize::try_from(n).unwrap();
450451
String::from_utf8(alloc.bytes[offset..(offset + n)].to_owned())
451452
.ok()
452453
.map(Constant::Str)

clippy_lints/src/replace_consts.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,6 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ReplaceConsts {
6969
const REPLACEMENTS: &[(&[&str], &str)] = &[
7070
// Once
7171
(&["core", "sync", "ONCE_INIT"], "Once::new()"),
72-
// Atomic
73-
(
74-
&["core", "sync", "atomic", "ATOMIC_BOOL_INIT"],
75-
"AtomicBool::new(false)",
76-
),
77-
(&["core", "sync", "atomic", "ATOMIC_ISIZE_INIT"], "AtomicIsize::new(0)"),
78-
(&["core", "sync", "atomic", "ATOMIC_I8_INIT"], "AtomicI8::new(0)"),
79-
(&["core", "sync", "atomic", "ATOMIC_I16_INIT"], "AtomicI16::new(0)"),
80-
(&["core", "sync", "atomic", "ATOMIC_I32_INIT"], "AtomicI32::new(0)"),
81-
(&["core", "sync", "atomic", "ATOMIC_I64_INIT"], "AtomicI64::new(0)"),
82-
(&["core", "sync", "atomic", "ATOMIC_USIZE_INIT"], "AtomicUsize::new(0)"),
83-
(&["core", "sync", "atomic", "ATOMIC_U8_INIT"], "AtomicU8::new(0)"),
84-
(&["core", "sync", "atomic", "ATOMIC_U16_INIT"], "AtomicU16::new(0)"),
85-
(&["core", "sync", "atomic", "ATOMIC_U32_INIT"], "AtomicU32::new(0)"),
86-
(&["core", "sync", "atomic", "ATOMIC_U64_INIT"], "AtomicU64::new(0)"),
8772
// Min
8873
(&["core", "isize", "MIN"], "isize::min_value()"),
8974
(&["core", "i8", "MIN"], "i8::min_value()"),

clippy_lints/src/utils/paths.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ pub const INDEX: [&str; 3] = ["core", "ops", "Index"];
3838
pub const INDEX_MUT: [&str; 3] = ["core", "ops", "IndexMut"];
3939
pub const INIT: [&str; 4] = ["core", "intrinsics", "", "init"];
4040
pub const INTO: [&str; 3] = ["core", "convert", "Into"];
41-
pub const INTO_ITERATOR: [&str; 4] = ["core", "iter", "traits", "IntoIterator"];
41+
pub const INTO_ITERATOR: [&str; 5] = ["core", "iter", "traits", "collect", "IntoIterator"];
4242
pub const IO_READ: [&str; 3] = ["std", "io", "Read"];
4343
pub const IO_WRITE: [&str; 3] = ["std", "io", "Write"];
44-
pub const ITERATOR: [&str; 4] = ["core", "iter", "iterator", "Iterator"];
44+
pub const ITERATOR: [&str; 5] = ["core", "iter", "traits", "iterator", "Iterator"];
4545
pub const LATE_CONTEXT: [&str; 4] = ["rustc", "lint", "context", "LateContext"];
4646
pub const LINKED_LIST: [&str; 4] = ["alloc", "collections", "linked_list", "LinkedList"];
4747
pub const LINT: [&str; 3] = ["rustc", "lint", "Lint"];

tests/ui/non_copy_const.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::borrow::Cow;
55
use std::cell::Cell;
66
use std::fmt::Display;
7-
use std::sync::atomic::{AtomicUsize, Ordering, ATOMIC_USIZE_INIT};
7+
use std::sync::atomic::{AtomicUsize, Ordering};
88
use std::sync::Once;
99

1010
const ATOMIC: AtomicUsize = AtomicUsize::new(5); //~ ERROR interior mutable
@@ -95,9 +95,6 @@ fn main() {
9595
ATOMIC.store(1, Ordering::SeqCst); //~ ERROR interior mutability
9696
assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutability
9797

98-
ATOMIC_USIZE_INIT.store(2, Ordering::SeqCst); //~ ERROR interior mutability
99-
assert_eq!(ATOMIC_USIZE_INIT.load(Ordering::SeqCst), 0); //~ ERROR interior mutability
100-
10198
let _once = ONCE_INIT;
10299
let _once_ref = &ONCE_INIT; //~ ERROR interior mutability
103100
let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability

tests/ui/non_copy_const.stderr

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -144,132 +144,116 @@ LL | assert_eq!(ATOMIC.load(Ordering::SeqCst), 5); //~ ERROR interior mutabi
144144
= help: assign this const to a local or static variable, and use the variable here
145145

146146
error: a const item with interior mutability should not be borrowed
147-
--> $DIR/non_copy_const.rs:98:5
148-
|
149-
LL | ATOMIC_USIZE_INIT.store(2, Ordering::SeqCst); //~ ERROR interior mutability
150-
| ^^^^^^^^^^^^^^^^^
151-
|
152-
= help: assign this const to a local or static variable, and use the variable here
153-
154-
error: a const item with interior mutability should not be borrowed
155-
--> $DIR/non_copy_const.rs:99:16
156-
|
157-
LL | assert_eq!(ATOMIC_USIZE_INIT.load(Ordering::SeqCst), 0); //~ ERROR interior mutability
158-
| ^^^^^^^^^^^^^^^^^
159-
|
160-
= help: assign this const to a local or static variable, and use the variable here
161-
162-
error: a const item with interior mutability should not be borrowed
163-
--> $DIR/non_copy_const.rs:102:22
147+
--> $DIR/non_copy_const.rs:99:22
164148
|
165149
LL | let _once_ref = &ONCE_INIT; //~ ERROR interior mutability
166150
| ^^^^^^^^^
167151
|
168152
= help: assign this const to a local or static variable, and use the variable here
169153

170154
error: a const item with interior mutability should not be borrowed
171-
--> $DIR/non_copy_const.rs:103:25
155+
--> $DIR/non_copy_const.rs:100:25
172156
|
173157
LL | let _once_ref_2 = &&ONCE_INIT; //~ ERROR interior mutability
174158
| ^^^^^^^^^
175159
|
176160
= help: assign this const to a local or static variable, and use the variable here
177161

178162
error: a const item with interior mutability should not be borrowed
179-
--> $DIR/non_copy_const.rs:104:27
163+
--> $DIR/non_copy_const.rs:101:27
180164
|
181165
LL | let _once_ref_4 = &&&&ONCE_INIT; //~ ERROR interior mutability
182166
| ^^^^^^^^^
183167
|
184168
= help: assign this const to a local or static variable, and use the variable here
185169

186170
error: a const item with interior mutability should not be borrowed
187-
--> $DIR/non_copy_const.rs:105:26
171+
--> $DIR/non_copy_const.rs:102:26
188172
|
189173
LL | let _once_mut = &mut ONCE_INIT; //~ ERROR interior mutability
190174
| ^^^^^^^^^
191175
|
192176
= help: assign this const to a local or static variable, and use the variable here
193177

194178
error: a const item with interior mutability should not be borrowed
195-
--> $DIR/non_copy_const.rs:116:14
179+
--> $DIR/non_copy_const.rs:113:14
196180
|
197181
LL | let _ = &ATOMIC_TUPLE; //~ ERROR interior mutability
198182
| ^^^^^^^^^^^^
199183
|
200184
= help: assign this const to a local or static variable, and use the variable here
201185

202186
error: a const item with interior mutability should not be borrowed
203-
--> $DIR/non_copy_const.rs:117:14
187+
--> $DIR/non_copy_const.rs:114:14
204188
|
205189
LL | let _ = &ATOMIC_TUPLE.0; //~ ERROR interior mutability
206190
| ^^^^^^^^^^^^
207191
|
208192
= help: assign this const to a local or static variable, and use the variable here
209193

210194
error: a const item with interior mutability should not be borrowed
211-
--> $DIR/non_copy_const.rs:118:19
195+
--> $DIR/non_copy_const.rs:115:19
212196
|
213197
LL | let _ = &(&&&&ATOMIC_TUPLE).0; //~ ERROR interior mutability
214198
| ^^^^^^^^^^^^
215199
|
216200
= help: assign this const to a local or static variable, and use the variable here
217201

218202
error: a const item with interior mutability should not be borrowed
219-
--> $DIR/non_copy_const.rs:119:14
203+
--> $DIR/non_copy_const.rs:116:14
220204
|
221205
LL | let _ = &ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
222206
| ^^^^^^^^^^^^
223207
|
224208
= help: assign this const to a local or static variable, and use the variable here
225209

226210
error: a const item with interior mutability should not be borrowed
227-
--> $DIR/non_copy_const.rs:120:13
211+
--> $DIR/non_copy_const.rs:117:13
228212
|
229213
LL | let _ = ATOMIC_TUPLE.0[0].load(Ordering::SeqCst); //~ ERROR interior mutability
230214
| ^^^^^^^^^^^^
231215
|
232216
= help: assign this const to a local or static variable, and use the variable here
233217

234218
error: a const item with interior mutability should not be borrowed
235-
--> $DIR/non_copy_const.rs:126:13
219+
--> $DIR/non_copy_const.rs:123:13
236220
|
237221
LL | let _ = ATOMIC_TUPLE.0[0]; //~ ERROR interior mutability
238222
| ^^^^^^^^^^^^
239223
|
240224
= help: assign this const to a local or static variable, and use the variable here
241225

242226
error: a const item with interior mutability should not be borrowed
243-
--> $DIR/non_copy_const.rs:131:5
227+
--> $DIR/non_copy_const.rs:128:5
244228
|
245229
LL | CELL.set(2); //~ ERROR interior mutability
246230
| ^^^^
247231
|
248232
= help: assign this const to a local or static variable, and use the variable here
249233

250234
error: a const item with interior mutability should not be borrowed
251-
--> $DIR/non_copy_const.rs:132:16
235+
--> $DIR/non_copy_const.rs:129:16
252236
|
253237
LL | assert_eq!(CELL.get(), 6); //~ ERROR interior mutability
254238
| ^^^^
255239
|
256240
= help: assign this const to a local or static variable, and use the variable here
257241

258242
error: a const item with interior mutability should not be borrowed
259-
--> $DIR/non_copy_const.rs:145:5
243+
--> $DIR/non_copy_const.rs:142:5
260244
|
261245
LL | u64::ATOMIC.store(5, Ordering::SeqCst); //~ ERROR interior mutability
262246
| ^^^^^^^^^^^
263247
|
264248
= help: assign this const to a local or static variable, and use the variable here
265249

266250
error: a const item with interior mutability should not be borrowed
267-
--> $DIR/non_copy_const.rs:146:16
251+
--> $DIR/non_copy_const.rs:143:16
268252
|
269253
LL | assert_eq!(u64::ATOMIC.load(Ordering::SeqCst), 9); //~ ERROR interior mutability
270254
| ^^^^^^^^^^^
271255
|
272256
= help: assign this const to a local or static variable, and use the variable here
273257

274-
error: aborting due to 31 previous errors
258+
error: aborting due to 29 previous errors
275259

tests/ui/replace_consts.fixed

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@ use std::sync::{Once, ONCE_INIT};
1010
fn bad() {
1111
// Once
1212
{ let foo = ONCE_INIT; };
13-
// Atomic
14-
{ let foo = AtomicBool::new(false); };
15-
{ let foo = AtomicIsize::new(0); };
16-
{ let foo = AtomicI8::new(0); };
17-
{ let foo = AtomicI16::new(0); };
18-
{ let foo = AtomicI32::new(0); };
19-
{ let foo = AtomicI64::new(0); };
20-
{ let foo = AtomicUsize::new(0); };
21-
{ let foo = AtomicU8::new(0); };
22-
{ let foo = AtomicU16::new(0); };
23-
{ let foo = AtomicU32::new(0); };
24-
{ let foo = AtomicU64::new(0); };
2513
// Min
2614
{ let foo = isize::min_value(); };
2715
{ let foo = i8::min_value(); };

tests/ui/replace_consts.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@ use std::sync::{Once, ONCE_INIT};
1010
fn bad() {
1111
// Once
1212
{ let foo = ONCE_INIT; };
13-
// Atomic
14-
{ let foo = ATOMIC_BOOL_INIT; };
15-
{ let foo = ATOMIC_ISIZE_INIT; };
16-
{ let foo = ATOMIC_I8_INIT; };
17-
{ let foo = ATOMIC_I16_INIT; };
18-
{ let foo = ATOMIC_I32_INIT; };
19-
{ let foo = ATOMIC_I64_INIT; };
20-
{ let foo = ATOMIC_USIZE_INIT; };
21-
{ let foo = ATOMIC_U8_INIT; };
22-
{ let foo = ATOMIC_U16_INIT; };
23-
{ let foo = ATOMIC_U32_INIT; };
24-
{ let foo = ATOMIC_U64_INIT; };
2513
// Min
2614
{ let foo = std::isize::MIN; };
2715
{ let foo = std::i8::MIN; };

0 commit comments

Comments
 (0)