1
Fork 0

Rollup merge of #94698 - WaffleLapkin:simplify-copy-suggestions, r=estebank

Remove redundant code from copy-suggestions

Follow up to #94375, just remove some code that is not necessary anymore. This may make the perf of such suggestions a little bit worse, but I don't think this is significant.

r? `@estebank`
This commit is contained in:
Dylan DPC 2022-03-17 22:55:03 +01:00 committed by GitHub
commit a8956e6618
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,9 +12,7 @@ use rustc_middle::mir::{
FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef, FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef,
ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm,
}; };
use rustc_middle::ty::{ use rustc_middle::ty::{self, suggest_constraining_type_params, PredicateKind, Ty};
self, suggest_constraining_type_param, suggest_constraining_type_params, PredicateKind, Ty,
};
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex}; use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
use rustc_span::symbol::sym; use rustc_span::symbol::sym;
use rustc_span::{BytePos, MultiSpan, Span}; use rustc_span::{BytePos, MultiSpan, Span};
@ -285,27 +283,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
Some(ref name) => format!("`{}`", name), Some(ref name) => format!("`{}`", name),
None => "value".to_owned(), None => "value".to_owned(),
}; };
if let ty::Param(param_ty) = ty.kind() {
let tcx = self.infcx.tcx;
let generics = tcx.generics_of(self.mir_def_id());
let param = generics.type_param(&param_ty, tcx);
if let Some(generics) = tcx
.typeck_root_def_id(self.mir_def_id().to_def_id())
.as_local()
.and_then(|def_id| tcx.hir().get_generics(def_id))
{
suggest_constraining_type_param(
tcx,
generics,
&mut err,
param.name.as_str(),
"Copy",
None,
);
}
} else {
// Try to find predicates on *generic params* that would allow copying `ty`
// Try to find predicates on *generic params* that would allow copying `ty`
let tcx = self.infcx.tcx; let tcx = self.infcx.tcx;
let generics = tcx.generics_of(self.mir_def_id()); let generics = tcx.generics_of(self.mir_def_id());
if let Some(hir_generics) = tcx if let Some(hir_generics) = tcx
@ -342,10 +321,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
match predicate.self_ty().kind() { match predicate.self_ty().kind() {
ty::Param(param_ty) => Ok(( ty::Param(param_ty) => Ok((
generics.type_param(param_ty, tcx), generics.type_param(param_ty, tcx),
predicate predicate.trait_ref.print_only_trait_path().to_string(),
.trait_ref
.print_only_trait_path()
.to_string(),
)), )),
_ => Err(()), _ => Err(()),
} }
@ -366,7 +342,6 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
); );
} }
} }
}
let span = if let Some(local) = place.as_local() { let span = if let Some(local) = place.as_local() {
let decl = &self.body.local_decls[local]; let decl = &self.body.local_decls[local];