Skip to content

Commit 97921ab

Browse files
authored
Rollup merge of rust-lang#110124 - Nilstrieb:📎-told-me-so, r=compiler-errors
Some clippy fixes in the compiler Best reviewed commit-by-commit 📎.
2 parents 6f2fd3e + 9fc1555 commit 97921ab

File tree

54 files changed

+141
-139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+141
-139
lines changed

compiler/rustc_abi/src/lib.rs

+1-1
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_arena/src/lib.rs

+9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#![feature(strict_provenance)]
2323
#![deny(rustc::untranslatable_diagnostic)]
2424
#![deny(rustc::diagnostic_outside_of_impl)]
25+
#![allow(clippy::mut_from_ref)] // Arena allocators are one of the places where this pattern is fine.
2526

2627
use smallvec::SmallVec;
2728

@@ -568,7 +569,9 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
568569
}
569570

570571
pub trait ArenaAllocatable<'tcx, C = rustc_arena::IsNotCopy>: Sized {
572+
#[allow(clippy::mut_from_ref)]
571573
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self;
574+
#[allow(clippy::mut_from_ref)]
572575
fn allocate_from_iter<'a>(
573576
arena: &'a Arena<'tcx>,
574577
iter: impl ::std::iter::IntoIterator<Item = Self>,
@@ -578,10 +581,12 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
578581
// Any type that impls `Copy` can be arena-allocated in the `DroplessArena`.
579582
impl<'tcx, T: Copy> ArenaAllocatable<'tcx, rustc_arena::IsCopy> for T {
580583
#[inline]
584+
#[allow(clippy::mut_from_ref)]
581585
fn allocate_on<'a>(self, arena: &'a Arena<'tcx>) -> &'a mut Self {
582586
arena.dropless.alloc(self)
583587
}
584588
#[inline]
589+
#[allow(clippy::mut_from_ref)]
585590
fn allocate_from_iter<'a>(
586591
arena: &'a Arena<'tcx>,
587592
iter: impl ::std::iter::IntoIterator<Item = Self>,
@@ -601,6 +606,7 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
601606
}
602607

603608
#[inline]
609+
#[allow(clippy::mut_from_ref)]
604610
fn allocate_from_iter<'a>(
605611
arena: &'a Arena<'tcx>,
606612
iter: impl ::std::iter::IntoIterator<Item = Self>,
@@ -616,19 +622,22 @@ pub macro declare_arena([$($a:tt $name:ident: $ty:ty,)*]) {
616622

617623
impl<'tcx> Arena<'tcx> {
618624
#[inline]
625+
#[allow(clippy::mut_from_ref)]
619626
pub fn alloc<T: ArenaAllocatable<'tcx, C>, C>(&self, value: T) -> &mut T {
620627
value.allocate_on(self)
621628
}
622629

623630
// Any type that impls `Copy` can have slices be arena-allocated in the `DroplessArena`.
624631
#[inline]
632+
#[allow(clippy::mut_from_ref)]
625633
pub fn alloc_slice<T: ::std::marker::Copy>(&self, value: &[T]) -> &mut [T] {
626634
if value.is_empty() {
627635
return &mut [];
628636
}
629637
self.dropless.alloc_slice(value)
630638
}
631639

640+
#[allow(clippy::mut_from_ref)]
632641
pub fn alloc_from_iter<'a, T: ArenaAllocatable<'tcx, C>, C>(
633642
&'a self,
634643
iter: impl ::std::iter::IntoIterator<Item = T>,

compiler/rustc_ast_passes/src/ast_validation.rs

+1-1
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

+5-2
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

+4-2
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
686686
fn bclose_maybe_open(&mut self, span: rustc_span::Span, empty: bool, close_box: bool) {
687687
let has_comment = self.maybe_print_comment(span.hi());
688688
if !empty || has_comment {
689-
self.break_offset_if_not_bol(1, -(INDENT_UNIT as isize));
689+
self.break_offset_if_not_bol(1, -INDENT_UNIT);
690690
}
691691
self.word("}");
692692
if close_box {
@@ -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

+2-8
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

+1-1
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/profiling.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ pub fn print_time_passes_entry(
778778
"rss_start": start_rss,
779779
"rss_end": end_rss,
780780
});
781-
eprintln!("time: {}", json.to_string());
781+
eprintln!("time: {json}");
782782
return;
783783
}
784784
TimePassesFormat::Text => (),

compiler/rustc_data_structures/src/sharded.rs

+1
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ pub fn make_hash<K: Hash + ?Sized>(val: &K) -> u64 {
140140
/// `hash` can be computed with any hasher, so long as that hasher is used
141141
/// consistently for each `Sharded` instance.
142142
#[inline]
143+
#[allow(clippy::modulo_one)]
143144
pub fn get_shard_index_by_hash(hash: u64) -> usize {
144145
let hash_len = mem::size_of::<usize>();
145146
// Ignore the top 7 bits as hashbrown uses these and get the next SHARD_BITS highest bits.

compiler/rustc_data_structures/src/stable_hasher.rs

+2-2
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

+1-1
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

+1-1
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

+2-2
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

+1-1
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

+5-5
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

+1-1
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

+1-1
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

+1-1
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_hir_analysis/src/coherence/inherent_impls_overlap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
302302
.iter()
303303
.flatten()
304304
.map(|r| r.impl_blocks.len() as isize - avg as isize)
305-
.map(|v| v.abs() as usize)
305+
.map(|v| v.unsigned_abs())
306306
.sum::<usize>();
307307
s / connected_regions.len()
308308
},

compiler/rustc_hir_pretty/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ pub fn enum_def_to_string(
242242
impl<'a> State<'a> {
243243
pub fn bclose_maybe_open(&mut self, span: rustc_span::Span, close_box: bool) {
244244
self.maybe_print_comment(span.hi());
245-
self.break_offset_if_not_bol(1, -(INDENT_UNIT as isize));
245+
self.break_offset_if_not_bol(1, -INDENT_UNIT);
246246
self.word("}");
247247
if close_box {
248248
self.end(); // close the outer-box

compiler/rustc_hir_typeck/src/_match.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
538538
// FIXME(rpitit): This will need to be fixed when we move to associated types
539539
assert!(matches!(
540540
*trait_pred.trait_ref.self_ty().kind(),
541-
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
542-
if def_id == rpit_def_id && substs == substs
541+
ty::Alias(_, ty::AliasTy { def_id, substs: alias_substs, .. })
542+
if def_id == rpit_def_id && substs == alias_substs
543543
));
544544
ty::PredicateKind::Clause(ty::Clause::Trait(
545545
trait_pred.with_self_ty(self.tcx, ty),
@@ -548,8 +548,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
548548
ty::PredicateKind::Clause(ty::Clause::Projection(mut proj_pred)) => {
549549
assert!(matches!(
550550
*proj_pred.projection_ty.self_ty().kind(),
551-
ty::Alias(_, ty::AliasTy { def_id, substs, .. })
552-
if def_id == rpit_def_id && substs == substs
551+
ty::Alias(_, ty::AliasTy { def_id, substs: alias_substs, .. })
552+
if def_id == rpit_def_id && substs == alias_substs
553553
));
554554
proj_pred = proj_pred.with_self_ty(self.tcx, ty);
555555
ty::PredicateKind::Clause(ty::Clause::Projection(proj_pred))

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
242242
let Some(arg) = segment
243243
.args()
244244
.args
245-
.iter()
246-
.nth(index) else { return false; };
245+
.get(index) else { return false; };
247246
error.obligation.cause.span = arg
248247
.span()
249248
.find_ancestor_in_same_ctxt(error.obligation.cause.span)

compiler/rustc_hir_typeck/src/generator_interior/drop_ranges/cfg_build.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -526,8 +526,9 @@ impl DropRangesBuilder {
526526
let mut next = <_>::from(0u32);
527527
for value in tracked_values {
528528
for_each_consumable(hir, value, |value| {
529-
if !tracked_value_map.contains_key(&value) {
530-
tracked_value_map.insert(value, next);
529+
if let std::collections::hash_map::Entry::Vacant(e) = tracked_value_map.entry(value)
530+
{
531+
e.insert(next);
531532
next = next + 1;
532533
}
533534
});

compiler/rustc_hir_typeck/src/generator_interior/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@ pub fn resolve_interior<'a, 'tcx>(
313313
// Extract type components to build the witness type.
314314
let type_list = fcx.tcx.mk_type_list_from_iter(type_causes.iter().map(|cause| cause.ty));
315315
let bound_vars = fcx.tcx.mk_bound_variable_kinds(&bound_vars);
316-
let witness =
317-
fcx.tcx.mk_generator_witness(ty::Binder::bind_with_vars(type_list, bound_vars.clone()));
316+
let witness = fcx.tcx.mk_generator_witness(ty::Binder::bind_with_vars(type_list, bound_vars));
318317

319318
drop(typeck_results);
320319
// Store the generator types and spans into the typeck results for this generator.

compiler/rustc_hir_typeck/src/method/probe.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1764,16 +1764,15 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
17641764
fn probe_for_similar_candidate(&mut self) -> Result<Option<ty::AssocItem>, MethodError<'tcx>> {
17651765
debug!("probing for method names similar to {:?}", self.method_name);
17661766

1767-
let steps = self.steps.clone();
17681767
self.probe(|_| {
17691768
let mut pcx = ProbeContext::new(
17701769
self.fcx,
17711770
self.span,
17721771
self.mode,
17731772
self.method_name,
17741773
self.return_type,
1775-
&self.orig_steps_var_values,
1776-
steps,
1774+
self.orig_steps_var_values,
1775+
self.steps,
17771776
self.scope_expr_id,
17781777
);
17791778
pcx.allow_similar_names = true;

compiler/rustc_index/src/bit_set.rs

+1-1
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

0 commit comments

Comments
 (0)