diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2015-01-11 14:52:37 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2015-01-11 14:52:37 -0500 |
| commit | 2b8678cf5df2b3521ed88b8aea8d7699799e67a0 (patch) | |
| tree | ea88717386d91d13b4fb08d8eeaac0410ac3b78e /src | |
| parent | 06e798a881d80eb959a71da5ebbd164f056a4531 (diff) | |
| download | rust-2b8678cf5df2b3521ed88b8aea8d7699799e67a0.tar.gz rust-2b8678cf5df2b3521ed88b8aea8d7699799e67a0.zip | |
Give where clauses priority over builtin rules. Fixes #20959.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/middle/traits/select.rs | 8 | ||||
| -rw-r--r-- | src/test/run-pass/trait-false-ambiguity-where-clause-builtin-bound.rs | 23 |
2 files changed, 31 insertions, 0 deletions
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<K> : Send`, + // then we wind up in a situation where there is a + // default rule (`Option<K>: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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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<K>(x: Option<K>) + where Option<K> : Sized +{ + let _y = x; +} + +fn main() { + foo(Some(22)); +} |
