Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
add UnsatisfiedPredicate type alias
  • Loading branch information
chenyukang committed Oct 22, 2025
commit 38e8066575cbd7160e43b802aba99e88cb8464cc
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/method/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use tracing::{debug, instrument};
pub(crate) use self::MethodError::*;
use self::probe::{IsSuggestion, ProbeScope};
use crate::FnCtxt;
use crate::method::probe::UnsatisfiedPredicates;

#[derive(Clone, Copy, Debug)]
pub(crate) struct MethodCallee<'tcx> {
Expand Down Expand Up @@ -71,8 +72,7 @@ pub(crate) enum MethodError<'tcx> {
#[derive(Debug)]
pub(crate) struct NoMatchData<'tcx> {
pub static_candidates: Vec<CandidateSource>,
pub unsatisfied_predicates:
Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>, Option<ObligationCause<'tcx>>)>,
pub unsatisfied_predicates: UnsatisfiedPredicates<'tcx>,
pub out_of_scope_traits: Vec<DefId>,
pub similar_candidate: Option<ty::AssocItem>,
pub mode: probe::Mode,
Expand Down
21 changes: 6 additions & 15 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,12 @@ struct PickDiagHints<'a, 'tcx> {

/// Collects near misses when trait bounds for type parameters are unsatisfied and is only used
/// for error reporting
unsatisfied_predicates: &'a mut Vec<(
ty::Predicate<'tcx>,
Option<ty::Predicate<'tcx>>,
Option<ObligationCause<'tcx>>,
)>,
unsatisfied_predicates: &'a mut UnsatisfiedPredicates<'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
/// the search for potentially shadowed methods to ensure we don't search
/// more candidates than strictly necessary.
Expand Down Expand Up @@ -1212,11 +1211,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {

fn pick_core(
&self,
unsatisfied_predicates: &mut Vec<(
ty::Predicate<'tcx>,
Option<ty::Predicate<'tcx>>,
Option<ObligationCause<'tcx>>,
)>,
unsatisfied_predicates: &mut UnsatisfiedPredicates<'tcx>,
) -> Option<PickResult<'tcx>> {
// Pick stable methods only first, and consider unstable candidates if not found.
self.pick_all_method(&mut PickDiagHints {
Expand Down Expand Up @@ -1889,11 +1884,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
self_ty: Ty<'tcx>,
instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
probe: &Candidate<'tcx>,
possibly_unsatisfied_predicates: &mut Vec<(
ty::Predicate<'tcx>,
Option<ty::Predicate<'tcx>>,
Option<ObligationCause<'tcx>>,
)>,
possibly_unsatisfied_predicates: &mut UnsatisfiedPredicates<'tcx>,
) -> ProbeResult {
self.probe(|snapshot| {
let outer_universe = self.universe();
Expand Down
47 changes: 10 additions & 37 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,14 @@ use rustc_trait_selection::error_reporting::traits::on_unimplemented::OnUnimplem
use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt as _;
use rustc_trait_selection::traits::{
FulfillmentError, Obligation, ObligationCause, ObligationCauseCode, supertraits,
FulfillmentError, Obligation, ObligationCauseCode, supertraits,
};
use tracing::{debug, info, instrument};

use super::probe::{AutorefOrPtrAdjustment, IsSuggestion, Mode, ProbeScope};
use super::{CandidateSource, MethodError, NoMatchData};
use crate::errors::{self, CandidateTraitNote, NoAssociatedItem};
use crate::method::probe::UnsatisfiedPredicates;
use crate::{Expectation, FnCtxt};

impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Expand All @@ -58,11 +59,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
&self,
ty: Ty<'tcx>,
span: Span,
unsatisfied_predicates: &Vec<(
ty::Predicate<'tcx>,
Option<ty::Predicate<'tcx>>,
Option<ObligationCause<'tcx>>,
)>,
unsatisfied_predicates: &UnsatisfiedPredicates<'tcx>,
) -> bool {
fn predicate_bounds_generic_param<'tcx>(
predicate: ty::Predicate<'_>,
Expand Down Expand Up @@ -410,11 +407,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
source: SelfSource<'tcx>,
is_method: bool,
sugg_span: Span,
unsatisfied_predicates: &Vec<(
ty::Predicate<'tcx>,
Option<ty::Predicate<'tcx>>,
Option<ObligationCause<'tcx>>,
)>,
unsatisfied_predicates: &UnsatisfiedPredicates<'tcx>,
) -> Diag<'_> {
// Don't show expanded generic arguments when the method can't be found in any
// implementation (#81576).
Expand Down Expand Up @@ -1096,11 +1089,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
mode: Mode,
source: SelfSource<'tcx>,
span: Span,
unsatisfied_predicates: &Vec<(
ty::Predicate<'tcx>,
Option<ty::Predicate<'tcx>>,
Option<ObligationCause<'tcx>>,
)>,
unsatisfied_predicates: &UnsatisfiedPredicates<'tcx>,
find_candidate_for_method: &mut bool,
) {
let ty_str = self.tcx.short_string(rcvr_ty, err.long_ty_path());
Expand Down Expand Up @@ -1198,11 +1187,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
item_ident: Ident,
span: Span,
source: SelfSource<'tcx>,
unsatisfied_predicates: &Vec<(
ty::Predicate<'tcx>,
Option<ty::Predicate<'tcx>>,
Option<ObligationCause<'tcx>>,
)>,
unsatisfied_predicates: &UnsatisfiedPredicates<'tcx>,
) {
// 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() {
Expand Down Expand Up @@ -1338,11 +1323,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
item_ident: Ident,
item_kind: &str,
span: Span,
unsatisfied_predicates: &Vec<(
ty::Predicate<'tcx>,
Option<ty::Predicate<'tcx>>,
Option<ObligationCause<'tcx>>,
)>,
unsatisfied_predicates: &UnsatisfiedPredicates<'tcx>,
restrict_type_params: &mut bool,
suggested_derive: &mut bool,
unsatisfied_bounds: &mut bool,
Expand Down Expand Up @@ -3122,13 +3103,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
fn note_predicate_source_and_get_derives(
&self,
err: &mut Diag<'_>,
unsatisfied_predicates: &[(
ty::Predicate<'tcx>,
Option<ty::Predicate<'tcx>>,
Option<ObligationCause<'tcx>>,
)],
unsatisfied_predicates: &UnsatisfiedPredicates<'tcx>,
) -> Vec<(String, Span, Symbol)> {
let mut derives = Vec::<(String, Span, Symbol)>::new();
let mut derives = Vec::new();
let mut traits = Vec::new();
for (pred, _, _) in unsatisfied_predicates {
let Some(ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_pred))) =
Expand Down Expand Up @@ -3204,11 +3181,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
pub(crate) fn suggest_derive(
&self,
err: &mut Diag<'_>,
unsatisfied_predicates: &[(
ty::Predicate<'tcx>,
Option<ty::Predicate<'tcx>>,
Option<ObligationCause<'tcx>>,
)],
unsatisfied_predicates: &UnsatisfiedPredicates<'tcx>,
) -> bool {
let mut derives = self.note_predicate_source_and_get_derives(err, unsatisfied_predicates);
derives.sort();
Expand Down
Loading