Skip to content

Commit dfa3677

Browse files
authored
Rollup merge of #72109 - matthiaskrgr:cl8ppy, r=Dylan-DPC
Fix clippy warnings Fixes clippy::{cone_on_copy, filter_next, redundant_closure, single_char_pattern, len_zero,redundant_field_names, useless_format, identity_conversion, map_clone, into_iter_on_ref, needless_return, option_as_ref_deref, unused_unit, unnecessary_mut_passed} r? @Dylan-DPC
2 parents dd53768 + 8bfd845 commit dfa3677

File tree

24 files changed

+68
-79
lines changed

24 files changed

+68
-79
lines changed

src/librustc_attr/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ pub fn eval_condition(
634634
[NestedMetaItem::Literal(Lit { span, .. })
635635
| NestedMetaItem::MetaItem(MetaItem { span, .. })] => {
636636
sess.span_diagnostic
637-
.struct_span_err(*span, &*format!("expected a version literal"))
637+
.struct_span_err(*span, "expected a version literal")
638638
.emit();
639639
return false;
640640
}

src/librustc_data_structures/tiny_list.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl<T: PartialEq> TinyList<T> {
5252
if &e.data == data {
5353
return true;
5454
}
55-
elem = e.next.as_ref().map(|e| &**e);
55+
elem = e.next.as_deref();
5656
}
5757
false
5858
}
@@ -62,7 +62,7 @@ impl<T: PartialEq> TinyList<T> {
6262
let (mut elem, mut count) = (self.head.as_ref(), 0);
6363
while let Some(ref e) = elem {
6464
count += 1;
65-
elem = e.next.as_ref().map(|e| &**e);
65+
elem = e.next.as_deref();
6666
}
6767
count
6868
}

src/librustc_infer/traits/util.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,7 @@ pub fn elaborate_predicates<'tcx>(
112112
tcx: TyCtxt<'tcx>,
113113
predicates: impl Iterator<Item = ty::Predicate<'tcx>>,
114114
) -> Elaborator<'tcx> {
115-
let obligations =
116-
predicates.into_iter().map(|predicate| predicate_obligation(predicate, None)).collect();
115+
let obligations = predicates.map(|predicate| predicate_obligation(predicate, None)).collect();
117116
elaborate_obligations(tcx, obligations)
118117
}
119118

@@ -149,7 +148,7 @@ impl Elaborator<'tcx> {
149148
// Get predicates declared on the trait.
150149
let predicates = tcx.super_predicates_of(data.def_id());
151150

152-
let obligations = predicates.predicates.into_iter().map(|(pred, span)| {
151+
let obligations = predicates.predicates.iter().map(|(pred, span)| {
153152
predicate_obligation(
154153
pred.subst_supertrait(tcx, &data.to_poly_trait_ref()),
155154
Some(*span),

src/librustc_interface/queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'tcx> Queries<'tcx> {
137137
let result = passes::register_plugins(
138138
self.session(),
139139
&*self.codegen_backend().metadata_loader(),
140-
self.compiler.register_lints.as_ref().map(|p| &**p).unwrap_or_else(|| empty),
140+
self.compiler.register_lints.as_deref().unwrap_or_else(|| empty),
141141
krate,
142142
&crate_name,
143143
);

src/librustc_middle/dep_graph/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ impl rustc_query_system::dep_graph::DepKind for DepKind {
7272
})
7373
}
7474

75-
fn read_deps<OP>(op: OP) -> ()
75+
fn read_deps<OP>(op: OP)
7676
where
77-
OP: for<'a> FnOnce(Option<&'a Lock<TaskDeps>>) -> (),
77+
OP: for<'a> FnOnce(Option<&'a Lock<TaskDeps>>),
7878
{
7979
ty::tls::with_context_opt(|icx| {
8080
let icx = if let Some(icx) = icx { icx } else { return };

src/librustc_middle/hir/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ pub fn provide(providers: &mut Providers<'_>) {
7878
&tcx.untracked_crate.modules[&module]
7979
};
8080
providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature;
81-
providers.hir_owner_nodes =
82-
|tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_ref().map(|nodes| &**nodes);
81+
providers.hir_owner_nodes = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_deref();
8382
map::provide(providers);
8483
}

src/librustc_middle/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl<'tcx> AssociatedItems<'tcx> {
280280
&self,
281281
name: Symbol,
282282
) -> impl '_ + Iterator<Item = &ty::AssocItem> {
283-
self.items.get_by_key(&name).map(|v| *v)
283+
self.items.get_by_key(&name).copied()
284284
}
285285

286286
/// Returns an iterator over all associated items with the given name.

src/librustc_middle/ty/trait_def.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -171,10 +171,7 @@ impl<'tcx> TyCtxt<'tcx> {
171171
pub fn all_impls(self, def_id: DefId) -> impl Iterator<Item = DefId> + 'tcx {
172172
let TraitImpls { blanket_impls, non_blanket_impls } = self.trait_impls_of(def_id);
173173

174-
blanket_impls
175-
.into_iter()
176-
.chain(non_blanket_impls.into_iter().map(|(_, v)| v).flatten())
177-
.cloned()
174+
blanket_impls.iter().chain(non_blanket_impls.iter().map(|(_, v)| v).flatten()).cloned()
178175
}
179176
}
180177

src/librustc_mir_build/hair/pattern/check_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl<'tcx> MatchVisitor<'_, 'tcx> {
246246
);
247247
}
248248

249-
adt_defined_here(&mut cx, &mut err, pattern_ty, &witnesses);
249+
adt_defined_here(&cx, &mut err, pattern_ty, &witnesses);
250250
err.note(&format!("the matched value is of type `{}`", pattern_ty));
251251
err.emit();
252252
}

src/librustc_mir_build/hair/pattern/const_to_pat.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
121121
)
122122
}
123123
traits::NonStructuralMatchTy::Dynamic => {
124-
format!("trait objects cannot be used in patterns")
124+
"trait objects cannot be used in patterns".to_string()
125125
}
126126
traits::NonStructuralMatchTy::Param => {
127127
bug!("use of constant whose type is a parameter inside a pattern")

src/librustc_passes/liveness.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
931931
if blk.targeted_by_break {
932932
self.break_ln.insert(blk.hir_id, succ);
933933
}
934-
let succ = self.propagate_through_opt_expr(blk.expr.as_ref().map(|e| &**e), succ);
934+
let succ = self.propagate_through_opt_expr(blk.expr.as_deref(), succ);
935935
blk.stmts.iter().rev().fold(succ, |succ, stmt| self.propagate_through_stmt(stmt, succ))
936936
}
937937

@@ -952,7 +952,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
952952
// initialization, which is mildly more complex than checking
953953
// once at the func header but otherwise equivalent.
954954

955-
let succ = self.propagate_through_opt_expr(local.init.as_ref().map(|e| &**e), succ);
955+
let succ = self.propagate_through_opt_expr(local.init.as_deref(), succ);
956956
self.define_bindings_in_pat(&local.pat, succ)
957957
}
958958
hir::StmtKind::Item(..) => succ,

src/librustc_passes/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ impl<'tcx> Visitor<'tcx> for RegionResolutionVisitor<'tcx> {
797797
resolve_expr(self, ex);
798798
}
799799
fn visit_local(&mut self, l: &'tcx Local<'tcx>) {
800-
resolve_local(self, Some(&l.pat), l.init.as_ref().map(|e| &**e));
800+
resolve_local(self, Some(&l.pat), l.init.as_deref());
801801
}
802802
}
803803

src/librustc_query_system/dep_graph/dep_node.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<K: DepKind> DepNode<K> {
8080
}
8181
}
8282

83-
return dep_node;
83+
dep_node
8484
}
8585
}
8686

src/librustc_query_system/dep_graph/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ pub trait DepKind: Copy + fmt::Debug + Eq + Ord + Hash {
7777
OP: FnOnce() -> R;
7878

7979
/// Access dependencies from current implicit context.
80-
fn read_deps<OP>(op: OP) -> ()
80+
fn read_deps<OP>(op: OP)
8181
where
82-
OP: for<'a> FnOnce(Option<&'a Lock<TaskDeps<Self>>>) -> ();
82+
OP: for<'a> FnOnce(Option<&'a Lock<TaskDeps<Self>>>);
8383

8484
fn can_reconstruct_query_key(&self) -> bool;
8585
}

src/librustc_trait_selection/traits/chalk_fulfill.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn environment<'tcx>(
3939
let ty::InstantiatedPredicates { predicates, .. } =
4040
tcx.predicates_of(def_id).instantiate_identity(tcx);
4141

42-
let clauses = predicates.into_iter().map(|pred| ChalkEnvironmentClause::Predicate(pred));
42+
let clauses = predicates.into_iter().map(ChalkEnvironmentClause::Predicate);
4343

4444
let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
4545
let node = tcx.hir().get(hir_id);
@@ -224,7 +224,7 @@ impl TraitEngine<'tcx> for FulfillmentContext<'tcx> {
224224
),
225225

226226
Err(_err) => errors.push(FulfillmentError {
227-
obligation: obligation,
227+
obligation,
228228
code: FulfillmentErrorCode::CodeSelectionError(
229229
SelectionError::Unimplemented,
230230
),
@@ -238,7 +238,7 @@ impl TraitEngine<'tcx> for FulfillmentContext<'tcx> {
238238
}
239239

240240
Err(NoSolution) => errors.push(FulfillmentError {
241-
obligation: obligation,
241+
obligation,
242242
code: FulfillmentErrorCode::CodeSelectionError(
243243
SelectionError::Unimplemented,
244244
),
@@ -257,6 +257,6 @@ impl TraitEngine<'tcx> for FulfillmentContext<'tcx> {
257257
}
258258

259259
fn pending_obligations(&self) -> Vec<PredicateObligation<'tcx>> {
260-
self.obligations.iter().map(|obligation| obligation.clone()).collect()
260+
self.obligations.iter().cloned().collect()
261261
}
262262
}

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1863,7 +1863,7 @@ impl NextTypeParamName for &[hir::GenericParam<'_>] {
18631863
fn next_type_param_name(&self, name: Option<&str>) -> String {
18641864
// This is the whitelist of possible parameter names that we might suggest.
18651865
let name = name.and_then(|n| n.chars().next()).map(|c| c.to_string().to_uppercase());
1866-
let name = name.as_ref().map(|s| s.as_str());
1866+
let name = name.as_deref();
18671867
let possible_names = [name.unwrap_or("T"), "T", "U", "V", "X", "Y", "Z", "A", "B", "C"];
18681868
let used_names = self
18691869
.iter()

src/librustc_traits/chalk/db.rs

+34-38
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
5959
// clauses or bounds?
6060
let predicates = self.tcx.predicates_defined_on(def_id).predicates;
6161
let where_clauses: Vec<_> = predicates
62-
.into_iter()
62+
.iter()
6363
.map(|(wc, _)| wc.subst(self.tcx, &bound_vars))
6464
.filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner)).collect();
6565

@@ -88,7 +88,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
8888
let binders = binders_for(&self.interner, bound_vars);
8989
let predicates = self.tcx.predicates_defined_on(def_id).predicates;
9090
let where_clauses: Vec<_> = predicates
91-
.into_iter()
91+
.iter()
9292
.map(|(wc, _)| wc.subst(self.tcx, &bound_vars))
9393
.filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner)).collect();
9494

@@ -134,7 +134,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
134134

135135
let predicates = self.tcx.predicates_of(adt_def_id).predicates;
136136
let where_clauses: Vec<_> = predicates
137-
.into_iter()
137+
.iter()
138138
.map(|(wc, _)| wc.subst(self.tcx, bound_vars))
139139
.filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner))
140140
.collect();
@@ -166,46 +166,42 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
166166
fundamental: adt_def.is_fundamental(),
167167
},
168168
});
169-
return struct_datum;
169+
struct_datum
170170
}
171-
RustDefId::Ref(_) => {
172-
return Arc::new(chalk_rust_ir::StructDatum {
173-
id: struct_id,
174-
binders: chalk_ir::Binders::new(
175-
chalk_ir::ParameterKinds::from(
176-
&self.interner,
177-
vec![
178-
chalk_ir::ParameterKind::Lifetime(()),
179-
chalk_ir::ParameterKind::Ty(()),
180-
],
181-
),
182-
chalk_rust_ir::StructDatumBound { fields: vec![], where_clauses: vec![] },
171+
RustDefId::Ref(_) => Arc::new(chalk_rust_ir::StructDatum {
172+
id: struct_id,
173+
binders: chalk_ir::Binders::new(
174+
chalk_ir::ParameterKinds::from(
175+
&self.interner,
176+
vec![
177+
chalk_ir::ParameterKind::Lifetime(()),
178+
chalk_ir::ParameterKind::Ty(()),
179+
],
183180
),
184-
flags: chalk_rust_ir::StructFlags { upstream: false, fundamental: false },
185-
});
186-
}
187-
RustDefId::Array | RustDefId::Slice => {
188-
return Arc::new(chalk_rust_ir::StructDatum {
189-
id: struct_id,
190-
binders: chalk_ir::Binders::new(
191-
chalk_ir::ParameterKinds::from(
192-
&self.interner,
193-
Some(chalk_ir::ParameterKind::Ty(())),
194-
),
195-
chalk_rust_ir::StructDatumBound { fields: vec![], where_clauses: vec![] },
181+
chalk_rust_ir::StructDatumBound { fields: vec![], where_clauses: vec![] },
182+
),
183+
flags: chalk_rust_ir::StructFlags { upstream: false, fundamental: false },
184+
}),
185+
RustDefId::Array | RustDefId::Slice => Arc::new(chalk_rust_ir::StructDatum {
186+
id: struct_id,
187+
binders: chalk_ir::Binders::new(
188+
chalk_ir::ParameterKinds::from(
189+
&self.interner,
190+
Some(chalk_ir::ParameterKind::Ty(())),
196191
),
197-
flags: chalk_rust_ir::StructFlags { upstream: false, fundamental: false },
198-
});
199-
}
192+
chalk_rust_ir::StructDatumBound { fields: vec![], where_clauses: vec![] },
193+
),
194+
flags: chalk_rust_ir::StructFlags { upstream: false, fundamental: false },
195+
}),
200196
RustDefId::Str | RustDefId::Never | RustDefId::FnDef(_) => {
201-
return Arc::new(chalk_rust_ir::StructDatum {
197+
Arc::new(chalk_rust_ir::StructDatum {
202198
id: struct_id,
203199
binders: chalk_ir::Binders::new(
204200
chalk_ir::ParameterKinds::new(&self.interner),
205201
chalk_rust_ir::StructDatumBound { fields: vec![], where_clauses: vec![] },
206202
),
207203
flags: chalk_rust_ir::StructFlags { upstream: false, fundamental: false },
208-
});
204+
})
209205
}
210206

211207
_ => bug!("Used not struct variant when expecting struct variant."),
@@ -228,7 +224,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
228224

229225
let predicates = self.tcx.predicates_of(def_id).predicates;
230226
let where_clauses: Vec<_> = predicates
231-
.into_iter()
227+
.iter()
232228
.map(|(wc, _)| wc.subst(self.tcx, bound_vars))
233229
.filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner)).collect();
234230

@@ -260,7 +256,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
260256
// not there yet.
261257

262258
let all_impls = self.tcx.all_impls(def_id);
263-
let matched_impls = all_impls.into_iter().filter(|impl_def_id| {
259+
let matched_impls = all_impls.filter(|impl_def_id| {
264260
use chalk_ir::could_match::CouldMatch;
265261
let trait_ref = self.tcx.impl_trait_ref(*impl_def_id).unwrap();
266262
let bound_vars = bound_vars_for_item(self.tcx, *impl_def_id);
@@ -304,7 +300,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
304300
_ => {}
305301
}
306302
}
307-
return false;
303+
false
308304
}
309305

310306
fn associated_ty_value(
@@ -379,7 +375,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
379375
ty::AdtKind::Struct | ty::AdtKind::Union => None,
380376
ty::AdtKind::Enum => {
381377
let constraint = self.tcx.adt_sized_constraint(adt_def_id);
382-
if constraint.0.len() > 0 {
378+
if !constraint.0.is_empty() {
383379
unimplemented!()
384380
} else {
385381
Some(true)
@@ -412,7 +408,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
412408
ty::AdtKind::Struct | ty::AdtKind::Union => None,
413409
ty::AdtKind::Enum => {
414410
let constraint = self.tcx.adt_sized_constraint(adt_def_id);
415-
if constraint.0.len() > 0 {
411+
if !constraint.0.is_empty() {
416412
unimplemented!()
417413
} else {
418414
Some(true)

src/librustc_traits/chalk/lowering.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
274274
let uint = |i| apply(chalk_ir::TypeName::Scalar(chalk_ir::Scalar::Uint(i)), empty());
275275
let float = |f| apply(chalk_ir::TypeName::Scalar(chalk_ir::Scalar::Float(f)), empty());
276276

277-
return match self.kind {
277+
match self.kind {
278278
Bool => apply(chalk_ir::TypeName::Scalar(chalk_ir::Scalar::Bool), empty()),
279279
Char => apply(chalk_ir::TypeName::Scalar(chalk_ir::Scalar::Char), empty()),
280280
Int(ty) => match ty {
@@ -370,7 +370,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
370370
.intern(interner),
371371
Infer(_infer) => unimplemented!(),
372372
Error => unimplemented!(),
373-
};
373+
}
374374
}
375375
}
376376

src/librustdoc/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ impl Options {
447447
None => return Err(3),
448448
};
449449

450-
match matches.opt_str("r").as_ref().map(|s| &**s) {
450+
match matches.opt_str("r").as_deref() {
451451
Some("rust") | None => {}
452452
Some(s) => {
453453
diag.struct_err(&format!("unknown input format: {}", s)).emit();

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<'tcx> DocContext<'tcx> {
129129
);
130130

131131
MAX_DEF_ID.with(|m| {
132-
m.borrow_mut().entry(def_id.krate.clone()).or_insert(start_def_id);
132+
m.borrow_mut().entry(def_id.krate).or_insert(start_def_id);
133133
});
134134

135135
self.all_fake_def_ids.borrow_mut().insert(def_id);

0 commit comments

Comments
 (0)