Skip to content

Commit 5b22aa7

Browse files
committed
Auto merge of rust-lang#2475 - RalfJung:rustc-lints, r=RalfJung
enable rustc lints Given how many rustc APIs we are using, this is probably a good idea. Seems like we are lint-clean right now. :)
2 parents a522442 + b36b5e3 commit 5b22aa7

File tree

10 files changed

+41
-28
lines changed

10 files changed

+41
-28
lines changed

cargo-miri/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![feature(let_else)]
2-
#![allow(clippy::useless_format, clippy::derive_partial_eq_without_eq)]
2+
#![allow(clippy::useless_format, clippy::derive_partial_eq_without_eq, rustc::internal)]
33

44
mod arg;
55
mod phases;

miri

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ fi
124124
if [ -z "$CARGO_PROFILE_DEV_OPT_LEVEL" ]; then
125125
export CARGO_PROFILE_DEV_OPT_LEVEL=2
126126
fi
127+
# Enable rustc-specific lints (ignored without `-Zunstable-options`).
128+
export RUSTFLAGS="-Zunstable-options -Wrustc::internal $RUSTFLAGS"
127129
# We set the rpath so that Miri finds the private rustc libraries it needs.
128130
export RUSTFLAGS="-C link-args=-Wl,-rpath,$LIBDIR $RUSTFLAGS"
129131

src/bin/miri.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,14 @@ struct MiriBeRustCompilerCalls {
101101
}
102102

103103
impl rustc_driver::Callbacks for MiriBeRustCompilerCalls {
104+
#[allow(rustc::potential_query_instability)] // rustc_codegen_ssa (where this code is copied from) also allows this lint
104105
fn config(&mut self, config: &mut Config) {
105106
if config.opts.prints.is_empty() && self.target_crate {
106107
// Queries overriden here affect the data stored in `rmeta` files of dependencies,
107108
// which will be used later in non-`MIRI_BE_RUSTC` mode.
108109
config.override_queries = Some(|_, local_providers, _| {
109-
// `exported_symbols()` provided by rustc always returns empty result if
110-
// `tcx.sess.opts.output_types.should_codegen()` is false.
110+
// `exported_symbols` and `reachable_non_generics` provided by rustc always returns
111+
// an empty result if `tcx.sess.opts.output_types.should_codegen()` is false.
111112
local_providers.exported_symbols = |tcx, cnum| {
112113
assert_eq!(cnum, LOCAL_CRATE);
113114
tcx.arena.alloc_from_iter(

src/eval.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//! Main evaluator loop and setting up the initial stack frame.
22
3-
use std::collections::HashSet;
43
use std::ffi::{OsStr, OsString};
54
use std::iter;
65
use std::panic::{self, AssertUnwindSafe};
76
use std::thread;
87

98
use log::info;
109

10+
use rustc_data_structures::fx::FxHashSet;
1111
use rustc_hir::def_id::DefId;
1212
use rustc_middle::ty::{
1313
self,
@@ -96,11 +96,11 @@ pub struct MiriConfig {
9696
/// The seed to use when non-determinism or randomness are required (e.g. ptr-to-int cast, `getrandom()`).
9797
pub seed: Option<u64>,
9898
/// The stacked borrows pointer ids to report about
99-
pub tracked_pointer_tags: HashSet<SbTag>,
99+
pub tracked_pointer_tags: FxHashSet<SbTag>,
100100
/// The stacked borrows call IDs to report about
101-
pub tracked_call_ids: HashSet<CallId>,
101+
pub tracked_call_ids: FxHashSet<CallId>,
102102
/// The allocation ids to report about.
103-
pub tracked_alloc_ids: HashSet<AllocId>,
103+
pub tracked_alloc_ids: FxHashSet<AllocId>,
104104
/// Determine if data race detection should be enabled
105105
pub data_race_detector: bool,
106106
/// Determine if weak memory emulation should be enabled. Requires data race detection to be enabled
@@ -144,9 +144,9 @@ impl Default for MiriConfig {
144144
forwarded_env_vars: vec![],
145145
args: vec![],
146146
seed: None,
147-
tracked_pointer_tags: HashSet::default(),
148-
tracked_call_ids: HashSet::default(),
149-
tracked_alloc_ids: HashSet::default(),
147+
tracked_pointer_tags: FxHashSet::default(),
148+
tracked_call_ids: FxHashSet::default(),
149+
tracked_alloc_ids: FxHashSet::default(),
150150
data_race_detector: true,
151151
weak_memory_emulation: true,
152152
track_outdated_loads: false,

src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
clippy::derive_partial_eq_without_eq,
2424
clippy::derive_hash_xor_eq,
2525
clippy::too_many_arguments,
26-
clippy::type_complexity
26+
clippy::type_complexity,
27+
// We are not implementing queries here so it's fine
28+
rustc::potential_query_instability
2729
)]
2830
#![warn(
2931
rust_2018_idioms,

src/machine.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,22 @@
33
44
use std::borrow::Cow;
55
use std::cell::RefCell;
6-
use std::collections::HashSet;
76
use std::fmt;
87
use std::time::Instant;
98

109
use rand::rngs::StdRng;
1110
use rand::SeedableRng;
1211

1312
use rustc_ast::ast::Mutability;
14-
use rustc_data_structures::fx::FxHashMap;
13+
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1514
#[allow(unused)]
1615
use rustc_data_structures::static_assert_size;
1716
use rustc_middle::{
1817
mir,
1918
ty::{
2019
self,
2120
layout::{LayoutCx, LayoutError, LayoutOf, TyAndLayout},
22-
Instance, TyCtxt, TypeAndMut,
21+
Instance, Ty, TyCtxt, TypeAndMut,
2322
},
2423
};
2524
use rustc_span::def_id::{CrateNum, DefId};
@@ -335,7 +334,7 @@ pub struct Evaluator<'mir, 'tcx> {
335334

336335
/// The allocation IDs to report when they are being allocated
337336
/// (helps for debugging memory leaks and use after free bugs).
338-
tracked_alloc_ids: HashSet<AllocId>,
337+
tracked_alloc_ids: FxHashSet<AllocId>,
339338

340339
/// Controls whether alignment of memory accesses is being checked.
341340
pub(crate) check_alignment: AlignmentCheck,
@@ -613,7 +612,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
613612
bin_op: mir::BinOp,
614613
left: &ImmTy<'tcx, Provenance>,
615614
right: &ImmTy<'tcx, Provenance>,
616-
) -> InterpResult<'tcx, (Scalar<Provenance>, bool, ty::Ty<'tcx>)> {
615+
) -> InterpResult<'tcx, (Scalar<Provenance>, bool, Ty<'tcx>)> {
617616
ecx.binary_ptr_op(bin_op, left, right)
618617
}
619618

src/shims/intrinsics/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ use log::trace;
77

88
use rustc_apfloat::{Float, Round};
99
use rustc_middle::ty::layout::{IntegerExt, LayoutOf};
10-
use rustc_middle::{mir, ty, ty::FloatTy};
10+
use rustc_middle::{
11+
mir,
12+
ty::{self, FloatTy, Ty},
13+
};
1114
use rustc_target::abi::Integer;
1215

1316
use crate::*;
@@ -377,7 +380,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
377380
fn float_to_int_unchecked<F>(
378381
&self,
379382
f: F,
380-
dest_ty: ty::Ty<'tcx>,
383+
dest_ty: Ty<'tcx>,
381384
) -> InterpResult<'tcx, Scalar<Provenance>>
382385
where
383386
F: Float + Into<Scalar<Provenance>>,

src/stacked_borrows/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ use rustc_middle::mir::RetagKind;
1313
use rustc_middle::ty::{
1414
self,
1515
layout::{HasParamEnv, LayoutOf},
16+
Ty,
1617
};
1718
use rustc_span::DUMMY_SP;
1819
use rustc_target::abi::Size;
1920
use smallvec::SmallVec;
20-
use std::collections::HashSet;
2121

2222
use crate::*;
2323

@@ -100,9 +100,9 @@ pub struct GlobalStateInner {
100100
/// `GlobalStateInner::end_call`. See `Stack::item_popped` for more details.
101101
protected_tags: FxHashSet<SbTag>,
102102
/// The pointer ids to trace
103-
tracked_pointer_tags: HashSet<SbTag>,
103+
tracked_pointer_tags: FxHashSet<SbTag>,
104104
/// The call ids to trace
105-
tracked_call_ids: HashSet<CallId>,
105+
tracked_call_ids: FxHashSet<CallId>,
106106
/// Whether to recurse into datatypes when searching for pointers to retag.
107107
retag_fields: bool,
108108
}
@@ -154,8 +154,8 @@ impl fmt::Display for RefKind {
154154
/// Utilities for initialization and ID generation
155155
impl GlobalStateInner {
156156
pub fn new(
157-
tracked_pointer_tags: HashSet<SbTag>,
158-
tracked_call_ids: HashSet<CallId>,
157+
tracked_pointer_tags: FxHashSet<SbTag>,
158+
tracked_call_ids: FxHashSet<CallId>,
159159
retag_fields: bool,
160160
) -> Self {
161161
GlobalStateInner {
@@ -1013,7 +1013,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
10131013
// Determine mutability and whether to add a protector.
10141014
// Cannot use `builtin_deref` because that reports *immutable* for `Box`,
10151015
// making it useless.
1016-
fn qualify(ty: ty::Ty<'_>, kind: RetagKind) -> Option<(RefKind, bool)> {
1016+
fn qualify(ty: Ty<'_>, kind: RetagKind) -> Option<(RefKind, bool)> {
10171017
match ty.kind() {
10181018
// References are simple.
10191019
ty::Ref(_, _, Mutability::Mut) =>

src/sync.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
use std::collections::{hash_map::Entry, HashMap, VecDeque};
1+
use std::collections::{hash_map::Entry, VecDeque};
22
use std::num::NonZeroU32;
33
use std::ops::Not;
44

55
use log::trace;
66

7+
use rustc_data_structures::fx::FxHashMap;
78
use rustc_index::vec::{Idx, IndexVec};
89

910
use crate::*;
@@ -77,7 +78,7 @@ struct RwLock {
7778
writer: Option<ThreadId>,
7879
/// The readers that currently own the lock and how many times they acquired
7980
/// the lock.
80-
readers: HashMap<ThreadId, usize>,
81+
readers: FxHashMap<ThreadId, usize>,
8182
/// The queue of writer threads waiting for this lock.
8283
writer_queue: VecDeque<ThreadId>,
8384
/// The queue of reader threads waiting for this lock.
@@ -153,7 +154,7 @@ pub(super) struct SynchronizationState {
153154
mutexes: IndexVec<MutexId, Mutex>,
154155
rwlocks: IndexVec<RwLockId, RwLock>,
155156
condvars: IndexVec<CondvarId, Condvar>,
156-
futexes: HashMap<u64, Futex>,
157+
futexes: FxHashMap<u64, Futex>,
157158
}
158159

159160
// Private extension trait for local helper methods

ui_test/src/lib.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
#![allow(clippy::enum_variant_names, clippy::useless_format, clippy::too_many_arguments)]
1+
#![allow(
2+
clippy::enum_variant_names,
3+
clippy::useless_format,
4+
clippy::too_many_arguments,
5+
rustc::internal
6+
)]
27

38
use std::collections::VecDeque;
49
use std::ffi::OsString;

0 commit comments

Comments
 (0)