@@ -845,16 +845,14 @@ fn scope_closes(sc: scope) -> option::t<node_id> {
845
845
}
846
846
847
847
fn def_is_local ( d : def ) -> bool {
848
- ret alt d {
849
- ast : : def_arg ( _, _) | ast:: def_local ( _, _) | ast:: def_binding ( _) |
850
- ast:: def_upvar ( _, _, _) {
851
- true
852
- }
853
- _ { false }
854
- } ;
848
+ alt d {
849
+ ast : : def_arg ( _, _) | ast:: def_local ( _, _) | ast:: def_binding ( _) |
850
+ ast:: def_upvar ( _, _, _) { true }
851
+ _ { false }
852
+ }
855
853
}
856
854
857
- fn def_is_obj_field ( d : def ) -> bool {
855
+ fn def_has_obj_scope ( d : def ) -> bool {
858
856
alt d {
859
857
ast : : def_obj_field ( _, _) | ast:: def_self ( _) { true }
860
858
_ { false }
@@ -947,37 +945,32 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
947
945
let fnd = in_scope ( e, sp, name, hd, ns) ;
948
946
if !is_none ( fnd) {
949
947
let df = option:: get ( fnd) ;
950
- let local = def_is_local ( df) ;
951
- if left_fn && local || left_fn_level2 && def_is_obj_field ( df)
952
- || scope_is_fn ( hd) && left_fn && def_is_ty_arg ( df) {
953
- let msg =
954
- alt ns {
955
- ns_type. {
956
- "Attempt to use a type argument out of scope"
957
- }
958
- ns_val ( v) {
959
- alt ( v) {
960
- ns_a_tag. {
961
- /* If we were looking for a tag, at this point
962
- we know it's bound to a non-tag value, and
963
- we can return none instead of failing */
964
- ret none ;
965
- }
966
- _ {
967
- "attempted dynamic environment-capture"
968
- }
969
- }
948
+ let local = def_is_local ( df) ,
949
+ obj_scope = def_has_obj_scope ( df) ;
950
+ if left_fn && local || left_fn_level2 && obj_scope
951
+ || scope_is_fn ( hd) && left_fn && def_is_ty_arg ( df) {
952
+ let msg = alt ns {
953
+ ns_type. {
954
+ "attempt to use a type argument out of scope"
955
+ }
956
+ ns_val ( v) {
957
+ alt ( v) {
958
+ /* If we were looking for a tag, at this point
959
+ we know it's bound to a non-tag value, and
960
+ we can return none instead of failing */
961
+ ns_a_tag. { ret none ; }
962
+ _ { "attempted dynamic environment-capture" }
970
963
}
971
- _ { "attempted dynamic environment-capture" }
972
- } ;
964
+ }
965
+ _ { "attempted dynamic environment-capture" }
966
+ } ;
973
967
e. sess . span_fatal ( sp, msg) ;
974
- } else if local {
968
+ } else if local || obj_scope {
975
969
let i = vec:: len ( closing) ;
976
970
while i > 0 u {
977
971
i -= 1 u;
978
- df =
979
- ast:: def_upvar ( def_id_of_def ( df) , @df,
980
- closing[ i] ) ;
972
+ df = ast:: def_upvar ( def_id_of_def ( df) , @df,
973
+ closing[ i] ) ;
981
974
fnd = some ( df) ;
982
975
}
983
976
}
0 commit comments