Skip to content

Commit 57020e0

Browse files
authored
Rollup merge of #130250 - compiler-errors:useless-conversion, r=jieyouxu
Fix `clippy::useless_conversion` Self-explanatory. Probably the last clippy change I'll actually put up since this is the only other one I've actually seen in the wild.
2 parents 3ba1275 + 6d06429 commit 57020e0

File tree

13 files changed

+20
-28
lines changed

13 files changed

+20
-28
lines changed

compiler/rustc_ast/src/ast.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -3486,7 +3486,7 @@ impl From<ForeignItemKind> for ItemKind {
34863486
fn from(foreign_item_kind: ForeignItemKind) -> ItemKind {
34873487
match foreign_item_kind {
34883488
ForeignItemKind::Static(box static_foreign_item) => {
3489-
ItemKind::Static(Box::new(static_foreign_item.into()))
3489+
ItemKind::Static(Box::new(static_foreign_item))
34903490
}
34913491
ForeignItemKind::Fn(fn_kind) => ItemKind::Fn(fn_kind),
34923492
ForeignItemKind::TyAlias(ty_alias_kind) => ItemKind::TyAlias(ty_alias_kind),
@@ -3500,9 +3500,7 @@ impl TryFrom<ItemKind> for ForeignItemKind {
35003500

35013501
fn try_from(item_kind: ItemKind) -> Result<ForeignItemKind, ItemKind> {
35023502
Ok(match item_kind {
3503-
ItemKind::Static(box static_item) => {
3504-
ForeignItemKind::Static(Box::new(static_item.into()))
3505-
}
3503+
ItemKind::Static(box static_item) => ForeignItemKind::Static(Box::new(static_item)),
35063504
ItemKind::Fn(fn_kind) => ForeignItemKind::Fn(fn_kind),
35073505
ItemKind::TyAlias(ty_alias_kind) => ForeignItemKind::TyAlias(ty_alias_kind),
35083506
ItemKind::MacCall(a) => ForeignItemKind::MacCall(a),

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,7 @@ fn eval_body_using_ecx<'tcx, R: InterpretationResult<'tcx>>(
7575

7676
// This can't use `init_stack_frame` since `body` is not a function,
7777
// so computing its ABI would fail. It's also not worth it since there are no arguments to pass.
78-
ecx.push_stack_frame_raw(
79-
cid.instance,
80-
body,
81-
&ret.clone().into(),
82-
StackPopCleanup::Root { cleanup: false },
83-
)?;
78+
ecx.push_stack_frame_raw(cid.instance, body, &ret, StackPopCleanup::Root { cleanup: false })?;
8479
ecx.storage_live_for_always_live_locals()?;
8580

8681
// The main interpreter loop.

compiler/rustc_const_eval/src/interpret/call.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
823823
(Abi::Rust, fn_abi),
824824
&[FnArg::Copy(arg.into())],
825825
false,
826-
&ret.into(),
826+
&ret,
827827
Some(target),
828828
unwind,
829829
)

compiler/rustc_errors/src/diagnostic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -681,10 +681,10 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
681681
" ".repeat(expected_padding),
682682
expected_label
683683
))];
684-
msg.extend(expected.0.into_iter());
684+
msg.extend(expected.0);
685685
msg.push(StringPart::normal(format!("`{expected_extra}\n")));
686686
msg.push(StringPart::normal(format!("{}{} `", " ".repeat(found_padding), found_label)));
687-
msg.extend(found.0.into_iter());
687+
msg.extend(found.0);
688688
msg.push(StringPart::normal(format!("`{found_extra}")));
689689

690690
// For now, just attach these as notes.

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1602,7 +1602,7 @@ fn check_fn_or_method<'tcx>(
16021602
function: def_id,
16031603
// Note that the `param_idx` of the output type is
16041604
// one greater than the index of the last input type.
1605-
param_idx: idx.try_into().unwrap(),
1605+
param_idx: idx,
16061606
}),
16071607
ty,
16081608
)
@@ -1611,7 +1611,7 @@ fn check_fn_or_method<'tcx>(
16111611
for (idx, ty) in sig.inputs_and_output.iter().enumerate() {
16121612
wfcx.register_wf_obligation(
16131613
arg_span(idx),
1614-
Some(WellFormedLoc::Param { function: def_id, param_idx: idx.try_into().unwrap() }),
1614+
Some(WellFormedLoc::Param { function: def_id, param_idx: idx }),
16151615
ty.into(),
16161616
);
16171617
}

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2565,7 +2565,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25652565
other_generic_param.name.ident() == generic_param.name.ident()
25662566
},
25672567
) {
2568-
idxs_matched.push(other_idx.into());
2568+
idxs_matched.push(other_idx);
25692569
}
25702570

25712571
if idxs_matched.is_empty() {

compiler/rustc_middle/src/ty/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ impl<'tcx> Const<'tcx> {
396396
Ok((tcx.type_of(unevaluated.def).instantiate(tcx, unevaluated.args), c))
397397
}
398398
Ok(Err(bad_ty)) => Err(Either::Left(bad_ty)),
399-
Err(err) => Err(Either::Right(err.into())),
399+
Err(err) => Err(Either::Right(err)),
400400
}
401401
}
402402
ConstKind::Value(ty, val) => Ok((ty, val)),

compiler/rustc_middle/src/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
15261526

15271527
let precedence = |binop: rustc_middle::mir::BinOp| {
15281528
use rustc_ast::util::parser::AssocOp;
1529-
AssocOp::from_ast_binop(binop.to_hir_binop().into()).precedence()
1529+
AssocOp::from_ast_binop(binop.to_hir_binop()).precedence()
15301530
};
15311531
let op_precedence = precedence(op);
15321532
let formatted_op = op.to_hir_binop().as_str();

compiler/rustc_next_trait_solver/src/solve/trait_goals.rs

-1
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,6 @@ where
883883
.into_iter()
884884
.chain(a_data.principal_def_id().into_iter().flat_map(|principal_def_id| {
885885
elaborate::supertrait_def_ids(self.cx(), principal_def_id)
886-
.into_iter()
887886
.filter(|def_id| self.cx().trait_is_auto(*def_id))
888887
}))
889888
.collect();

compiler/rustc_parse/src/parser/attr_wrapper.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ impl<'a> Parser<'a> {
383383
self.capture_state
384384
.parser_replacements
385385
.drain(parser_replacements_start..parser_replacements_end)
386-
.chain(inner_attr_parser_replacements.into_iter())
386+
.chain(inner_attr_parser_replacements)
387387
.map(|(parser_range, data)| {
388388
(NodeRange::new(parser_range, collect_pos.start_pos), data)
389389
})

compiler/rustc_parse/src/parser/item.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ impl<'a> Parser<'a> {
15881588
(thin_vec![], Recovered::Yes(guar))
15891589
}
15901590
};
1591-
VariantData::Struct { fields, recovered: recovered.into() }
1591+
VariantData::Struct { fields, recovered }
15921592
} else if this.check(&token::OpenDelim(Delimiter::Parenthesis)) {
15931593
let body = match this.parse_tuple_struct_body() {
15941594
Ok(body) => body,
@@ -1672,7 +1672,7 @@ impl<'a> Parser<'a> {
16721672
class_name.span,
16731673
generics.where_clause.has_where_token,
16741674
)?;
1675-
VariantData::Struct { fields, recovered: recovered.into() }
1675+
VariantData::Struct { fields, recovered }
16761676
}
16771677
// No `where` so: `struct Foo<T>;`
16781678
} else if self.eat(&token::Semi) {
@@ -1684,7 +1684,7 @@ impl<'a> Parser<'a> {
16841684
class_name.span,
16851685
generics.where_clause.has_where_token,
16861686
)?;
1687-
VariantData::Struct { fields, recovered: recovered.into() }
1687+
VariantData::Struct { fields, recovered }
16881688
// Tuple-style struct definition with optional where-clause.
16891689
} else if self.token == token::OpenDelim(Delimiter::Parenthesis) {
16901690
let body = VariantData::Tuple(self.parse_tuple_struct_body()?, DUMMY_NODE_ID);
@@ -1713,14 +1713,14 @@ impl<'a> Parser<'a> {
17131713
class_name.span,
17141714
generics.where_clause.has_where_token,
17151715
)?;
1716-
VariantData::Struct { fields, recovered: recovered.into() }
1716+
VariantData::Struct { fields, recovered }
17171717
} else if self.token == token::OpenDelim(Delimiter::Brace) {
17181718
let (fields, recovered) = self.parse_record_struct_body(
17191719
"union",
17201720
class_name.span,
17211721
generics.where_clause.has_where_token,
17221722
)?;
1723-
VariantData::Struct { fields, recovered: recovered.into() }
1723+
VariantData::Struct { fields, recovered }
17241724
} else {
17251725
let token_str = super::token_descr(&self.token);
17261726
let msg = format!("expected `where` or `{{` after union name, found {token_str}");

compiler/rustc_symbol_mangling/src/v0.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ impl<'tcx> Printer<'tcx> for SymbolMangler<'tcx> {
381381
let consts = [
382382
start.unwrap_or(self.tcx.consts.unit),
383383
end.unwrap_or(self.tcx.consts.unit),
384-
ty::Const::from_bool(self.tcx, include_end).into(),
384+
ty::Const::from_bool(self.tcx, include_end),
385385
];
386386
// HACK: Represent as tuple until we have something better.
387387
// HACK: constants are used in arrays, even if the types don't match.

compiler/rustc_trait_selection/src/traits/project.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ pub(super) fn opt_normalize_projection_term<'a, 'b, 'tcx>(
408408
debug!("opt_normalize_projection_type: found error");
409409
let result = normalize_to_error(selcx, param_env, projection_term, cause, depth);
410410
obligations.extend(result.obligations);
411-
return Ok(Some(result.value.into()));
411+
return Ok(Some(result.value));
412412
}
413413
}
414414

@@ -478,7 +478,7 @@ pub(super) fn opt_normalize_projection_term<'a, 'b, 'tcx>(
478478
}
479479
let result = normalize_to_error(selcx, param_env, projection_term, cause, depth);
480480
obligations.extend(result.obligations);
481-
Ok(Some(result.value.into()))
481+
Ok(Some(result.value))
482482
}
483483
}
484484
}

0 commit comments

Comments
 (0)