Skip to content

Commit 60368e1

Browse files
author
Herman Venter
authored
Satisfy the -D rust-2018-idioms compiler flag (facebookexperimental#92)
1 parent e87bf65 commit 60368e1

9 files changed

+38
-43
lines changed

src/abstract_domains.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub struct AbstractDomain {
3232
}
3333

3434
impl Debug for AbstractDomain {
35-
fn fmt(&self, f: &mut Formatter) -> Result {
35+
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
3636
self.expression.fmt(f)
3737
}
3838
}
@@ -75,7 +75,7 @@ pub const TRUE: AbstractDomain = AbstractDomain {
7575
};
7676

7777
impl<'a> From<&TyKind<'a>> for ExpressionType {
78-
fn from(ty_kind: &TyKind) -> ExpressionType {
78+
fn from(ty_kind: &TyKind<'a>) -> ExpressionType {
7979
match ty_kind {
8080
TyKind::Bool => ExpressionType::Bool,
8181
TyKind::Char => ExpressionType::Char,

src/abstract_value.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub const TRUE: AbstractValue = AbstractValue {
6262
};
6363

6464
impl Debug for AbstractValue {
65-
fn fmt(&self, f: &mut Formatter) -> Result {
65+
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
6666
self.domain.fmt(f)
6767
}
6868
}

src/callbacks.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ use syntax::{ast, errors};
2626
pub struct MiraiCallbacks {
2727
/// Called after static analysis is complete.
2828
/// Gives test harness a way to process intercepted diagnostics.
29-
consume_buffered_diagnostics: Box<Fn(&Vec<Diagnostic>) -> ()>,
29+
consume_buffered_diagnostics: Box<dyn Fn(&Vec<Diagnostic>) -> ()>,
3030
/// Use these to just defer to the Rust compiler's implementations.
3131
default_calls: Box<RustcDefaultCalls>,
3232
/// Called when static analysis reports a diagnostic message.
3333
/// By default, this just emits the message. When overridden it can
3434
/// intercept and buffer the diagnostics, which is used by the test harness.
35-
emit_diagnostic: fn(&mut DiagnosticBuilder, &mut Vec<Diagnostic>) -> (),
35+
emit_diagnostic: fn(&mut DiagnosticBuilder<'_>, &mut Vec<Diagnostic>) -> (),
3636
/// A path to the directory where analysis output, such as the summary cache, should be stored.
3737
output_directory: PathBuf,
3838
/// True if this run is done via cargo test
@@ -45,15 +45,15 @@ impl MiraiCallbacks {
4545
MiraiCallbacks {
4646
consume_buffered_diagnostics: box |_bd: &Vec<Diagnostic>| {},
4747
default_calls: box RustcDefaultCalls,
48-
emit_diagnostic: |db: &mut DiagnosticBuilder, _buf: &mut Vec<Diagnostic>| db.emit(),
48+
emit_diagnostic: |db: &mut DiagnosticBuilder<'_>, _buf: &mut Vec<Diagnostic>| db.emit(),
4949
output_directory: PathBuf::default(),
5050
test_run: false,
5151
}
5252
}
5353

5454
pub fn with_buffered_diagnostics(
55-
consume_buffered_diagnostics: Box<Fn(&Vec<Diagnostic>) -> ()>,
56-
emit_diagnostic: fn(&mut DiagnosticBuilder, &mut Vec<Diagnostic>) -> (),
55+
consume_buffered_diagnostics: Box<dyn Fn(&Vec<Diagnostic>) -> ()>,
56+
emit_diagnostic: fn(&mut DiagnosticBuilder<'_>, &mut Vec<Diagnostic>) -> (),
5757
) -> MiraiCallbacks {
5858
MiraiCallbacks {
5959
consume_buffered_diagnostics,
@@ -97,7 +97,7 @@ impl<'a> CompilerCalls<'a> for MiraiCallbacks {
9797
/// is called), after all arguments etc. have been completely handled.
9898
fn late_callback(
9999
&mut self,
100-
codegen_backend: &CodegenBackend,
100+
codegen_backend: &dyn CodegenBackend,
101101
matches: &::getopts::Matches,
102102
session: &Session,
103103
crate_store: &CStore,
@@ -159,9 +159,9 @@ impl<'a> CompilerCalls<'a> for MiraiCallbacks {
159159
/// At this point the compiler is ready to tell us all it knows and we can proceed to do abstract
160160
/// interpretation of all of the functions that will end up in the compiler output.
161161
fn after_analysis(
162-
state: &mut driver::CompileState,
163-
consume_buffered_diagnostics: &Box<Fn(&Vec<Diagnostic>) -> ()>,
164-
emit_diagnostic: fn(&mut DiagnosticBuilder, &mut Vec<Diagnostic>) -> (),
162+
state: &mut driver::CompileState<'_, '_>,
163+
consume_buffered_diagnostics: &Box<dyn Fn(&Vec<Diagnostic>) -> ()>,
164+
emit_diagnostic: fn(&mut DiagnosticBuilder<'_>, &mut Vec<Diagnostic>) -> (),
165165
output_directory: &mut PathBuf,
166166
) {
167167
let session = state.session;

src/constant_domain.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ impl ConstantDomain {
5757
/// Returns a constant value that is a reference to a function
5858
pub fn for_function(
5959
def_id: DefId,
60-
tcx: &TyCtxt,
61-
summary_cache: &mut PersistentSummaryCache,
60+
tcx: &TyCtxt<'_, '_, '_>,
61+
summary_cache: &mut PersistentSummaryCache<'_, '_>,
6262
) -> ConstantDomain {
6363
let summary_cache_key = summary_cache.get_summary_key_for(def_id);
6464
ConstantDomain::Function {
@@ -633,8 +633,8 @@ impl ConstantValueCache {
633633
pub fn get_function_constant_for(
634634
&mut self,
635635
def_id: DefId,
636-
tcx: &TyCtxt,
637-
summary_cache: &mut PersistentSummaryCache,
636+
tcx: &TyCtxt<'_, '_, '_>,
637+
summary_cache: &mut PersistentSummaryCache<'_, '_>,
638638
) -> &ConstantDomain {
639639
self.function_cache
640640
.entry(def_id)

src/environment.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Environment {
3434
}
3535

3636
impl Debug for Environment {
37-
fn fmt(&self, f: &mut Formatter) -> Result {
37+
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
3838
self.value_map.fmt(f)
3939
}
4040
}

src/lib.rs

-6
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,16 @@
1919
extern crate getopts;
2020
extern crate rustc;
2121
extern crate rustc_codegen_utils;
22-
extern crate rustc_data_structures;
2322
extern crate rustc_driver;
2423
extern crate rustc_metadata;
2524
extern crate rustc_target;
2625
extern crate syntax;
2726
extern crate syntax_pos;
2827

29-
extern crate bincode;
3028
#[macro_use]
3129
extern crate log;
32-
//#[macro_use]
33-
extern crate rpds;
34-
extern crate sled;
3530
#[macro_use]
3631
extern crate serde_derive;
37-
extern crate serde;
3832

3933
pub mod abstract_domains;
4034
pub mod abstract_value;

src/utils.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn find_sysroot() -> String {
3232

3333
/// Returns true if the function identified by def_id is a Rust intrinsic function.
3434
/// Warning: it is not clear what will happen if def_id does not identify a function.
35-
pub fn is_rust_intrinsic(def_id: DefId, tcx: &TyCtxt) -> bool {
35+
pub fn is_rust_intrinsic(def_id: DefId, tcx: &TyCtxt<'_, '_, '_>) -> bool {
3636
let binder = tcx.fn_sig(def_id);
3737
let sig = binder.skip_binder();
3838
match sig.abi {
@@ -42,7 +42,7 @@ pub fn is_rust_intrinsic(def_id: DefId, tcx: &TyCtxt) -> bool {
4242
}
4343

4444
/// Returns true if the function identified by def_id is a public function.
45-
pub fn is_public(def_id: DefId, tcx: &TyCtxt) -> bool {
45+
pub fn is_public(def_id: DefId, tcx: &TyCtxt<'_, '_, '_>) -> bool {
4646
if let Some(node) = tcx.hir().get_if_local(def_id) {
4747
match node {
4848
Node::Item(item) => {
@@ -73,7 +73,7 @@ pub fn is_public(def_id: DefId, tcx: &TyCtxt) -> bool {
7373
/// the summary cache, which is a key value store. The string will always be the same as
7474
/// long as the definition does not change its name or location, so it can be used to
7575
/// transfer information from one compilation to the next, making incremental analysis possible.
76-
pub fn summary_key_str(tcx: &TyCtxt, def_id: DefId) -> String {
76+
pub fn summary_key_str(tcx: &TyCtxt<'_, '_, '_>, def_id: DefId) -> String {
7777
let crate_name = if def_id.is_local() {
7878
tcx.crate_name.as_interned_str().as_str().get()
7979
} else {

src/visitors.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,27 @@ pub struct MirVisitorCrateContext<'a, 'b: 'a, 'tcx: 'b, E> {
2929
pub buffered_diagnostics: &'a mut Vec<Diagnostic>,
3030
/// A call back that the test harness can use to buffer the diagnostic message.
3131
/// By default this just calls emit on the diagnostic.
32-
pub emit_diagnostic: fn(&mut DiagnosticBuilder, buf: &mut Vec<Diagnostic>) -> (),
32+
pub emit_diagnostic: fn(&mut DiagnosticBuilder<'_>, buf: &mut Vec<Diagnostic>) -> (),
3333
pub session: &'tcx Session,
3434
pub tcx: TyCtxt<'b, 'tcx, 'tcx>,
3535
pub def_id: hir::def_id::DefId,
3636
pub mir: &'a mir::Mir<'tcx>,
3737
pub constant_value_cache: &'a mut ConstantValueCache,
3838
pub summary_cache: &'a mut PersistentSummaryCache<'b, 'tcx>,
39-
pub smt_solver: &'a mut SmtSolver<E>,
39+
pub smt_solver: &'a mut dyn SmtSolver<E>,
4040
}
4141

4242
/// Holds the state for the MIR test visitor.
4343
pub struct MirVisitor<'a, 'b: 'a, 'tcx: 'b, E> {
4444
buffered_diagnostics: &'a mut Vec<Diagnostic>,
45-
emit_diagnostic: fn(&mut DiagnosticBuilder, buf: &mut Vec<Diagnostic>) -> (),
45+
emit_diagnostic: fn(&mut DiagnosticBuilder<'_>, buf: &mut Vec<Diagnostic>) -> (),
4646
session: &'tcx Session,
4747
tcx: TyCtxt<'b, 'tcx, 'tcx>,
4848
def_id: hir::def_id::DefId,
4949
mir: &'a mir::Mir<'tcx>,
5050
constant_value_cache: &'a mut ConstantValueCache,
5151
summary_cache: &'a mut PersistentSummaryCache<'b, 'tcx>,
52-
smt_solver: &'a mut SmtSolver<E>,
52+
smt_solver: &'a mut dyn SmtSolver<E>,
5353

5454
check_for_errors: bool,
5555
current_environment: Environment,
@@ -446,7 +446,7 @@ impl<'a, 'b: 'a, 'tcx: 'b, E> MirVisitor<'a, 'b, 'tcx, E> {
446446
&mut self,
447447
asm: &hir::InlineAsm,
448448
outputs: &[mir::Place<'tcx>],
449-
inputs: &[(syntax_pos::Span, mir::Operand)],
449+
inputs: &[(syntax_pos::Span, mir::Operand<'tcx>)],
450450
) {
451451
debug!(
452452
"default visit_inline_asm(asm: {:?}, outputs: {:?}, inputs: {:?})",
@@ -544,7 +544,7 @@ impl<'a, 'b: 'a, 'tcx: 'b, E> MirVisitor<'a, 'b, 'tcx, E> {
544544
fn visit_switch_int(
545545
&mut self,
546546
discr: &mir::Operand<'tcx>,
547-
switch_ty: rustc::ty::Ty,
547+
switch_ty: rustc::ty::Ty<'tcx>,
548548
values: &[u128],
549549
targets: &[mir::BasicBlock],
550550
) {
@@ -937,7 +937,7 @@ impl<'a, 'b: 'a, 'tcx: 'b, E> MirVisitor<'a, 'b, 'tcx, E> {
937937
&mut self,
938938
cond: &mir::Operand<'tcx>,
939939
expected: bool,
940-
msg: &mir::AssertMessage,
940+
msg: &mir::AssertMessage<'tcx>,
941941
target: mir::BasicBlock,
942942
cleanup: Option<mir::BasicBlock>,
943943
) {
@@ -1334,7 +1334,7 @@ impl<'a, 'b: 'a, 'tcx: 'b, E> MirVisitor<'a, 'b, 'tcx, E> {
13341334
fn visit_ref(
13351335
&mut self,
13361336
path: Path,
1337-
region: rustc::ty::Region,
1337+
region: rustc::ty::Region<'tcx>,
13381338
borrow_kind: mir::BorrowKind,
13391339
place: &mir::Place<'tcx>,
13401340
) {
@@ -1379,7 +1379,7 @@ impl<'a, 'b: 'a, 'tcx: 'b, E> MirVisitor<'a, 'b, 'tcx, E> {
13791379
path: Path,
13801380
cast_kind: mir::CastKind,
13811381
operand: &mir::Operand<'tcx>,
1382-
ty: rustc::ty::Ty,
1382+
ty: rustc::ty::Ty<'tcx>,
13831383
) {
13841384
debug!(
13851385
"default visit_cast(path: {:?}, cast_kind: {:?}, operand: {:?}, ty: {:?})",
@@ -1481,7 +1481,7 @@ impl<'a, 'b: 'a, 'tcx: 'b, E> MirVisitor<'a, 'b, 'tcx, E> {
14811481
}
14821482

14831483
/// Create a value based on the given type and assign it to path.
1484-
fn visit_nullary_op(&mut self, path: Path, null_op: mir::NullOp, ty: rustc::ty::Ty) {
1484+
fn visit_nullary_op(&mut self, path: Path, null_op: mir::NullOp, ty: rustc::ty::Ty<'tcx>) {
14851485
debug!(
14861486
"default visit_nullary_op(path: {:?}, null_op: {:?}, ty: {:?})",
14871487
path, null_op, ty
@@ -1542,7 +1542,7 @@ impl<'a, 'b: 'a, 'tcx: 'b, E> MirVisitor<'a, 'b, 'tcx, E> {
15421542
fn visit_aggregate(
15431543
&mut self,
15441544
path: Path,
1545-
aggregate_kinds: &mir::AggregateKind,
1545+
aggregate_kinds: &mir::AggregateKind<'tcx>,
15461546
operands: &[mir::Operand<'tcx>],
15471547
) {
15481548
debug!(
@@ -1659,9 +1659,9 @@ impl<'a, 'b: 'a, 'tcx: 'b, E> MirVisitor<'a, 'b, 'tcx, E> {
16591659
/// Synthesizes a constant value.
16601660
fn visit_constant(
16611661
&mut self,
1662-
ty: Ty,
1662+
ty: Ty<'tcx>,
16631663
user_ty: Option<UserTypeAnnotationIndex>,
1664-
literal: &LazyConst,
1664+
literal: &LazyConst<'tcx>,
16651665
) -> AbstractValue {
16661666
use rustc::mir::interpret::{AllocKind, ConstValue, Scalar};
16671667
debug!(
@@ -2103,7 +2103,7 @@ impl<'a, 'b: 'a, 'tcx: 'b, E> MirVisitor<'a, 'b, 'tcx, E> {
21032103
/// but which can be serialized.
21042104
fn visit_projection_elem(
21052105
&mut self,
2106-
projection_elem: &mir::ProjectionElem<mir::Local, &rustc::ty::TyS>,
2106+
projection_elem: &mir::ProjectionElem<'tcx, mir::Local, &rustc::ty::TyS<'tcx>>,
21072107
) -> PathSelector {
21082108
debug!(
21092109
"visit_projection_elem(projection_elem: {:?})",
@@ -2143,7 +2143,7 @@ impl<'a, 'b: 'a, 'tcx: 'b, E> MirVisitor<'a, 'b, 'tcx, E> {
21432143
}
21442144

21452145
/// Returns the rustc TyKind of the given place in memory.
2146-
fn get_rustc_place_type(&self, place: &mir::Place<'tcx>) -> &TyKind<'a> {
2146+
fn get_rustc_place_type(&self, place: &mir::Place<'tcx>) -> &TyKind<'tcx> {
21472147
match place {
21482148
mir::Place::Base(base_place) => match base_place {
21492149
mir::PlaceBase::Local(local) => {
@@ -2160,7 +2160,7 @@ impl<'a, 'b: 'a, 'tcx: 'b, E> MirVisitor<'a, 'b, 'tcx, E> {
21602160
}
21612161

21622162
/// Returns the rustc TyKind of the element selected by projection_elem.
2163-
fn get_type_for_projection_element(&self, place: &mir::Place<'tcx>) -> &TyKind<'a> {
2163+
fn get_type_for_projection_element(&self, place: &mir::Place<'tcx>) -> &TyKind<'tcx> {
21642164
if let mir::Place::Projection(boxed_place_projection) = place {
21652165
let base_ty = self.get_rustc_place_type(&boxed_place_projection.base);
21662166
match boxed_place_projection.elem {

tests/validate.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ cargo fmt --all
99
# Run lint checks
1010
cargo clippy -- -D warnings
1111
# Build
12-
time cargo build
12+
cargo rustc --lib -- -D rust-2018-idioms
13+
cargo build
1314
# Run mirai on itself
1415
cargo uninstall mirai || true
1516
cargo install --debug --path .

0 commit comments

Comments
 (0)