Skip to content

Commit

Permalink
Give where clauses priority over builtin rules. Fixes #20959.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Jan 11, 2015
1 parent 06e798a commit 2b8678c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/librustc/middle/traits/select.rs
Expand Up @@ -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
Expand Down
@@ -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));
}

6 comments on commit 2b8678c

@bors
Copy link
Contributor

@bors bors commented on 2b8678c Jan 13, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nick29581
at nikomatsakis@2b8678c

@bors
Copy link
Contributor

@bors bors commented on 2b8678c Jan 13, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging nikomatsakis/rust/assoc-types-struct-field-access = 2b8678c into auto

@bors
Copy link
Contributor

@bors bors commented on 2b8678c Jan 13, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status: {"merge_sha": "4fc9b41238c5b8d36afd6765c770b6604bf7ef04"}

@bors
Copy link
Contributor

@bors bors commented on 2b8678c Jan 13, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nikomatsakis/rust/assoc-types-struct-field-access = 2b8678c merged ok, testing candidate = 4fc9b41

@bors
Copy link
Contributor

@bors bors commented on 2b8678c Jan 13, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 4fc9b41

Please sign in to comment.