mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 11:07:42 +00:00
Stop passing traitref/traitpredicate by ref
This commit is contained in:
parent
f8d12d9189
commit
2c0348a0d8
@ -546,7 +546,7 @@ impl<T> Trait<T> for X {
|
|||||||
for pred in hir_generics.bounds_for_param(def_id) {
|
for pred in hir_generics.bounds_for_param(def_id) {
|
||||||
if self.constrain_generic_bound_associated_type_structured_suggestion(
|
if self.constrain_generic_bound_associated_type_structured_suggestion(
|
||||||
diag,
|
diag,
|
||||||
&trait_ref,
|
trait_ref,
|
||||||
pred.bounds,
|
pred.bounds,
|
||||||
assoc,
|
assoc,
|
||||||
assoc_args,
|
assoc_args,
|
||||||
@ -715,7 +715,7 @@ fn foo(&self) -> Self::T { String::new() }
|
|||||||
|
|
||||||
self.constrain_generic_bound_associated_type_structured_suggestion(
|
self.constrain_generic_bound_associated_type_structured_suggestion(
|
||||||
diag,
|
diag,
|
||||||
&trait_ref,
|
trait_ref,
|
||||||
opaque_hir_ty.bounds,
|
opaque_hir_ty.bounds,
|
||||||
assoc,
|
assoc,
|
||||||
assoc_args,
|
assoc_args,
|
||||||
@ -869,7 +869,7 @@ fn foo(&self) -> Self::T { String::new() }
|
|||||||
fn constrain_generic_bound_associated_type_structured_suggestion(
|
fn constrain_generic_bound_associated_type_structured_suggestion(
|
||||||
&self,
|
&self,
|
||||||
diag: &mut Diag<'_>,
|
diag: &mut Diag<'_>,
|
||||||
trait_ref: &ty::TraitRef<'tcx>,
|
trait_ref: ty::TraitRef<'tcx>,
|
||||||
bounds: hir::GenericBounds<'_>,
|
bounds: hir::GenericBounds<'_>,
|
||||||
assoc: ty::AssocItem,
|
assoc: ty::AssocItem,
|
||||||
assoc_args: &[ty::GenericArg<'tcx>],
|
assoc_args: &[ty::GenericArg<'tcx>],
|
||||||
|
@ -285,8 +285,7 @@ impl<'tcx, O: Elaboratable<'tcx>> Elaborator<'tcx, O> {
|
|||||||
let obligations =
|
let obligations =
|
||||||
predicates.predicates.iter().enumerate().map(|(index, &(clause, span))| {
|
predicates.predicates.iter().enumerate().map(|(index, &(clause, span))| {
|
||||||
elaboratable.child_with_derived_cause(
|
elaboratable.child_with_derived_cause(
|
||||||
clause
|
clause.instantiate_supertrait(tcx, bound_clause.rebind(data.trait_ref)),
|
||||||
.instantiate_supertrait(tcx, &bound_clause.rebind(data.trait_ref)),
|
|
||||||
span,
|
span,
|
||||||
bound_clause.rebind(data),
|
bound_clause.rebind(data),
|
||||||
index,
|
index,
|
||||||
|
@ -37,7 +37,7 @@ impl<'tcx> Elaborator<'tcx> {
|
|||||||
let super_predicates =
|
let super_predicates =
|
||||||
self.tcx.super_predicates_of(trait_ref.def_id()).predicates.iter().filter_map(
|
self.tcx.super_predicates_of(trait_ref.def_id()).predicates.iter().filter_map(
|
||||||
|&(pred, _)| {
|
|&(pred, _)| {
|
||||||
let clause = pred.instantiate_supertrait(self.tcx, &trait_ref);
|
let clause = pred.instantiate_supertrait(self.tcx, trait_ref);
|
||||||
self.visited.insert(clause).then_some(clause)
|
self.visited.insert(clause).then_some(clause)
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -313,7 +313,7 @@ impl<'tcx> Clause<'tcx> {
|
|||||||
pub fn instantiate_supertrait(
|
pub fn instantiate_supertrait(
|
||||||
self,
|
self,
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
trait_ref: &ty::PolyTraitRef<'tcx>,
|
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||||
) -> Clause<'tcx> {
|
) -> Clause<'tcx> {
|
||||||
// The interaction between HRTB and supertraits is not entirely
|
// The interaction between HRTB and supertraits is not entirely
|
||||||
// obvious. Let me walk you (and myself) through an example.
|
// obvious. Let me walk you (and myself) through an example.
|
||||||
|
@ -3597,7 +3597,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
&self,
|
&self,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
err: &mut Diag<'_>,
|
err: &mut Diag<'_>,
|
||||||
trait_ref: &ty::PolyTraitRef<'tcx>,
|
trait_ref: ty::PolyTraitRef<'tcx>,
|
||||||
) {
|
) {
|
||||||
let rhs_span = match obligation.cause.code() {
|
let rhs_span = match obligation.cause.code() {
|
||||||
ObligationCauseCode::BinOp { rhs_span: Some(span), rhs_is_lit, .. } if *rhs_is_lit => {
|
ObligationCauseCode::BinOp { rhs_span: Some(span), rhs_is_lit, .. } if *rhs_is_lit => {
|
||||||
@ -4863,7 +4863,7 @@ impl<'a, 'hir> hir::intravisit::Visitor<'hir> for ReplaceImplTraitVisitor<'a> {
|
|||||||
pub(super) fn get_explanation_based_on_obligation<'tcx>(
|
pub(super) fn get_explanation_based_on_obligation<'tcx>(
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
trait_predicate: &ty::PolyTraitPredicate<'tcx>,
|
trait_predicate: ty::PolyTraitPredicate<'tcx>,
|
||||||
pre_message: String,
|
pre_message: String,
|
||||||
) -> String {
|
) -> String {
|
||||||
if let ObligationCauseCode::MainFunctionType = obligation.cause.code() {
|
if let ObligationCauseCode::MainFunctionType = obligation.cause.code() {
|
||||||
|
@ -532,7 +532,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let err_msg = self.get_standard_error_message(
|
let err_msg = self.get_standard_error_message(
|
||||||
&main_trait_predicate,
|
main_trait_predicate,
|
||||||
message,
|
message,
|
||||||
predicate_is_const,
|
predicate_is_const,
|
||||||
append_const_msg,
|
append_const_msg,
|
||||||
@ -603,7 +603,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
let explanation = get_explanation_based_on_obligation(
|
let explanation = get_explanation_based_on_obligation(
|
||||||
self.tcx,
|
self.tcx,
|
||||||
&obligation,
|
&obligation,
|
||||||
&leaf_trait_predicate,
|
leaf_trait_predicate,
|
||||||
pre_message,
|
pre_message,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -658,7 +658,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
|
|
||||||
let UnsatisfiedConst(unsatisfied_const) = self
|
let UnsatisfiedConst(unsatisfied_const) = self
|
||||||
.maybe_add_note_for_unsatisfied_const(
|
.maybe_add_note_for_unsatisfied_const(
|
||||||
&leaf_trait_predicate,
|
leaf_trait_predicate,
|
||||||
&mut err,
|
&mut err,
|
||||||
span,
|
span,
|
||||||
);
|
);
|
||||||
@ -675,7 +675,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
err.span_label(tcx.def_span(body), s);
|
err.span_label(tcx.def_span(body), s);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.suggest_floating_point_literal(&obligation, &mut err, &leaf_trait_ref);
|
self.suggest_floating_point_literal(&obligation, &mut err, leaf_trait_ref);
|
||||||
self.suggest_dereferencing_index(&obligation, &mut err, leaf_trait_predicate);
|
self.suggest_dereferencing_index(&obligation, &mut err, leaf_trait_predicate);
|
||||||
suggested |= self.suggest_dereferences(&obligation, &mut err, leaf_trait_predicate);
|
suggested |= self.suggest_dereferences(&obligation, &mut err, leaf_trait_predicate);
|
||||||
suggested |= self.suggest_fn_call(&obligation, &mut err, leaf_trait_predicate);
|
suggested |= self.suggest_fn_call(&obligation, &mut err, leaf_trait_predicate);
|
||||||
@ -710,7 +710,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
span,
|
span,
|
||||||
leaf_trait_predicate,
|
leaf_trait_predicate,
|
||||||
);
|
);
|
||||||
self.note_version_mismatch(&mut err, &leaf_trait_ref);
|
self.note_version_mismatch(&mut err, leaf_trait_ref);
|
||||||
self.suggest_remove_await(&obligation, &mut err);
|
self.suggest_remove_await(&obligation, &mut err);
|
||||||
self.suggest_derive(&obligation, &mut err, leaf_trait_predicate);
|
self.suggest_derive(&obligation, &mut err, leaf_trait_predicate);
|
||||||
|
|
||||||
@ -758,7 +758,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
|
|
||||||
self.try_to_add_help_message(
|
self.try_to_add_help_message(
|
||||||
&obligation,
|
&obligation,
|
||||||
&leaf_trait_predicate,
|
leaf_trait_predicate,
|
||||||
&mut err,
|
&mut err,
|
||||||
span,
|
span,
|
||||||
is_fn_trait,
|
is_fn_trait,
|
||||||
@ -2234,11 +2234,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
/// If the `Self` type of the unsatisfied trait `trait_ref` implements a trait
|
/// If the `Self` type of the unsatisfied trait `trait_ref` implements a trait
|
||||||
/// with the same path as `trait_ref`, a help message about
|
/// with the same path as `trait_ref`, a help message about
|
||||||
/// a probable version mismatch is added to `err`
|
/// a probable version mismatch is added to `err`
|
||||||
fn note_version_mismatch(
|
fn note_version_mismatch(&self, err: &mut Diag<'_>, trait_ref: ty::PolyTraitRef<'tcx>) -> bool {
|
||||||
&self,
|
|
||||||
err: &mut Diag<'_>,
|
|
||||||
trait_ref: &ty::PolyTraitRef<'tcx>,
|
|
||||||
) -> bool {
|
|
||||||
let get_trait_impls = |trait_def_id| {
|
let get_trait_impls = |trait_def_id| {
|
||||||
let mut trait_impls = vec![];
|
let mut trait_impls = vec![];
|
||||||
self.tcx.for_each_relevant_impl(
|
self.tcx.for_each_relevant_impl(
|
||||||
@ -3042,7 +3038,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
|
|
||||||
fn get_standard_error_message(
|
fn get_standard_error_message(
|
||||||
&self,
|
&self,
|
||||||
trait_predicate: &ty::PolyTraitPredicate<'tcx>,
|
trait_predicate: ty::PolyTraitPredicate<'tcx>,
|
||||||
message: Option<String>,
|
message: Option<String>,
|
||||||
predicate_is_const: bool,
|
predicate_is_const: bool,
|
||||||
append_const_msg: Option<AppendConstMessage>,
|
append_const_msg: Option<AppendConstMessage>,
|
||||||
@ -3213,7 +3209,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
fn try_to_add_help_message(
|
fn try_to_add_help_message(
|
||||||
&self,
|
&self,
|
||||||
obligation: &PredicateObligation<'tcx>,
|
obligation: &PredicateObligation<'tcx>,
|
||||||
trait_predicate: &ty::PolyTraitPredicate<'tcx>,
|
trait_predicate: ty::PolyTraitPredicate<'tcx>,
|
||||||
err: &mut Diag<'_>,
|
err: &mut Diag<'_>,
|
||||||
span: Span,
|
span: Span,
|
||||||
is_fn_trait: bool,
|
is_fn_trait: bool,
|
||||||
@ -3245,7 +3241,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
params,
|
params,
|
||||||
);
|
);
|
||||||
} else if !trait_predicate.has_non_region_infer()
|
} else if !trait_predicate.has_non_region_infer()
|
||||||
&& self.predicate_can_apply(obligation.param_env, *trait_predicate)
|
&& self.predicate_can_apply(obligation.param_env, trait_predicate)
|
||||||
{
|
{
|
||||||
// If a where-clause may be useful, remind the
|
// If a where-clause may be useful, remind the
|
||||||
// user that they can add it.
|
// user that they can add it.
|
||||||
@ -3256,7 +3252,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
// which is somewhat confusing.
|
// which is somewhat confusing.
|
||||||
self.suggest_restricting_param_bound(
|
self.suggest_restricting_param_bound(
|
||||||
err,
|
err,
|
||||||
*trait_predicate,
|
trait_predicate,
|
||||||
None,
|
None,
|
||||||
obligation.cause.body_id,
|
obligation.cause.body_id,
|
||||||
);
|
);
|
||||||
@ -3271,7 +3267,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
);
|
);
|
||||||
} else if !suggested && !unsatisfied_const {
|
} else if !suggested && !unsatisfied_const {
|
||||||
// Can't show anything else useful, try to find similar impls.
|
// Can't show anything else useful, try to find similar impls.
|
||||||
let impl_candidates = self.find_similar_impl_candidates(*trait_predicate);
|
let impl_candidates = self.find_similar_impl_candidates(trait_predicate);
|
||||||
if !self.report_similar_impl_candidates(
|
if !self.report_similar_impl_candidates(
|
||||||
&impl_candidates,
|
&impl_candidates,
|
||||||
trait_predicate.to_poly_trait_ref(),
|
trait_predicate.to_poly_trait_ref(),
|
||||||
@ -3282,7 +3278,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
) {
|
) {
|
||||||
self.report_similar_impl_candidates_for_root_obligation(
|
self.report_similar_impl_candidates_for_root_obligation(
|
||||||
obligation,
|
obligation,
|
||||||
*trait_predicate,
|
trait_predicate,
|
||||||
body_def_id,
|
body_def_id,
|
||||||
err,
|
err,
|
||||||
);
|
);
|
||||||
@ -3356,7 +3352,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||||||
|
|
||||||
fn maybe_add_note_for_unsatisfied_const(
|
fn maybe_add_note_for_unsatisfied_const(
|
||||||
&self,
|
&self,
|
||||||
_trait_predicate: &ty::PolyTraitPredicate<'tcx>,
|
_trait_predicate: ty::PolyTraitPredicate<'tcx>,
|
||||||
_err: &mut Diag<'_>,
|
_err: &mut Diag<'_>,
|
||||||
_span: Span,
|
_span: Span,
|
||||||
) -> UnsatisfiedConst {
|
) -> UnsatisfiedConst {
|
||||||
|
@ -194,7 +194,7 @@ fn predicates_reference_self(
|
|||||||
predicates
|
predicates
|
||||||
.predicates
|
.predicates
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&(predicate, sp)| (predicate.instantiate_supertrait(tcx, &trait_ref), sp))
|
.map(|&(predicate, sp)| (predicate.instantiate_supertrait(tcx, trait_ref), sp))
|
||||||
.filter_map(|predicate| predicate_references_self(tcx, predicate))
|
.filter_map(|predicate| predicate_references_self(tcx, predicate))
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
@ -1866,7 +1866,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
|||||||
// the param_env so that it can be given the lowest priority. See
|
// the param_env so that it can be given the lowest priority. See
|
||||||
// #50825 for the motivation for this.
|
// #50825 for the motivation for this.
|
||||||
let is_global =
|
let is_global =
|
||||||
|cand: &ty::PolyTraitPredicate<'tcx>| cand.is_global() && !cand.has_bound_vars();
|
|cand: ty::PolyTraitPredicate<'tcx>| cand.is_global() && !cand.has_bound_vars();
|
||||||
|
|
||||||
// (*) Prefer `BuiltinCandidate { has_nested: false }`, `PointeeCandidate`,
|
// (*) Prefer `BuiltinCandidate { has_nested: false }`, `PointeeCandidate`,
|
||||||
// `DiscriminantKindCandidate`, `ConstDestructCandidate`
|
// `DiscriminantKindCandidate`, `ConstDestructCandidate`
|
||||||
@ -1909,7 +1909,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
(
|
(
|
||||||
ParamCandidate(ref other_cand),
|
ParamCandidate(other_cand),
|
||||||
ImplCandidate(..)
|
ImplCandidate(..)
|
||||||
| AutoImplCandidate
|
| AutoImplCandidate
|
||||||
| ClosureCandidate { .. }
|
| ClosureCandidate { .. }
|
||||||
@ -1934,12 +1934,12 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
|||||||
//
|
//
|
||||||
// Global bounds from the where clause should be ignored
|
// Global bounds from the where clause should be ignored
|
||||||
// here (see issue #50825).
|
// here (see issue #50825).
|
||||||
DropVictim::drop_if(!is_global(other_cand))
|
DropVictim::drop_if(!is_global(*other_cand))
|
||||||
}
|
}
|
||||||
(ObjectCandidate(_) | ProjectionCandidate(_), ParamCandidate(ref victim_cand)) => {
|
(ObjectCandidate(_) | ProjectionCandidate(_), ParamCandidate(victim_cand)) => {
|
||||||
// Prefer these to a global where-clause bound
|
// Prefer these to a global where-clause bound
|
||||||
// (see issue #50825).
|
// (see issue #50825).
|
||||||
if is_global(victim_cand) { DropVictim::Yes } else { DropVictim::No }
|
if is_global(*victim_cand) { DropVictim::Yes } else { DropVictim::No }
|
||||||
}
|
}
|
||||||
(
|
(
|
||||||
ImplCandidate(_)
|
ImplCandidate(_)
|
||||||
@ -1957,12 +1957,12 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
|||||||
| TraitUpcastingUnsizeCandidate(_)
|
| TraitUpcastingUnsizeCandidate(_)
|
||||||
| BuiltinCandidate { has_nested: true }
|
| BuiltinCandidate { has_nested: true }
|
||||||
| TraitAliasCandidate,
|
| TraitAliasCandidate,
|
||||||
ParamCandidate(ref victim_cand),
|
ParamCandidate(victim_cand),
|
||||||
) => {
|
) => {
|
||||||
// Prefer these to a global where-clause bound
|
// Prefer these to a global where-clause bound
|
||||||
// (see issue #50825).
|
// (see issue #50825).
|
||||||
DropVictim::drop_if(
|
DropVictim::drop_if(
|
||||||
is_global(victim_cand) && other.evaluation.must_apply_modulo_regions(),
|
is_global(*victim_cand) && other.evaluation.must_apply_modulo_regions(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ impl<'tcx> TraitAliasExpander<'tcx> {
|
|||||||
debug!(?predicates);
|
debug!(?predicates);
|
||||||
|
|
||||||
let items = predicates.predicates.iter().rev().filter_map(|(pred, span)| {
|
let items = predicates.predicates.iter().rev().filter_map(|(pred, span)| {
|
||||||
pred.instantiate_supertrait(tcx, &trait_ref)
|
pred.instantiate_supertrait(tcx, trait_ref)
|
||||||
.as_trait_clause()
|
.as_trait_clause()
|
||||||
.map(|trait_ref| item.clone_and_push(trait_ref.map_bound(|t| t.trait_ref), *span))
|
.map(|trait_ref| item.clone_and_push(trait_ref.map_bound(|t| t.trait_ref), *span))
|
||||||
});
|
});
|
||||||
|
@ -125,7 +125,7 @@ fn prepare_vtable_segments_inner<'tcx, T>(
|
|||||||
.predicates
|
.predicates
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(move |(pred, _)| {
|
.filter_map(move |(pred, _)| {
|
||||||
pred.instantiate_supertrait(tcx, &inner_most_trait_ref).as_trait_clause()
|
pred.instantiate_supertrait(tcx, inner_most_trait_ref).as_trait_clause()
|
||||||
});
|
});
|
||||||
|
|
||||||
// Find an unvisited supertrait
|
// Find an unvisited supertrait
|
||||||
|
@ -13,4 +13,4 @@ impl<'s, T: Foo<'s>> From<T> for Bar {
|
|||||||
fn main() {
|
fn main() {
|
||||||
let _: Bar = ((),).into();
|
let _: Bar = ((),).into();
|
||||||
//~^ ERROR he trait bound `((),): Into<Bar>` is not satisfied
|
//~^ ERROR he trait bound `((),): Into<Bar>` is not satisfied
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user