Never consider int and float vars for FnPtr
candidates
This solves a regression where `0.0.cmp()` was ambiguous when a custom trait with a `cmp` method was in scope. FOr integers it shouldn't be a problem in practice so I wasn't able to add a test.
This commit is contained in:
parent
d0eed58a1e
commit
ca79b82c6c
3 changed files with 24 additions and 8 deletions
|
@ -998,8 +998,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
||||||
| ty::Alias(..)
|
| ty::Alias(..)
|
||||||
| ty::Param(..)
|
| ty::Param(..)
|
||||||
| ty::Bound(..)
|
| ty::Bound(..)
|
||||||
| ty::Error(_) => {}
|
| ty::Error(_)
|
||||||
ty::Infer(_) => {
|
| ty::Infer(
|
||||||
|
ty::InferTy::IntVar(_)
|
||||||
|
| ty::InferTy::FloatVar(_)
|
||||||
|
| ty::InferTy::FreshIntTy(_)
|
||||||
|
| ty::InferTy::FreshFloatTy(_),
|
||||||
|
) => {}
|
||||||
|
ty::Infer(ty::InferTy::TyVar(_) | ty::InferTy::FreshTy(_)) => {
|
||||||
candidates.ambiguous = true;
|
candidates.ambiguous = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -177,14 +177,14 @@ struct TraitObligationStack<'prev, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SelectionCandidateSet<'tcx> {
|
struct SelectionCandidateSet<'tcx> {
|
||||||
// A list of candidates that definitely apply to the current
|
/// A list of candidates that definitely apply to the current
|
||||||
// obligation (meaning: types unify).
|
/// obligation (meaning: types unify).
|
||||||
vec: Vec<SelectionCandidate<'tcx>>,
|
vec: Vec<SelectionCandidate<'tcx>>,
|
||||||
|
|
||||||
// If `true`, then there were candidates that might or might
|
/// If `true`, then there were candidates that might or might
|
||||||
// not have applied, but we couldn't tell. This occurs when some
|
/// not have applied, but we couldn't tell. This occurs when some
|
||||||
// of the input types are type variables, in which case there are
|
/// of the input types are type variables, in which case there are
|
||||||
// various "builtin" rules that might or might not trigger.
|
/// various "builtin" rules that might or might not trigger.
|
||||||
ambiguous: bool,
|
ambiguous: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
tests/ui/fn/fn-ptr-trait-int-float-infer-var.rs
Normal file
10
tests/ui/fn/fn-ptr-trait-int-float-infer-var.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
// check-pass
|
||||||
|
trait MyCmp {
|
||||||
|
fn cmp(&self) {}
|
||||||
|
}
|
||||||
|
impl MyCmp for f32 {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// Ensure that `impl<F: FnPtr> Ord for F` is never considered for int and float infer vars.
|
||||||
|
0.0.cmp();
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue