Auto merge of #114358 - matthiaskrgr:rollup-d810m9e, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #114178 (Account for macros when suggesting a new let binding) - #114199 (Don't unsize coerce infer vars in select in new solver) - #114301 (Don't check unnecessarily that impl trait is RPIT) - #114314 (Tweaks to `adt_sized_constraint`) - #114322 (Fix invalid slice coercion suggestion reported in turbofish) - #114340 ([rustc_attr][nit] Replace `filter` + `is_some` with `map_or`.) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
7a5d2d0138
25 changed files with 168 additions and 69 deletions
|
@ -150,7 +150,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<'tcx>(
|
|||
|
||||
ty::Adt(def, args) => {
|
||||
let sized_crit = def.sized_constraint(ecx.tcx());
|
||||
Ok(sized_crit.iter_instantiated_copied(ecx.tcx(), args).collect())
|
||||
Ok(sized_crit.iter_instantiated(ecx.tcx(), args).collect())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -235,7 +235,10 @@ fn rematch_unsize<'tcx>(
|
|||
goal.param_env,
|
||||
&mut nested,
|
||||
);
|
||||
|
||||
match (a_ty.kind(), b_ty.kind()) {
|
||||
// Don't try to coerce `?0` to `dyn Trait`
|
||||
(ty::Infer(ty::TyVar(_)), _) | (_, ty::Infer(ty::TyVar(_))) => Ok(None),
|
||||
// Stall any ambiguous upcasting goals, since we can't rematch those
|
||||
(ty::Dynamic(_, _, ty::Dyn), ty::Dynamic(_, _, ty::Dyn)) => match certainty {
|
||||
Certainty::Yes => Ok(Some(ImplSource::Builtin(source, nested))),
|
||||
|
|
|
@ -3030,8 +3030,9 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
self.report_similar_impl_candidates_for_root_obligation(&obligation, *trait_predicate, body_def_id, err);
|
||||
}
|
||||
|
||||
self.maybe_suggest_convert_to_slice(
|
||||
self.suggest_convert_to_slice(
|
||||
err,
|
||||
obligation,
|
||||
trait_ref,
|
||||
impl_candidates.as_slice(),
|
||||
span,
|
||||
|
|
|
@ -398,9 +398,10 @@ pub trait TypeErrCtxtExt<'tcx> {
|
|||
param_env: ty::ParamEnv<'tcx>,
|
||||
) -> Vec<Option<(Span, (DefId, Ty<'tcx>))>>;
|
||||
|
||||
fn maybe_suggest_convert_to_slice(
|
||||
fn suggest_convert_to_slice(
|
||||
&self,
|
||||
err: &mut Diagnostic,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||
candidate_impls: &[ImplCandidate<'tcx>],
|
||||
span: Span,
|
||||
|
@ -3944,13 +3945,20 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
/// If the type that failed selection is an array or a reference to an array,
|
||||
/// but the trait is implemented for slices, suggest that the user converts
|
||||
/// the array into a slice.
|
||||
fn maybe_suggest_convert_to_slice(
|
||||
fn suggest_convert_to_slice(
|
||||
&self,
|
||||
err: &mut Diagnostic,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||
candidate_impls: &[ImplCandidate<'tcx>],
|
||||
span: Span,
|
||||
) {
|
||||
// We can only suggest the slice coersion for function arguments since the suggestion
|
||||
// would make no sense in turbofish or call
|
||||
let ObligationCauseCode::FunctionArgumentObligation { .. } = obligation.cause.code() else {
|
||||
return;
|
||||
};
|
||||
|
||||
// Three cases where we can make a suggestion:
|
||||
// 1. `[T; _]` (array of T)
|
||||
// 2. `&[T; _]` (reference to array of T)
|
||||
|
|
|
@ -2099,7 +2099,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
|||
Where(
|
||||
obligation
|
||||
.predicate
|
||||
.rebind(sized_crit.iter_instantiated_copied(self.tcx(), args).collect()),
|
||||
.rebind(sized_crit.iter_instantiated(self.tcx(), args).collect()),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue