Skip to content

Commit c6f6468

Browse files
committed
Add some helpful logging.
This commit adds some helpful logging statements to help work out what is going on.
1 parent 827a141 commit c6f6468

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

src/librustc_typeck/check/method/probe.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
491491
}
492492

493493
fn reset(&mut self) {
494+
debug!("reset");
494495
self.inherent_candidates.clear();
495496
self.extension_candidates.clear();
496497
self.impl_dups.clear();
@@ -505,13 +506,16 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
505506
candidate: Candidate<'tcx>,
506507
is_inherent: bool)
507508
{
509+
debug!("push_candidate: candidate={:?} is_inherent={:?}", candidate, is_inherent);
508510
let is_accessible = if let Some(name) = self.method_name {
509511
let item = candidate.item;
510512
let def_scope = self.tcx.adjust_ident(name, item.container.id(), self.body_id).1;
511513
item.vis.is_accessible_from(def_scope, self.tcx)
512514
} else {
513515
true
514516
};
517+
518+
debug!("push_candidate: is_accessible={:?}", is_accessible);
515519
if is_accessible {
516520
if is_inherent {
517521
self.inherent_candidates.push(candidate);
@@ -847,6 +851,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
847851
}
848852

849853
fn assemble_extension_candidates_for_all_traits(&mut self) -> Result<(), MethodError<'tcx>> {
854+
debug!("assemble_extension_candidates_for_all_traits");
850855
let mut duplicates = FxHashSet::default();
851856
for trait_info in suggest::all_traits(self.tcx) {
852857
if duplicates.insert(trait_info.def_id) {
@@ -939,6 +944,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
939944
// THE ACTUAL SEARCH
940945

941946
fn pick(mut self) -> PickResult<'tcx> {
947+
debug!("pick: method_name={:?}", self.method_name);
942948
assert!(self.method_name.is_some());
943949

944950
if let Some(r) = self.pick_core() {
@@ -958,9 +964,13 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
958964
self.assemble_extension_candidates_for_all_traits()?;
959965

960966
let out_of_scope_traits = match self.pick_core() {
961-
Some(Ok(p)) => vec![p.item.container.id()],
967+
Some(Ok(p)) => {
968+
debug!("pick: (ok) p={:?}", p);
969+
vec![p.item.container.id()]
970+
},
962971
//Some(Ok(p)) => p.iter().map(|p| p.item.container().id()).collect(),
963972
Some(Err(MethodError::Ambiguity(v))) => {
973+
debug!("pick: (ambiguity) v={:?}", v);
964974
v.into_iter()
965975
.map(|source| {
966976
match source {
@@ -979,6 +989,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
979989
.collect()
980990
}
981991
Some(Err(MethodError::NoMatch(NoMatchData { out_of_scope_traits: others, .. }))) => {
992+
debug!("pick: (no match) others={:?}", others);
982993
assert!(others.is_empty());
983994
vec![]
984995
}
@@ -990,6 +1001,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
9901001
}
9911002
let lev_candidate = self.probe_for_lev_candidate()?;
9921003

1004+
debug!("pick: out_of_scope_traits={:?}", out_of_scope_traits);
9931005
Err(MethodError::NoMatch(NoMatchData::new(static_candidates,
9941006
unsatisfied_predicates,
9951007
out_of_scope_traits,
@@ -1302,13 +1314,20 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
13021314
let predicate = trait_ref.to_predicate();
13031315
let obligation =
13041316
traits::Obligation::new(cause, self.param_env, predicate);
1317+
debug!(
1318+
"consider_probe: predicate={:?} obligation={:?} trait_ref={:?}",
1319+
predicate, obligation, trait_ref
1320+
);
13051321
if !self.predicate_may_hold(&obligation) {
1322+
debug!("consider_probe: predicate did not hold");
13061323
if self.probe(|_| self.select_trait_candidate(trait_ref).is_err()) {
1324+
debug!("consider_probe: select_trait_candidate.is_err=true");
13071325
// This candidate's primary obligation doesn't even
13081326
// select - don't bother registering anything in
13091327
// `potentially_unsatisfied_predicates`.
13101328
return ProbeResult::NoMatch;
13111329
} else {
1330+
debug!("consider_probe: nested subobligation");
13121331
// Some nested subobligation of this predicate
13131332
// failed.
13141333
//

src/librustc_typeck/check/method/suggest.rs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -430,15 +430,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
430430
bound_list));
431431
}
432432

433-
if actual.is_numeric() && actual.is_fresh() {
434-
435-
} else {
436-
self.suggest_traits_to_import(&mut err,
437-
span,
438-
rcvr_ty,
439-
item_name,
440-
source,
441-
out_of_scope_traits);
433+
if !actual.is_numeric() || !actual.is_fresh() {
434+
self.suggest_traits_to_import(
435+
&mut err, span, rcvr_ty, item_name, source, out_of_scope_traits
436+
);
442437
}
443438

444439
if let Some(lev_candidate) = lev_candidate {
@@ -575,13 +570,20 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
575570
}
576571
}
577572

578-
fn suggest_traits_to_import<'b>(&self,
579-
err: &mut DiagnosticBuilder,
580-
span: Span,
581-
rcvr_ty: Ty<'tcx>,
582-
item_name: ast::Ident,
583-
source: SelfSource<'b>,
584-
valid_out_of_scope_traits: Vec<DefId>) {
573+
fn suggest_traits_to_import(
574+
&self,
575+
err: &mut DiagnosticBuilder,
576+
span: Span,
577+
rcvr_ty: Ty<'tcx>,
578+
item_name: ast::Ident,
579+
source: SelfSource<'a>,
580+
valid_out_of_scope_traits: Vec<DefId>
581+
) {
582+
debug!(
583+
"suggest_traits_to_import: rcvr_ty={:?} item_name={:?} source={:?} \
584+
valid_out_of_scope_traits={:?}",
585+
rcvr_ty, item_name, source, valid_out_of_scope_traits,
586+
);
585587
if self.suggest_valid_traits(err, valid_out_of_scope_traits) {
586588
return;
587589
}
@@ -610,6 +612,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
610612
})
611613
.collect::<Vec<_>>();
612614

615+
debug!("suggest_traits_to_import: candidates={:?}", candidates);
613616
if !candidates.is_empty() {
614617
// Sort from most relevant to least relevant.
615618
candidates.sort_by(|a, b| a.cmp(b).reverse());
@@ -676,13 +679,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
676679
}
677680
}
678681

679-
#[derive(Copy, Clone)]
682+
#[derive(Copy, Clone, Debug)]
680683
pub enum SelfSource<'a> {
681684
QPath(&'a hir::Ty),
682685
MethodCall(&'a hir::Expr /* rcvr */),
683686
}
684687

685-
#[derive(Copy, Clone)]
688+
#[derive(Copy, Clone, Debug)]
686689
pub struct TraitInfo {
687690
pub def_id: DefId,
688691
}
@@ -692,12 +695,15 @@ impl PartialEq for TraitInfo {
692695
self.cmp(other) == Ordering::Equal
693696
}
694697
}
698+
695699
impl Eq for TraitInfo {}
700+
696701
impl PartialOrd for TraitInfo {
697702
fn partial_cmp(&self, other: &TraitInfo) -> Option<Ordering> {
698703
Some(self.cmp(other))
699704
}
700705
}
706+
701707
impl Ord for TraitInfo {
702708
fn cmp(&self, other: &TraitInfo) -> Ordering {
703709
// Local crates are more important than remote ones (local:

0 commit comments

Comments
 (0)