diff --git a/src/rustc/middle/trans/base.rs b/src/rustc/middle/trans/base.rs index d4ee78d19f3..618c7cda97b 100644 --- a/src/rustc/middle/trans/base.rs +++ b/src/rustc/middle/trans/base.rs @@ -1683,7 +1683,7 @@ fn trans_assign_op(bcx: block, ex: @ast::expr, op: ast::binop, fn root_value(bcx: block, val: ValueRef, ty: ty::t, scope_id: ast::node_id) { - if !bcx.sess().opts.no_asm_comments { + if !bcx.sess().no_asm_comments() { add_comment(bcx, #fmt["preserving until end of scope %d", scope_id]); } diff --git a/src/rustc/middle/typeck/astconv.rs b/src/rustc/middle/typeck/astconv.rs index c74d491ff21..2810c6b8c8d 100644 --- a/src/rustc/middle/typeck/astconv.rs +++ b/src/rustc/middle/typeck/astconv.rs @@ -45,6 +45,7 @@ an rptr (`&r.T`) use the region `r` that appears in the rptr. "]; import check::fn_ctxt; +import rscope::*; iface ast_conv { fn tcx() -> ty::ctxt; @@ -55,74 +56,6 @@ iface ast_conv { fn ty_infer(span: span) -> ty::t; } -iface region_scope { - fn anon_region() -> result; - fn named_region(id: str) -> result; -} - -enum empty_rscope { empty_rscope } -impl of region_scope for empty_rscope { - fn anon_region() -> result { - result::err("region types are not allowed here") - } - fn named_region(id: str) -> result { - if id == "static" { result::ok(ty::re_static) } - else { result::err("only the static region is allowed here") } - } -} - -enum type_rscope = ast::region_param; -impl of region_scope for type_rscope { - fn anon_region() -> result { - alt *self { - ast::rp_self { result::ok(ty::re_bound(ty::br_self)) } - ast::rp_none { - result::err("to use region types here, the containing type \ - must be declared with a region bound") - } - } - } - fn named_region(id: str) -> result { - empty_rscope.named_region(id).chain_err { |_e| - if id == "self" { self.anon_region() } - else { - result::err("named regions other than `self` are not \ - allowed as part of a type declaration") - } - } - } -} - -enum anon_rscope = {anon: ty::region, base: region_scope}; -fn in_anon_rscope(self: RS, r: ty::region) - -> @anon_rscope { - @anon_rscope({anon: r, base: self as region_scope}) -} -impl of region_scope for @anon_rscope { - fn anon_region() -> result { - result::ok(self.anon) - } - fn named_region(id: str) -> result { - self.base.named_region(id) - } -} - -enum binding_rscope = {base: region_scope}; -fn in_binding_rscope(self: RS) -> @binding_rscope { - let base = self as region_scope; - @binding_rscope({base: base}) -} -impl of region_scope for @binding_rscope { - fn anon_region() -> result { - result::ok(ty::re_bound(ty::br_anon)) - } - fn named_region(id: str) -> result { - self.base.named_region(id).chain_err {|_e| - result::ok(ty::re_bound(ty::br_named(id))) - } - } -} - fn get_region_reporting_err(tcx: ty::ctxt, span: span, res: result) -> ty::region { diff --git a/src/rustc/middle/typeck/check.rs b/src/rustc/middle/typeck/check.rs index 069fc7fab7d..80894b67b63 100644 --- a/src/rustc/middle/typeck/check.rs +++ b/src/rustc/middle/typeck/check.rs @@ -66,13 +66,13 @@ type parameter). */ -import astconv::{ast_conv, region_scope, empty_rscope, ast_ty_to_ty, - in_anon_rscope}; +import astconv::{ast_conv, ast_ty_to_ty}; import collect::{methods}; // ccx.to_ty() import method::{methods}; // methods for method::lookup import regionmanip::{universally_quantify_regions_before_call, region_of, replace_bound_regions, collect_bound_regions_in_tys}; +import rscope::*; type fn_ctxt = // var_bindings, locals and next_var_id are shared @@ -335,7 +335,7 @@ fn class_types(ccx: @crate_ctxt, members: [@ast::class_member], rp: ast::region_param) -> class_map { let rslt = int_hash::(); - let rs = astconv::type_rscope(rp); + let rs = rscope::type_rscope(rp); for members.each { |m| alt m.node { ast::instance_var(_,t,_,id,_) { @@ -375,7 +375,7 @@ fn check_item(ccx: @crate_ctxt, it: @ast::item) { check_bare_fn(ccx, decl, body, dtor_id, none); } ast::item_impl(tps, rp, _, ty, ms) { - let self_ty = ccx.to_ty(astconv::type_rscope(rp), ty); + let self_ty = ccx.to_ty(rscope::type_rscope(rp), ty); for ms.each {|m| check_method(ccx, m, self_ty);} } ast::item_class(tps, ifaces, members, ctor, m_dtor, rp) { @@ -652,7 +652,7 @@ fn impl_self_ty(fcx: @fn_ctxt, did: ast::def_id) -> ty_param_substs_and_ty { _}, _)) { {n_tps: ts.len(), rp: rp, - raw_ty: fcx.ccx.to_ty(astconv::type_rscope(rp), st)} + raw_ty: fcx.ccx.to_ty(rscope::type_rscope(rp), st)} } some(ast_map::node_item(@{node: ast::item_class(ts, _,_,_,_,rp), id: class_id, _},_)) { diff --git a/src/rustc/middle/typeck/collect.rs b/src/rustc/middle/typeck/collect.rs index a9006e9583a..69c2e778d3d 100644 --- a/src/rustc/middle/typeck/collect.rs +++ b/src/rustc/middle/typeck/collect.rs @@ -20,8 +20,8 @@ are represented as `ty_param()` instances. */ -import astconv::{type_rscope, empty_rscope, in_binding_rscope, ast_conv, - ty_of_fn_decl, ty_of_arg, region_scope, ast_ty_to_ty}; +import astconv::{ast_conv, ty_of_fn_decl, ty_of_arg, ast_ty_to_ty}; +import rscope::*; fn collect_item_types(ccx: @crate_ctxt, crate: @ast::crate) { diff --git a/src/rustc/middle/typeck/rscope.rs b/src/rustc/middle/typeck/rscope.rs new file mode 100644 index 00000000000..cf5d78a0f2f --- /dev/null +++ b/src/rustc/middle/typeck/rscope.rs @@ -0,0 +1,69 @@ +import result::result; + +iface region_scope { + fn anon_region() -> result; + fn named_region(id: str) -> result; +} + +enum empty_rscope { empty_rscope } +impl of region_scope for empty_rscope { + fn anon_region() -> result { + result::err("region types are not allowed here") + } + fn named_region(id: str) -> result { + if id == "static" { result::ok(ty::re_static) } + else { result::err("only the static region is allowed here") } + } +} + +enum type_rscope = ast::region_param; +impl of region_scope for type_rscope { + fn anon_region() -> result { + alt *self { + ast::rp_self { result::ok(ty::re_bound(ty::br_self)) } + ast::rp_none { + result::err("to use region types here, the containing type \ + must be declared with a region bound") + } + } + } + fn named_region(id: str) -> result { + empty_rscope.named_region(id).chain_err { |_e| + if id == "self" { self.anon_region() } + else { + result::err("named regions other than `self` are not \ + allowed as part of a type declaration") + } + } + } +} + +enum anon_rscope = {anon: ty::region, base: region_scope}; +fn in_anon_rscope(self: RS, r: ty::region) + -> @anon_rscope { + @anon_rscope({anon: r, base: self as region_scope}) +} +impl of region_scope for @anon_rscope { + fn anon_region() -> result { + result::ok(self.anon) + } + fn named_region(id: str) -> result { + self.base.named_region(id) + } +} + +enum binding_rscope = {base: region_scope}; +fn in_binding_rscope(self: RS) -> @binding_rscope { + let base = self as region_scope; + @binding_rscope({base: base}) +} +impl of region_scope for @binding_rscope { + fn anon_region() -> result { + result::ok(ty::re_bound(ty::br_anon)) + } + fn named_region(id: str) -> result { + self.base.named_region(id).chain_err {|_e| + result::ok(ty::re_bound(ty::br_named(id))) + } + } +} diff --git a/src/rustc/rustc.rc b/src/rustc/rustc.rc index 74a48820d9d..fb4468754ca 100644 --- a/src/rustc/rustc.rc +++ b/src/rustc/rustc.rc @@ -61,6 +61,7 @@ mod middle { mod demand; mod method; } + mod rscope; mod astconv; mod infer; mod collect;