Skip to content

Commit b4cc2d4

Browse files
committed
Rebased
1 parent 7b9df5b commit b4cc2d4

File tree

10 files changed

+56
-72
lines changed

10 files changed

+56
-72
lines changed

src/libcore/iter.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ use option::Option::{self, Some, None};
7070
use marker::Sized;
7171
use usize;
7272

73-
fn _assert_is_object_safe(_: &Iterator) {}
73+
fn _assert_is_object_safe(_: &Iterator<Item=()>) {}
7474

7575
/// An interface for dealing with "external iterators". These types of iterators
7676
/// can be resumed at any time as all state is stored internally as opposed to

src/librustc/middle/expr_use_visitor.rs

+21-46
Original file line numberDiff line numberDiff line change
@@ -799,18 +799,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
799799
self.delegate_consume(expr.id, expr.span, cmt_unadjusted);
800800
}
801801
ty::AdjustDerefRef(ref adj) => {
802-
self.walk_autoderefs(expr, adj.autoderefs);
803-
if let Some(ref r) = adj.autoref {
804-
self.walk_autoref(expr, r, adj.autoderefs);
805-
} else if adj.unsize.is_some() {
806-
assert!(adj.autoderefs == 0,
807-
format!("Expected no derefs with \
808-
unsize AutoRefs, found: {}",
809-
adj.repr(self.tcx())));
810-
let cmt_unadjusted =
811-
return_if_err!(self.mc.cat_expr_unadjusted(expr));
812-
self.delegate_consume(expr.id, expr.span, cmt_unadjusted);
813-
}
802+
self.walk_autoderefref(expr, adj);
814803
}
815804
}
816805
}
@@ -860,29 +849,29 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
860849
self.walk_autoderefs(expr, adj.autoderefs);
861850

862851
// Weird hacky special case: AutoUnsizeUniq, which converts
863-
// from a ~T to a ~Trait etc, always comes in a stylized
852+
// from a Box<T> to a Box<Trait> etc, always comes in a stylized
864853
// fashion. In particular, we want to consume the ~ pointer
865854
// being dereferenced, not the dereferenced content (as the
866855
// content is, at least for upcasts, unsized).
867-
match adj.autoref {
868-
Some(ty::AutoUnsizeUniq(_)) => {
869-
assert!(adj.autoderefs == 1,
870-
format!("Expected exactly 1 deref with Uniq AutoRefs, found: {}",
871-
adj.autoderefs));
856+
if let Some(ty) = adj.unsize {
857+
if let ty::ty_uniq(_) = ty.sty {
858+
assert!(adj.autoderefs == 0,
859+
format!("Expected no derefs with unsize AutoRefs, found: {}",
860+
adj.repr(self.tcx())));
872861
let cmt_unadjusted =
873862
return_if_err!(self.mc.cat_expr_unadjusted(expr));
874863
self.delegate_consume(expr.id, expr.span, cmt_unadjusted);
875864
return;
876865
}
877-
_ => { }
878866
}
879867

880-
let autoref = adj.autoref.as_ref();
868+
//let autoref = adj.autoref.as_ref();
881869
let cmt_derefd = return_if_err!(
882870
self.mc.cat_expr_autoderefd(expr, adj.autoderefs));
883-
self.walk_autoref(expr, &cmt_derefd, autoref);
871+
self.walk_autoref(expr, cmt_derefd, adj.autoref);
884872
}
885873

874+
886875
/// Walks the autoref `opt_autoref` applied to the autoderef'd
887876
/// `expr`. `cmt_derefd` is the mem-categorized form of `expr`
888877
/// after all relevant autoderefs have occurred. Because AutoRefs
@@ -893,25 +882,25 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
893882
/// autoref.
894883
fn walk_autoref(&mut self,
895884
expr: &ast::Expr,
896-
cmt_derefd: &mc::cmt<'tcx>,
897-
opt_autoref: Option<&ty::AutoRef<'tcx>>)
885+
cmt_base: mc::cmt<'tcx>,
886+
opt_autoref: Option<ty::AutoRef<'tcx>>)
898887
-> mc::cmt<'tcx>
899888
{
900889
debug!("walk_autoref(expr.id={} cmt_derefd={} opt_autoref={:?})",
901890
expr.id,
902-
cmt_derefd.repr(self.tcx()),
891+
cmt_base.repr(self.tcx()),
903892
opt_autoref);
904893

894+
let cmt_base_ty = cmt_base.ty;
895+
905896
let autoref = match opt_autoref {
906-
Some(autoref) => autoref,
897+
Some(ref autoref) => autoref,
907898
None => {
908-
// No recursive step here, this is a base case.
909-
return cmt_derefd.clone();
899+
// No AutoRef.
900+
return cmt_base;
910901
}
911902
};
912903

913-
let cmt_base = self.walk_autoref_recursively(expr, cmt_derefd, baseref);
914-
915904
debug!("walk_autoref: expr.id={} cmt_base={}",
916905
expr.id,
917906
cmt_base.repr(self.tcx()));
@@ -920,15 +909,13 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
920909
ty::AutoPtr(r, m) => {
921910
self.delegate.borrow(expr.id,
922911
expr.span,
923-
cmt_derefd,
912+
cmt_base,
924913
*r,
925914
ty::BorrowKind::from_mutbl(m),
926915
AutoRef);
927916
}
928917

929-
ty::AutoUnsafe(m, ref baseref) => {
930-
let cmt_base = self.walk_autoref_recursively(expr, cmt_derefd, baseref);
931-
918+
ty::AutoUnsafe(m) => {
932919
debug!("walk_autoref: expr.id={} cmt_base={}",
933920
expr.id,
934921
cmt_base.repr(self.tcx()));
@@ -953,24 +940,12 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
953940

954941
let adj_ty =
955942
ty::adjust_ty_for_autoref(self.tcx(),
956-
expr.span,
957-
cmt_derefd.ty,
943+
cmt_base_ty,
958944
opt_autoref);
959945

960946
self.mc.cat_rvalue_node(expr.id, expr.span, adj_ty)
961947
}
962948

963-
fn walk_autoref_recursively(&mut self,
964-
expr: &ast::Expr,
965-
cmt_derefd: &mc::cmt<'tcx>,
966-
autoref: &Option<Box<ty::AutoRef<'tcx>>>)
967-
-> mc::cmt<'tcx>
968-
{
969-
// Shuffle from a ref to an optional box to an optional ref.
970-
let autoref: Option<&ty::AutoRef<'tcx>> = autoref.as_ref().map(|b| &**b);
971-
self.walk_autoref(expr, cmt_derefd, autoref)
972-
}
973-
974949

975950
// When this returns true, it means that the expression *is* a
976951
// method-call (i.e. via the operator-overload). This true result

src/librustc/middle/ty.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@ pub enum AutoAdjustment<'tcx> {
290290

291291
#[derive(Copy, Clone, Debug)]
292292
pub struct AutoDerefRef<'tcx> {
293+
// FIXME with more powerful date structures we could have a better design
294+
// here. Some constraints:
295+
// unsize => autoref
296+
// unsize => autodefs == 0
297+
298+
293299
/// Apply a number of dereferences, producing an lvalue.
294300
pub autoderefs: usize,
295301

@@ -303,11 +309,11 @@ pub struct AutoDerefRef<'tcx> {
303309

304310
#[derive(Copy, Clone, PartialEq, Debug)]
305311
pub enum AutoRef<'tcx> {
306-
/// Convert from T to &T
312+
/// Convert from T to &T.
307313
AutoPtr(&'tcx Region, ast::Mutability),
308314

309-
/// Convert from T to *T
310-
/// Value to thin pointer
315+
/// Convert from T to *T.
316+
/// Value to thin pointer.
311317
AutoUnsafe(ast::Mutability),
312318
}
313319

@@ -407,7 +413,7 @@ impl MethodCall {
407413
}
408414
}
409415

410-
pub fn autoderef(expr_id: ast::NodeId, autoderef: usize) -> MethodCall {
416+
pub fn autoderef(expr_id: ast::NodeId, autoderef: u32) -> MethodCall {
411417
MethodCall {
412418
expr_id: expr_id,
413419
autoderef: 1 + autoderef
@@ -4480,8 +4486,8 @@ pub fn adjust_ty<'tcx, F>(cx: &ctxt<'tcx>,
44804486
let method_call = MethodCall::autoderef(expr_id, i as u32);
44814487
match method_type(method_call) {
44824488
Some(method_ty) => {
4483-
// overloaded deref operators have all late-bound
4484-
// regions fully instantiated and coverge
4489+
// Overloaded deref operators have all late-bound
4490+
// regions fully instantiated and coverge.
44854491
let fn_ret =
44864492
ty::no_late_bound_regions(cx,
44874493
&ty_fn_ret(method_ty)).unwrap();
@@ -4494,8 +4500,7 @@ pub fn adjust_ty<'tcx, F>(cx: &ctxt<'tcx>,
44944500
None => {
44954501
cx.sess.span_bug(
44964502
span,
4497-
&format!("the {}th autoderef failed: \
4498-
{}",
4503+
&format!("the {}th autoderef failed: {}",
44994504
i,
45004505
ty_to_string(cx, adjusted_ty))
45014506
);

src/librustc_typeck/check/coercion.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ use syntax::ast;
7979
struct Coerce<'a, 'tcx: 'a> {
8080
fcx: &'a FnCtxt<'a, 'tcx>,
8181
origin: infer::TypeOrigin,
82-
trace: TypeTrace<'tcx>,
8382
unsizing_obligation: Cell<Option<Ty<'tcx>>>
8483
}
8584

@@ -266,7 +265,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
266265
if let Some(target) = self.unsize_ty(mt_a.ty, mt_b.ty) {
267266
try!(coerce_mutbls(mt_a.mutbl, mt_b.mutbl));
268267

269-
let coercion = Coercion(self.trace.clone());
268+
let coercion = Coercion(self.origin.span());
270269
let r_borrow = self.fcx.infcx().next_region_var(coercion);
271270
let region = self.tcx().mk_region(r_borrow);
272271
(Some(ty::AutoPtr(region, mt_b.mutbl)), target)
@@ -293,7 +292,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
293292
};
294293

295294
let target = ty::adjust_ty_for_autoref(self.tcx(), target, reborrow);
296-
try!(self.fcx.infcx().try(|_| self.subtype(target, b)));
295+
try!(self.subtype(target, b));
297296
let adjustment = AutoDerefRef {
298297
autoderefs: if reborrow.is_some() { 1 } else { 0 },
299298
autoref: reborrow,
@@ -374,7 +373,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
374373
assert!(ty_substs_a.len() == ty_substs_b.len());
375374

376375
let tps = ty_substs_a.iter().zip(ty_substs_b.iter()).enumerate();
377-
for (i, (&tp_a, &tp_b)) in tps {
376+
for (i, (tp_a, tp_b)) in tps {
378377
if self.subtype(*tp_a, *tp_b).is_ok() {
379378
continue;
380379
}
@@ -498,12 +497,10 @@ pub fn mk_assignty<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
498497
-> RelateResult<'tcx, ()> {
499498
debug!("mk_assignty({} -> {})", a.repr(fcx.tcx()), b.repr(fcx.tcx()));
500499
let (adjustment, unsizing_obligation) = try!(indent(|| {
501-
fcx.infcx().commit_if_ok(|| {
502-
let origin = infer::ExprAssignable(expr.span);
500+
fcx.infcx().commit_if_ok(|_| {
503501
let coerce = Coerce {
504502
fcx: fcx,
505503
origin: infer::ExprAssignable(expr.span),
506-
trace: infer::TypeTrace::types(origin, false, a, b),
507504
unsizing_obligation: Cell::new(None)
508505
};
509506
Ok((try!(coerce.coerce(expr, a, b)),

src/librustc_typeck/check/op.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -313,9 +313,15 @@ fn lookup_op_method<'a, 'tcx>(fcx: &'a FnCtxt<'a, 'tcx>,
313313

314314
let method = match trait_did {
315315
Some(trait_did) => {
316-
let noop = ty::AutoDerefRef { autoderefs: 0, autoref: None };
317-
method::lookup_in_trait_adjusted(fcx, expr.span, Some(lhs_expr), opname,
318-
trait_did, noop, lhs_ty, Some(other_tys))
316+
method::lookup_in_trait_adjusted(fcx,
317+
expr.span,
318+
Some(lhs_expr),
319+
opname,
320+
trait_did,
321+
0,
322+
false,
323+
lhs_ty,
324+
Some(other_tys))
319325
}
320326
None => None
321327
};

src/librustc_typeck/check/regionck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ fn link_autoref(rcx: &Rcx,
11341134

11351135
ty::AutoUnsafe(m) => {
11361136
let r = ty::ReScope(CodeExtent::from_node_id(expr.id));
1137-
link_region(rcx, expr.span, r, ty::BorrowKind::from_mutbl(m), expr_cmt);
1137+
link_region(rcx, expr.span, &r, ty::BorrowKind::from_mutbl(m), expr_cmt);
11381138
}
11391139
}
11401140
}

src/librustc_typeck/check/vtable.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use middle::traits::{self, ObjectSafetyViolation, MethodViolationCode};
1313
use middle::traits::{Obligation, ObligationCause};
1414
use middle::traits::report_fulfillment_errors;
1515
use middle::ty::{self, Ty, AsPredicate};
16-
use syntax::ast;
1716
use syntax::codemap::Span;
1817
use util::ppaux::{Repr, UserString};
1918

src/test/compile-fail/associated-type-projection-from-multiple-supertraits.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ fn dent<C:BoxCar>(c: C, color: C::Color) {
3434

3535
fn dent_object<COLOR>(c: BoxCar<Color=COLOR>) {
3636
//~^ ERROR ambiguous associated type
37-
//~| ERROR the associated type `Color` (from the trait `Box`) must be specified
38-
//~| ERROR the associated type `Color` (from the trait `Vehicle`) must be specified
37+
//~| ERROR the value of the associated type `Color` (from the trait `Vehicle`) must be specified
38+
//~| NOTE could derive from `Vehicle`
39+
//~| NOTE could derive from `Box`
3940
}
4041

4142
fn paint<C:BoxCar>(c: C, d: C::Color) {

src/test/compile-fail/issue-22560.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::ops::{Add, Sub};
1414

1515
type Test = Add +
1616
//~^ ERROR the type parameter `RHS` must be explicitly specified in an object type because its default value `Self` references the type `Self`
17+
//~^^ ERROR the value of the associated type `Output` (from the trait `core::ops::Add`) must be specified [E0191]
1718
Sub;
1819
//~^ ERROR only the builtin traits can be used as closure or object bounds
1920

src/test/run-make/save-analysis/foo.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#![ crate_name = "test" ]
1212
#![allow(unstable)]
13-
#![feature(box_syntax, old_io, rustc_private, core)]
13+
#![feature(box_syntax, old_io, rustc_private, core, zero_one)]
1414

1515
extern crate graphviz;
1616
// A simple rust project
@@ -25,7 +25,7 @@ use std::old_io::stdio::println;
2525
use sub::sub2 as msalias;
2626
use sub::sub2;
2727
use sub::sub2::nested_struct as sub_struct;
28-
use std::num::Float;
28+
use std::num::One;
2929
use std::num::cast;
3030
use std::num::{from_int,from_i8,from_i32};
3131

@@ -42,7 +42,7 @@ fn test_alias<I: Iterator>(i: Option<<I as Iterator>::Item>) {
4242
let s = sub_struct{ field2: 45, };
4343

4444
// import tests
45-
fn foo(x: &Float) {}
45+
fn foo(x: &One) {}
4646
let _: Option<u8> = from_i32(45);
4747

4848
let x = 42;

0 commit comments

Comments
 (0)