Skip to content

Commit 920bb89

Browse files
committed
---
yaml --- r: 12547 b: refs/heads/master c: f3f34bf h: refs/heads/master i: 12545: e7c19d1 12543: 9ffd073 v: v3
1 parent 761ba1e commit 920bb89

File tree

3 files changed

+61
-52
lines changed

3 files changed

+61
-52
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: bbfb83c2c5501ce3944ea77e7610b83a3bdbfc04
2+
refs/heads/master: f3f34bf09b2512cac0e77281d8f2249d64cf2743
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/rustc/middle/typeck.rs

Lines changed: 49 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1975,13 +1975,17 @@ fn universally_quantify_from_sty(fcx: @fn_ctxt,
19751975
bound_tys: [ty::t],
19761976
sty: ty::sty) -> ty::t {
19771977

1978-
let tcx = fcx.tcx();
1979-
let isr = collect_named_regions_in_tys(tcx, @nil, bound_tys) { |_id|
1980-
fcx.next_region_var()
1981-
};
1982-
let anon_r = fcx.next_region_var();
1983-
ty::fold_sty_to_ty(fcx.ccx.tcx, sty) {|t|
1984-
replace_bound_regions(tcx, span, anon_r, isr, t)
1978+
#debug["universally_quantify_from_sty(bound_tys=%?)",
1979+
bound_tys.map {|x| fcx.ty_to_str(x) }];
1980+
indent {||
1981+
let tcx = fcx.tcx();
1982+
let isr = collect_named_regions_in_tys(tcx, @nil, bound_tys) { |_id|
1983+
fcx.next_region_var()
1984+
};
1985+
let anon_r = fcx.next_region_var();
1986+
ty::fold_sty_to_ty(fcx.ccx.tcx, sty) { |t|
1987+
replace_bound_regions(tcx, span, anon_r, isr, t)
1988+
}
19851989
}
19861990
}
19871991

@@ -2000,7 +2004,9 @@ fn universally_quantify_regions(fcx: @fn_ctxt,
20002004
fn universally_quantify_before_call(fcx: @fn_ctxt,
20012005
span: span,
20022006
ty: ty::t) -> ty::t {
2003-
if !ty::type_has_regions(ty) { ret ty; }
2007+
2008+
#debug["universally_quantify_before_call(ty=%s)",
2009+
fcx.ty_to_str(ty)];
20042010

20052011
// This is subtle: we expect `ty` to be a function type, which normally
20062012
// introduce a level of binding. In this case, we want to process the
@@ -2018,12 +2024,14 @@ fn universally_quantify_before_call(fcx: @fn_ctxt,
20182024
// - Finally, we can use fold_sty_to_ty() and replace_bound_regions()
20192025
// to replace the bound regions as well as the bound anonymous region.
20202026
// We have to use fold_sty_to_ty() to ignore the outer fn().
2021-
alt ty::get(ty).struct {
2027+
alt structure_of(fcx, span, ty) {
20222028
sty @ ty::ty_fn(fty) {
20232029
let all_tys = fty.inputs.map({|a| a.ty}) + [fty.output];
20242030
universally_quantify_from_sty(fcx, span, all_tys, sty)
20252031
}
2026-
_ {
2032+
sty {
2033+
#debug["not a fn ty: %?", sty];
2034+
20272035
// if not a function type, we're gonna' report an error
20282036
// at some point, since the user is trying to call this thing
20292037
ty
@@ -2719,45 +2727,44 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
27192727
let fty = universally_quantify_before_call(fcx, sp, fty);
27202728
#debug["check_call_or_bind: after universal quant., fty=%s",
27212729
fcx.ty_to_str(fty)];
2722-
let sty = structure_of(fcx, sp, fty);
2730+
2731+
let supplied_arg_count = vec::len(args);
2732+
27232733
// Grab the argument types
2724-
let mut arg_tys = alt sty {
2725-
ty::ty_fn({inputs: arg_tys, _}) { arg_tys }
2734+
let arg_tys = alt structure_of(fcx, sp, fty) {
2735+
ty::ty_fn({inputs: arg_tys, output: ret_ty, _}) {
2736+
let expected_arg_count = vec::len(arg_tys);
2737+
if expected_arg_count == supplied_arg_count {
2738+
arg_tys.map { |a| a.ty }
2739+
} else {
2740+
fcx.ccx.tcx.sess.span_err(
2741+
sp, #fmt["this function takes %u parameter%s but %u \
2742+
parameter%s supplied", expected_arg_count,
2743+
if expected_arg_count == 1u {
2744+
""
2745+
} else {
2746+
"s"
2747+
},
2748+
supplied_arg_count,
2749+
if supplied_arg_count == 1u {
2750+
" was"
2751+
} else {
2752+
"s were"
2753+
}]);
2754+
fcx.next_ty_vars(supplied_arg_count)
2755+
}
2756+
}
2757+
27262758
_ {
2759+
// I would like to make this span_err, but it's really hard due to
2760+
// the way that expr_bind() is written.
27272761
fcx.ccx.tcx.sess.span_fatal(sp, "mismatched types: \
27282762
expected function or native \
27292763
function but found "
2730-
+ fcx.ty_to_str(fty))
2764+
+ fcx.ty_to_str(fty));
27312765
}
27322766
};
27332767

2734-
// Check that the correct number of arguments were supplied.
2735-
let expected_arg_count = vec::len(arg_tys);
2736-
let supplied_arg_count = vec::len(args);
2737-
if expected_arg_count != supplied_arg_count {
2738-
fcx.ccx.tcx.sess.span_err(
2739-
sp, #fmt["this function takes %u parameter%s but %u \
2740-
parameter%s supplied", expected_arg_count,
2741-
if expected_arg_count == 1u {
2742-
""
2743-
} else {
2744-
"s"
2745-
},
2746-
supplied_arg_count,
2747-
if supplied_arg_count == 1u {
2748-
" was"
2749-
} else {
2750-
"s were"
2751-
}]);
2752-
2753-
// Just use fresh type variables for the types,
2754-
// since we don't know them.
2755-
arg_tys = vec::from_fn(supplied_arg_count) {|_i|
2756-
{mode: ast::expl(ast::by_ref),
2757-
ty: fcx.next_ty_var()}
2758-
};
2759-
}
2760-
27612768
// Check the arguments.
27622769
// We do this in a pretty awful way: first we typecheck any arguments
27632770
// that are not anonymous functions, then we typecheck the anonymous
@@ -2775,7 +2782,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
27752782
_ { false }
27762783
};
27772784
if is_block == check_blocks {
2778-
let arg_ty = arg_tys[i].ty;
2785+
let arg_ty = arg_tys[i];
27792786
bot |= check_expr_with_unifier(fcx, a, arg_ty) {||
27802787
demand::assign(fcx, a.span, arg_ty, a);
27812788
};

trunk/src/test/compile-fail/regions-scoping.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// xfail-test
2-
31
fn with<T>(t: T, f: fn(T)) { f(t) }
42

53
fn nested(x: &x.int) { // (1)
@@ -26,15 +24,19 @@ fn nested(x: &x.int) { // (1)
2624
//!^ ERROR mismatched types: expected `&x.int` but found `&y.int`
2725
fail;
2826
}
29-
) {|f|
27+
) {|foo|
28+
29+
let a: &x.int = foo(x, x) { |_x, _y, z| z };
30+
let b: &x.int = foo(x, a) { |_x, _y, z| z };
31+
let c: &x.int = foo(a, a) { |_x, _y, z| z };
3032

31-
let a: &x.int = f(x, x) { |_x, _y, z| z };
32-
let b: &x.int = f(x, a) { |_x, _y, z| z };
33-
let c: &x.int = f(a, a) { |_x, _y, z| z };
33+
let z = 3;
34+
let d: &x.int = foo(x, x) { |_x, _y, z| z };
35+
let e: &x.int = foo(x, &z) { |_x, _y, z| z };
36+
let f: &x.int = foo(&z, &z) { |_x, _y, z| z }; //! ERROR mismatched types: expected `&x.int` but found
3437
35-
let d: &x.int = f(x, x) { |_x, _y, z| z };
36-
let e: &x.int = f(x, &a) { |_x, _y, z| z };
37-
let f: &x.int = f(&a, &a) { |_x, _y, z| z };
38+
foo(x, &z) { |x, _y, _z| x }; //! ERROR mismatched types: expected `&z.int` but found `&x.int`
39+
foo(x, &z) { |_x, y, _z| y }; //! ERROR mismatched types: expected `&z.int` but found `&<block at
3840
}
3941
}
4042

0 commit comments

Comments
 (0)