add UnsatisfiedPredicate type alias
This commit is contained in:
@@ -1953,7 +1953,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.suggest_derive(diag, &[(trait_ref.upcast(self.tcx), None, None)]);
|
self.suggest_derive(diag, &vec![(trait_ref.upcast(self.tcx), None, None)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ use tracing::{debug, instrument};
|
|||||||
pub(crate) use self::MethodError::*;
|
pub(crate) use self::MethodError::*;
|
||||||
use self::probe::{IsSuggestion, ProbeScope};
|
use self::probe::{IsSuggestion, ProbeScope};
|
||||||
use crate::FnCtxt;
|
use crate::FnCtxt;
|
||||||
|
use crate::method::probe::UnsatisfiedPredicates;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub(crate) struct MethodCallee<'tcx> {
|
pub(crate) struct MethodCallee<'tcx> {
|
||||||
@@ -71,8 +72,7 @@ pub(crate) enum MethodError<'tcx> {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub(crate) struct NoMatchData<'tcx> {
|
pub(crate) struct NoMatchData<'tcx> {
|
||||||
pub static_candidates: Vec<CandidateSource>,
|
pub static_candidates: Vec<CandidateSource>,
|
||||||
pub unsatisfied_predicates:
|
pub unsatisfied_predicates: UnsatisfiedPredicates<'tcx>,
|
||||||
Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>, Option<ObligationCause<'tcx>>)>,
|
|
||||||
pub out_of_scope_traits: Vec<DefId>,
|
pub out_of_scope_traits: Vec<DefId>,
|
||||||
pub similar_candidate: Option<ty::AssocItem>,
|
pub similar_candidate: Option<ty::AssocItem>,
|
||||||
pub mode: probe::Mode,
|
pub mode: probe::Mode,
|
||||||
|
|||||||
@@ -165,13 +165,12 @@ struct PickDiagHints<'a, 'tcx> {
|
|||||||
|
|
||||||
/// Collects near misses when trait bounds for type parameters are unsatisfied and is only used
|
/// Collects near misses when trait bounds for type parameters are unsatisfied and is only used
|
||||||
/// for error reporting
|
/// for error reporting
|
||||||
unsatisfied_predicates: &'a mut Vec<(
|
unsatisfied_predicates: &'a mut UnsatisfiedPredicates<'tcx>,
|
||||||
ty::Predicate<'tcx>,
|
|
||||||
Option<ty::Predicate<'tcx>>,
|
|
||||||
Option<ObligationCause<'tcx>>,
|
|
||||||
)>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub(crate) type UnsatisfiedPredicates<'tcx> =
|
||||||
|
Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>, Option<ObligationCause<'tcx>>)>;
|
||||||
|
|
||||||
/// Criteria to apply when searching for a given Pick. This is used during
|
/// Criteria to apply when searching for a given Pick. This is used during
|
||||||
/// the search for potentially shadowed methods to ensure we don't search
|
/// the search for potentially shadowed methods to ensure we don't search
|
||||||
/// more candidates than strictly necessary.
|
/// more candidates than strictly necessary.
|
||||||
@@ -1212,11 +1211,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
|||||||
|
|
||||||
fn pick_core(
|
fn pick_core(
|
||||||
&self,
|
&self,
|
||||||
unsatisfied_predicates: &mut Vec<(
|
unsatisfied_predicates: &mut UnsatisfiedPredicates<'tcx>,
|
||||||
ty::Predicate<'tcx>,
|
|
||||||
Option<ty::Predicate<'tcx>>,
|
|
||||||
Option<ObligationCause<'tcx>>,
|
|
||||||
)>,
|
|
||||||
) -> Option<PickResult<'tcx>> {
|
) -> Option<PickResult<'tcx>> {
|
||||||
// Pick stable methods only first, and consider unstable candidates if not found.
|
// Pick stable methods only first, and consider unstable candidates if not found.
|
||||||
self.pick_all_method(&mut PickDiagHints {
|
self.pick_all_method(&mut PickDiagHints {
|
||||||
@@ -1889,11 +1884,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
|||||||
self_ty: Ty<'tcx>,
|
self_ty: Ty<'tcx>,
|
||||||
instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
|
instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
|
||||||
probe: &Candidate<'tcx>,
|
probe: &Candidate<'tcx>,
|
||||||
possibly_unsatisfied_predicates: &mut Vec<(
|
possibly_unsatisfied_predicates: &mut UnsatisfiedPredicates<'tcx>,
|
||||||
ty::Predicate<'tcx>,
|
|
||||||
Option<ty::Predicate<'tcx>>,
|
|
||||||
Option<ObligationCause<'tcx>>,
|
|
||||||
)>,
|
|
||||||
) -> ProbeResult {
|
) -> ProbeResult {
|
||||||
self.probe(|snapshot| {
|
self.probe(|snapshot| {
|
||||||
let outer_universe = self.universe();
|
let outer_universe = self.universe();
|
||||||
|
|||||||
@@ -38,13 +38,14 @@ use rustc_trait_selection::error_reporting::traits::on_unimplemented::OnUnimplem
|
|||||||
use rustc_trait_selection::infer::InferCtxtExt;
|
use rustc_trait_selection::infer::InferCtxtExt;
|
||||||
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
|
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
|
||||||
use rustc_trait_selection::traits::{
|
use rustc_trait_selection::traits::{
|
||||||
FulfillmentError, Obligation, ObligationCause, ObligationCauseCode, supertraits,
|
FulfillmentError, Obligation, ObligationCauseCode, supertraits,
|
||||||
};
|
};
|
||||||
use tracing::{debug, info, instrument};
|
use tracing::{debug, info, instrument};
|
||||||
|
|
||||||
use super::probe::{AutorefOrPtrAdjustment, IsSuggestion, Mode, ProbeScope};
|
use super::probe::{AutorefOrPtrAdjustment, IsSuggestion, Mode, ProbeScope};
|
||||||
use super::{CandidateSource, MethodError, NoMatchData};
|
use super::{CandidateSource, MethodError, NoMatchData};
|
||||||
use crate::errors::{self, CandidateTraitNote, NoAssociatedItem};
|
use crate::errors::{self, CandidateTraitNote, NoAssociatedItem};
|
||||||
|
use crate::method::probe::UnsatisfiedPredicates;
|
||||||
use crate::{Expectation, FnCtxt};
|
use crate::{Expectation, FnCtxt};
|
||||||
|
|
||||||
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
@@ -58,11 +59,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
&self,
|
&self,
|
||||||
ty: Ty<'tcx>,
|
ty: Ty<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
unsatisfied_predicates: &Vec<(
|
unsatisfied_predicates: &UnsatisfiedPredicates<'tcx>,
|
||||||
ty::Predicate<'tcx>,
|
|
||||||
Option<ty::Predicate<'tcx>>,
|
|
||||||
Option<ObligationCause<'tcx>>,
|
|
||||||
)>,
|
|
||||||
) -> bool {
|
) -> bool {
|
||||||
fn predicate_bounds_generic_param<'tcx>(
|
fn predicate_bounds_generic_param<'tcx>(
|
||||||
predicate: ty::Predicate<'_>,
|
predicate: ty::Predicate<'_>,
|
||||||
@@ -410,11 +407,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
source: SelfSource<'tcx>,
|
source: SelfSource<'tcx>,
|
||||||
is_method: bool,
|
is_method: bool,
|
||||||
sugg_span: Span,
|
sugg_span: Span,
|
||||||
unsatisfied_predicates: &Vec<(
|
unsatisfied_predicates: &UnsatisfiedPredicates<'tcx>,
|
||||||
ty::Predicate<'tcx>,
|
|
||||||
Option<ty::Predicate<'tcx>>,
|
|
||||||
Option<ObligationCause<'tcx>>,
|
|
||||||
)>,
|
|
||||||
) -> Diag<'_> {
|
) -> Diag<'_> {
|
||||||
// Don't show expanded generic arguments when the method can't be found in any
|
// Don't show expanded generic arguments when the method can't be found in any
|
||||||
// implementation (#81576).
|
// implementation (#81576).
|
||||||
@@ -1096,11 +1089,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
mode: Mode,
|
mode: Mode,
|
||||||
source: SelfSource<'tcx>,
|
source: SelfSource<'tcx>,
|
||||||
span: Span,
|
span: Span,
|
||||||
unsatisfied_predicates: &Vec<(
|
unsatisfied_predicates: &UnsatisfiedPredicates<'tcx>,
|
||||||
ty::Predicate<'tcx>,
|
|
||||||
Option<ty::Predicate<'tcx>>,
|
|
||||||
Option<ObligationCause<'tcx>>,
|
|
||||||
)>,
|
|
||||||
find_candidate_for_method: &mut bool,
|
find_candidate_for_method: &mut bool,
|
||||||
) {
|
) {
|
||||||
let ty_str = self.tcx.short_string(rcvr_ty, err.long_ty_path());
|
let ty_str = self.tcx.short_string(rcvr_ty, err.long_ty_path());
|
||||||
@@ -1198,11 +1187,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
item_ident: Ident,
|
item_ident: Ident,
|
||||||
span: Span,
|
span: Span,
|
||||||
source: SelfSource<'tcx>,
|
source: SelfSource<'tcx>,
|
||||||
unsatisfied_predicates: &Vec<(
|
unsatisfied_predicates: &UnsatisfiedPredicates<'tcx>,
|
||||||
ty::Predicate<'tcx>,
|
|
||||||
Option<ty::Predicate<'tcx>>,
|
|
||||||
Option<ObligationCause<'tcx>>,
|
|
||||||
)>,
|
|
||||||
) {
|
) {
|
||||||
// Don't emit a suggestion if we found an actual method that had unsatisfied trait bounds
|
// Don't emit a suggestion if we found an actual method that had unsatisfied trait bounds
|
||||||
if !unsatisfied_predicates.is_empty() || !rcvr_ty.is_enum() {
|
if !unsatisfied_predicates.is_empty() || !rcvr_ty.is_enum() {
|
||||||
@@ -1338,11 +1323,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
item_ident: Ident,
|
item_ident: Ident,
|
||||||
item_kind: &str,
|
item_kind: &str,
|
||||||
span: Span,
|
span: Span,
|
||||||
unsatisfied_predicates: &Vec<(
|
unsatisfied_predicates: &UnsatisfiedPredicates<'tcx>,
|
||||||
ty::Predicate<'tcx>,
|
|
||||||
Option<ty::Predicate<'tcx>>,
|
|
||||||
Option<ObligationCause<'tcx>>,
|
|
||||||
)>,
|
|
||||||
restrict_type_params: &mut bool,
|
restrict_type_params: &mut bool,
|
||||||
suggested_derive: &mut bool,
|
suggested_derive: &mut bool,
|
||||||
unsatisfied_bounds: &mut bool,
|
unsatisfied_bounds: &mut bool,
|
||||||
@@ -3122,13 +3103,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
fn note_predicate_source_and_get_derives(
|
fn note_predicate_source_and_get_derives(
|
||||||
&self,
|
&self,
|
||||||
err: &mut Diag<'_>,
|
err: &mut Diag<'_>,
|
||||||
unsatisfied_predicates: &[(
|
unsatisfied_predicates: &UnsatisfiedPredicates<'tcx>,
|
||||||
ty::Predicate<'tcx>,
|
|
||||||
Option<ty::Predicate<'tcx>>,
|
|
||||||
Option<ObligationCause<'tcx>>,
|
|
||||||
)],
|
|
||||||
) -> Vec<(String, Span, Symbol)> {
|
) -> Vec<(String, Span, Symbol)> {
|
||||||
let mut derives = Vec::<(String, Span, Symbol)>::new();
|
let mut derives = Vec::new();
|
||||||
let mut traits = Vec::new();
|
let mut traits = Vec::new();
|
||||||
for (pred, _, _) in unsatisfied_predicates {
|
for (pred, _, _) in unsatisfied_predicates {
|
||||||
let Some(ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_pred))) =
|
let Some(ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_pred))) =
|
||||||
@@ -3204,11 +3181,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
pub(crate) fn suggest_derive(
|
pub(crate) fn suggest_derive(
|
||||||
&self,
|
&self,
|
||||||
err: &mut Diag<'_>,
|
err: &mut Diag<'_>,
|
||||||
unsatisfied_predicates: &[(
|
unsatisfied_predicates: &UnsatisfiedPredicates<'tcx>,
|
||||||
ty::Predicate<'tcx>,
|
|
||||||
Option<ty::Predicate<'tcx>>,
|
|
||||||
Option<ObligationCause<'tcx>>,
|
|
||||||
)],
|
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let mut derives = self.note_predicate_source_and_get_derives(err, unsatisfied_predicates);
|
let mut derives = self.note_predicate_source_and_get_derives(err, unsatisfied_predicates);
|
||||||
derives.sort();
|
derives.sort();
|
||||||
|
|||||||
Reference in New Issue
Block a user