Skip to content

Commit f121d5c

Browse files
committed
---
yaml --- r: 167402 b: refs/heads/snap-stage3 c: 05eb2ee h: refs/heads/master v: v3
1 parent 3c711f9 commit f121d5c

File tree

7 files changed

+101
-24
lines changed

7 files changed

+101
-24
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 023dfb0c898d851dee6ace2f8339b73b5287136b
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: c197911c60ce7eaea53ecb357d0409d3e38ff914
4+
refs/heads/snap-stage3: 05eb2eeb61985f481982285ae7714d5cc0d7bdb7
55
refs/heads/try: 5204084bd2e46af7cc6e0147430e44dd0d657bbb
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d

branches/snap-stage3/src/librustc/metadata/decoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1366,7 +1366,7 @@ pub fn get_dylib_dependency_formats(cdata: Cmd)
13661366
if spec.len() == 0 { continue }
13671367
let cnum = spec.split(':').nth(0).unwrap();
13681368
let link = spec.split(':').nth(1).unwrap();
1369-
let cnum = cnum.parse().unwrap();
1369+
let cnum: ast::CrateNum = cnum.parse().unwrap();
13701370
let cnum = match cdata.cnum_map.get(&cnum) {
13711371
Some(&n) => n,
13721372
None => panic!("didn't find a crate in the cnum_map")

branches/snap-stage3/src/librustc/middle/traits/select.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -736,10 +736,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
736736
let trait_def_id = match poly_trait_predicate.0.trait_ref.self_ty().sty {
737737
ty::ty_projection(ref data) => data.trait_ref.def_id,
738738
ty::ty_infer(ty::TyVar(_)) => {
739-
// TODO ignore potential ambiguity so that we can do
740-
// better inference, need to get our story
741-
// straight(er) here, I think.
742-
// candidates.ambiguous = true;
739+
// If the self-type is an inference variable, then it MAY wind up
740+
// being a projected type, so induce an ambiguity.
741+
//
742+
// FIXME(#20297) -- being strict about this can cause
743+
// inference failures with BorrowFrom, which is
744+
// unfortunate. Can we do better here?
745+
candidates.ambiguous = true;
743746
return;
744747
}
745748
_ => { return; }

branches/snap-stage3/src/librustc_typeck/check/method/confirm.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010

1111
use super::probe;
1212

13-
use check::{mod, FnCtxt, NoPreference, PreferMutLvalue, callee};
13+
use check::{mod, FnCtxt, NoPreference, PreferMutLvalue, callee, demand};
14+
use middle::mem_categorization::Typer;
1415
use middle::subst::{mod};
1516
use middle::traits;
1617
use middle::ty::{mod, Ty};
@@ -540,7 +541,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
540541
// Don't retry the first one or we might infinite loop!
541542
if i != 0 {
542543
match expr.node {
543-
ast::ExprIndex(ref base_expr, _) => {
544+
ast::ExprIndex(ref base_expr, ref index_expr) => {
544545
let mut base_adjustment =
545546
match self.fcx.inh.adjustments.borrow().get(&base_expr.id) {
546547
Some(&ty::AdjustDerefRef(ref adr)) => (*adr).clone(),
@@ -576,14 +577,22 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
576577
&**base_expr,
577578
Some(&ty::AdjustDerefRef(base_adjustment.clone())));
578579

579-
check::try_index_step(
580+
let result = check::try_index_step(
580581
self.fcx,
581582
MethodCall::expr(expr.id),
582583
*expr,
583584
&**base_expr,
584585
adjusted_base_ty,
585586
base_adjustment,
586587
PreferMutLvalue);
588+
589+
if let Some((input_ty, return_ty)) = result {
590+
let index_expr_ty = self.fcx.expr_ty(&**index_expr);
591+
demand::suptype(self.fcx, index_expr.span, input_ty, index_expr_ty);
592+
593+
let expr_ty = self.fcx.expr_ty(&**expr);
594+
demand::suptype(self.fcx, expr.span, expr_ty, return_ty);
595+
}
587596
}
588597
ast::ExprUnary(ast::UnDeref, ref base_expr) => {
589598
// if this is an overloaded deref, then re-evaluate with

branches/snap-stage3/src/test/run-pass/multidispatch-infer-from-single-impl.rs renamed to branches/snap-stage3/src/test/compile-fail/associated-types-bound-failure.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,32 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// Test that we correctly infer that `E` must be `()` here. This is
12-
// known because there is just one impl that could apply where
13-
// `Self=()`.
11+
// Test equality constraints on associated types in a where clause.
1412

15-
pub trait FromError<E> {
16-
fn from_error(err: E) -> Self;
13+
#![feature(associated_types)]
14+
15+
pub trait ToInt {
16+
fn to_int(&self) -> int;
17+
}
18+
19+
pub trait GetToInt
20+
{
21+
type R;
22+
23+
fn get(&self) -> <Self as GetToInt>::R;
1724
}
1825

19-
impl<E> FromError<E> for E {
20-
fn from_error(err: E) -> E {
21-
err
22-
}
26+
fn foo<G>(g: G) -> int
27+
where G : GetToInt
28+
{
29+
ToInt::to_int(&g.get()) //~ ERROR not implemented
2330
}
2431

25-
fn test() -> Result<(), ()> {
26-
Err(FromError::from_error(()))
32+
fn bar<G : GetToInt>(g: G) -> int
33+
where G::R : ToInt
34+
{
35+
ToInt::to_int(&g.get()) // OK
2736
}
2837

29-
fn main() {
30-
let result = (|| Err(FromError::from_error(())))();
31-
let foo: () = result.unwrap_or(());
38+
pub fn main() {
3239
}

branches/snap-stage3/src/test/run-pass/issue-12028.rs renamed to branches/snap-stage3/src/test/compile-fail/issue-12028.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// Test an example where we fail to infer the type parameter H. This
12+
// is because there is really nothing constraining it. At one time, we
13+
// would infer based on the where clauses in scope, but that no longer
14+
// works.
15+
1116
trait Hash<H> {
1217
fn hash2(&self, hasher: &H) -> u64;
1318
}
@@ -30,7 +35,7 @@ trait StreamHash<S: Stream, H: StreamHasher<S>>: Hash<H> {
3035
impl<S: Stream, H: StreamHasher<S>> Hash<H> for u8 {
3136
fn hash2(&self, hasher: &H) -> u64 {
3237
let mut stream = hasher.stream();
33-
self.input_stream(&mut stream);
38+
self.input_stream(&mut stream); //~ ERROR type annotations required
3439
stream.result()
3540
}
3641
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test equality constraints on associated types in a where clause.
12+
13+
#![feature(associated_types)]
14+
15+
pub trait ToInt {
16+
fn to_int(&self) -> int;
17+
}
18+
19+
impl ToInt for int {
20+
fn to_int(&self) -> int { *self }
21+
}
22+
23+
impl ToInt for uint {
24+
fn to_int(&self) -> int { *self as int }
25+
}
26+
27+
pub trait GetToInt
28+
{
29+
type R : ToInt;
30+
31+
fn get(&self) -> <Self as GetToInt>::R;
32+
}
33+
34+
impl GetToInt for int {
35+
type R = int;
36+
fn get(&self) -> int { *self }
37+
}
38+
39+
impl GetToInt for uint {
40+
type R = uint;
41+
fn get(&self) -> uint { *self }
42+
}
43+
44+
fn foo<G>(g: G) -> int
45+
where G : GetToInt
46+
{
47+
ToInt::to_int(&g.get())
48+
}
49+
50+
pub fn main() {
51+
assert_eq!(foo(22i), 22i);
52+
assert_eq!(foo(22u), 22i);
53+
}

0 commit comments

Comments
 (0)