Skip to content

Commit 21bfe52

Browse files
authored
Rollup merge of #75270 - matthiaskrgr:clippy_aug_1, r=Dylan-DPC
fix a couple of clippy findings
2 parents 81546de + a605e51 commit 21bfe52

File tree

27 files changed

+48
-53
lines changed

27 files changed

+48
-53
lines changed

library/test/src/helpers/concurrency.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::env;
44

55
#[allow(deprecated)]
66
pub fn get_concurrency() -> usize {
7-
return match env::var("RUST_TEST_THREADS") {
7+
match env::var("RUST_TEST_THREADS") {
88
Ok(s) => {
99
let opt_n: Option<usize> = s.parse().ok();
1010
match opt_n {
@@ -13,7 +13,7 @@ pub fn get_concurrency() -> usize {
1313
}
1414
}
1515
Err(..) => num_cpus(),
16-
};
16+
}
1717
}
1818

1919
cfg_if::cfg_if! {

src/librustc_codegen_llvm/debuginfo/metadata.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -960,15 +960,15 @@ fn pointer_type_metadata(
960960
fn param_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
961961
debug!("param_type_metadata: {:?}", t);
962962
let name = format!("{:?}", t);
963-
return unsafe {
963+
unsafe {
964964
llvm::LLVMRustDIBuilderCreateBasicType(
965965
DIB(cx),
966966
name.as_ptr().cast(),
967967
name.len(),
968968
Size::ZERO.bits(),
969969
DW_ATE_unsigned,
970970
)
971-
};
971+
}
972972
}
973973

974974
pub fn compile_unit_metadata(

src/librustc_codegen_ssa/back/write.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ fn copy_all_cgu_workproducts_to_incr_comp_cache_dir(
490490
let _timer = sess.timer("copy_all_cgu_workproducts_to_incr_comp_cache_dir");
491491

492492
for module in compiled_modules.modules.iter().filter(|m| m.kind == ModuleKind::Regular) {
493-
let path = module.object.as_ref().map(|path| path.clone());
493+
let path = module.object.as_ref().cloned();
494494

495495
if let Some((id, product)) =
496496
copy_cgu_workproduct_to_incr_comp_cache_dir(sess, &module.name, &path)

src/librustc_infer/infer/error_reporting/nice_region_error/named_anon_conflict.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
8585

8686
debug!("try_report_named_anon_conflict: ret ty {:?}", ty);
8787
if sub == &ty::ReStatic
88-
&& v.0
89-
.into_iter()
90-
.filter(|t| t.span.desugaring_kind().is_none())
91-
.next()
92-
.is_some()
88+
&& v.0.into_iter().find(|t| t.span.desugaring_kind().is_none()).is_some()
9389
{
9490
// If the failure is due to a `'static` requirement coming from a `dyn` or
9591
// `impl` Trait that *isn't* caused by `async fn` desugaring, handle this case

src/librustc_infer/infer/error_reporting/nice_region_error/static_impl_trait.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
257257
param.param_ty.to_string(),
258258
Applicability::MaybeIncorrect,
259259
);
260-
} else if let Some(_) = opaque
260+
} else if opaque
261261
.bounds
262262
.iter()
263263
.filter_map(|arg| match arg {
@@ -269,6 +269,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
269269
_ => None,
270270
})
271271
.next()
272+
.is_some()
272273
{
273274
} else {
274275
err.span_suggestion_verbose(

src/librustc_infer/infer/glb.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl TypeRelation<'tcx> for Glb<'combine, 'infcx, 'tcx> {
5050
ty::Invariant => self.fields.equate(self.a_is_expected).relate(a, b),
5151
ty::Covariant => self.relate(a, b),
5252
// FIXME(#41044) -- not correct, need test
53-
ty::Bivariant => Ok(a.clone()),
53+
ty::Bivariant => Ok(a),
5454
ty::Contravariant => self.fields.lub(self.a_is_expected).relate(a, b),
5555
}
5656
}
@@ -97,7 +97,7 @@ impl TypeRelation<'tcx> for Glb<'combine, 'infcx, 'tcx> {
9797
// very challenging, switch to invariance. This is obviously
9898
// overly conservative but works ok in practice.
9999
self.relate_with_variance(ty::Variance::Invariant, a, b)?;
100-
Ok(a.clone())
100+
Ok(a)
101101
}
102102
}
103103

src/librustc_infer/infer/nll_relate/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ where
719719
self.a_scopes.pop().unwrap();
720720
}
721721

722-
Ok(a.clone())
722+
Ok(a)
723723
}
724724
}
725725

src/librustc_infer/infer/region_constraints/leak_check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ impl<'me, 'tcx> LeakCheck<'me, 'tcx> {
288288
) -> TypeError<'tcx> {
289289
debug!("error: placeholder={:?}, other_region={:?}", placeholder, other_region);
290290
if self.overly_polymorphic {
291-
return TypeError::RegionsOverlyPolymorphic(placeholder.name, other_region);
291+
TypeError::RegionsOverlyPolymorphic(placeholder.name, other_region)
292292
} else {
293-
return TypeError::RegionsInsufficientlyPolymorphic(placeholder.name, other_region);
293+
TypeError::RegionsInsufficientlyPolymorphic(placeholder.name, other_region)
294294
}
295295
}
296296
}

src/librustc_infer/infer/sub.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
6868
match variance {
6969
ty::Invariant => self.fields.equate(self.a_is_expected).relate(a, b),
7070
ty::Covariant => self.relate(a, b),
71-
ty::Bivariant => Ok(a.clone()),
71+
ty::Bivariant => Ok(a),
7272
ty::Contravariant => self.with_expected_switched(|this| this.relate(b, a)),
7373
}
7474
}

src/librustc_lint/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
10741074
}
10751075
// If `ty` is a `repr(transparent)` newtype, and the non-zero-sized type is a generic
10761076
// argument, which after substitution, is `()`, then this branch can be hit.
1077-
FfiResult::FfiUnsafe { ty, .. } if is_return_type && ty.is_unit() => return,
1077+
FfiResult::FfiUnsafe { ty, .. } if is_return_type && ty.is_unit() => {}
10781078
FfiResult::FfiUnsafe { ty, reason, help } => {
10791079
self.emit_ffi_unsafe_type_lint(ty, sp, &reason, help.as_deref());
10801080
}

src/librustc_metadata/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl<'a, 'tcx> SpecializedEncoder<ExpnId> for EncodeContext<'a, 'tcx> {
162162
fn specialized_encode(&mut self, expn: &ExpnId) -> Result<(), Self::Error> {
163163
rustc_span::hygiene::raw_encode_expn_id(
164164
*expn,
165-
&mut self.hygiene_ctxt,
165+
&self.hygiene_ctxt,
166166
ExpnDataEncodeMode::Metadata,
167167
self,
168168
)

src/librustc_middle/traits/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ pub struct DropckOutlivesResult<'tcx> {
128128

129129
impl<'tcx> DropckOutlivesResult<'tcx> {
130130
pub fn report_overflows(&self, tcx: TyCtxt<'tcx>, span: Span, ty: Ty<'tcx>) {
131-
if let Some(overflow_ty) = self.overflows.iter().next() {
131+
if let Some(overflow_ty) = self.overflows.get(0) {
132132
let mut err = struct_span_err!(
133133
tcx.sess,
134134
span,

src/librustc_mir/borrow_check/diagnostics/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
868868
}
869869
}
870870
}
871-
return normal_ret;
871+
normal_ret
872872
}
873873

874874
/// Finds the span of arguments of a closure (within `maybe_closure_span`)

src/librustc_mir/transform/simplify_try.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ fn optimization_applies<'tcx>(
361361
}
362362

363363
trace!("SUCCESS: optimization applies!");
364-
return true;
364+
true
365365
}
366366

367367
impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity {

src/librustc_mir/transform/validate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub fn equal_up_to_regions(
115115
T: Relate<'tcx>,
116116
{
117117
self.relate(a.skip_binder(), b.skip_binder())?;
118-
Ok(a.clone())
118+
Ok(a)
119119
}
120120
}
121121

src/librustc_parse_format/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ fn find_skips_from_snippet(
820820
}
821821

822822
let r_start = str_style.map(|r| r + 1).unwrap_or(0);
823-
let r_end = str_style.map(|r| r).unwrap_or(0);
823+
let r_end = str_style.unwrap_or(0);
824824
let s = &snippet[r_start + 1..snippet.len() - r_end - 1];
825825
(find_skips(s, str_style.is_some()), true)
826826
}

src/librustc_save_analysis/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ impl<'tcx> SaveContext<'tcx> {
702702
Res::Def(HirDefKind::ConstParam, def_id) => {
703703
Some(Ref { kind: RefKind::Variable, span, ref_id: id_from_def_id(def_id) })
704704
}
705-
Res::Def(HirDefKind::Ctor(_, ..), def_id) => {
705+
Res::Def(HirDefKind::Ctor(..), def_id) => {
706706
// This is a reference to a tuple struct or an enum variant where the def_id points
707707
// to an invisible constructor function. That is not a very useful
708708
// def, so adjust to point to the tuple struct or enum variant itself.

src/librustc_session/filesearch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'a> FileSearch<'a> {
9898
p.push(RUST_LIB_DIR);
9999
p.push(&self.triple);
100100
p.push("bin");
101-
if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p.clone()] }
101+
if self_contained { vec![p.clone(), p.join("self-contained")] } else { vec![p] }
102102
}
103103
}
104104

src/librustc_span/hygiene.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ pub fn decode_expn_id<
10301030
drop(expns);
10311031
expn_id
10321032
});
1033-
return Ok(expn_id);
1033+
Ok(expn_id)
10341034
}
10351035

10361036
// Decodes `SyntaxContext`, using the provided `HygieneDecodeContext`
@@ -1103,7 +1103,7 @@ pub fn decode_syntax_context<
11031103
assert_eq!(dummy.dollar_crate_name, kw::Invalid);
11041104
});
11051105

1106-
return Ok(new_ctxt);
1106+
Ok(new_ctxt)
11071107
}
11081108

11091109
pub fn num_syntax_ctxts() -> usize {

src/librustc_trait_selection/autoderef.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
187187
}
188188

189189
pub fn span(&self) -> Span {
190-
self.span.clone()
190+
self.span
191191
}
192192

193193
pub fn reached_recursion_limit(&self) -> bool {

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
495495
if let Ok(src) = self.tcx.sess.source_map().span_to_snippet(span) {
496496
// Don't care about `&mut` because `DerefMut` is used less
497497
// often and user will not expect autoderef happens.
498-
if src.starts_with("&") && !src.starts_with("&mut ") {
498+
if src.starts_with('&') && !src.starts_with("&mut ") {
499499
let derefs = "*".repeat(steps);
500500
err.span_suggestion(
501501
span,

src/librustc_traits/chalk/db.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
141141

142142
let predicates = self.tcx.predicates_of(adt_def.did).predicates;
143143
let where_clauses: Vec<_> = predicates
144-
.into_iter()
144+
.iter()
145145
.map(|(wc, _)| wc.subst(self.tcx, bound_vars))
146146
.filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner))
147147
.collect();
@@ -174,7 +174,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
174174
phantom_data: adt_def.is_phantom_data(),
175175
},
176176
});
177-
return struct_datum;
177+
struct_datum
178178
}
179179

180180
fn fn_def_datum(
@@ -187,7 +187,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
187187

188188
let predicates = self.tcx.predicates_defined_on(def_id).predicates;
189189
let where_clauses: Vec<_> = predicates
190-
.into_iter()
190+
.iter()
191191
.map(|(wc, _)| wc.subst(self.tcx, &bound_vars))
192192
.filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner)).collect();
193193

@@ -276,7 +276,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
276276
parameters[0].assert_ty_ref(&self.interner).could_match(&self.interner, &lowered_ty)
277277
});
278278

279-
let impls = matched_impls.map(|matched_impl| chalk_ir::ImplId(matched_impl)).collect();
279+
let impls = matched_impls.map(chalk_ir::ImplId).collect();
280280
impls
281281
}
282282

@@ -379,7 +379,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
379379
ty::AdtKind::Struct | ty::AdtKind::Union => None,
380380
ty::AdtKind::Enum => {
381381
let constraint = self.tcx.adt_sized_constraint(adt_def.did);
382-
if constraint.0.len() > 0 { unimplemented!() } else { Some(true) }
382+
if !constraint.0.is_empty() { unimplemented!() } else { Some(true) }
383383
}
384384
},
385385
_ => None,
@@ -398,7 +398,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
398398
ty::AdtKind::Struct | ty::AdtKind::Union => None,
399399
ty::AdtKind::Enum => {
400400
let constraint = self.tcx.adt_sized_constraint(adt_def.did);
401-
if constraint.0.len() > 0 { unimplemented!() } else { Some(true) }
401+
if !constraint.0.is_empty() { unimplemented!() } else { Some(true) }
402402
}
403403
},
404404
_ => None,
@@ -440,7 +440,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
440440
FnOnce => self.tcx.lang_items().fn_once_trait(),
441441
Unsize => self.tcx.lang_items().unsize_trait(),
442442
};
443-
def_id.map(|t| chalk_ir::TraitId(t))
443+
def_id.map(chalk_ir::TraitId)
444444
}
445445

446446
fn is_object_safe(&self, trait_id: chalk_ir::TraitId<RustInterner<'tcx>>) -> bool {

src/librustc_ty/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ fn opaque_type_projection_predicates(
443443

444444
let bounds = tcx.predicates_of(def_id);
445445
let predicates =
446-
util::elaborate_predicates(tcx, bounds.predicates.into_iter().map(|&(pred, _)| pred));
446+
util::elaborate_predicates(tcx, bounds.predicates.iter().map(|&(pred, _)| pred));
447447

448448
let filtered_predicates = predicates.filter_map(|obligation| {
449449
let pred = obligation.predicate;

src/librustc_typeck/check/dropck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,6 @@ impl TypeRelation<'tcx> for SimpleEqRelation<'tcx> {
368368
let anon_b = self.tcx.anonymize_late_bound_regions(&b);
369369
self.relate(anon_a.skip_binder(), anon_b.skip_binder())?;
370370

371-
Ok(a.clone())
371+
Ok(a)
372372
}
373373
}

src/librustc_typeck/check/place_op.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
200200
// Gather up expressions we want to munge.
201201
let mut exprs = vec![expr];
202202

203-
loop {
204-
match exprs.last().unwrap().kind {
205-
hir::ExprKind::Field(ref expr, _)
206-
| hir::ExprKind::Index(ref expr, _)
207-
| hir::ExprKind::Unary(hir::UnOp::UnDeref, ref expr) => exprs.push(&expr),
208-
_ => break,
209-
}
203+
while let hir::ExprKind::Field(ref expr, _)
204+
| hir::ExprKind::Index(ref expr, _)
205+
| hir::ExprKind::Unary(hir::UnOp::UnDeref, ref expr) = exprs.last().unwrap().kind
206+
{
207+
exprs.push(&expr);
210208
}
211209

212210
debug!("convert_place_derefs_to_mutable: exprs={:?}", exprs);

src/librustc_typeck/mem_categorization.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
583583
self.tcx()
584584
.sess
585585
.delay_span_bug(span, "struct or tuple struct pattern not applied to an ADT");
586-
return Err(());
586+
Err(())
587587
}
588588
}
589589
}
@@ -596,7 +596,7 @@ impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
596596
ty::Tuple(substs) => Ok(substs.len()),
597597
_ => {
598598
self.tcx().sess.delay_span_bug(span, "tuple pattern not applied to a tuple");
599-
return Err(());
599+
Err(())
600600
}
601601
}
602602
}

src/librustdoc/docfs.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ impl DocFS {
6969
let sender = self.errors.clone().expect("can't write after closing");
7070
rayon::spawn(move || {
7171
fs::write(&path, contents).unwrap_or_else(|e| {
72-
sender
73-
.send(format!("\"{}\": {}", path.display(), e))
74-
.expect(&format!("failed to send error on \"{}\"", path.display()));
72+
sender.send(format!("\"{}\": {}", path.display(), e)).unwrap_or_else(|_| {
73+
panic!("failed to send error on \"{}\"", path.display())
74+
})
7575
});
7676
});
77-
Ok(())
7877
} else {
79-
Ok(try_err!(fs::write(&path, contents), path))
78+
try_err!(fs::write(&path, contents), path);
8079
}
80+
Ok(())
8181
}
8282
}

0 commit comments

Comments
 (0)