Skip to content

Commit 97921ab

Browse files
authored
Rollup merge of #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

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

Lines changed: 9 additions & 0 deletions
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

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: 4 additions & 2 deletions
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

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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

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
}

0 commit comments

Comments
 (0)