From 2b8678cf5df2b3521ed88b8aea8d7699799e67a0 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Sun, 11 Jan 2015 14:52:37 -0500 Subject: [PATCH] Give where clauses priority over builtin rules. Fixes #20959. --- src/librustc/middle/traits/select.rs | 8 +++++++ ...se-ambiguity-where-clause-builtin-bound.rs | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/test/run-pass/trait-false-ambiguity-where-clause-builtin-bound.rs diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index d6302976b9f..c3cf23042f9 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -1166,6 +1166,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .is_ok() }) } + (&BuiltinCandidate(_), &ParamCandidate(_)) => { + // If we have a where-clause like `Option : Send`, + // then we wind up in a situation where there is a + // default rule (`Option:Send if K:Send) and the + // where-clause that both seem applicable. Just take + // the where-clause in that case. + true + } (&ProjectionCandidate, &ParamCandidate(_)) => { // FIXME(#20297) -- this gives where clauses precedent // over projections. Really these are just two means diff --git a/src/test/run-pass/trait-false-ambiguity-where-clause-builtin-bound.rs b/src/test/run-pass/trait-false-ambiguity-where-clause-builtin-bound.rs new file mode 100644 index 00000000000..ca66a106c43 --- /dev/null +++ b/src/test/run-pass/trait-false-ambiguity-where-clause-builtin-bound.rs @@ -0,0 +1,23 @@ +// Copyright 2015 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that we do not error out because of a (False) ambiguity +// between the builtin rules for Sized and the where clause. Issue +// #20959. + +fn foo(x: Option) + where Option : Sized +{ + let _y = x; +} + +fn main() { + foo(Some(22)); +}