Skip to content

Commit 02b96b3

Browse files
authored
Rollup merge of #69529 - matthiaskrgr:clippy_identity_conversion, r=Mark-Simulacrum
don't use .into() to convert types into identical types. This removes redundant `.into()` calls. example: `let s: String = format!("hello").into();`
2 parents 4c9e44f + 7be94a8 commit 02b96b3

File tree

32 files changed

+42
-62
lines changed

32 files changed

+42
-62
lines changed

src/librustc/mir/interpret/allocation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ impl<'tcx, Tag: Copy, Extra: AllocationExtra<Tag>> Allocation<Tag, Extra> {
472472
val: ScalarMaybeUndef<Tag>,
473473
) -> InterpResult<'tcx> {
474474
let ptr_size = cx.data_layout().pointer_size;
475-
self.write_scalar(cx, ptr.into(), val, ptr_size)
475+
self.write_scalar(cx, ptr, val, ptr_size)
476476
}
477477
}
478478

src/librustc/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1519,7 +1519,7 @@ impl<'tcx> TerminatorKind<'tcx> {
15191519
values
15201520
.iter()
15211521
.map(|&u| {
1522-
ty::Const::from_scalar(tcx, Scalar::from_uint(u, size).into(), switch_ty)
1522+
ty::Const::from_scalar(tcx, Scalar::from_uint(u, size), switch_ty)
15231523
.to_string()
15241524
.into()
15251525
})

src/librustc/mir/tcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ impl<'tcx> Rvalue<'tcx> {
156156
}
157157
Rvalue::AddressOf(mutability, ref place) => {
158158
let place_ty = place.ty(local_decls, tcx).ty;
159-
tcx.mk_ptr(ty::TypeAndMut { ty: place_ty, mutbl: mutability.into() })
159+
tcx.mk_ptr(ty::TypeAndMut { ty: place_ty, mutbl: mutability })
160160
}
161161
Rvalue::Len(..) => tcx.types.usize,
162162
Rvalue::Cast(.., ty) => ty,

src/librustc/traits/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -820,8 +820,7 @@ impl ObjectSafetyViolation {
820820
MethodViolationCode::UndispatchableReceiver,
821821
span,
822822
) => (
823-
format!("consider changing method `{}`'s `self` parameter to be `&self`", name)
824-
.into(),
823+
format!("consider changing method `{}`'s `self` parameter to be `&self`", name),
825824
Some(("&Self".to_string(), span)),
826825
),
827826
ObjectSafetyViolation::AssocConst(name, _)

src/librustc_ast_lowering/expr.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -831,8 +831,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
831831
.last()
832832
.cloned()
833833
.map(|id| Ok(self.lower_node_id(id)))
834-
.unwrap_or(Err(hir::LoopIdError::OutsideLoopScope))
835-
.into(),
834+
.unwrap_or(Err(hir::LoopIdError::OutsideLoopScope)),
836835
};
837836
hir::Destination { label: destination.map(|(_, label)| label), target_id }
838837
}
@@ -841,7 +840,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
841840
if self.is_in_loop_condition && opt_label.is_none() {
842841
hir::Destination {
843842
label: None,
844-
target_id: Err(hir::LoopIdError::UnlabeledCfInWhileCondition).into(),
843+
target_id: Err(hir::LoopIdError::UnlabeledCfInWhileCondition),
845844
}
846845
} else {
847846
self.lower_loop_destination(opt_label.map(|label| (id, label)))
@@ -912,7 +911,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
912911
.collect(),
913912
asm: asm.asm,
914913
asm_str_style: asm.asm_str_style,
915-
clobbers: asm.clobbers.clone().into(),
914+
clobbers: asm.clobbers.clone(),
916915
volatile: asm.volatile,
917916
alignstack: asm.alignstack,
918917
dialect: asm.dialect,

src/librustc_codegen_ssa/mir/operand.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
9292
let a = Scalar::from(Pointer::new(
9393
bx.tcx().alloc_map.lock().create_memory_alloc(data),
9494
Size::from_bytes(start as u64),
95-
))
96-
.into();
95+
));
9796
let a_llval = bx.scalar_to_backend(
9897
a,
9998
a_scalar,

src/librustc_codegen_ssa/mir/rvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
387387

388388
mir::Rvalue::AddressOf(mutability, ref place) => {
389389
let mk_ptr = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| {
390-
tcx.mk_ptr(ty::TypeAndMut { ty, mutbl: mutability.into() })
390+
tcx.mk_ptr(ty::TypeAndMut { ty, mutbl: mutability })
391391
};
392392
self.codegen_place_to_pointer(bx, place, mk_ptr)
393393
}

src/librustc_expand/mbe/quoted.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn parse_tree(
112112
sess.span_diagnostic.span_err(span.entire(), &msg);
113113
}
114114
// Parse the contents of the sequence itself
115-
let sequence = parse(tts.into(), expect_matchers, sess);
115+
let sequence = parse(tts, expect_matchers, sess);
116116
// Get the Kleene operator and optional separator
117117
let (separator, kleene) = parse_sep_and_kleene_op(trees, span.entire(), sess);
118118
// Count the number of captured "names" (i.e., named metavars)
@@ -159,7 +159,7 @@ fn parse_tree(
159159
// descend into the delimited set and further parse it.
160160
tokenstream::TokenTree::Delimited(span, delim, tts) => TokenTree::Delimited(
161161
span,
162-
Lrc::new(Delimited { delim, tts: parse(tts.into(), expect_matchers, sess) }),
162+
Lrc::new(Delimited { delim, tts: parse(tts, expect_matchers, sess) }),
163163
),
164164
}
165165
}

src/librustc_expand/mbe/transcribe.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ pub(super) fn transcribe(
155155
}
156156

157157
// Step back into the parent Delimited.
158-
let tree =
159-
TokenTree::Delimited(span, forest.delim, TokenStream::new(result).into());
158+
let tree = TokenTree::Delimited(span, forest.delim, TokenStream::new(result));
160159
result = result_stack.pop().unwrap();
161160
result.push(tree.into());
162161
}

src/librustc_expand/proc_macro_server.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
6060
let Token { kind, span } = match tree {
6161
tokenstream::TokenTree::Delimited(span, delim, tts) => {
6262
let delimiter = Delimiter::from_internal(delim);
63-
return TokenTree::Group(Group { delimiter, stream: tts.into(), span });
63+
return TokenTree::Group(Group { delimiter, stream: tts, span });
6464
}
6565
tokenstream::TokenTree::Token(token) => token,
6666
};
@@ -196,12 +196,8 @@ impl ToInternal<TokenStream> for TokenTree<Group, Punct, Ident, Literal> {
196196
let (ch, joint, span) = match self {
197197
TokenTree::Punct(Punct { ch, joint, span }) => (ch, joint, span),
198198
TokenTree::Group(Group { delimiter, stream, span }) => {
199-
return tokenstream::TokenTree::Delimited(
200-
span,
201-
delimiter.to_internal(),
202-
stream.into(),
203-
)
204-
.into();
199+
return tokenstream::TokenTree::Delimited(span, delimiter.to_internal(), stream)
200+
.into();
205201
}
206202
TokenTree::Ident(self::Ident { sym, is_raw, span }) => {
207203
return tokenstream::TokenTree::token(Ident(sym, is_raw), span).into();

src/librustc_infer/infer/canonical/canonicalizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
669669
} else {
670670
let var = self.canonical_var(info, const_var.into());
671671
self.tcx().mk_const(ty::Const {
672-
val: ty::ConstKind::Bound(self.binder_index, var.into()),
672+
val: ty::ConstKind::Bound(self.binder_index, var),
673673
ty: self.fold_ty(const_var.ty),
674674
})
675675
}

src/librustc_infer/infer/outlives/verify.rs

-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
140140
// Extend with bounds that we can find from the trait.
141141
let trait_bounds = self
142142
.projection_declared_bounds_from_trait(projection_ty)
143-
.into_iter()
144143
.map(|r| VerifyBound::OutlivedBy(r));
145144

146145
// see the extensive comment in projection_must_outlive

src/librustc_infer/traits/select.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3202,7 +3202,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
32023202
obligation.predicate.def_id(),
32033203
obligation.recursion_depth + 1,
32043204
a_last.expect_ty(),
3205-
&[b_last.into()],
3205+
&[b_last],
32063206
));
32073207
}
32083208

src/librustc_interface/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ impl<'a, 'b> ReplaceBodyWithLoop<'a, 'b> {
639639
ast::GenericArg::Type(ty) => Some(ty),
640640
_ => None,
641641
});
642-
any_involves_impl_trait(types.into_iter())
642+
any_involves_impl_trait(types)
643643
|| data.constraints.iter().any(|c| match c.kind {
644644
ast::AssocTyConstraintKind::Bound { .. } => true,
645645
ast::AssocTyConstraintKind::Equality { ref ty } => {

src/librustc_mir/borrow_check/region_infer/reverse_sccs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl RegionInferenceContext<'_> {
5656
let mut scc_regions = FxHashMap::default();
5757
let mut start = 0;
5858
for (scc, group) in &paired_scc_regions.into_iter().group_by(|(scc, _)| *scc) {
59-
let group_size = group.into_iter().count();
59+
let group_size = group.count();
6060
scc_regions.insert(scc, start..start + group_size);
6161
start += group_size;
6262
}

src/librustc_mir/const_eval/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub(crate) fn const_caller_location<'tcx>(
5252

5353
let loc_place = ecx.alloc_caller_location(file, line, col);
5454
intern_const_alloc_recursive(&mut ecx, InternKind::Constant, loc_place, false).unwrap();
55-
ConstValue::Scalar(loc_place.ptr.into())
55+
ConstValue::Scalar(loc_place.ptr)
5656
}
5757

5858
// this function uses `unwrap` copiously, because an already validated constant

src/librustc_mir/interpret/intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ crate fn eval_nullary_intrinsic<'tcx>(
6767
};
6868
ConstValue::from_machine_usize(n, &tcx)
6969
}
70-
sym::type_id => ConstValue::from_u64(tcx.type_id_hash(tp_ty).into()),
70+
sym::type_id => ConstValue::from_u64(tcx.type_id_hash(tp_ty)),
7171
other => bug!("`{}` is not a zero arg intrinsic", other),
7272
})
7373
}

src/librustc_mir/interpret/terminator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
293293
let (&untuple_arg, args) = args.split_last().unwrap();
294294
trace!("eval_fn_call: Will pass last argument by untupling");
295295
Cow::from(args.iter().map(|&a| Ok(a))
296-
.chain((0..untuple_arg.layout.fields.count()).into_iter()
296+
.chain((0..untuple_arg.layout.fields.count())
297297
.map(|i| self.operand_field(untuple_arg, i as u64))
298298
)
299299
.collect::<InterpResult<'_, Vec<OpTy<'tcx, M::PointerTag>>>>()?)

src/librustc_mir/transform/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs {
209209

210210
// We return the qualifs in the return place for every MIR body, even though it is only used
211211
// when deciding to promote a reference to a `const` for now.
212-
validator.qualifs_in_return_place().into()
212+
validator.qualifs_in_return_place()
213213
}
214214

215215
fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> &Steal<BodyAndCache<'_>> {

src/librustc_mir/util/aggregate.rs

-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ pub fn expand_aggregate<'tcx>(
4949
};
5050

5151
operands
52-
.into_iter()
5352
.enumerate()
5453
.map(move |(i, (op, ty))| {
5554
let lhs_field = if let AggregateKind::Array(_) = kind {

src/librustc_mir_build/build/matches/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1942,8 +1942,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
19421942
let tcx = self.hir.tcx();
19431943
let debug_source_info = SourceInfo { span: source_info.span, scope: visibility_scope };
19441944
let binding_mode = match mode {
1945-
BindingMode::ByValue => ty::BindingMode::BindByValue(mutability.into()),
1946-
BindingMode::ByRef(_) => ty::BindingMode::BindByReference(mutability.into()),
1945+
BindingMode::ByValue => ty::BindingMode::BindByValue(mutability),
1946+
BindingMode::ByRef(_) => ty::BindingMode::BindByReference(mutability),
19471947
};
19481948
debug!("declare_binding: user_ty={:?}", user_ty);
19491949
let local = LocalDecl::<'tcx> {

src/librustc_mir_build/build/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
882882
span: tcx_hir.span(var_id),
883883
},
884884
place: Place {
885-
local: closure_env_arg.into(),
885+
local: closure_env_arg,
886886
projection: tcx.intern_place_elems(&projs),
887887
},
888888
});
@@ -927,7 +927,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
927927
self.local_decls[local].local_info = if let Some(kind) = self_binding {
928928
LocalInfo::User(ClearCrossCrate::Set(BindingForm::ImplicitSelf(*kind)))
929929
} else {
930-
let binding_mode = ty::BindingMode::BindByValue(mutability.into());
930+
let binding_mode = ty::BindingMode::BindByValue(mutability);
931931
LocalInfo::User(ClearCrossCrate::Set(BindingForm::Var(
932932
VarBindingForm {
933933
binding_mode,

src/librustc_parse/lexer/mod.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,7 @@ impl<'a> StringReader<'a> {
327327
match kind {
328328
rustc_lexer::LiteralKind::Char { terminated } => {
329329
if !terminated {
330-
self.fatal_span_(start, suffix_start, "unterminated character literal".into())
331-
.raise()
330+
self.fatal_span_(start, suffix_start, "unterminated character literal").raise()
332331
}
333332
let content_start = start + BytePos(1);
334333
let content_end = suffix_start - BytePos(1);
@@ -338,12 +337,8 @@ impl<'a> StringReader<'a> {
338337
}
339338
rustc_lexer::LiteralKind::Byte { terminated } => {
340339
if !terminated {
341-
self.fatal_span_(
342-
start + BytePos(1),
343-
suffix_start,
344-
"unterminated byte constant".into(),
345-
)
346-
.raise()
340+
self.fatal_span_(start + BytePos(1), suffix_start, "unterminated byte constant")
341+
.raise()
347342
}
348343
let content_start = start + BytePos(2);
349344
let content_end = suffix_start - BytePos(1);
@@ -353,7 +348,7 @@ impl<'a> StringReader<'a> {
353348
}
354349
rustc_lexer::LiteralKind::Str { terminated } => {
355350
if !terminated {
356-
self.fatal_span_(start, suffix_start, "unterminated double quote string".into())
351+
self.fatal_span_(start, suffix_start, "unterminated double quote string")
357352
.raise()
358353
}
359354
let content_start = start + BytePos(1);
@@ -367,7 +362,7 @@ impl<'a> StringReader<'a> {
367362
self.fatal_span_(
368363
start + BytePos(1),
369364
suffix_start,
370-
"unterminated double quote byte string".into(),
365+
"unterminated double quote byte string",
371366
)
372367
.raise()
373368
}

src/librustc_parse/lexer/tokentrees.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl<'a> TokenTreesReader<'a> {
209209
_ => {}
210210
}
211211

212-
Ok(TokenTree::Delimited(delim_span, delim, tts.into()).into())
212+
Ok(TokenTree::Delimited(delim_span, delim, tts).into())
213213
}
214214
token::CloseDelim(delim) => {
215215
// An unexpected closing delimiter (i.e., there is no

src/librustc_parse/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ fn prepend_attrs(
420420
builder.push(tokenstream::TokenTree::Delimited(
421421
delim_span,
422422
token::DelimToken::Bracket,
423-
brackets.build().into(),
423+
brackets.build(),
424424
));
425425
}
426426
builder.push(tokens.clone());

src/librustc_parse/parser/mod.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@ impl TokenCursor {
263263
]
264264
.iter()
265265
.cloned()
266-
.collect::<TokenStream>()
267-
.into(),
266+
.collect::<TokenStream>(),
268267
);
269268

270269
self.stack.push(mem::replace(
@@ -389,7 +388,7 @@ impl<'a> Parser<'a> {
389388
root_module_name: None,
390389
expected_tokens: Vec::new(),
391390
token_cursor: TokenCursor {
392-
frame: TokenCursorFrame::new(DelimSpan::dummy(), token::NoDelim, &tokens.into()),
391+
frame: TokenCursorFrame::new(DelimSpan::dummy(), token::NoDelim, &tokens),
393392
stack: Vec::new(),
394393
},
395394
desugar_doc_comments,
@@ -1006,7 +1005,7 @@ impl<'a> Parser<'a> {
10061005
);
10071006
self.set_token(Token::new(TokenKind::CloseDelim(frame.delim), frame.span.close));
10081007
self.bump();
1009-
TokenTree::Delimited(frame.span, frame.delim, frame.tree_cursor.stream.into())
1008+
TokenTree::Delimited(frame.span, frame.delim, frame.tree_cursor.stream)
10101009
}
10111010
token::CloseDelim(_) | token::Eof => unreachable!(),
10121011
_ => {

src/librustc_parse/parser/stmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ impl<'a> Parser<'a> {
169169
}
170170

171171
fn parse_local_mk(&mut self, lo: Span, attrs: AttrVec) -> PResult<'a, Stmt> {
172-
let local = self.parse_local(attrs.into())?;
172+
let local = self.parse_local(attrs)?;
173173
Ok(self.mk_stmt(lo.to(self.prev_span), StmtKind::Local(local)))
174174
}
175175

src/librustc_passes/loops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ impl<'a, 'hir> Visitor<'hir> for CheckLoopVisitor<'a, 'hir> {
7777
return;
7878
}
7979

80-
let loop_id = match label.target_id.into() {
80+
let loop_id = match label.target_id {
8181
Ok(loop_id) => loop_id,
8282
Err(hir::LoopIdError::OutsideLoopScope) => hir::DUMMY_HIR_ID,
8383
Err(hir::LoopIdError::UnlabeledCfInWhileCondition) => {

src/librustc_traits/generic_types.rs

-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ crate fn fn_ptr(
2424
) -> Ty<'tcx> {
2525
let inputs_and_output = tcx.mk_type_list(
2626
(0..arity_and_output)
27-
.into_iter()
2827
.map(|i| ty::BoundVar::from(i))
2928
// DebruijnIndex(1) because we are going to inject these in a `PolyFnSig`
3029
.map(|var| tcx.mk_ty(ty::Bound(ty::DebruijnIndex::from(1usize), var.into()))),
@@ -37,7 +36,6 @@ crate fn fn_ptr(
3736
crate fn type_list(tcx: TyCtxt<'tcx>, arity: usize) -> SubstsRef<'tcx> {
3837
tcx.mk_substs(
3938
(0..arity)
40-
.into_iter()
4139
.map(|i| ty::BoundVar::from(i))
4240
.map(|var| tcx.mk_ty(ty::Bound(ty::INNERMOST, var.into())))
4341
.map(|ty| GenericArg::from(ty)),

src/librustc_typeck/outlives/implicit_infer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,6 @@ pub fn check_explicit_predicates<'tcx>(
312312

313313
let predicate = outlives_predicate.subst(tcx, substs);
314314
debug!("predicate = {:?}", &predicate);
315-
insert_outlives_predicate(tcx, predicate.0.into(), predicate.1, span, required_predicates);
315+
insert_outlives_predicate(tcx, predicate.0, predicate.1, span, required_predicates);
316316
}
317317
}

src/libstd/sys/unix/process/process_common.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,7 @@ impl CStringArray {
287287

288288
fn construct_envp(env: BTreeMap<OsString, OsString>, saw_nul: &mut bool) -> CStringArray {
289289
let mut result = CStringArray::with_capacity(env.len());
290-
for (k, v) in env {
291-
let mut k: OsString = k.into();
292-
290+
for (mut k, v) in env {
293291
// Reserve additional space for '=' and null terminator
294292
k.reserve_exact(v.len() + 2);
295293
k.push("=");

0 commit comments

Comments
 (0)