Skip to content

Commit 81c320e

Browse files
committed
Fix some clippy::complexity
1 parent 6fceb0f commit 81c320e

File tree

28 files changed

+62
-63
lines changed

28 files changed

+62
-63
lines changed

compiler/rustc_abi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ impl FieldsShape {
11761176

11771177
/// Gets source indices of the fields by increasing offsets.
11781178
#[inline]
1179-
pub fn index_by_increasing_offset<'a>(&'a self) -> impl Iterator<Item = usize> + 'a {
1179+
pub fn index_by_increasing_offset(&self) -> impl Iterator<Item = usize> + '_ {
11801180
let mut inverse_small = [0u8; 64];
11811181
let mut inverse_big = IndexVec::new();
11821182
let use_small = self.count() <= inverse_small.len();

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ fn validate_generic_param_order(
691691
GenericParamKind::Lifetime => (),
692692
GenericParamKind::Const { ty: _, kw_span: _, default: Some(default) } => {
693693
ordered_params += " = ";
694-
ordered_params += &pprust::expr_to_string(&*default.value);
694+
ordered_params += &pprust::expr_to_string(&default.value);
695695
}
696696
GenericParamKind::Const { ty: _, kw_span: _, default: None } => (),
697697
}

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,11 +404,14 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
404404
);
405405
} else {
406406
// And if it isn't, cancel the early-pass warning.
407-
self.sess
407+
if let Some(err) = self
408+
.sess
408409
.parse_sess
409410
.span_diagnostic
410411
.steal_diagnostic(e.span, StashKey::EarlySyntaxWarning)
411-
.map(|err| err.cancel());
412+
{
413+
err.cancel()
414+
}
412415
}
413416
}
414417
ast::ExprKind::TryBlock(_) => {

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,9 @@ impl<'a> State<'a> {
988988

989989
pub fn print_assoc_constraint(&mut self, constraint: &ast::AssocConstraint) {
990990
self.print_ident(constraint.ident);
991-
constraint.gen_args.as_ref().map(|args| self.print_generic_args(args, false));
991+
if let Some(args) = constraint.gen_args.as_ref() {
992+
self.print_generic_args(args, false)
993+
}
992994
self.space();
993995
match &constraint.kind {
994996
ast::AssocConstraintKind::Equality { term } => {

compiler/rustc_data_structures/src/graph/implementation/mod.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,11 @@ impl<N: Debug, E: Debug> Graph<N, E> {
206206
AdjacentEdges { graph: self, direction, next: first_edge }
207207
}
208208

209-
pub fn successor_nodes<'a>(
210-
&'a self,
211-
source: NodeIndex,
212-
) -> impl Iterator<Item = NodeIndex> + 'a {
209+
pub fn successor_nodes(&self, source: NodeIndex) -> impl Iterator<Item = NodeIndex> + '_ {
213210
self.outgoing_edges(source).targets()
214211
}
215212

216-
pub fn predecessor_nodes<'a>(
217-
&'a self,
218-
target: NodeIndex,
219-
) -> impl Iterator<Item = NodeIndex> + 'a {
213+
pub fn predecessor_nodes(&self, target: NodeIndex) -> impl Iterator<Item = NodeIndex> + '_ {
220214
self.incoming_edges(target).sources()
221215
}
222216

compiler/rustc_data_structures/src/memmap.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ impl Deref for Mmap {
4040

4141
impl AsRef<[u8]> for Mmap {
4242
fn as_ref(&self) -> &[u8] {
43-
&*self.0
43+
&self.0
4444
}
4545
}
4646

compiler/rustc_data_structures/src/stable_hasher.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,14 +312,14 @@ impl<CTX> HashStable<CTX> for ::std::num::NonZeroUsize {
312312

313313
impl<CTX> HashStable<CTX> for f32 {
314314
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
315-
let val: u32 = unsafe { ::std::mem::transmute(*self) };
315+
let val: u32 = self.to_bits();
316316
val.hash_stable(ctx, hasher);
317317
}
318318
}
319319

320320
impl<CTX> HashStable<CTX> for f64 {
321321
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
322-
let val: u64 = unsafe { ::std::mem::transmute(*self) };
322+
let val: u64 = self.to_bits();
323323
val.hash_stable(ctx, hasher);
324324
}
325325
}

compiler/rustc_data_structures/src/stack.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const RED_ZONE: usize = 100 * 1024; // 100k
55

66
// Only the first stack that is pushed, grows exponentially (2^n * STACK_PER_RECURSION) from then
77
// on. This flag has performance relevant characteristics. Don't set it too high.
8-
const STACK_PER_RECURSION: usize = 1 * 1024 * 1024; // 1MB
8+
const STACK_PER_RECURSION: usize = 1024 * 1024; // 1MB
99

1010
/// Grows the stack on demand to prevent stack overflow. Call this in strategic locations
1111
/// to "break up" recursive calls. E.g. almost any call to `visit_expr` or equivalent can benefit

compiler/rustc_data_structures/src/sync/vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl<T: Copy> AppendOnlyVec<T> {
8484
}
8585

8686
pub fn iter(&self) -> impl Iterator<Item = T> + '_ {
87-
(0..).map(|i| self.get(i)).take_while(|o| o.is_some()).filter_map(|o| o)
87+
(0..).map(|i| self.get(i)).take_while(|o| o.is_some()).flatten()
8888
}
8989
}
9090

compiler/rustc_data_structures/src/unord.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl<V: Eq + Hash> UnordSet<V> {
224224
}
225225

226226
#[inline]
227-
pub fn items<'a>(&'a self) -> UnordItems<&'a V, impl Iterator<Item = &'a V>> {
227+
pub fn items(&self) -> UnordItems<&V, impl Iterator<Item = &V>> {
228228
UnordItems(self.inner.iter())
229229
}
230230

@@ -415,7 +415,7 @@ impl<K: Eq + Hash, V> UnordMap<K, V> {
415415
}
416416

417417
#[inline]
418-
pub fn items<'a>(&'a self) -> UnordItems<(&'a K, &'a V), impl Iterator<Item = (&'a K, &'a V)>> {
418+
pub fn items(&self) -> UnordItems<(&K, &V), impl Iterator<Item = (&K, &V)>> {
419419
UnordItems(self.inner.iter())
420420
}
421421

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ impl Diagnostic {
956956
// Exact iteration order of diagnostic arguments shouldn't make a difference to output because
957957
// they're only used in interpolation.
958958
#[allow(rustc::potential_query_instability)]
959-
pub fn args<'a>(&'a self) -> impl Iterator<Item = DiagnosticArg<'a, 'static>> {
959+
pub fn args(&self) -> impl Iterator<Item = DiagnosticArg<'_, 'static>> {
960960
self.args.iter()
961961
}
962962

compiler/rustc_errors/src/emitter.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,7 @@ impl EmitterWriter {
14071407
// Account for newlines to align output to its label.
14081408
for (line, text) in normalize_whitespace(&text).lines().enumerate() {
14091409
buffer.append(
1410-
0 + line,
1410+
line,
14111411
&format!(
14121412
"{}{}",
14131413
if line == 0 { String::new() } else { " ".repeat(label_width) },
@@ -1918,7 +1918,7 @@ impl EmitterWriter {
19181918
let last_line = unhighlighted_lines.pop();
19191919
let first_line = unhighlighted_lines.drain(..).next();
19201920

1921-
first_line.map(|(p, l)| {
1921+
if let Some((p, l)) = first_line {
19221922
self.draw_code_line(
19231923
&mut buffer,
19241924
&mut row_num,
@@ -1930,12 +1930,12 @@ impl EmitterWriter {
19301930
&file_lines,
19311931
is_multiline,
19321932
)
1933-
});
1933+
}
19341934

19351935
buffer.puts(row_num, max_line_num_len - 1, "...", Style::LineNumber);
19361936
row_num += 1;
19371937

1938-
last_line.map(|(p, l)| {
1938+
if let Some((p, l)) = last_line {
19391939
self.draw_code_line(
19401940
&mut buffer,
19411941
&mut row_num,
@@ -1947,7 +1947,7 @@ impl EmitterWriter {
19471947
&file_lines,
19481948
is_multiline,
19491949
)
1950-
});
1950+
}
19511951
}
19521952
}
19531953

compiler/rustc_expand/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ impl<'a> StripUnconfigured<'a> {
466466
//
467467
// N.B., this is intentionally not part of the visit_expr() function
468468
// in order for filter_map_expr() to be able to avoid this check
469-
if let Some(attr) = expr.attrs().iter().find(|a| is_cfg(*a)) {
469+
if let Some(attr) = expr.attrs().iter().find(|a| is_cfg(a)) {
470470
self.sess.emit_err(RemoveExprNotSupported { span: attr.span });
471471
}
472472

compiler/rustc_expand/src/mbe/metavar_expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl MetaVarExpr {
4141
};
4242
check_trailing_token(&mut tts, sess)?;
4343
let mut iter = args.trees();
44-
let rslt = match &*ident.as_str() {
44+
let rslt = match ident.as_str() {
4545
"count" => parse_count(&mut iter, sess, ident.span)?,
4646
"ignore" => MetaVarExpr::Ignore(parse_ident(&mut iter, sess, ident.span)?),
4747
"index" => MetaVarExpr::Index(parse_depth(&mut iter, sess, ident.span)?),

compiler/rustc_hir/src/lang_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl LanguageItems {
4949
self.get(it).ok_or_else(|| LangItemError(it))
5050
}
5151

52-
pub fn iter<'a>(&'a self) -> impl Iterator<Item = (LangItem, DefId)> + 'a {
52+
pub fn iter(&self) -> impl Iterator<Item = (LangItem, DefId)> + '_ {
5353
self.items
5454
.iter()
5555
.enumerate()

compiler/rustc_index/src/bit_set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1850,7 +1850,7 @@ impl<R: Idx, C: Idx> SparseBitMatrix<R, C> {
18501850

18511851
/// Iterates through all the columns set to true in a given row of
18521852
/// the matrix.
1853-
pub fn iter<'a>(&'a self, row: R) -> impl Iterator<Item = C> + 'a {
1853+
pub fn iter(&self, row: R) -> impl Iterator<Item = C> + '_ {
18541854
self.row(row).into_iter().flat_map(|r| r.iter())
18551855
}
18561856

compiler/rustc_index/src/vec.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,18 +201,15 @@ impl<I: Idx, T> IndexVec<I, T> {
201201
}
202202

203203
#[inline]
204-
pub fn drain<'a, R: RangeBounds<usize>>(
205-
&'a mut self,
206-
range: R,
207-
) -> impl Iterator<Item = T> + 'a {
204+
pub fn drain<R: RangeBounds<usize>>(&mut self, range: R) -> impl Iterator<Item = T> + '_ {
208205
self.raw.drain(range)
209206
}
210207

211208
#[inline]
212-
pub fn drain_enumerated<'a, R: RangeBounds<usize>>(
213-
&'a mut self,
209+
pub fn drain_enumerated<R: RangeBounds<usize>>(
210+
&mut self,
214211
range: R,
215-
) -> impl Iterator<Item = (I, T)> + 'a {
212+
) -> impl Iterator<Item = (I, T)> + '_ {
216213
let begin = match range.start_bound() {
217214
std::ops::Bound::Included(i) => *i,
218215
std::ops::Bound::Excluded(i) => i.checked_add(1).unwrap(),

compiler/rustc_macros/src/diagnostics/diagnostic_builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ impl DiagnosticDeriveBuilder {
119119
impl<'a> DiagnosticDeriveVariantBuilder<'a> {
120120
/// Generates calls to `code` and similar functions based on the attributes on the type or
121121
/// variant.
122-
pub fn preamble<'s>(&mut self, variant: &VariantInfo<'s>) -> TokenStream {
122+
pub fn preamble(&mut self, variant: &VariantInfo<'_>) -> TokenStream {
123123
let ast = variant.ast();
124124
let attrs = &ast.attrs;
125125
let preamble = attrs.iter().map(|attr| {
@@ -133,7 +133,7 @@ impl<'a> DiagnosticDeriveVariantBuilder<'a> {
133133

134134
/// Generates calls to `span_label` and similar functions based on the attributes on fields or
135135
/// calls to `set_arg` when no attributes are present.
136-
pub fn body<'s>(&mut self, variant: &VariantInfo<'s>) -> TokenStream {
136+
pub fn body(&mut self, variant: &VariantInfo<'_>) -> TokenStream {
137137
let mut body = quote! {};
138138
// Generate `set_arg` calls first..
139139
for binding in variant.bindings().iter().filter(|bi| should_generate_set_arg(bi.ast())) {

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ pub enum LocalInfo<'tcx> {
915915

916916
impl<'tcx> LocalDecl<'tcx> {
917917
pub fn local_info(&self) -> &LocalInfo<'tcx> {
918-
&**self.local_info.as_ref().assert_crate_local()
918+
&self.local_info.as_ref().assert_crate_local()
919919
}
920920

921921
/// Returns `true` only if local is a binding that can itself be

compiler/rustc_middle/src/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ impl ObjectSafetyViolation {
923923
}
924924
}
925925
ObjectSafetyViolation::SupertraitNonLifetimeBinder(_) => {
926-
format!("where clause cannot reference non-lifetime `for<...>` variables").into()
926+
"where clause cannot reference non-lifetime `for<...>` variables".into()
927927
}
928928
ObjectSafetyViolation::Method(name, MethodViolationCode::StaticMethod(_), _) => {
929929
format!("associated function `{}` has no `self` parameter", name).into()

compiler/rustc_middle/src/traits/solve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl<'tcx> std::ops::Deref for ExternalConstraints<'tcx> {
105105
type Target = ExternalConstraintsData<'tcx>;
106106

107107
fn deref(&self) -> &Self::Target {
108-
&*self.0
108+
&self.0
109109
}
110110
}
111111

compiler/rustc_middle/src/ty/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ impl<'tcx> TyCtxt<'tcx> {
924924
crate_name,
925925
// Don't print the whole stable crate id. That's just
926926
// annoying in debug output.
927-
stable_crate_id.to_u64() >> 8 * 6,
927+
stable_crate_id.to_u64() >> (8 * 6),
928928
self.def_path(def_id).to_string_no_crate_verbose()
929929
)
930930
}
@@ -2379,7 +2379,7 @@ impl<'tcx> TyCtxt<'tcx> {
23792379
pub fn in_scope_traits(self, id: HirId) -> Option<&'tcx [TraitCandidate]> {
23802380
let map = self.in_scope_traits_map(id.owner)?;
23812381
let candidates = map.get(&id.local_id)?;
2382-
Some(&*candidates)
2382+
Some(candidates)
23832383
}
23842384

23852385
pub fn named_bound_var(self, id: HirId) -> Option<resolve_bound_vars::ResolvedArg> {

compiler/rustc_parse/src/lexer/unicode_chars.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ const ASCII_ARRAY: &[(&str, &str, Option<token::TokenKind>)] = &[
336336
("\"", "Quotation Mark", None),
337337
];
338338

339-
pub(super) fn check_for_substitution<'a>(
340-
reader: &StringReader<'a>,
339+
pub(super) fn check_for_substitution(
340+
reader: &StringReader<'_>,
341341
pos: BytePos,
342342
ch: char,
343343
count: usize,

compiler/rustc_parse/src/parser/generics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'a> Parser<'a> {
5353
let snapshot = self.create_snapshot_for_diagnostic();
5454
match self.parse_ty() {
5555
Ok(p) => {
56-
if let TyKind::ImplTrait(_, bounds) = &(*p).kind {
56+
if let TyKind::ImplTrait(_, bounds) = &p.kind {
5757
let span = impl_span.to(self.token.span.shrink_to_lo());
5858
let mut err = self.struct_span_err(
5959
span,

compiler/rustc_query_system/src/query/caches.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,9 @@ where
136136
}
137137

138138
fn iter(&self, f: &mut dyn FnMut(&Self::Key, &Self::Value, DepNodeIndex)) {
139-
self.cache.lock().as_ref().map(|value| f(&(), &value.0, value.1));
139+
if let Some(value) = self.cache.lock().as_ref() {
140+
f(&(), &value.0, value.1)
141+
}
140142
}
141143
}
142144

compiler/rustc_session/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
14261426
opt::opt_s(
14271427
"",
14281428
"edition",
1429-
&*EDITION_STRING,
1429+
&EDITION_STRING,
14301430
EDITION_NAME_LIST,
14311431
),
14321432
opt::multi_s(

compiler/rustc_session/src/parse.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ impl SymbolGallery {
8484

8585
/// Construct a diagnostic for a language feature error due to the given `span`.
8686
/// The `feature`'s `Symbol` is the one you used in `active.rs` and `rustc_span::symbols`.
87-
pub fn feature_err<'a>(
88-
sess: &'a ParseSess,
87+
pub fn feature_err(
88+
sess: &ParseSess,
8989
feature: Symbol,
9090
span: impl Into<MultiSpan>,
9191
explain: impl Into<DiagnosticMessage>,
92-
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
92+
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
9393
feature_err_issue(sess, feature, span, GateIssue::Language, explain)
9494
}
9595

@@ -98,20 +98,21 @@ pub fn feature_err<'a>(
9898
/// This variant allows you to control whether it is a library or language feature.
9999
/// Almost always, you want to use this for a language feature. If so, prefer `feature_err`.
100100
#[track_caller]
101-
pub fn feature_err_issue<'a>(
102-
sess: &'a ParseSess,
101+
pub fn feature_err_issue(
102+
sess: &ParseSess,
103103
feature: Symbol,
104104
span: impl Into<MultiSpan>,
105105
issue: GateIssue,
106106
explain: impl Into<DiagnosticMessage>,
107-
) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
107+
) -> DiagnosticBuilder<'_, ErrorGuaranteed> {
108108
let span = span.into();
109109

110110
// Cancel an earlier warning for this same error, if it exists.
111111
if let Some(span) = span.primary_span() {
112-
sess.span_diagnostic
113-
.steal_diagnostic(span, StashKey::EarlySyntaxWarning)
114-
.map(|err| err.cancel());
112+
if let Some(err) = sess.span_diagnostic.steal_diagnostic(span, StashKey::EarlySyntaxWarning)
113+
{
114+
err.cancel()
115+
}
115116
}
116117

117118
let mut err = sess.create_err(FeatureGateError { span, explain: explain.into() });

0 commit comments

Comments
 (0)