Skip to content

Commit c089a16

Browse files
committed
Fix some unnecessary casts
`x clippy compiler -Aclippy::all -Wclippy::unnecessary_cast --fix` with some manual review to ensure every fix is correct.
1 parent 097261f commit c089a16

File tree

10 files changed

+18
-30
lines changed

10 files changed

+18
-30
lines changed

compiler/rustc_codegen_ssa/src/mir/place.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -474,27 +474,25 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
474474
cg_base.project_index(bx, llindex)
475475
}
476476
mir::ProjectionElem::ConstantIndex { offset, from_end: false, min_length: _ } => {
477-
let lloffset = bx.cx().const_usize(offset as u64);
477+
let lloffset = bx.cx().const_usize(offset);
478478
cg_base.project_index(bx, lloffset)
479479
}
480480
mir::ProjectionElem::ConstantIndex { offset, from_end: true, min_length: _ } => {
481-
let lloffset = bx.cx().const_usize(offset as u64);
481+
let lloffset = bx.cx().const_usize(offset);
482482
let lllen = cg_base.len(bx.cx());
483483
let llindex = bx.sub(lllen, lloffset);
484484
cg_base.project_index(bx, llindex)
485485
}
486486
mir::ProjectionElem::Subslice { from, to, from_end } => {
487-
let mut subslice = cg_base.project_index(bx, bx.cx().const_usize(from as u64));
487+
let mut subslice = cg_base.project_index(bx, bx.cx().const_usize(from));
488488
let projected_ty =
489489
PlaceTy::from_ty(cg_base.layout.ty).projection_ty(tcx, *elem).ty;
490490
subslice.layout = bx.cx().layout_of(self.monomorphize(projected_ty));
491491

492492
if subslice.layout.is_unsized() {
493493
assert!(from_end, "slice subslices should be `from_end`");
494-
subslice.llextra = Some(bx.sub(
495-
cg_base.llextra.unwrap(),
496-
bx.cx().const_usize((from as u64) + (to as u64)),
497-
));
494+
subslice.llextra =
495+
Some(bx.sub(cg_base.llextra.unwrap(), bx.cx().const_usize(from + to)));
498496
}
499497

500498
subslice

compiler/rustc_const_eval/src/const_eval/machine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
485485
};
486486

487487
let ptr = ecx.allocate_ptr(
488-
Size::from_bytes(size as u64),
488+
Size::from_bytes(size),
489489
align,
490490
interpret::MemoryKind::Machine(MemoryKind::Heap),
491491
)?;

compiler/rustc_hir_typeck/src/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18611861
// method yet. So create fresh variables here for those too,
18621862
// if there are any.
18631863
let generics = self.tcx.generics_of(method);
1864-
assert_eq!(args.len(), generics.parent_count as usize);
1864+
assert_eq!(args.len(), generics.parent_count);
18651865

18661866
let xform_fn_sig = if generics.params.is_empty() {
18671867
fn_sig.instantiate(self.tcx, args)

compiler/rustc_infer/src/infer/fudge.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for InferenceFudger<'a, 'tcx> {
187187
if self.type_vars.0.contains(&vid) {
188188
// This variable was created during the fudging.
189189
// Recreate it with a fresh variable here.
190-
let idx = (vid.as_usize() - self.type_vars.0.start.as_usize()) as usize;
190+
let idx = vid.as_usize() - self.type_vars.0.start.as_usize();
191191
let origin = self.type_vars.1[idx];
192192
self.infcx.next_ty_var(origin)
193193
} else {
@@ -236,7 +236,7 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for InferenceFudger<'a, 'tcx> {
236236
if self.const_vars.0.contains(&vid) {
237237
// This variable was created during the fudging.
238238
// Recreate it with a fresh variable here.
239-
let idx = (vid.index() - self.const_vars.0.start.index()) as usize;
239+
let idx = vid.index() - self.const_vars.0.start.index();
240240
let origin = self.const_vars.1[idx];
241241
self.infcx.next_const_var(ct.ty(), origin)
242242
} else {

compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -681,17 +681,13 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
681681
for constraint in self.data.constraints.keys() {
682682
match *constraint {
683683
Constraint::VarSubVar(a_id, b_id) => {
684-
graph.add_edge(
685-
NodeIndex(a_id.index() as usize),
686-
NodeIndex(b_id.index() as usize),
687-
*constraint,
688-
);
684+
graph.add_edge(NodeIndex(a_id.index()), NodeIndex(b_id.index()), *constraint);
689685
}
690686
Constraint::RegSubVar(_, b_id) => {
691-
graph.add_edge(dummy_source, NodeIndex(b_id.index() as usize), *constraint);
687+
graph.add_edge(dummy_source, NodeIndex(b_id.index()), *constraint);
692688
}
693689
Constraint::VarSubReg(a_id, _) => {
694-
graph.add_edge(NodeIndex(a_id.index() as usize), dummy_sink, *constraint);
690+
graph.add_edge(NodeIndex(a_id.index()), dummy_sink, *constraint);
695691
}
696692
Constraint::RegSubReg(..) => {
697693
// this would be an edge from `dummy_source` to
@@ -878,7 +874,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
878874
) {
879875
debug!("process_edges(source_vid={:?}, dir={:?})", source_vid, dir);
880876

881-
let source_node_index = NodeIndex(source_vid.index() as usize);
877+
let source_node_index = NodeIndex(source_vid.index());
882878
for (_, edge) in graph.adjacent_edges(source_node_index, dir) {
883879
match edge.data {
884880
Constraint::VarSubVar(from_vid, to_vid) => {

compiler/rustc_infer/src/infer/region_constraints/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl<'tcx> RegionConstraintStorage<'tcx> {
316316
match undo_entry {
317317
AddVar(vid) => {
318318
self.var_infos.pop().unwrap();
319-
assert_eq!(self.var_infos.len(), vid.index() as usize);
319+
assert_eq!(self.var_infos.len(), vid.index());
320320
}
321321
AddConstraint(ref constraint) => {
322322
self.data.constraints.remove(constraint);

compiler/rustc_metadata/src/rmeta/encoder.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -2269,11 +2269,7 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>, path: &Path) {
22692269
file.seek(std::io::SeekFrom::Start(pos_before_seek)).unwrap();
22702270

22712271
// Record metadata size for self-profiling
2272-
tcx.prof.artifact_size(
2273-
"crate_metadata",
2274-
"crate_metadata",
2275-
file.metadata().unwrap().len() as u64,
2276-
);
2272+
tcx.prof.artifact_size("crate_metadata", "crate_metadata", file.metadata().unwrap().len());
22772273
}
22782274

22792275
pub fn provide(providers: &mut Providers) {

compiler/rustc_metadata/src/rmeta/table.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ impl<I: Idx, const N: usize, T: FixedSizeEncoding<ByteArray = [u8; N]>> TableBui
497497
}
498498

499499
LazyTable::from_position_and_encoded_size(
500-
NonZeroUsize::new(pos as usize).unwrap(),
500+
NonZeroUsize::new(pos).unwrap(),
501501
width,
502502
self.blocks.len(),
503503
)

compiler/rustc_middle/src/mir/tcx.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ impl<'tcx> PlaceTy<'tcx> {
9595
ProjectionElem::Subslice { from, to, from_end } => {
9696
PlaceTy::from_ty(match self.ty.kind() {
9797
ty::Slice(..) => self.ty,
98-
ty::Array(inner, _) if !from_end => {
99-
Ty::new_array(tcx, *inner, (to - from) as u64)
100-
}
98+
ty::Array(inner, _) if !from_end => Ty::new_array(tcx, *inner, to - from),
10199
ty::Array(inner, size) if from_end => {
102100
let size = size.eval_target_usize(tcx, param_env);
103101
let len = size - from - to;

compiler/rustc_symbol_mangling/src/v0.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ impl<'tcx> SymbolMangler<'tcx> {
189189
self.push("N");
190190
self.out.push(ns);
191191
print_prefix(self)?;
192-
self.push_disambiguator(disambiguator as u64);
192+
self.push_disambiguator(disambiguator);
193193
self.push_ident(name);
194194
Ok(())
195195
}

0 commit comments

Comments
 (0)