@@ -1975,13 +1975,17 @@ fn universally_quantify_from_sty(fcx: @fn_ctxt,
1975
1975
bound_tys : [ ty:: t ] ,
1976
1976
sty : ty:: sty ) -> ty:: t {
1977
1977
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
+ }
1985
1989
}
1986
1990
}
1987
1991
@@ -2000,7 +2004,9 @@ fn universally_quantify_regions(fcx: @fn_ctxt,
2000
2004
fn universally_quantify_before_call ( fcx : @fn_ctxt ,
2001
2005
span : span ,
2002
2006
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) ] ;
2004
2010
2005
2011
// This is subtle: we expect `ty` to be a function type, which normally
2006
2012
// 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,
2018
2024
// - Finally, we can use fold_sty_to_ty() and replace_bound_regions()
2019
2025
// to replace the bound regions as well as the bound anonymous region.
2020
2026
// 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) {
2022
2028
sty @ ty:: ty_fn ( fty) {
2023
2029
let all_tys = fty. inputs . map ( { |a| a. ty } ) + [ fty. output ] ;
2024
2030
universally_quantify_from_sty ( fcx, span, all_tys, sty)
2025
2031
}
2026
- _ {
2032
+ sty {
2033
+ #debug[ "not a fn ty: %?", sty] ;
2034
+
2027
2035
// if not a function type, we're gonna' report an error
2028
2036
// at some point, since the user is trying to call this thing
2029
2037
ty
@@ -2719,45 +2727,44 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
2719
2727
let fty = universally_quantify_before_call ( fcx, sp, fty) ;
2720
2728
#debug[ "check_call_or_bind: after universal quant., fty=%s" ,
2721
2729
fcx. ty_to_str ( fty) ] ;
2722
- let sty = structure_of ( fcx, sp, fty) ;
2730
+
2731
+ let supplied_arg_count = vec:: len ( args) ;
2732
+
2723
2733
// 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 == 1 u {
2744
+ ""
2745
+ } else {
2746
+ "s"
2747
+ } ,
2748
+ supplied_arg_count,
2749
+ if supplied_arg_count == 1 u {
2750
+ " was"
2751
+ } else {
2752
+ "s were"
2753
+ } ] ) ;
2754
+ fcx. next_ty_vars ( supplied_arg_count)
2755
+ }
2756
+ }
2757
+
2726
2758
_ {
2759
+ // I would like to make this span_err, but it's really hard due to
2760
+ // the way that expr_bind() is written.
2727
2761
fcx. ccx . tcx . sess . span_fatal ( sp, "mismatched types: \
2728
2762
expected function or native \
2729
2763
function but found "
2730
- + fcx. ty_to_str ( fty) )
2764
+ + fcx. ty_to_str ( fty) ) ;
2731
2765
}
2732
2766
} ;
2733
2767
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 == 1 u {
2742
- ""
2743
- } else {
2744
- "s"
2745
- } ,
2746
- supplied_arg_count,
2747
- if supplied_arg_count == 1 u {
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
-
2761
2768
// Check the arguments.
2762
2769
// We do this in a pretty awful way: first we typecheck any arguments
2763
2770
// that are not anonymous functions, then we typecheck the anonymous
@@ -2775,7 +2782,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
2775
2782
_ { false }
2776
2783
} ;
2777
2784
if is_block == check_blocks {
2778
- let arg_ty = arg_tys[ i] . ty ;
2785
+ let arg_ty = arg_tys[ i] ;
2779
2786
bot |= check_expr_with_unifier ( fcx, a, arg_ty) { ||
2780
2787
demand:: assign ( fcx, a. span , arg_ty, a) ;
2781
2788
} ;
0 commit comments