Fix clippy::needless_borrow
in the compiler
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
This commit is contained in:
parent
0ff8610964
commit
21a870515b
304 changed files with 1101 additions and 1174 deletions
|
@ -97,7 +97,7 @@ pub(super) trait GoalKind<'tcx>:
|
|||
bug!("expected object type in `consider_object_bound_candidate`");
|
||||
};
|
||||
ecx.add_goals(structural_traits::predicates_for_object_candidate(
|
||||
&ecx,
|
||||
ecx,
|
||||
goal.param_env,
|
||||
goal.predicate.trait_ref(tcx),
|
||||
bounds,
|
||||
|
|
|
@ -50,14 +50,14 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_auto_trait<'tcx>(
|
|||
|
||||
ty::Array(element_ty, _) | ty::Slice(element_ty) => Ok(vec![element_ty]),
|
||||
|
||||
ty::Tuple(ref tys) => {
|
||||
ty::Tuple(tys) => {
|
||||
// (T1, ..., Tn) -- meets any bound that all of T1...Tn meet
|
||||
Ok(tys.iter().collect())
|
||||
}
|
||||
|
||||
ty::Closure(_, ref args) => Ok(vec![args.as_closure().tupled_upvars_ty()]),
|
||||
ty::Closure(_, args) => Ok(vec![args.as_closure().tupled_upvars_ty()]),
|
||||
|
||||
ty::Coroutine(_, ref args, _) => {
|
||||
ty::Coroutine(_, args, _) => {
|
||||
let coroutine_args = args.as_coroutine();
|
||||
Ok(vec![coroutine_args.tupled_upvars_ty(), coroutine_args.witness()])
|
||||
}
|
||||
|
|
|
@ -175,7 +175,7 @@ impl<'a, 'tcx> InspectGoal<'a, 'tcx> {
|
|||
warn!("unexpected root evaluation: {:?}", self.evaluation);
|
||||
return vec![];
|
||||
}
|
||||
inspect::CanonicalGoalEvaluationKind::Evaluation { ref revisions } => {
|
||||
inspect::CanonicalGoalEvaluationKind::Evaluation { revisions } => {
|
||||
if let Some(last) = revisions.last() {
|
||||
last
|
||||
} else {
|
||||
|
|
|
@ -252,7 +252,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
|
|||
fresh_preds.insert(self.clean_pred(infcx, predicate.as_predicate()));
|
||||
}
|
||||
|
||||
let mut select = SelectionContext::new(&infcx);
|
||||
let mut select = SelectionContext::new(infcx);
|
||||
|
||||
let mut already_visited = FxHashSet::default();
|
||||
let mut predicates = VecDeque::new();
|
||||
|
|
|
@ -108,7 +108,7 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
|
|||
param_env: ty::ParamEnv<'tcx>,
|
||||
value: T,
|
||||
) -> T {
|
||||
let infer_ok = self.infcx.at(&cause, param_env).normalize(value);
|
||||
let infer_ok = self.infcx.at(cause, param_env).normalize(value);
|
||||
self.register_infer_ok_obligations(infer_ok)
|
||||
}
|
||||
|
||||
|
@ -204,7 +204,7 @@ impl<'a, 'tcx> ObligationCtxt<'a, 'tcx> {
|
|||
generic_param_scope: LocalDefId,
|
||||
outlives_env: &OutlivesEnvironment<'tcx>,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
let errors = self.infcx.resolve_regions(&outlives_env);
|
||||
let errors = self.infcx.resolve_regions(outlives_env);
|
||||
if errors.is_empty() {
|
||||
Ok(())
|
||||
} else {
|
||||
|
|
|
@ -61,8 +61,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
|||
.params
|
||||
.iter()
|
||||
.map(|arg| {
|
||||
if let hir::Pat { kind: hir::PatKind::Tuple(ref args, _), span, .. } =
|
||||
*arg.pat
|
||||
if let hir::Pat { kind: hir::PatKind::Tuple(args, _), span, .. } = *arg.pat
|
||||
{
|
||||
Some(ArgKind::Tuple(
|
||||
Some(span),
|
||||
|
@ -92,7 +91,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
|||
.inputs
|
||||
.iter()
|
||||
.map(|arg| match arg.kind {
|
||||
hir::TyKind::Tup(ref tys) => ArgKind::Tuple(
|
||||
hir::TyKind::Tup(tys) => ArgKind::Tuple(
|
||||
Some(arg.span),
|
||||
vec![("_".to_owned(), "_".to_owned()); tys.len()],
|
||||
),
|
||||
|
@ -100,7 +99,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
|||
})
|
||||
.collect::<Vec<ArgKind>>(),
|
||||
),
|
||||
Node::Ctor(ref variant_data) => {
|
||||
Node::Ctor(variant_data) => {
|
||||
let span = variant_data.ctor_hir_id().map_or(DUMMY_SP, |id| hir.span(id));
|
||||
(span, None, vec![ArgKind::empty(); variant_data.fields().len()])
|
||||
}
|
||||
|
|
|
@ -482,7 +482,7 @@ impl<'tcx> OnUnimplementedDirective {
|
|||
match Self::parse(
|
||||
tcx,
|
||||
item_def_id,
|
||||
&items,
|
||||
items,
|
||||
item.span(),
|
||||
false,
|
||||
is_diagnostic_namespace_variant,
|
||||
|
@ -875,7 +875,7 @@ impl<'tcx> OnUnimplementedFormatString {
|
|||
// don't break messages using these two arguments incorrectly
|
||||
&empty_string
|
||||
} else if s == sym::ItemContext {
|
||||
&item_context
|
||||
item_context
|
||||
} else if s == sym::integral {
|
||||
"{integral}"
|
||||
} else if s == sym::integer_ {
|
||||
|
|
|
@ -99,7 +99,7 @@ impl<'tcx, 'a> CoroutineData<'tcx, 'a> {
|
|||
.awaits
|
||||
.into_iter()
|
||||
.map(|id| hir.expect_expr(id))
|
||||
.find(|await_expr| ty_matches(ty::Binder::dummy(self.0.expr_ty_adjusted(&await_expr))))
|
||||
.find(|await_expr| ty_matches(ty::Binder::dummy(self.0.expr_ty_adjusted(await_expr))))
|
||||
.map(|expr| expr.span)
|
||||
}
|
||||
}
|
||||
|
@ -501,7 +501,7 @@ pub fn suggest_restriction<'tcx>(
|
|||
impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
||||
fn suggest_restricting_param_bound(
|
||||
&self,
|
||||
mut err: &mut Diagnostic,
|
||||
err: &mut Diagnostic,
|
||||
trait_pred: ty::PolyTraitPredicate<'tcx>,
|
||||
associated_ty: Option<(&'static str, Ty<'tcx>)>,
|
||||
mut body_id: LocalDefId,
|
||||
|
@ -533,7 +533,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
suggest_restriction(
|
||||
self.tcx,
|
||||
body_id,
|
||||
&generics,
|
||||
generics,
|
||||
"`Self`",
|
||||
err,
|
||||
None,
|
||||
|
@ -552,7 +552,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
assert!(param_ty);
|
||||
// Restricting `Self` for a single method.
|
||||
suggest_restriction(
|
||||
self.tcx, body_id, &generics, "`Self`", err, None, projection, trait_pred,
|
||||
self.tcx, body_id, generics, "`Self`", err, None, projection, trait_pred,
|
||||
None,
|
||||
);
|
||||
return;
|
||||
|
@ -575,7 +575,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
suggest_restriction(
|
||||
self.tcx,
|
||||
body_id,
|
||||
&generics,
|
||||
generics,
|
||||
"the associated type",
|
||||
err,
|
||||
Some(fn_sig),
|
||||
|
@ -595,7 +595,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
suggest_restriction(
|
||||
self.tcx,
|
||||
body_id,
|
||||
&generics,
|
||||
generics,
|
||||
"the associated type",
|
||||
err,
|
||||
None,
|
||||
|
@ -662,7 +662,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
if suggest_constraining_type_param(
|
||||
self.tcx,
|
||||
generics,
|
||||
&mut err,
|
||||
err,
|
||||
¶m_name,
|
||||
&constraint,
|
||||
Some(trait_pred.def_id()),
|
||||
|
@ -690,7 +690,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
if suggest_arbitrary_trait_bound(
|
||||
self.tcx,
|
||||
generics,
|
||||
&mut err,
|
||||
err,
|
||||
trait_pred,
|
||||
associated_ty,
|
||||
) {
|
||||
|
@ -1273,7 +1273,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
let code = if let ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } =
|
||||
obligation.cause.code()
|
||||
{
|
||||
&parent_code
|
||||
parent_code
|
||||
} else if let ObligationCauseCode::ItemObligation(_)
|
||||
| ObligationCauseCode::ExprItemObligation(..) = obligation.cause.code()
|
||||
{
|
||||
|
@ -1867,7 +1867,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
let body = self.tcx.hir().body(self.tcx.hir().body_owned_by(obligation.cause.body_id));
|
||||
|
||||
let mut visitor = ReturnsVisitor::default();
|
||||
visitor.visit_body(&body);
|
||||
visitor.visit_body(body);
|
||||
|
||||
let mut sugg =
|
||||
vec![(span.shrink_to_lo(), "Box<".to_string()), (span.shrink_to_hi(), ">".to_string())];
|
||||
|
@ -1922,7 +1922,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
let body = hir.body(*body_id);
|
||||
// Point at all the `return`s in the function as they have failed trait bounds.
|
||||
let mut visitor = ReturnsVisitor::default();
|
||||
visitor.visit_body(&body);
|
||||
visitor.visit_body(body);
|
||||
let typeck_results = self.typeck_results.as_ref().unwrap();
|
||||
for expr in &visitor.returns {
|
||||
if let Some(returned_ty) = typeck_results.node_type_opt(expr.hir_id) {
|
||||
|
@ -2300,7 +2300,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
// cycles. If we can't use resolved types because the coroutine comes from another crate,
|
||||
// we still provide a targeted error but without all the relevant spans.
|
||||
let coroutine_data = match &self.typeck_results {
|
||||
Some(t) if t.hir_owner.to_def_id() == coroutine_did_root => CoroutineData(&t),
|
||||
Some(t) if t.hir_owner.to_def_id() == coroutine_did_root => CoroutineData(t),
|
||||
_ if coroutine_did.is_local() => {
|
||||
CoroutineData(self.tcx.typeck(coroutine_did.expect_local()))
|
||||
}
|
||||
|
@ -2344,7 +2344,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
|
||||
if interior_or_upvar_span.is_none() {
|
||||
interior_or_upvar_span =
|
||||
coroutine_data.try_get_upvar_span(&self, coroutine_did, ty_matches);
|
||||
coroutine_data.try_get_upvar_span(self, coroutine_did, ty_matches);
|
||||
}
|
||||
|
||||
if interior_or_upvar_span.is_none() && !coroutine_did.is_local() {
|
||||
|
@ -2517,7 +2517,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
CoroutineInteriorOrUpvar::Upvar(upvar_span) => {
|
||||
// `Some((ref_ty, is_mut))` if `target_ty` is `&T` or `&mut T` and fails to impl `Send`
|
||||
let non_send = match target_ty.kind() {
|
||||
ty::Ref(_, ref_ty, mutability) => match self.evaluate_obligation(&obligation) {
|
||||
ty::Ref(_, ref_ty, mutability) => match self.evaluate_obligation(obligation) {
|
||||
Ok(eval) if !eval.may_apply() => Some((ref_ty, mutability.is_mut())),
|
||||
_ => None,
|
||||
},
|
||||
|
@ -3305,7 +3305,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
err,
|
||||
predicate,
|
||||
param_env,
|
||||
&parent_code,
|
||||
parent_code,
|
||||
obligated_types,
|
||||
seen_requirements,
|
||||
)
|
||||
|
@ -3660,9 +3660,9 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
// If the expression we're calling on is a binding, we want to point at the
|
||||
// `let` when talking about the type. Otherwise we'll point at every part
|
||||
// of the method chain with the type.
|
||||
self.point_at_chain(binding_expr, &typeck_results, type_diffs, param_env, err);
|
||||
self.point_at_chain(binding_expr, typeck_results, type_diffs, param_env, err);
|
||||
} else {
|
||||
self.point_at_chain(expr, &typeck_results, type_diffs, param_env, err);
|
||||
self.point_at_chain(expr, typeck_results, type_diffs, param_env, err);
|
||||
}
|
||||
}
|
||||
let call_node = hir.find(call_hir_id);
|
||||
|
@ -3856,7 +3856,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
suggest_restriction(
|
||||
tcx,
|
||||
hir.body_owner_def_id(body_id),
|
||||
&generics,
|
||||
generics,
|
||||
&format!("type parameter `{ty}`"),
|
||||
err,
|
||||
node.fn_sig(),
|
||||
|
|
|
@ -511,7 +511,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
|
||||
if Some(trait_ref.def_id()) == tcx.lang_items().tuple_trait() {
|
||||
self.add_tuple_trait_message(
|
||||
&obligation.cause.code().peel_derives(),
|
||||
obligation.cause.code().peel_derives(),
|
||||
&mut err,
|
||||
);
|
||||
}
|
||||
|
@ -569,7 +569,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
if Some(trait_ref.def_id()) == self.tcx.lang_items().sized_trait() {
|
||||
self.suggest_borrowing_for_object_cast(
|
||||
&mut err,
|
||||
&root_obligation,
|
||||
root_obligation,
|
||||
source,
|
||||
target,
|
||||
);
|
||||
|
@ -1965,7 +1965,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
ObligationCauseCode::FunctionArgumentObligation { parent_code, .. } => {
|
||||
self.get_parent_trait_ref(&parent_code)
|
||||
self.get_parent_trait_ref(parent_code)
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
|
@ -2180,7 +2180,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
self.tcx.hir().maybe_body_owned_by(obligation.cause.body_id)
|
||||
{
|
||||
let mut expr_finder = FindExprBySpan::new(span);
|
||||
expr_finder.visit_expr(&self.tcx.hir().body(body_id).value);
|
||||
expr_finder.visit_expr(self.tcx.hir().body(body_id).value);
|
||||
|
||||
if let Some(hir::Expr {
|
||||
kind: hir::ExprKind::Path(hir::QPath::Resolved(None, path)),
|
||||
|
@ -2932,7 +2932,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
obligation.param_env,
|
||||
) {
|
||||
self.report_similar_impl_candidates_for_root_obligation(
|
||||
&obligation,
|
||||
obligation,
|
||||
*trait_predicate,
|
||||
body_def_id,
|
||||
err,
|
||||
|
@ -3044,13 +3044,13 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
(ty::ClosureKind::FnOnce, Some((span, place))) => {
|
||||
err.fn_once_label = Some(ClosureFnOnceLabel {
|
||||
span: *span,
|
||||
place: ty::place_to_string_for_capture(self.tcx, &place),
|
||||
place: ty::place_to_string_for_capture(self.tcx, place),
|
||||
})
|
||||
}
|
||||
(ty::ClosureKind::FnMut, Some((span, place))) => {
|
||||
err.fn_mut_label = Some(ClosureFnMutLabel {
|
||||
span: *span,
|
||||
place: ty::place_to_string_for_capture(self.tcx, &place),
|
||||
place: ty::place_to_string_for_capture(self.tcx, place),
|
||||
})
|
||||
}
|
||||
_ => {}
|
||||
|
@ -3162,7 +3162,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
let mut not_tupled = false;
|
||||
|
||||
let found = match found_trait_ref.skip_binder().args.type_at(1).kind() {
|
||||
ty::Tuple(ref tys) => vec![ArgKind::empty(); tys.len()],
|
||||
ty::Tuple(tys) => vec![ArgKind::empty(); tys.len()],
|
||||
_ => {
|
||||
not_tupled = true;
|
||||
vec![ArgKind::empty()]
|
||||
|
@ -3171,7 +3171,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
|
||||
let expected_ty = expected_trait_ref.skip_binder().args.type_at(1);
|
||||
let expected = match expected_ty.kind() {
|
||||
ty::Tuple(ref tys) => {
|
||||
ty::Tuple(tys) => {
|
||||
tys.iter().map(|t| ArgKind::from_expected_ty(t, Some(span))).collect()
|
||||
}
|
||||
_ => {
|
||||
|
|
|
@ -84,7 +84,7 @@ fn check_is_object_safe(tcx: TyCtxt<'_>, trait_def_id: DefId) -> bool {
|
|||
span,
|
||||
) = violation
|
||||
{
|
||||
lint_object_unsafe_trait(tcx, *span, trait_def_id, &violation);
|
||||
lint_object_unsafe_trait(tcx, *span, trait_def_id, violation);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -584,7 +584,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
|
|||
data,
|
||||
self.cause.clone(),
|
||||
self.depth,
|
||||
&mut self.obligations,
|
||||
self.obligations,
|
||||
)
|
||||
} else {
|
||||
opt_normalize_projection_type(
|
||||
|
@ -593,7 +593,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
|
|||
data,
|
||||
self.cause.clone(),
|
||||
self.depth,
|
||||
&mut self.obligations,
|
||||
self.obligations,
|
||||
)
|
||||
.ok()
|
||||
.flatten()
|
||||
|
@ -632,7 +632,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
|
|||
data,
|
||||
self.cause.clone(),
|
||||
self.depth,
|
||||
&mut self.obligations,
|
||||
self.obligations,
|
||||
)
|
||||
.ok()
|
||||
.flatten()
|
||||
|
@ -717,7 +717,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
|
|||
data,
|
||||
self.cause.clone(),
|
||||
self.depth,
|
||||
&mut self.obligations,
|
||||
self.obligations,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -732,7 +732,7 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
|
|||
data,
|
||||
self.cause.clone(),
|
||||
self.depth,
|
||||
&mut self.obligations,
|
||||
self.obligations,
|
||||
);
|
||||
|
||||
PlaceholderReplacer::replace_placeholders(
|
||||
|
|
|
@ -48,9 +48,7 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
|
|||
// (T1..Tn) and closures have same properties as T1..Tn --
|
||||
// check if *all* of them are trivial.
|
||||
ty::Tuple(tys) => tys.iter().all(|t| trivial_dropck_outlives(tcx, t)),
|
||||
ty::Closure(_, ref args) => {
|
||||
trivial_dropck_outlives(tcx, args.as_closure().tupled_upvars_ty())
|
||||
}
|
||||
ty::Closure(_, args) => trivial_dropck_outlives(tcx, args.as_closure().tupled_upvars_ty()),
|
||||
|
||||
ty::Adt(def, _) => {
|
||||
if Some(def.did()) == tcx.lang_items().manually_drop() {
|
||||
|
|
|
@ -108,7 +108,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
|
|||
match self.evaluate_obligation(obligation) {
|
||||
Ok(result) => result,
|
||||
Err(OverflowError::Canonical) => {
|
||||
let mut selcx = SelectionContext::new(&self);
|
||||
let mut selcx = SelectionContext::new(self);
|
||||
selcx.evaluate_root_obligation(obligation).unwrap_or_else(|r| match r {
|
||||
OverflowError::Canonical => {
|
||||
span_bug!(
|
||||
|
|
|
@ -634,7 +634,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
|
||||
let self_ty = placeholder_trait_predicate.self_ty();
|
||||
let principal_trait_ref = match self_ty.kind() {
|
||||
ty::Dynamic(ref data, ..) => {
|
||||
ty::Dynamic(data, ..) => {
|
||||
if data.auto_traits().any(|did| did == obligation.predicate.def_id()) {
|
||||
debug!(
|
||||
"assemble_candidates_from_object_ty: matched builtin bound, \
|
||||
|
@ -759,10 +759,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
|
||||
match (source.kind(), target.kind()) {
|
||||
// Trait+Kx+'a -> Trait+Ky+'b (upcasts).
|
||||
(
|
||||
&ty::Dynamic(ref a_data, a_region, ty::Dyn),
|
||||
&ty::Dynamic(ref b_data, b_region, ty::Dyn),
|
||||
) => {
|
||||
(&ty::Dynamic(a_data, a_region, ty::Dyn), &ty::Dynamic(b_data, b_region, ty::Dyn)) => {
|
||||
// Upcast coercions permit several things:
|
||||
//
|
||||
// 1. Dropping auto traits, e.g., `Foo + Send` to `Foo`
|
||||
|
|
|
@ -394,7 +394,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
obligation.recursion_depth + 1,
|
||||
obligation.param_env,
|
||||
trait_def_id,
|
||||
&trait_ref.args,
|
||||
trait_ref.args,
|
||||
obligation.predicate,
|
||||
);
|
||||
|
||||
|
@ -455,7 +455,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
recursion_depth,
|
||||
param_env,
|
||||
impl_def_id,
|
||||
&args.value,
|
||||
args.value,
|
||||
parent_trait_pred,
|
||||
);
|
||||
|
||||
|
@ -708,7 +708,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
obligation.recursion_depth,
|
||||
obligation.param_env,
|
||||
trait_def_id,
|
||||
&args,
|
||||
args,
|
||||
obligation.predicate,
|
||||
);
|
||||
|
||||
|
@ -986,7 +986,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
|
||||
Ok(match (source.kind(), target.kind()) {
|
||||
// Trait+Kx+'a -> Trait+Ky+'b (auto traits and lifetime subtyping).
|
||||
(&ty::Dynamic(ref data_a, r_a, dyn_a), &ty::Dynamic(ref data_b, r_b, dyn_b))
|
||||
(&ty::Dynamic(data_a, r_a, dyn_a), &ty::Dynamic(data_b, r_b, dyn_b))
|
||||
if dyn_a == dyn_b =>
|
||||
{
|
||||
// See `assemble_candidates_for_unsizing` for more info.
|
||||
|
@ -1031,7 +1031,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
}
|
||||
|
||||
// `T` -> `Trait`
|
||||
(_, &ty::Dynamic(ref data, r, ty::Dyn)) => {
|
||||
(_, &ty::Dynamic(data, r, ty::Dyn)) => {
|
||||
let mut object_dids = data.auto_traits().chain(data.principal_def_id());
|
||||
if let Some(did) = object_dids.find(|did| !tcx.check_is_object_safe(*did)) {
|
||||
return Err(TraitNotObjectSafe(did));
|
||||
|
|
|
@ -367,7 +367,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
debug_assert!(!self.infcx.next_trait_solver());
|
||||
// Watch out for overflow. This intentionally bypasses (and does
|
||||
// not update) the cache.
|
||||
self.check_recursion_limit(&stack.obligation, &stack.obligation)?;
|
||||
self.check_recursion_limit(stack.obligation, stack.obligation)?;
|
||||
|
||||
// Check the cache. Note that we freshen the trait-ref
|
||||
// separately rather than using `stack.fresh_trait_ref` --
|
||||
|
@ -416,7 +416,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||
let mut no_candidates_apply = true;
|
||||
|
||||
for c in candidate_set.vec.iter() {
|
||||
if self.evaluate_candidate(stack, &c)?.may_apply() {
|
||||
if self.evaluate_candidate(stack, c)?.may_apply() {
|
||||
no_candidates_apply = false;
|
||||
break;
|
||||
}
|
||||
|
@ -2218,7 +2218,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
ty::CoroutineWitness(def_id, ref args) => {
|
||||
ty::CoroutineWitness(def_id, args) => {
|
||||
let hidden_types = bind_coroutine_hidden_types_above(
|
||||
self.infcx,
|
||||
def_id,
|
||||
|
@ -2307,23 +2307,23 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
|||
|
||||
ty::Array(element_ty, _) | ty::Slice(element_ty) => t.rebind(vec![element_ty]),
|
||||
|
||||
ty::Tuple(ref tys) => {
|
||||
ty::Tuple(tys) => {
|
||||
// (T1, ..., Tn) -- meets any bound that all of T1...Tn meet
|
||||
t.rebind(tys.iter().collect())
|
||||
}
|
||||
|
||||
ty::Closure(_, ref args) => {
|
||||
ty::Closure(_, args) => {
|
||||
let ty = self.infcx.shallow_resolve(args.as_closure().tupled_upvars_ty());
|
||||
t.rebind(vec![ty])
|
||||
}
|
||||
|
||||
ty::Coroutine(_, ref args, _) => {
|
||||
ty::Coroutine(_, args, _) => {
|
||||
let ty = self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty());
|
||||
let witness = args.as_coroutine().witness();
|
||||
t.rebind([ty].into_iter().chain(iter::once(witness)).collect())
|
||||
}
|
||||
|
||||
ty::CoroutineWitness(def_id, ref args) => {
|
||||
ty::CoroutineWitness(def_id, args) => {
|
||||
bind_coroutine_hidden_types_above(self.infcx, def_id, args, t.bound_vars())
|
||||
}
|
||||
|
||||
|
|
|
@ -107,7 +107,7 @@ pub fn translate_args_with_cause<'tcx>(
|
|||
param_env, source_impl, source_args, target_node
|
||||
);
|
||||
let source_trait_ref =
|
||||
infcx.tcx.impl_trait_ref(source_impl).unwrap().instantiate(infcx.tcx, &source_args);
|
||||
infcx.tcx.impl_trait_ref(source_impl).unwrap().instantiate(infcx.tcx, source_args);
|
||||
|
||||
// translate the Self and Param parts of the substitution, since those
|
||||
// vary across impls
|
||||
|
@ -197,25 +197,22 @@ fn fulfill_implication<'tcx>(
|
|||
param_env, source_trait_ref, target_impl
|
||||
);
|
||||
|
||||
let source_trait_ref = match traits::fully_normalize(
|
||||
&infcx,
|
||||
ObligationCause::dummy(),
|
||||
param_env,
|
||||
source_trait_ref,
|
||||
) {
|
||||
Ok(source_trait_ref) => source_trait_ref,
|
||||
Err(_errors) => {
|
||||
infcx.tcx.sess.delay_span_bug(
|
||||
infcx.tcx.def_span(source_impl),
|
||||
format!("failed to fully normalize {source_trait_ref}"),
|
||||
);
|
||||
source_trait_ref
|
||||
}
|
||||
};
|
||||
let source_trait_ref =
|
||||
match traits::fully_normalize(infcx, ObligationCause::dummy(), param_env, source_trait_ref)
|
||||
{
|
||||
Ok(source_trait_ref) => source_trait_ref,
|
||||
Err(_errors) => {
|
||||
infcx.tcx.sess.delay_span_bug(
|
||||
infcx.tcx.def_span(source_impl),
|
||||
format!("failed to fully normalize {source_trait_ref}"),
|
||||
);
|
||||
source_trait_ref
|
||||
}
|
||||
};
|
||||
|
||||
let source_trait = ImplSubject::Trait(source_trait_ref);
|
||||
|
||||
let selcx = &mut SelectionContext::new(&infcx);
|
||||
let selcx = &mut SelectionContext::new(infcx);
|
||||
let target_args = infcx.fresh_args_for_item(DUMMY_SP, target_impl);
|
||||
let (target_trait, obligations) =
|
||||
util::impl_subject_and_oblig(selcx, param_env, target_impl, target_args, error_cause);
|
||||
|
|
|
@ -624,7 +624,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> {
|
|||
// Note that we handle the len is implicitly checked while walking `arg`.
|
||||
}
|
||||
|
||||
ty::Tuple(ref tys) => {
|
||||
ty::Tuple(tys) => {
|
||||
if let Some((_last, rest)) = tys.split_last() {
|
||||
for &elem in rest {
|
||||
self.require_sized(elem, traits::TupleElem);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue