Skip to content

A couple simple cleanup patches #8889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions src/librustc/middle/typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/*!
* Conversion from AST representation of types to the ty.rs
* representation. The main routine here is `ast_ty_to_ty()`: each use
* is parameterized by an instance of `AstConv` and a `region_scope`.
* is parameterized by an instance of `AstConv` and a `RegionScope`.
*
* The parameterization of `ast_ty_to_ty()` is because it behaves
* somewhat differently during the collect and check phases,
Expand All @@ -23,12 +23,12 @@
* In the check phase, when the @FnCtxt is used as the `AstConv`,
* `get_item_ty()` just looks up the item type in `tcx.tcache`.
*
* The `region_scope` trait controls how region references are
* The `RegionScope` trait controls how region references are
* handled. It has two methods which are used to resolve anonymous
* region references (e.g., `&T`) and named region references (e.g.,
* `&a.T`). There are numerous region scopes that can be used, but most
* commonly you want either `empty_rscope`, which permits only the static
* region, or `type_rscope`, which permits the self region if the type in
* commonly you want either `EmptyRscope`, which permits only the static
* region, or `TypeRscope`, which permits the self region if the type in
* question is parameterized by a region.
*
* Unlike the `AstConv` trait, the region scope can change as we descend
Expand Down Expand Up @@ -58,7 +58,7 @@ use middle::ty::{substs};
use middle::ty::{ty_param_substs_and_ty};
use middle::ty;
use middle::typeck::rscope::in_binding_rscope;
use middle::typeck::rscope::{region_scope, RegionError};
use middle::typeck::rscope::{RegionScope, RegionError};
use middle::typeck::rscope::RegionParamNames;
use middle::typeck::lookup_def_tcx;

Expand Down Expand Up @@ -104,7 +104,7 @@ pub fn get_region_reporting_err(
}
}

pub fn ast_region_to_region<AC:AstConv,RS:region_scope + Clone + 'static>(
pub fn ast_region_to_region<AC:AstConv,RS:RegionScope + Clone + 'static>(
this: &AC,
rscope: &RS,
default_span: span,
Expand All @@ -129,7 +129,7 @@ pub fn ast_region_to_region<AC:AstConv,RS:region_scope + Clone + 'static>(
get_region_reporting_err(this.tcx(), span, opt_lifetime, res)
}

fn ast_path_substs<AC:AstConv,RS:region_scope + Clone + 'static>(
fn ast_path_substs<AC:AstConv,RS:RegionScope + Clone + 'static>(
this: &AC,
rscope: &RS,
def_id: ast::def_id,
Expand Down Expand Up @@ -200,7 +200,7 @@ fn ast_path_substs<AC:AstConv,RS:region_scope + Clone + 'static>(
}

pub fn ast_path_to_substs_and_ty<AC:AstConv,
RS:region_scope + Clone + 'static>(
RS:RegionScope + Clone + 'static>(
this: &AC,
rscope: &RS,
did: ast::def_id,
Expand All @@ -217,7 +217,7 @@ pub fn ast_path_to_substs_and_ty<AC:AstConv,
ty_param_substs_and_ty { substs: substs, ty: ty }
}

pub fn ast_path_to_trait_ref<AC:AstConv,RS:region_scope + Clone + 'static>(
pub fn ast_path_to_trait_ref<AC:AstConv,RS:RegionScope + Clone + 'static>(
this: &AC,
rscope: &RS,
trait_def_id: ast::def_id,
Expand All @@ -240,7 +240,7 @@ pub fn ast_path_to_trait_ref<AC:AstConv,RS:region_scope + Clone + 'static>(
return trait_ref;
}

pub fn ast_path_to_ty<AC:AstConv,RS:region_scope + Clone + 'static>(
pub fn ast_path_to_ty<AC:AstConv,RS:RegionScope + Clone + 'static>(
this: &AC,
rscope: &RS,
did: ast::def_id,
Expand All @@ -262,10 +262,10 @@ pub static NO_TPS: uint = 2;
// Parses the programmer's textual representation of a type into our
// internal notion of a type. `getter` is a function that returns the type
// corresponding to a definition ID:
pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Clone + 'static>(
pub fn ast_ty_to_ty<AC:AstConv, RS:RegionScope + Clone + 'static>(
this: &AC, rscope: &RS, ast_ty: &ast::Ty) -> ty::t {

fn ast_mt_to_mt<AC:AstConv, RS:region_scope + Clone + 'static>(
fn ast_mt_to_mt<AC:AstConv, RS:RegionScope + Clone + 'static>(
this: &AC, rscope: &RS, mt: &ast::mt) -> ty::mt {

ty::mt {ty: ast_ty_to_ty(this, rscope, mt.ty), mutbl: mt.mutbl}
Expand All @@ -274,7 +274,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Clone + 'static>(
// Handle @, ~, and & being able to mean estrs and evecs.
// If a_seq_ty is a str or a vec, make it an estr/evec.
// Also handle first-class trait types.
fn mk_pointer<AC:AstConv,RS:region_scope + Clone + 'static>(
fn mk_pointer<AC:AstConv,RS:RegionScope + Clone + 'static>(
this: &AC,
rscope: &RS,
a_seq_ty: &ast::mt,
Expand Down Expand Up @@ -540,7 +540,7 @@ pub fn ast_ty_to_ty<AC:AstConv, RS:region_scope + Clone + 'static>(
}

pub fn ty_of_arg<AC:AstConv,
RS:region_scope + Clone + 'static>(
RS:RegionScope + Clone + 'static>(
this: &AC,
rscope: &RS,
a: &ast::arg,
Expand Down Expand Up @@ -588,7 +588,7 @@ struct SelfInfo {
explicit_self: ast::explicit_self
}

pub fn ty_of_method<AC:AstConv,RS:region_scope + Clone + 'static>(
pub fn ty_of_method<AC:AstConv,RS:RegionScope + Clone + 'static>(
this: &AC,
rscope: &RS,
purity: ast::purity,
Expand All @@ -606,7 +606,7 @@ pub fn ty_of_method<AC:AstConv,RS:region_scope + Clone + 'static>(
(a.unwrap(), b)
}

pub fn ty_of_bare_fn<AC:AstConv,RS:region_scope + Clone + 'static>(
pub fn ty_of_bare_fn<AC:AstConv,RS:RegionScope + Clone + 'static>(
this: &AC,
rscope: &RS,
purity: ast::purity,
Expand All @@ -619,7 +619,7 @@ pub fn ty_of_bare_fn<AC:AstConv,RS:region_scope + Clone + 'static>(
b
}

fn ty_of_method_or_bare_fn<AC:AstConv,RS:region_scope + Clone + 'static>(
fn ty_of_method_or_bare_fn<AC:AstConv,RS:RegionScope + Clone + 'static>(
this: &AC,
rscope: &RS,
purity: ast::purity,
Expand Down Expand Up @@ -657,7 +657,7 @@ fn ty_of_method_or_bare_fn<AC:AstConv,RS:region_scope + Clone + 'static>(
output: output_ty}
});

fn transform_self_ty<AC:AstConv,RS:region_scope + Clone + 'static>(
fn transform_self_ty<AC:AstConv,RS:RegionScope + Clone + 'static>(
this: &AC,
rscope: &RS,
self_info: &SelfInfo) -> Option<ty::t>
Expand Down Expand Up @@ -690,7 +690,7 @@ fn ty_of_method_or_bare_fn<AC:AstConv,RS:region_scope + Clone + 'static>(
}
}

pub fn ty_of_closure<AC:AstConv,RS:region_scope + Clone + 'static>(
pub fn ty_of_closure<AC:AstConv,RS:RegionScope + Clone + 'static>(
this: &AC,
rscope: &RS,
sigil: ast::Sigil,
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ use middle::typeck::infer::{resolve_type, force_tvar};
use middle::typeck::infer;
use middle::typeck::rscope::bound_self_region;
use middle::typeck::rscope::{RegionError};
use middle::typeck::rscope::region_scope;
use middle::typeck::rscope::RegionScope;
use middle::typeck::{isr_alist, lookup_def_ccx};
use middle::typeck::no_params;
use middle::typeck::{require_same_types, method_map, vtable_map};
Expand Down Expand Up @@ -705,7 +705,7 @@ impl FnCtxt {
}
}

impl region_scope for FnCtxt {
impl RegionScope for FnCtxt {
fn anon_region(&self, span: span) -> Result<ty::Region, RegionError> {
result::Ok(self.infcx().next_region_var(infer::MiscVariable(span)))
}
Expand Down
22 changes: 11 additions & 11 deletions src/librustc/middle/typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,15 @@ pub fn collect_item_types(ccx: @mut CrateCtxt, crate: &ast::Crate) {
}

pub trait ToTy {
fn to_ty<RS:region_scope + Clone + 'static>(
fn to_ty<RS:RegionScope + Clone + 'static>(
&self,
rs: &RS,
ast_ty: &ast::Ty)
-> ty::t;
}

impl ToTy for CrateCtxt {
fn to_ty<RS:region_scope + Clone + 'static>(
fn to_ty<RS:RegionScope + Clone + 'static>(
&self,
rs: &RS,
ast_ty: &ast::Ty)
Expand Down Expand Up @@ -163,7 +163,7 @@ pub fn get_enum_variant_types(ccx: &CrateCtxt,
let result_ty;
match variant.node.kind {
ast::tuple_variant_kind(ref args) if args.len() > 0 => {
let rs = type_rscope(region_parameterization);
let rs = TypeRscope(region_parameterization);
let input_tys = args.map(|va| ccx.to_ty(&rs, &va.ty));
result_ty = Some(ty::mk_ctor_fn(tcx, input_tys, enum_ty));
}
Expand Down Expand Up @@ -724,7 +724,7 @@ pub fn convert_field(ccx: &CrateCtxt,
generics: &ast::Generics) {
let region_parameterization =
RegionParameterization::from_variance_and_generics(rp, generics);
let tt = ccx.to_ty(&type_rscope(region_parameterization), &v.node.ty);
let tt = ccx.to_ty(&TypeRscope(region_parameterization), &v.node.ty);
write_ty_to_tcx(ccx.tcx, v.node.id, tt);
/* add the field to the tcache */
ccx.tcx.tcache.insert(local_def(v.node.id),
Expand Down Expand Up @@ -863,7 +863,7 @@ pub fn convert(ccx: &CrateCtxt, it: &ast::item) {
let i_ty_generics = ty_generics(ccx, rp, generics, 0);
let region_parameterization =
RegionParameterization::from_variance_and_generics(rp, generics);
let selfty = ccx.to_ty(&type_rscope(region_parameterization), selfty);
let selfty = ccx.to_ty(&TypeRscope(region_parameterization), selfty);
write_ty_to_tcx(tcx, it.id, selfty);
tcx.tcache.insert(local_def(it.id),
ty_param_bounds_and_ty {
Expand Down Expand Up @@ -1024,7 +1024,7 @@ pub fn instantiate_trait_ref(ccx: &CrateCtxt,

let rp = RegionParameterization::from_variance_and_generics(rp, generics);

let rscope = type_rscope(rp);
let rscope = TypeRscope(rp);

match lookup_def_tcx(ccx.tcx, ast_trait_ref.path.span, ast_trait_ref.ref_id) {
ast::def_trait(trait_did) => {
Expand Down Expand Up @@ -1099,7 +1099,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item)
let rp = tcx.region_paramd_items.find(&it.id).map_move(|x| *x);
match it.node {
ast::item_static(ref t, _, _) => {
let typ = ccx.to_ty(&empty_rscope, t);
let typ = ccx.to_ty(&EmptyRscope, t);
let tpt = no_params(typ);
tcx.tcache.insert(local_def(it.id), tpt);
return tpt;
Expand All @@ -1108,7 +1108,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item)
assert!(rp.is_none());
let ty_generics = ty_generics(ccx, None, generics, 0);
let tofd = astconv::ty_of_bare_fn(ccx,
&empty_rscope,
&EmptyRscope,
purity,
abi,
&generics.lifetimes,
Expand Down Expand Up @@ -1137,7 +1137,7 @@ pub fn ty_of_item(ccx: &CrateCtxt, it: &ast::item)
let region_parameterization =
RegionParameterization::from_variance_and_generics(rp, generics);
let tpt = {
let ty = ccx.to_ty(&type_rscope(region_parameterization), t);
let ty = ccx.to_ty(&TypeRscope(region_parameterization), t);
ty_param_bounds_and_ty {
generics: ty_generics(ccx, rp, generics, 0),
ty: ty
Expand Down Expand Up @@ -1197,7 +1197,7 @@ pub fn ty_of_foreign_item(ccx: &CrateCtxt,
type_param_defs: @~[],
region_param: None,
},
ty: ast_ty_to_ty(ccx, &empty_rscope, t)
ty: ast_ty_to_ty(ccx, &EmptyRscope, t)
}
}
}
Expand Down Expand Up @@ -1282,7 +1282,7 @@ pub fn ty_of_foreign_fn_decl(ccx: &CrateCtxt,
-> ty::ty_param_bounds_and_ty {
let ty_generics = ty_generics(ccx, None, ast_generics, 0);
let region_param_names = RegionParamNames::from_generics(ast_generics);
let rb = in_binding_rscope(&empty_rscope, region_param_names);
let rb = in_binding_rscope(&EmptyRscope, region_param_names);
let input_tys = decl.inputs.map(|a| ty_of_arg(ccx, &rb, a, None) );
let output_ty = ast_ty_to_ty(ccx, &rb, &decl.output);

Expand Down
38 changes: 19 additions & 19 deletions src/librustc/middle/typeck/rscope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ pub struct RegionError {
replacement: ty::Region
}

pub trait region_scope {
pub trait RegionScope {
fn anon_region(&self, span: span) -> Result<ty::Region, RegionError>;
fn self_region(&self, span: span) -> Result<ty::Region, RegionError>;
fn named_region(&self, span: span, id: ast::ident)
-> Result<ty::Region, RegionError>;
}

#[deriving(Clone)]
pub enum empty_rscope { empty_rscope }
impl region_scope for empty_rscope {
pub struct EmptyRscope;
impl RegionScope for EmptyRscope {
fn anon_region(&self, _span: span) -> Result<ty::Region, RegionError> {
result::Err(RegionError {
msg: ~"only 'static is allowed here",
Expand Down Expand Up @@ -175,7 +175,7 @@ impl MethodRscope {
}
}

impl region_scope for MethodRscope {
impl RegionScope for MethodRscope {
fn anon_region(&self, _span: span) -> Result<ty::Region, RegionError> {
result::Err(RegionError {
msg: ~"anonymous lifetimes are not permitted here",
Expand All @@ -202,7 +202,7 @@ impl region_scope for MethodRscope {
if !self.region_param_names.has_ident(id) {
return RegionParamNames::undeclared_name(None);
}
do empty_rscope.named_region(span, id).chain_err |_e| {
do EmptyRscope.named_region(span, id).chain_err |_e| {
result::Err(RegionError {
msg: ~"lifetime is not in scope",
replacement: ty::re_bound(ty::br_self)
Expand All @@ -212,9 +212,9 @@ impl region_scope for MethodRscope {
}

#[deriving(Clone)]
pub struct type_rscope(Option<RegionParameterization>);
pub struct TypeRscope(Option<RegionParameterization>);

impl type_rscope {
impl TypeRscope {
fn replacement(&self) -> ty::Region {
if self.is_some() {
ty::re_bound(ty::br_self)
Expand All @@ -223,7 +223,7 @@ impl type_rscope {
}
}
}
impl region_scope for type_rscope {
impl RegionScope for TypeRscope {
fn anon_region(&self, _span: span) -> Result<ty::Region, RegionError> {
result::Err(RegionError {
msg: ~"anonymous lifetimes are not permitted here",
Expand Down Expand Up @@ -251,7 +251,7 @@ impl region_scope for type_rscope {
}
fn named_region(&self, span: span, id: ast::ident)
-> Result<ty::Region, RegionError> {
do empty_rscope.named_region(span, id).chain_err |_e| {
do EmptyRscope.named_region(span, id).chain_err |_e| {
result::Err(RegionError {
msg: ~"only 'self is allowed as part of a type declaration",
replacement: self.replacement()
Expand All @@ -268,36 +268,36 @@ pub fn bound_self_region(rp: Option<ty::region_variance>)
}
}

pub struct binding_rscope {
base: @region_scope,
pub struct BindingRscope {
base: @RegionScope,
anon_bindings: @mut uint,
region_param_names: RegionParamNames,
}

impl Clone for binding_rscope {
fn clone(&self) -> binding_rscope {
binding_rscope {
impl Clone for BindingRscope {
fn clone(&self) -> BindingRscope {
BindingRscope {
base: self.base,
anon_bindings: self.anon_bindings,
region_param_names: self.region_param_names.clone(),
}
}
}

pub fn in_binding_rscope<RS:region_scope + Clone + 'static>(
pub fn in_binding_rscope<RS:RegionScope + Clone + 'static>(
this: &RS,
region_param_names: RegionParamNames)
-> binding_rscope {
-> BindingRscope {
let base = @(*this).clone();
let base = base as @region_scope;
binding_rscope {
let base = base as @RegionScope;
BindingRscope {
base: base,
anon_bindings: @mut 0,
region_param_names: region_param_names,
}
}

impl region_scope for binding_rscope {
impl RegionScope for BindingRscope {
fn anon_region(&self, _span: span) -> Result<ty::Region, RegionError> {
let idx = *self.anon_bindings;
*self.anon_bindings += 1;
Expand Down
1 change: 0 additions & 1 deletion src/libstd/fmt/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,6 @@ impl<'self> Parser<'self> {
mod tests {
use super::*;
use prelude::*;
use realstd::fmt::{String};

fn same(fmt: &'static str, p: ~[Piece<'static>]) {
let mut parser = Parser::new(fmt);
Expand Down
Loading