Skip to content

Commit fbdbeda

Browse files
committed
---
yaml --- r: 172013 b: refs/heads/beta c: 480374a h: refs/heads/master i: 172011: 8995b7e v: v3
1 parent 3f9109c commit fbdbeda

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ refs/heads/automation-fail: 1bf06495443584539b958873e04cc2f864ab10e4
3131
refs/heads/issue-18208-method-dispatch-3-quick-reject: 2009f85b9f99dedcec4404418eda9ddba90258a2
3232
refs/heads/batch: b5571ed71a5879c0495a982506258d5d267744ed
3333
refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
34-
refs/heads/beta: 77ed4974569fbe71c0ba76327b5e2a34a515ed73
34+
refs/heads/beta: 480374a696a4d23d27ade99ac8280c16b5b01e85
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928

branches/beta/src/librustc/middle/check_const.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &ast::Expr) {
165165
ast::ExprParen(..) |
166166
ast::ExprField(..) |
167167
ast::ExprTupField(..) |
168-
ast::ExprIndex(..) |
169168
ast::ExprTup(..) |
170169
ast::ExprRepeat(..) |
171170
ast::ExprStruct(..) => {}

branches/beta/src/librustc_typeck/check/method/confirm.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -562,18 +562,19 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx> {
562562
self.fcx.adjust_expr_ty(
563563
&**base_expr,
564564
Some(&ty::AdjustDerefRef(base_adjustment.clone())));
565-
565+
let index_expr_ty = self.fcx.expr_ty(&**index_expr);
566+
566567
let result = check::try_index_step(
567568
self.fcx,
568569
MethodCall::expr(expr.id),
569570
*expr,
570571
&**base_expr,
571572
adjusted_base_ty,
572573
base_adjustment,
573-
PreferMutLvalue);
574+
PreferMutLvalue,
575+
index_expr_ty);
574576

575577
if let Some((input_ty, return_ty)) = result {
576-
let index_expr_ty = self.fcx.expr_ty(&**index_expr);
577578
demand::suptype(self.fcx, index_expr.span, input_ty, index_expr_ty);
578579

579580
let expr_ty = self.fcx.expr_ty(&**expr);

branches/beta/src/librustc_typeck/check/mod.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,18 +2387,30 @@ fn try_index_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
23872387
base_expr: &ast::Expr,
23882388
adjusted_ty: Ty<'tcx>,
23892389
adjustment: ty::AutoDerefRef<'tcx>,
2390-
lvalue_pref: LvaluePreference)
2390+
lvalue_pref: LvaluePreference,
2391+
index_ty: Ty<'tcx>)
23912392
-> Option<(/*index type*/ Ty<'tcx>, /*element type*/ Ty<'tcx>)>
23922393
{
23932394
let tcx = fcx.tcx();
2394-
debug!("try_index_step(expr={}, base_expr.id={}, adjusted_ty={}, adjustment={})",
2395+
debug!("try_index_step(expr={}, base_expr.id={}, adjusted_ty={}, adjustment={}, index_ty={})",
23952396
expr.repr(tcx),
23962397
base_expr.repr(tcx),
23972398
adjusted_ty.repr(tcx),
2398-
adjustment);
2399+
adjustment,
2400+
index_ty.repr(tcx));
23992401

24002402
let input_ty = fcx.infcx().next_ty_var();
24012403

2404+
// First, try built-in indexing.
2405+
match (ty::index(adjusted_ty), &index_ty.sty) {
2406+
(Some(ty), &ty::ty_uint(ast::TyU)) | (Some(ty), &ty::ty_infer(ty::IntVar(_))) => {
2407+
debug!("try_index_step: success, using built-in indexing");
2408+
fcx.write_adjustment(base_expr.id, base_expr.span, ty::AdjustDerefRef(adjustment));
2409+
return Some((tcx.types.uint, ty));
2410+
}
2411+
_ => {}
2412+
}
2413+
24022414
// Try `IndexMut` first, if preferred.
24032415
let method = match (lvalue_pref, tcx.lang_items.index_mut_trait()) {
24042416
(PreferMutLvalue, Some(trait_did)) => {
@@ -2429,18 +2441,6 @@ fn try_index_step<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
24292441
(method, _) => method,
24302442
};
24312443

2432-
if method.is_none() {
2433-
// If there are no overridden index impls, use built-in indexing.
2434-
match ty::index(adjusted_ty) {
2435-
Some(ty) => {
2436-
debug!("try_index_step: success, using built-in indexing");
2437-
fcx.write_adjustment(base_expr.id, base_expr.span, ty::AdjustDerefRef(adjustment));
2438-
return Some((tcx.types.uint, ty));
2439-
}
2440-
None => {}
2441-
}
2442-
}
2443-
24442444
// If some lookup succeeds, write callee into table and extract index/element
24452445
// type from the method signature.
24462446
// If some lookup succeeded, install method in table
@@ -4205,11 +4205,14 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>,
42054205
&**base,
42064206
adj_ty,
42074207
adj,
4208-
lvalue_pref)
4208+
lvalue_pref,
4209+
idx_t)
42094210
});
42104211

42114212
match result {
42124213
Some((index_ty, element_ty)) => {
4214+
// FIXME: we've already checked idx above, we should
4215+
// probably just demand subtype or something here.
42134216
check_expr_has_type(fcx, &**idx, index_ty);
42144217
fcx.write_ty(id, element_ty);
42154218
}

0 commit comments

Comments
 (0)