Skip to content

Commit

Permalink
Track IsSuggestion in ProbeContext. Don't warn stability for suggesti…
Browse files Browse the repository at this point in the history
…ons.
  • Loading branch information
kennytm committed Mar 23, 2018
1 parent db4f3f9 commit 17cc3d7
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/librustc_typeck/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub use self::PickKind::*;

/// Boolean flag used to indicate if this search is for a suggestion
/// or not. If true, we can allow ambiguity and so forth.
#[derive(Clone, Copy)]
pub struct IsSuggestion(pub bool);

struct ProbeContext<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
Expand Down Expand Up @@ -66,6 +67,8 @@ struct ProbeContext<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
/// Collects near misses when trait bounds for type parameters are unsatisfied and is only used
/// for error reporting
unsatisfied_predicates: Vec<TraitRef<'tcx>>,

is_suggestion: IsSuggestion,
}

impl<'a, 'gcx, 'tcx> Deref for ProbeContext<'a, 'gcx, 'tcx> {
Expand Down Expand Up @@ -277,8 +280,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
// this creates one big transaction so that all type variables etc
// that we create during the probe process are removed later
self.probe(|_| {
let mut probe_cx =
ProbeContext::new(self, span, mode, method_name, return_type, Rc::new(steps));
let mut probe_cx = ProbeContext::new(
self, span, mode, method_name, return_type, Rc::new(steps), is_suggestion,
);

probe_cx.assemble_inherent_candidates();
match scope {
Expand Down Expand Up @@ -379,7 +383,8 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
mode: Mode,
method_name: Option<ast::Name>,
return_type: Option<Ty<'tcx>>,
steps: Rc<Vec<CandidateStep<'tcx>>>)
steps: Rc<Vec<CandidateStep<'tcx>>>,
is_suggestion: IsSuggestion)
-> ProbeContext<'a, 'gcx, 'tcx> {
ProbeContext {
fcx,
Expand All @@ -395,6 +400,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
allow_similar_names: false,
private_candidate: None,
unsatisfied_predicates: Vec::new(),
is_suggestion,
}
}

Expand Down Expand Up @@ -952,14 +958,12 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
Some(&mut unstable_candidates),
);
if let Some(pick) = res {
if !unstable_candidates.is_empty() && !self_ty.is_ty_var() {
if !self.is_suggestion.0 && !unstable_candidates.is_empty() {
if let Ok(p) = &pick {
// Emit a lint if there are unstable candidates alongside the stable ones.
//
// Note, we suppress warning if `self_ty` is TyVar (`_`), since every
// possible candidates of every type will be considered, which leads to
// bogus ambiguity like `str::rsplit` vs `[_]::rsplit`. This condition is
// seen in `src/test/compile-fail/occurs-check-2.rs`.
// We suppress warning if we're picking the method only because it is a
// suggestion.
self.emit_unstable_name_collision_hint(p, &unstable_candidates);
}
}
Expand Down Expand Up @@ -1265,7 +1269,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> {
let steps = self.steps.clone();
self.probe(|_| {
let mut pcx = ProbeContext::new(self.fcx, self.span, self.mode, self.method_name,
self.return_type, steps);
self.return_type, steps, IsSuggestion(true));
pcx.allow_similar_names = true;
pcx.assemble_inherent_candidates();
pcx.assemble_extension_candidates_for_traits_in_scope(ast::DUMMY_NODE_ID)?;
Expand Down

0 comments on commit 17cc3d7

Please sign in to comment.