Skip to content

Commit 45b989a

Browse files
Enable 2021 compatibility lints for all in-tree code
This just applies the suggested fixes from the compatibility warnings, leaving any that are in practice spurious in. This is primarily intended to provide a starting point to identify possible fixes to the migrations (e.g., by avoiding spurious warnings). A secondary commit cleans these up where they are false positives (as is true in many of the cases).
1 parent 5e1a614 commit 45b989a

File tree

12 files changed

+52
-34
lines changed

12 files changed

+52
-34
lines changed

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -906,8 +906,11 @@ impl ThinLTOKeysMap {
906906
) -> Self {
907907
let keys = iter::zip(modules, names)
908908
.map(|(module, name)| {
909-
let key = build_string(|rust_str| unsafe {
910-
llvm::LLVMRustComputeLTOCacheKey(rust_str, module.identifier, data.0);
909+
let key = build_string(|rust_str| {
910+
let _ = &data;
911+
unsafe {
912+
llvm::LLVMRustComputeLTOCacheKey(rust_str, module.identifier, data.0);
913+
}
911914
})
912915
.expect("Invalid ThinLTO module key");
913916
(name.clone().into_string().unwrap(), key)

compiler/rustc_const_eval/src/interpret/validity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ macro_rules! throw_validation_failure {
7777
///
7878
macro_rules! try_validation {
7979
($e:expr, $where:expr,
80-
$( $( $p:pat )|+ => { $( $what_fmt:expr ),+ } $( expected { $( $expected_fmt:expr ),+ } )? ),+ $(,)?
80+
$( $( $p:pat_param )|+ => { $( $what_fmt:expr ),+ } $( expected { $( $expected_fmt:expr ),+ } )? ),+ $(,)?
8181
) => {{
8282
match $e {
8383
Ok(x) => x,

compiler/rustc_infer/src/infer/at.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
195195
let Trace { at, trace, a_is_expected } = self;
196196
at.infcx.commit_if_ok(|_| {
197197
let mut fields = at.infcx.combine_fields(trace, at.param_env);
198-
fields
199-
.sub(a_is_expected)
200-
.relate(a, b)
201-
.map(move |_| InferOk { value: (), obligations: fields.obligations })
198+
fields.sub(a_is_expected).relate(a, b).map(move |_| {
199+
let _ = &fields;
200+
InferOk { value: (), obligations: fields.obligations }
201+
})
202202
})
203203
}
204204

@@ -212,10 +212,10 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
212212
let Trace { at, trace, a_is_expected } = self;
213213
at.infcx.commit_if_ok(|_| {
214214
let mut fields = at.infcx.combine_fields(trace, at.param_env);
215-
fields
216-
.equate(a_is_expected)
217-
.relate(a, b)
218-
.map(move |_| InferOk { value: (), obligations: fields.obligations })
215+
fields.equate(a_is_expected).relate(a, b).map(move |_| {
216+
let _ = &fields;
217+
InferOk { value: (), obligations: fields.obligations }
218+
})
219219
})
220220
}
221221

@@ -227,10 +227,10 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
227227
let Trace { at, trace, a_is_expected } = self;
228228
at.infcx.commit_if_ok(|_| {
229229
let mut fields = at.infcx.combine_fields(trace, at.param_env);
230-
fields
231-
.lub(a_is_expected)
232-
.relate(a, b)
233-
.map(move |t| InferOk { value: t, obligations: fields.obligations })
230+
fields.lub(a_is_expected).relate(a, b).map(move |t| {
231+
let _ = &fields;
232+
InferOk { value: t, obligations: fields.obligations }
233+
})
234234
})
235235
}
236236

@@ -242,10 +242,10 @@ impl<'a, 'tcx> Trace<'a, 'tcx> {
242242
let Trace { at, trace, a_is_expected } = self;
243243
at.infcx.commit_if_ok(|_| {
244244
let mut fields = at.infcx.combine_fields(trace, at.param_env);
245-
fields
246-
.glb(a_is_expected)
247-
.relate(a, b)
248-
.map(move |t| InferOk { value: t, obligations: fields.obligations })
245+
fields.glb(a_is_expected).relate(a, b).map(move |t| {
246+
let _ = &fields;
247+
InferOk { value: t, obligations: fields.obligations }
248+
})
249249
})
250250
}
251251
}

compiler/rustc_interface/src/util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ pub fn scoped_thread<F: FnOnce() -> R + Send, R: Send>(cfg: thread::Builder, f:
125125
let result_ptr = Ptr(&mut result as *mut _ as *mut ());
126126

127127
let thread = cfg.spawn(move || {
128+
let _ = (&run, &result_ptr);
128129
let run = unsafe { (*(run.0 as *mut Option<F>)).take().unwrap() };
129130
let result = unsafe { &mut *(result_ptr.0 as *mut Option<R>) };
130131
*result = Some(run());

compiler/rustc_mir_build/src/lints.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ crate fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
4141
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
4242
let sp = tcx.sess.source_map().guess_head_span(tcx.hir().span_with_body(hir_id));
4343
tcx.struct_span_lint_hir(UNCONDITIONAL_RECURSION, hir_id, sp, |lint| {
44+
let _ = &vis;
4445
let mut db = lint.build("function cannot return without recursing");
4546
db.span_label(sp, "cannot return without recursing");
4647
// offer some help to the programmer.

compiler/rustc_trait_selection/src/traits/query/type_op/custom.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ where
4040
info!("fully_perform({:?})", self);
4141
}
4242

43-
scrape_region_constraints(infcx, || (self.closure)(infcx))
43+
scrape_region_constraints(infcx, || {
44+
let _ = &self;
45+
(self.closure)(infcx)
46+
})
4447
}
4548
}
4649

compiler/rustc_trait_selection/src/traits/specialize/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ fn report_conflicting_impls(
394394
// now because the struct_lint methods don't return back the DiagnosticBuilder
395395
// that's passed in.
396396
let decorate = |err: LintDiagnosticBuilder<'_>| {
397+
let _ = &overlap;
397398
let msg = format!(
398399
"conflicting implementations of trait `{}`{}{}",
399400
overlap.trait_desc,

compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,22 @@ impl ChildrenExt for Children {
104104
let self_ty = trait_ref.self_ty();
105105

106106
// FIXME: should postpone string formatting until we decide to actually emit.
107-
with_no_trimmed_paths(|| OverlapError {
108-
with_impl: possible_sibling,
109-
trait_desc: trait_ref.print_only_trait_path().to_string(),
110-
// Only report the `Self` type if it has at least
111-
// some outer concrete shell; otherwise, it's
112-
// not adding much information.
113-
self_desc: if self_ty.has_concrete_skeleton() {
114-
Some(self_ty.to_string())
115-
} else {
116-
None
117-
},
118-
intercrate_ambiguity_causes: overlap.intercrate_ambiguity_causes,
119-
involves_placeholder: overlap.involves_placeholder,
107+
with_no_trimmed_paths(|| {
108+
let _ = &overlap;
109+
OverlapError {
110+
with_impl: possible_sibling,
111+
trait_desc: trait_ref.print_only_trait_path().to_string(),
112+
// Only report the `Self` type if it has at least
113+
// some outer concrete shell; otherwise, it's
114+
// not adding much information.
115+
self_desc: if self_ty.has_concrete_skeleton() {
116+
Some(self_ty.to_string())
117+
} else {
118+
None
119+
},
120+
intercrate_ambiguity_causes: overlap.intercrate_ambiguity_causes,
121+
involves_placeholder: overlap.involves_placeholder,
122+
}
120123
})
121124
};
122125

compiler/rustc_typeck/src/check/compare_method.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,7 @@ fn compare_type_predicate_entailment<'tcx>(
11921192
normalize_cause.clone(),
11931193
);
11941194
tcx.infer_ctxt().enter(|infcx| {
1195+
let _ = &impl_ty_own_bounds;
11951196
let inh = Inherited::new(infcx, impl_ty.def_id.expect_local());
11961197
let infcx = &inh.infcx;
11971198

compiler/rustc_typeck/src/check/method/probe.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
441441
// this creates one big transaction so that all type variables etc
442442
// that we create during the probe process are removed later
443443
self.probe(|_| {
444+
let _ = &steps;
444445
let mut probe_cx = ProbeContext::new(
445446
self,
446447
span,

src/librustdoc/doctest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@ impl Tester for Collector {
964964
test_type: test::TestType::DocTest,
965965
},
966966
testfn: test::DynTestFn(Box::new(move || {
967+
let _ = &config;
967968
let report_unused_externs = |uext| {
968969
unused_externs.lock().unwrap().push(uext);
969970
};

src/tools/clippy/clippy_utils/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -990,7 +990,10 @@ pub fn can_move_expr_to_closure(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) ->
990990
captures: HirIdMap::default(),
991991
};
992992
v.visit_expr(expr);
993-
v.allow_closure.then(|| v.captures)
993+
v.allow_closure.then(|| {
994+
let _ = &v;
995+
v.captures
996+
})
994997
}
995998

996999
/// Returns the method names and argument list of nested method call expressions that make up

0 commit comments

Comments
 (0)