diff --git a/src/librustc/front/core_inject.rs b/src/librustc/front/core_inject.rs index a7c015d29a187..387cc9f80a7f6 100644 --- a/src/librustc/front/core_inject.rs +++ b/src/librustc/front/core_inject.rs @@ -77,7 +77,7 @@ fn inject_libcore_ref(sess: Session, fold_mod: |module, fld| { let n2 = sess.next_node_id(); - let prelude_path = @ast::path { + let prelude_path = @ast::Path { span: dummy_sp(), global: false, idents: ~[ diff --git a/src/librustc/front/test.rs b/src/librustc/front/test.rs index 139ffbb5f5bb3..0cb1fdf91829a 100644 --- a/src/librustc/front/test.rs +++ b/src/librustc/front/test.rs @@ -336,16 +336,16 @@ fn nospan(t: T) -> codemap::spanned { codemap::spanned { node: t, span: dummy_sp() } } -fn path_node(+ids: ~[ast::ident]) -> @ast::path { - @ast::path { span: dummy_sp(), +fn path_node(+ids: ~[ast::ident]) -> @ast::Path { + @ast::Path { span: dummy_sp(), global: false, idents: ids, rp: None, types: ~[] } } -fn path_node_global(+ids: ~[ast::ident]) -> @ast::path { - @ast::path { span: dummy_sp(), +fn path_node_global(+ids: ~[ast::ident]) -> @ast::Path { + @ast::Path { span: dummy_sp(), global: true, idents: ids, rp: None, diff --git a/src/librustc/metadata/tydecode.rs b/src/librustc/metadata/tydecode.rs index 867fe0cd816cc..72391b7aec2a1 100644 --- a/src/librustc/metadata/tydecode.rs +++ b/src/librustc/metadata/tydecode.rs @@ -137,7 +137,7 @@ pub fn parse_arg_data(data: @~[u8], crate_num: int, pos: uint, tcx: ty::ctxt, parse_arg(st, conv) } -fn parse_path(st: @mut PState) -> @ast::path { +fn parse_path(st: @mut PState) -> @ast::Path { let mut idents: ~[ast::ident] = ~[]; fn is_last(c: char) -> bool { return c == '(' || c == ':'; } idents.push(parse_ident_(st, is_last)); @@ -146,7 +146,7 @@ fn parse_path(st: @mut PState) -> @ast::path { ':' => { next(st); next(st); } c => { if c == '(' { - return @ast::path { span: dummy_sp(), + return @ast::Path { span: dummy_sp(), global: false, idents: idents, rp: None, diff --git a/src/librustc/middle/pat_util.rs b/src/librustc/middle/pat_util.rs index 2e2048b7ae4cd..df0e508398ee4 100644 --- a/src/librustc/middle/pat_util.rs +++ b/src/librustc/middle/pat_util.rs @@ -72,7 +72,7 @@ pub fn pat_is_binding_or_wild(dm: resolve::DefMap, pat: @pat) -> bool { } pub fn pat_bindings(dm: resolve::DefMap, pat: @pat, - it: &fn(binding_mode, node_id, span, @path)) { + it: &fn(binding_mode, node_id, span, @Path)) { do walk_pat(pat) |p| { match p.node { pat_ident(binding_mode, pth, _) if pat_is_binding(dm, p) => { diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 50e8ed23446de..e59ca9e658123 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -26,7 +26,7 @@ use syntax::ast::{decl_item, def, def_fn, def_id, def_static_method}; use syntax::ast::{def_variant, expr_field, expr_method_call, expr_path}; use syntax::ast::{expr_struct, expr_unary, ident, inherited, item_enum}; use syntax::ast::{item_foreign_mod, item_fn, item_impl, item_struct}; -use syntax::ast::{item_trait, local_crate, node_id, pat_struct, path}; +use syntax::ast::{item_trait, local_crate, node_id, pat_struct, Path}; use syntax::ast::{private, provided, public, required, stmt_decl, visibility}; use syntax::ast; use syntax::ast_map::{node_foreign_item, node_item, node_method}; @@ -276,7 +276,7 @@ pub fn check_crate(tcx: ty::ctxt, }; // Checks that a private path is in scope. - let check_path: @fn(span: span, def: def, path: @path) = + let check_path: @fn(span: span, def: def, path: @Path) = |span, def, path| { debug!("checking path"); match def { diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index fcf0b7022a7a7..1c4a1c4564796 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -48,7 +48,7 @@ use syntax::ast::{item_const, item_enum, item_fn, item_foreign_mod}; use syntax::ast::{item_impl, item_mac, item_mod, item_trait, item_ty, le}; use syntax::ast::{local, local_crate, lt, method, mode, mul}; use syntax::ast::{named_field, ne, neg, node_id, pat, pat_enum, pat_ident}; -use syntax::ast::{path, pat_lit, pat_range, pat_struct}; +use syntax::ast::{Path, pat_lit, pat_range, pat_struct}; use syntax::ast::{prim_ty, private, provided}; use syntax::ast::{public, required, rem, self_ty_, shl, shr, stmt_decl}; use syntax::ast::{struct_dtor, struct_field, struct_variant_kind}; @@ -4368,7 +4368,7 @@ pub impl Resolver { /// If `check_ribs` is true, checks the local definitions first; i.e. /// doesn't skip straight to the containing module. fn resolve_path(@mut self, - path: @path, + path: @Path, namespace: Namespace, check_ribs: bool, visitor: ResolveVisitor) @@ -4493,7 +4493,7 @@ pub impl Resolver { return NoNameDefinition; } - fn intern_module_part_of_path(@mut self, path: @path) -> ~[ident] { + fn intern_module_part_of_path(@mut self, path: @Path) -> ~[ident] { let mut module_path_idents = ~[]; for path.idents.eachi |index, ident| { if index == path.idents.len() - 1 { @@ -4507,7 +4507,7 @@ pub impl Resolver { } fn resolve_module_relative_path(@mut self, - path: @path, + path: @Path, +xray: XrayFlag, namespace: Namespace) -> Option { @@ -4553,7 +4553,7 @@ pub impl Resolver { /// Invariant: This must be called only during main resolution, not during /// import resolution. fn resolve_crate_relative_path(@mut self, - path: @path, + path: @Path, +xray: XrayFlag, namespace: Namespace) -> Option { diff --git a/src/librustc/middle/typeck/astconv.rs b/src/librustc/middle/typeck/astconv.rs index bfc9d646dbb6c..a0c12ff1a204c 100644 --- a/src/librustc/middle/typeck/astconv.rs +++ b/src/librustc/middle/typeck/astconv.rs @@ -136,7 +136,7 @@ fn ast_path_substs( def_id: ast::def_id, decl_generics: &ty::Generics, self_ty: Option, - path: @ast::path) -> ty::substs + path: @ast::Path) -> ty::substs { /*! * @@ -188,7 +188,7 @@ pub fn ast_path_to_substs_and_ty( self: &AC, rscope: &RS, did: ast::def_id, - path: @ast::path) -> ty_param_substs_and_ty + path: @ast::Path) -> ty_param_substs_and_ty { let tcx = self.tcx(); let ty::ty_param_bounds_and_ty { @@ -206,7 +206,7 @@ pub fn ast_path_to_trait_ref( rscope: &RS, trait_def_id: ast::def_id, self_ty: Option, - path: @ast::path) -> @ty::TraitRef + path: @ast::Path) -> @ty::TraitRef { let trait_def = self.get_trait_def(trait_def_id); @@ -229,7 +229,7 @@ pub fn ast_path_to_ty( self: &AC, rscope: &RS, did: ast::def_id, - path: @ast::path) + path: @ast::Path) -> ty_param_substs_and_ty { // Look up the polytype of the item and then substitute the provided types @@ -318,7 +318,7 @@ pub fn ast_ty_to_ty( } fn check_path_args(tcx: ty::ctxt, - path: @ast::path, + path: @ast::Path, flags: uint) { if (flags & NO_TPS) != 0u { if path.types.len() > 0u { diff --git a/src/librustc/middle/typeck/check/_match.rs b/src/librustc/middle/typeck/check/_match.rs index aa2414eac6240..e2dd0d1ed9ed2 100644 --- a/src/librustc/middle/typeck/check/_match.rs +++ b/src/librustc/middle/typeck/check/_match.rs @@ -99,7 +99,7 @@ pub struct pat_ctxt { block_region: ty::Region, // Region for the block of the arm } -pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path, +pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::Path, subpats: &Option<~[@ast::pat]>, expected: ty::t) { // Typecheck the path. @@ -234,7 +234,7 @@ pub fn check_pat_variant(pcx: pat_ctxt, pat: @ast::pat, path: @ast::path, /// `etc` is true if the pattern said '...' and false otherwise. pub fn check_struct_pat_fields(pcx: pat_ctxt, span: span, - path: @ast::path, + path: @ast::Path, fields: &[ast::field_pat], class_fields: ~[ty::field_ty], class_id: ast::def_id, @@ -285,7 +285,7 @@ pub fn check_struct_pat_fields(pcx: pat_ctxt, } pub fn check_struct_pat(pcx: pat_ctxt, pat_id: ast::node_id, span: span, - expected: ty::t, path: @ast::path, + expected: ty::t, path: @ast::Path, fields: &[ast::field_pat], etc: bool, class_id: ast::def_id, substitutions: &ty::substs) { let fcx = pcx.fcx; @@ -326,7 +326,7 @@ pub fn check_struct_like_enum_variant_pat(pcx: pat_ctxt, pat_id: ast::node_id, span: span, expected: ty::t, - path: @ast::path, + path: @ast::Path, fields: &[ast::field_pat], etc: bool, enum_id: ast::def_id, diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 2455201907447..0eb2e5387c3bc 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -3211,7 +3211,7 @@ pub fn ty_param_bounds_and_ty_for_def(fcx: @mut FnCtxt, // Instantiates the given path, which must refer to an item with the given // number of type parameters and type. pub fn instantiate_path(fcx: @mut FnCtxt, - pth: @ast::path, + pth: @ast::Path, tpt: ty_param_bounds_and_ty, span: span, node_id: ast::node_id, diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index ec77b54a85371..4add371a36f82 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -113,7 +113,7 @@ pub struct Lifetime { #[auto_encode] #[auto_decode] #[deriving(Eq)] -pub struct path { +pub struct Path { span: span, global: bool, idents: ~[ident], @@ -301,10 +301,10 @@ pub enum pat_ { // which it is. The resolver determines this, and // records this pattern's node_id in an auxiliary // set (of "pat_idents that refer to nullary enums") - pat_ident(binding_mode, @path, Option<@pat>), - pat_enum(@path, Option<~[@pat]>), /* "none" means a * pattern where + pat_ident(binding_mode, @Path, Option<@pat>), + pat_enum(@Path, Option<~[@pat]>), /* "none" means a * pattern where * we don't bind the fields to names */ - pat_struct(@path, ~[field_pat], bool), + pat_struct(@Path, ~[field_pat], bool), pat_tup(~[@pat]), pat_box(@pat), pat_uniq(@pat), @@ -567,7 +567,7 @@ pub enum expr_ { expr_assign_op(binop, @expr, @expr), expr_field(@expr, ident, ~[@Ty]), expr_index(@expr, @expr), - expr_path(@path), + expr_path(@Path), expr_addr_of(mutability, @expr), expr_break(Option), expr_again(Option), @@ -579,7 +579,7 @@ pub enum expr_ { expr_mac(mac), // A struct literal expression. - expr_struct(@path, ~[field], Option<@expr>), + expr_struct(@Path, ~[field], Option<@expr>), // A vector literal constructed from one repeated element. expr_repeat(@expr /* element */, @expr /* count */, mutability), @@ -697,7 +697,7 @@ pub type mac = spanned; #[auto_decode] #[deriving(Eq)] pub enum mac_ { - mac_invoc_tt(@path,~[token_tree]), // new macro-invocation + mac_invoc_tt(@Path,~[token_tree]), // new macro-invocation } pub type lit = spanned; @@ -894,7 +894,7 @@ pub enum ty_ { ty_closure(@TyClosure), ty_bare_fn(@TyBareFn), ty_tup(~[@Ty]), - ty_path(@path, node_id), + ty_path(@Path, node_id), ty_mac(mac), // ty_infer means the type should be inferred instead of it having been // specified. This should only appear at the "top level" of a type and not @@ -1118,13 +1118,13 @@ pub enum view_path_ { // or just // // foo::bar::baz (with 'baz =' implicitly on the left) - view_path_simple(ident, @path, namespace, node_id), + view_path_simple(ident, @Path, namespace, node_id), // foo::bar::* - view_path_glob(@path, node_id), + view_path_glob(@Path, node_id), // foo::bar::{a,b,c} - view_path_list(@path, ~[path_list_ident], node_id) + view_path_list(@Path, ~[path_list_ident], node_id) } #[auto_encode] @@ -1177,7 +1177,7 @@ pub struct attribute_ { #[auto_decode] #[deriving(Eq)] pub struct trait_ref { - path: @path, + path: @Path, ref_id: node_id, } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index c7227fa17687c..e83a3ef8bad52 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -30,7 +30,7 @@ pub fn path_name_i(idents: &[ident], intr: @token::ident_interner) -> ~str { } -pub fn path_to_ident(p: @path) -> ident { copy *p.idents.last() } +pub fn path_to_ident(p: @Path) -> ident { copy *p.idents.last() } pub fn local_def(id: node_id) -> def_id { ast::def_id { crate: local_crate, node: id } @@ -223,8 +223,8 @@ pub fn default_block( } } -pub fn ident_to_path(s: span, +i: ident) -> @path { - @ast::path { span: s, +pub fn ident_to_path(s: span, +i: ident) -> @Path { + @ast::Path { span: s, global: false, idents: ~[i], rp: None, diff --git a/src/libsyntax/codemap.rs b/src/libsyntax/codemap.rs index fc08073686d0d..0ed371d9c9afe 100644 --- a/src/libsyntax/codemap.rs +++ b/src/libsyntax/codemap.rs @@ -206,8 +206,12 @@ pub struct FileLines lines: ~[uint] } +// represents the origin of a file: pub enum FileSubstr { + // indicates that this is a normal standalone file: pub FssNone, + // indicates that this "file" is actually a substring + // of another file that appears earlier in the codemap pub FssInternal(span), } diff --git a/src/libsyntax/ext/auto_encode.rs b/src/libsyntax/ext/auto_encode.rs index 97bc89248acf2..f9dadb560e3d0 100644 --- a/src/libsyntax/ext/auto_encode.rs +++ b/src/libsyntax/ext/auto_encode.rs @@ -224,7 +224,7 @@ priv impl @ext_ctxt { &self, _span: span, ident: ast::ident, - path: @ast::path, + path: @ast::Path, bounds: @OptVec ) -> ast::TyParam { let bound = ast::TraitTyParamBound(@ast::trait_ref { @@ -248,8 +248,8 @@ priv impl @ext_ctxt { } } - fn path(&self, span: span, +strs: ~[ast::ident]) -> @ast::path { - @ast::path { + fn path(&self, span: span, +strs: ~[ast::ident]) -> @ast::Path { + @ast::Path { span: span, global: false, idents: strs, @@ -258,8 +258,8 @@ priv impl @ext_ctxt { } } - fn path_global(&self, span: span, +strs: ~[ast::ident]) -> @ast::path { - @ast::path { + fn path_global(&self, span: span, +strs: ~[ast::ident]) -> @ast::Path { + @ast::Path { span: span, global: true, idents: strs, @@ -273,8 +273,8 @@ priv impl @ext_ctxt { span: span, +strs: ~[ast::ident], +tps: ~[@ast::Ty] - ) -> @ast::path { - @ast::path { + ) -> @ast::Path { + @ast::Path { span: span, global: false, idents: strs, @@ -288,8 +288,8 @@ priv impl @ext_ctxt { span: span, +strs: ~[ast::ident], +tps: ~[@ast::Ty] - ) -> @ast::path { - @ast::path { + ) -> @ast::Path { + @ast::Path { span: span, global: true, idents: strs, @@ -439,7 +439,7 @@ fn mk_impl( span: span, ident: ast::ident, ty_param: ast::TyParam, - path: @ast::path, + path: @ast::Path, generics: &ast::Generics, f: &fn(@ast::Ty) -> @ast::method ) -> @ast::item { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 43f0c9edcb964..0f84ac4153272 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -63,8 +63,8 @@ pub fn mk_unary(cx: @ext_ctxt, sp: span, op: ast::unop, e: @ast::expr) cx.next_id(); // see ast_util::op_expr_callee_id mk_expr(cx, sp, ast::expr_unary(op, e)) } -pub fn mk_raw_path(sp: span, +idents: ~[ast::ident]) -> @ast::path { - let p = @ast::path { span: sp, +pub fn mk_raw_path(sp: span, +idents: ~[ast::ident]) -> @ast::Path { + let p = @ast::Path { span: sp, global: false, idents: idents, rp: None, @@ -74,15 +74,15 @@ pub fn mk_raw_path(sp: span, +idents: ~[ast::ident]) -> @ast::path { pub fn mk_raw_path_(sp: span, +idents: ~[ast::ident], +types: ~[@ast::Ty]) - -> @ast::path { - @ast::path { span: sp, + -> @ast::Path { + @ast::Path { span: sp, global: false, idents: idents, rp: None, types: types } } -pub fn mk_raw_path_global(sp: span, +idents: ~[ast::ident]) -> @ast::path { - @ast::path { span: sp, +pub fn mk_raw_path_global(sp: span, +idents: ~[ast::ident]) -> @ast::Path { + @ast::Path { span: sp, global: true, idents: idents, rp: None, @@ -295,7 +295,7 @@ pub fn mk_pat_ident_with_binding_mode(cx: @ext_ctxt, } pub fn mk_pat_enum(cx: @ext_ctxt, span: span, - path: @ast::path, + path: @ast::Path, +subpats: ~[@ast::pat]) -> @ast::pat { let pat = ast::pat_enum(path, Some(subpats)); @@ -303,7 +303,7 @@ pub fn mk_pat_enum(cx: @ext_ctxt, } pub fn mk_pat_struct(cx: @ext_ctxt, span: span, - path: @ast::path, + path: @ast::Path, +field_pats: ~[ast::field_pat]) -> @ast::pat { let pat = ast::pat_struct(path, field_pats, false); diff --git a/src/libsyntax/ext/concat_idents.rs b/src/libsyntax/ext/concat_idents.rs index 0c3bef56459b5..f4901191b8ac9 100644 --- a/src/libsyntax/ext/concat_idents.rs +++ b/src/libsyntax/ext/concat_idents.rs @@ -41,7 +41,7 @@ pub fn expand_syntax_ext(cx: @ext_ctxt, sp: span, tts: &[ast::token_tree]) id: cx.next_id(), callee_id: cx.next_id(), node: ast::expr_path( - @ast::path { + @ast::Path { span: sp, global: false, idents: ~[res], diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index ccd9a33757dd5..4337546930ff9 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -185,7 +185,7 @@ pub fn create_derived_impl(cx: @ext_ctxt, }); // Create the reference to the trait. - let trait_path = ast::path { + let trait_path = ast::Path { span: span, global: true, idents: trait_path.map(|x| *x), diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs index 1d1a101d61f1d..5eea58b89b1c6 100644 --- a/src/libsyntax/ext/pipes/ast_builder.rs +++ b/src/libsyntax/ext/pipes/ast_builder.rs @@ -34,16 +34,16 @@ mod syntax { pub use parse; } -pub fn path(+ids: ~[ident], span: span) -> @ast::path { - @ast::path { span: span, +pub fn path(+ids: ~[ident], span: span) -> @ast::Path { + @ast::Path { span: span, global: false, idents: ids, rp: None, types: ~[] } } -pub fn path_global(+ids: ~[ident], span: span) -> @ast::path { - @ast::path { span: span, +pub fn path_global(+ids: ~[ident], span: span) -> @ast::Path { + @ast::Path { span: span, global: true, idents: ids, rp: None, @@ -51,20 +51,20 @@ pub fn path_global(+ids: ~[ident], span: span) -> @ast::path { } pub trait append_types { - fn add_ty(&self, ty: @ast::Ty) -> @ast::path; - fn add_tys(&self, +tys: ~[@ast::Ty]) -> @ast::path; + fn add_ty(&self, ty: @ast::Ty) -> @ast::Path; + fn add_tys(&self, +tys: ~[@ast::Ty]) -> @ast::Path; } -impl append_types for @ast::path { - fn add_ty(&self, ty: @ast::Ty) -> @ast::path { - @ast::path { +impl append_types for @ast::Path { + fn add_ty(&self, ty: @ast::Ty) -> @ast::Path { + @ast::Path { types: vec::append_one(copy self.types, ty), .. copy **self } } - fn add_tys(&self, +tys: ~[@ast::Ty]) -> @ast::path { - @ast::path { + fn add_tys(&self, +tys: ~[@ast::Ty]) -> @ast::Path { + @ast::Path { types: vec::append(copy self.types, tys), .. copy **self } @@ -108,7 +108,7 @@ pub trait ext_ctxt_ast_builder { span: span, +struct_def: ast::struct_def) -> @ast::item; fn struct_expr(&self, - path: @ast::path, + path: @ast::Path, +fields: ~[ast::field]) -> @ast::expr; fn variant(&self, name: ident, @@ -118,7 +118,7 @@ pub trait ext_ctxt_ast_builder { name: ident, span: span, +items: ~[@ast::item]) -> @ast::item; - fn ty_path_ast_builder(&self, path: @ast::path) -> @ast::Ty; + fn ty_path_ast_builder(&self, path: @ast::Path) -> @ast::Ty; fn item_ty_poly(&self, name: ident, span: span, @@ -328,7 +328,7 @@ impl ext_ctxt_ast_builder for @ext_ctxt { self.item(name, span, ast::item_struct(@struct_def, generics)) } - fn struct_expr(&self, path: @ast::path, + fn struct_expr(&self, path: @ast::Path, +fields: ~[ast::field]) -> @ast::expr { @ast::expr { id: self.next_id(), @@ -397,7 +397,7 @@ impl ext_ctxt_ast_builder for @ext_ctxt { ) } - fn ty_path_ast_builder(&self, path: @ast::path) -> @ast::Ty { + fn ty_path_ast_builder(&self, path: @ast::Path) -> @ast::Ty { @ast::Ty { id: self.next_id(), node: ast::ty_path(path, self.next_id()), diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 5aa51c262e174..768dba2141250 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -36,7 +36,7 @@ pub trait ast_fold { fn fold_foreign_mod(@self, &foreign_mod) -> foreign_mod; fn fold_variant(@self, &variant) -> variant; fn fold_ident(@self, ident) -> ident; - fn fold_path(@self, @path) -> @path; + fn fold_path(@self, @Path) -> @Path; fn fold_local(@self, @local) -> @local; fn map_exprs(@self, @fn(@expr) -> @expr, &[@expr]) -> ~[@expr]; fn new_id(@self, node_id) -> node_id; @@ -65,7 +65,7 @@ pub struct AstFoldFns { fold_foreign_mod: @fn(&foreign_mod, @ast_fold) -> foreign_mod, fold_variant: @fn(&variant_, span, @ast_fold) -> (variant_, span), fold_ident: @fn(ident, @ast_fold) -> ident, - fold_path: @fn(@path, @ast_fold) -> path, + fold_path: @fn(@Path, @ast_fold) -> Path, fold_local: @fn(&local_, span, @ast_fold) -> (local_, span), map_exprs: @fn(@fn(@expr) -> @expr, &[@expr]) -> ~[@expr], new_id: @fn(node_id) -> node_id, @@ -702,8 +702,8 @@ fn noop_fold_ident(i: ident, _fld: @ast_fold) -> ident { /* FIXME (#2543) */ copy i } -fn noop_fold_path(p: @path, fld: @ast_fold) -> path { - ast::path { +fn noop_fold_path(p: @Path, fld: @ast_fold) -> Path { + ast::Path { span: fld.new_span(p.span), global: p.global, idents: p.idents.map(|x| fld.fold_ident(*x)), @@ -851,7 +851,7 @@ impl ast_fold for AstFoldFns { fn fold_ident(@self, x: ident) -> ident { (self.fold_ident)(x, self as @ast_fold) } - fn fold_path(@self, x: @path) -> @path { + fn fold_path(@self, x: @Path) -> @Path { @(self.fold_path)(x, self as @ast_fold) } fn fold_local(@self, x: @local) -> @local { diff --git a/src/libsyntax/parse/eval.rs b/src/libsyntax/parse/eval.rs deleted file mode 100644 index 5d44db084d600..0000000000000 --- a/src/libsyntax/parse/eval.rs +++ /dev/null @@ -1,174 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use parser::Parser; -use attr::parser_attr; -use codemap::{span, mk_sp}; - -type ctx = - @{sess: parse::parse_sess, - cfg: ast::crate_cfg}; - -fn eval_crate_directives(cx: ctx, - cdirs: ~[@ast::crate_directive], - prefix: &Path, - view_items: &mut~[@ast::view_item], - items: &mut~[@ast::item]) { - for cdirs.each |sub_cdir| { - eval_crate_directive(cx, *sub_cdir, prefix, view_items, items); - } -} - -pub fn eval_crate_directives_to_mod(cx: ctx, cdirs: ~[@ast::crate_directive], - prefix: &Path, suffix: &Option) - -> (ast::_mod, ~[ast::attribute]) { - let (cview_items, citems, cattrs) - = parse_companion_mod(cx, prefix, suffix); - let mut view_items: ~[@ast::view_item] = ~[]; - let mut items: ~[@ast::item] = ~[]; - eval_crate_directives(cx, cdirs, prefix, &mut view_items, &mut items); - return ({view_items: vec::append(view_items, cview_items), - items: vec::append(items, citems)}, - cattrs); -} - -/* -The 'companion mod'. So .rc crates and directory mod crate directives define -modules but not a .rs file to fill those mods with stuff. The companion mod is -a convention for location a .rs file to go with them. For .rc files the -companion mod is a .rs file with the same name; for directory mods the -companion mod is a .rs file with the same name as the directory. - -We build the path to the companion mod by combining the prefix and the -optional suffix then adding the .rs extension. -*/ -fn parse_companion_mod(cx: ctx, prefix: &Path, suffix: &Option) - -> (~[@ast::view_item], ~[@ast::item], ~[ast::attribute]) { - - fn companion_file(prefix: &Path, suffix: &Option) -> Path { - return match *suffix { - option::Some(s) => prefix.push_many(s.components), - option::None => copy *prefix - }.with_filetype("rs"); - } - - fn file_exists(path: &Path) -> bool { - // Crude, but there's no lib function for this and I'm not - // up to writing it just now - match io::file_reader(path) { - result::Ok(_) => true, - result::Err(_) => false - } - } - - let modpath = &companion_file(prefix, suffix); - if file_exists(modpath) { - debug!("found companion mod"); - // XXX: Using a dummy span, but this code will go away soon - let p0 = new_sub_parser_from_file(cx.sess, cx.cfg, - modpath, - codemap::dummy_sp()); - let (inner, next) = p0.parse_inner_attrs_and_next(); - let m0 = p0.parse_mod_items(token::EOF, next); - return (m0.view_items, m0.items, inner); - } else { - return (~[], ~[], ~[]); - } -} - -fn cdir_path_opt(default: ~str, attrs: ~[ast::attribute]) -> ~str { - match ::attr::first_attr_value_str_by_name(attrs, ~"path") { - Some(d) => d, - None => default - } -} - -pub fn eval_src_mod(cx: ctx, prefix: &Path, - outer_attrs: ~[ast::attribute], - id: ast::ident, sp: span) - -> (ast::item_, ~[ast::attribute]) { - let file_path = Path(cdir_path_opt( - cx.sess.interner.get(id) + ~".rs", outer_attrs)); - eval_src_mod_from_path(cx, prefix, &file_path, outer_attrs, sp) -} - -pub fn eval_src_mod_from_path(cx: ctx, prefix: &Path, path: &Path, - outer_attrs: ~[ast::attribute], - sp: span) - -> (ast::item_, ~[ast::attribute]) { - let full_path = if path.is_absolute { - copy *path - } else { - prefix.push_many(path.components) - }; - let p0 = - new_sub_parser_from_file(cx.sess, cx.cfg, - &full_path, sp); - let (inner, next) = p0.parse_inner_attrs_and_next(); - let mod_attrs = vec::append(outer_attrs, inner); - let first_item_outer_attrs = next; - let m0 = p0.parse_mod_items(token::EOF, first_item_outer_attrs); - return (ast::item_mod(m0), mod_attrs); -} - -// XXX: Duplicated from parser.rs -fn mk_item(ctx: ctx, lo: BytePos, hi: BytePos, +ident: ast::ident, - +node: ast::item_, vis: ast::visibility, - +attrs: ~[ast::attribute]) -> @ast::item { - return @{ident: ident, - attrs: attrs, - id: next_node_id(ctx.sess), - node: node, - vis: vis, - span: mk_sp(lo, hi)}; -} - -fn eval_crate_directive(cx: ctx, cdir: @ast::crate_directive, prefix: &Path, - view_items: &mut ~[@ast::view_item], - items: &mut ~[@ast::item]) { - match cdir.node { - ast::cdir_src_mod(vis, id, attrs) => { - let (m, mod_attrs) = eval_src_mod(cx, prefix, attrs, id, cdir.span); - let i = mk_item(cx, cdir.span.lo, cdir.span.hi, - /* FIXME (#2543) */ copy id, - m, vis, mod_attrs); - items.push(i); - } - ast::cdir_dir_mod(vis, id, cdirs, attrs) => { - let path = Path(cdir_path_opt(*cx.sess.interner.get(id), attrs)); - let full_path = if path.is_absolute { - copy path - } else { - prefix.push_many(path.components) - }; - let (m0, a0) = eval_crate_directives_to_mod( - cx, cdirs, &full_path, &None); - let i = - @{ident: /* FIXME (#2543) */ copy id, - attrs: vec::append(attrs, a0), - id: cx.sess.next_id, - node: ast::item_mod(m0), - vis: vis, - span: cdir.span}; - cx.sess.next_id += 1; - items.push(i); - } - ast::cdir_view_item(vi) => view_items.push(vi), - } -} -// -// Local Variables: -// mode: rust -// fill-column: 78; -// indent-tabs-mode: nil -// c-basic-offset: 4 -// buffer-file-coding-system: utf-8-unix -// End: -// diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 3a3597828cd24..fb3e8a5ded5a8 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -705,6 +705,7 @@ pub impl Parser { @Ty {id: self.get_id(), node: t, span: sp} } + // parse the type following a @ or a ~ fn parse_box_or_uniq_pointee( &self, sigil: ast::Sigil, @@ -897,7 +898,7 @@ pub impl Parser { // parse a path that doesn't have type parameters attached fn parse_path_without_tps(&self) - -> @ast::path { + -> @ast::Path { maybe_whole!(self, nt_path); let lo = self.span.lo; let global = self.eat(&token::MOD_SEP); @@ -917,7 +918,7 @@ pub impl Parser { break; } } - @ast::path { span: mk_sp(lo, self.last_span.hi), + @ast::Path { span: mk_sp(lo, self.last_span.hi), global: global, idents: ids, rp: None, @@ -927,7 +928,7 @@ pub impl Parser { // parse a path optionally with type parameters. If 'colons' // is true, then type parameters must be preceded by colons, // as in a::t:: - fn parse_path_with_tps(&self, colons: bool) -> @ast::path { + fn parse_path_with_tps(&self, colons: bool) -> @ast::Path { debug!("parse_path_with_tps(colons=%b)", colons); maybe_whole!(self, nt_path); @@ -982,18 +983,14 @@ pub impl Parser { } }; - @ast::path { span: mk_sp(lo, hi), + @ast::Path { span: mk_sp(lo, hi), rp: rp, types: tps, .. copy *path } } + /// parses 0 or 1 lifetime fn parse_opt_lifetime(&self) -> Option<@ast::Lifetime> { - /*! - * - * Parses 0 or 1 lifetime. - */ - match *self.token { token::LIFETIME(*) => { Some(@self.parse_lifetime()) @@ -1022,12 +1019,9 @@ pub impl Parser { } } + /// Parses a single lifetime + // matches lifetime = ( LIFETIME ) | ( IDENT / ) fn parse_lifetime(&self) -> ast::Lifetime { - /*! - * - * Parses a single lifetime. - */ - match *self.token { token::LIFETIME(i) => { let span = copy self.span; @@ -1147,6 +1141,9 @@ pub impl Parser { } } + // at the bottom (top?) of the precedence hierarchy, + // parse things like parenthesized exprs, + // macros, return, etc. fn parse_bottom_expr(&self) -> @expr { maybe_whole_expr!(self); @@ -1350,6 +1347,7 @@ pub impl Parser { return self.mk_expr(blk.span.lo, blk.span.hi, expr_block(blk)); } + // parse a.b or a(13) or just a fn parse_dot_or_call_expr(&self) -> @expr { let b = self.parse_bottom_expr(); self.parse_dot_or_call_expr_with(b) @@ -1618,7 +1616,7 @@ pub impl Parser { return spanned(lo, self.span.hi, m); } - + // parse a prefix-operator expr fn parse_prefix_expr(&self) -> @expr { let lo = self.span.lo; let mut hi; @@ -1629,7 +1627,6 @@ pub impl Parser { self.bump(); let e = self.parse_prefix_expr(); hi = e.span.hi; - self.get_id(); // see ast_util::op_expr_callee_id ex = expr_unary(not, e); } token::BINOP(b) => { @@ -1638,7 +1635,6 @@ pub impl Parser { self.bump(); let e = self.parse_prefix_expr(); hi = e.span.hi; - self.get_id(); // see ast_util::op_expr_callee_id ex = expr_unary(neg, e); } token::STAR => { @@ -1738,7 +1734,6 @@ pub impl Parser { self.bump(); let expr = self.parse_prefix_expr(); let rhs = self.parse_more_binops(expr, cur_prec); - self.get_id(); // see ast_util::op_expr_callee_id let bin = self.mk_expr(lhs.span.lo, rhs.span.hi, expr_binary(cur_op, lhs, rhs)); self.parse_more_binops(bin, min_prec) @@ -1789,7 +1784,6 @@ pub impl Parser { token::SHL => aop = shl, token::SHR => aop = shr } - self.get_id(); // see ast_util::op_expr_callee_id self.mk_expr(lo, rhs.span.hi, expr_assign_op(aop, lhs, rhs)) } @@ -2556,11 +2550,14 @@ pub impl Parser { } fn parse_block(&self) -> blk { + // disallow inner attrs: let (attrs, blk) = self.parse_inner_attrs_and_block(false); assert!(vec::is_empty(attrs)); return blk; } + // I claim the existence of the 'parse_attrs' flag strongly + // suggests a name-change or refactoring for this function. fn parse_inner_attrs_and_block(&self, parse_attrs: bool) -> (~[attribute], blk) { @@ -2601,6 +2598,7 @@ pub impl Parser { self.parse_block_tail_(lo, s, ~[]) } + // parse the rest of a block expression or function body fn parse_block_tail_(&self, lo: BytePos, s: blk_check_mode, +first_item_attrs: ~[attribute]) -> blk { let mut stmts = ~[]; @@ -2797,6 +2795,10 @@ pub impl Parser { ast::TyParam { ident: ident, id: self.get_id(), bounds: bounds } } + // parse a set of optional generic type parameter declarations + // matches generics = ( ) | ( < > ) | ( < typaramseq ( , )? > ) | ( < lifetimes ( , )? > ) + // | ( < lifetimes , typaramseq ( , )? > ) + // where typaramseq = ( typaram ) | ( typaram , typaramseq ) fn parse_generics(&self) -> ast::Generics { if self.eat(&token::LT) { let lifetimes = self.parse_lifetimes(); @@ -2809,6 +2811,7 @@ pub impl Parser { } } + // parse a generic use site fn parse_generic_values( &self) -> (OptVec, ~[@Ty]) { @@ -3099,6 +3102,7 @@ pub impl Parser { } } + // parse trait Foo { ... } fn parse_item_trait(&self) -> item_info { let ident = self.parse_ident(); self.parse_region_param(); @@ -3177,6 +3181,7 @@ pub impl Parser { (ident, item_impl(generics, opt_trait, ty, meths), None) } + // parse a::B<~str,int> fn parse_trait_ref(&self) -> @trait_ref { @ast::trait_ref { path: self.parse_path_with_tps(false), @@ -3184,6 +3189,7 @@ pub impl Parser { } } + // parse B + C<~str,int> + D fn parse_trait_ref_list(&self, ket: &token::Token) -> ~[@trait_ref] { self.parse_seq_to_before_end( ket, @@ -3192,6 +3198,7 @@ pub impl Parser { ) } + // parse struct Foo { ... } fn parse_item_struct(&self) -> item_info { let class_name = self.parse_ident(); self.parse_region_param(); @@ -3441,6 +3448,7 @@ pub impl Parser { (id, item_const(ty, e), None) } + // parse a mod { ...} item fn parse_item_mod(&self, outer_attrs: ~[ast::attribute]) -> item_info { let id_span = *self.span; let id = self.parse_ident(); @@ -3697,7 +3705,7 @@ pub impl Parser { } }; - // extern mod { ... } + // extern mod foo { ... } or extern { ... } if items_allowed && self.eat(&token::LBRACE) { let abis = opt_abis.get_or_default(AbiSet::C()); @@ -3732,6 +3740,7 @@ pub impl Parser { (lo, id) } + // parse type Foo = Bar; fn parse_item_type(&self) -> item_info { let (_, ident) = self.parse_type_decl(); self.parse_region_param(); @@ -3742,6 +3751,7 @@ pub impl Parser { (ident, item_ty(ty, tps), None) } + // parse obsolete region parameter fn parse_region_param(&self) { if self.eat(&token::BINOP(token::SLASH)) { self.obsolete(*self.last_span, ObsoleteLifetimeNotation); @@ -3859,6 +3869,7 @@ pub impl Parser { let generics = self.parse_generics(); // Newtype syntax if *self.token == token::EQ { + // enum x = ty; self.bump(); let ty = self.parse_ty(false); self.expect(&token::SEMI); @@ -3883,6 +3894,7 @@ pub impl Parser { None ); } + // enum X { ... } self.expect(&token::LBRACE); let enum_definition = self.parse_enum_def(&generics); @@ -3986,7 +3998,7 @@ pub impl Parser { (self.is_keyword(&~"const") || (self.is_keyword(&~"static") && !self.token_is_keyword(&~"fn", &self.look_ahead(1)))) { - // CONST ITEM + // CONST / STATIC ITEM if self.is_keyword(&~"const") { self.obsolete(*self.span, ObsoleteConstItem); } @@ -4002,10 +4014,9 @@ pub impl Parser { let item = self.parse_item_foreign_const(visibility, attrs); return iovi_foreign_item(item); } - if items_allowed && - // FUNCTION ITEM (not sure about lookahead condition...) - self.is_keyword(&~"fn") && + if items_allowed && self.is_keyword(&~"fn") && !self.fn_expr_lookahead(self.look_ahead(1u)) { + // FUNCTION ITEM self.bump(); let (ident, item_, extra_attrs) = self.parse_item_fn(impure_fn, AbiSet::Rust()); @@ -4014,7 +4025,7 @@ pub impl Parser { maybe_append(attrs, extra_attrs))); } if items_allowed && self.eat_keyword(&~"pure") { - // PURE FUNCTION ITEM + // PURE FUNCTION ITEM (obsolete) self.obsolete(*self.last_span, ObsoletePurity); self.expect_keyword(&~"fn"); let (ident, item_, extra_attrs) = @@ -4192,6 +4203,12 @@ pub impl Parser { return view_item_use(self.parse_view_paths()); } + + // matches view_path : MOD? IDENT EQ non_global_path + // | MOD? non_global_path MOD_SEP LBRACE RBRACE + // | MOD? non_global_path MOD_SEP LBRACE ident_seq RBRACE + // | MOD? non_global_path MOD_SEP STAR + // | MOD? non_global_path fn parse_view_path(&self) -> @view_path { let lo = self.span.lo; @@ -4215,7 +4232,7 @@ pub impl Parser { let id = self.parse_ident(); path.push(id); } - let path = @ast::path { span: mk_sp(lo, self.span.hi), + let path = @ast::Path { span: mk_sp(lo, self.span.hi), global: false, idents: path, rp: None, @@ -4244,7 +4261,7 @@ pub impl Parser { seq_sep_trailing_allowed(token::COMMA), |p| p.parse_path_list_ident() ); - let path = @ast::path { span: mk_sp(lo, self.span.hi), + let path = @ast::Path { span: mk_sp(lo, self.span.hi), global: false, idents: path, rp: None, @@ -4256,7 +4273,7 @@ pub impl Parser { // foo::bar::* token::BINOP(token::STAR) => { self.bump(); - let path = @ast::path { span: mk_sp(lo, self.span.hi), + let path = @ast::Path { span: mk_sp(lo, self.span.hi), global: false, idents: path, rp: None, @@ -4272,7 +4289,7 @@ pub impl Parser { _ => () } let last = path[vec::len(path) - 1u]; - let path = @ast::path { span: mk_sp(lo, self.span.hi), + let path = @ast::Path { span: mk_sp(lo, self.span.hi), global: false, idents: path, rp: None, @@ -4281,6 +4298,7 @@ pub impl Parser { view_path_simple(last, path, namespace, self.get_id())); } + // matches view_paths = view_path | view_path , view_paths fn parse_view_paths(&self) -> ~[@view_path] { let mut vp = ~[self.parse_view_path()]; while *self.token == token::COMMA { @@ -4330,6 +4348,9 @@ pub impl Parser { // Parses a sequence of items. Stops when it finds program // text that can't be parsed as an item + // - mod_items uses VIEW_ITEMS_AND_ITEMS_ALLOWED + // - block_tail_ uses IMPORTS_AND_ITEMS_ALLOWED + // - foreign_mod_items uses FOREIGN_ITEMS_ALLOWED fn parse_items_and_view_items(&self, +first_item_attrs: ~[attribute], mode: view_item_parse_mode, macros_allowed: bool) diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 713a6e8947554..54b2ad8514781 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -113,7 +113,7 @@ pub enum nonterminal { nt_expr(@ast::expr), nt_ty( @ast::Ty), nt_ident(ast::ident, bool), - nt_path(@ast::path), + nt_path(@ast::Path), nt_tt( @ast::token_tree), //needs @ed to break a circularity nt_matchers(~[ast::matcher]) } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 20fc99baf2179..fa1b97275660c 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -178,7 +178,7 @@ pub fn generics_to_str(generics: &ast::Generics, to_str(generics, print_generics, intr) } -pub fn path_to_str(&&p: @ast::path, intr: @ident_interner) -> ~str { +pub fn path_to_str(&&p: @ast::Path, intr: @ident_interner) -> ~str { to_str(p, |a,b| print_path(a, b, false), intr) } @@ -1486,7 +1486,7 @@ pub fn print_for_decl(s: @ps, loc: @ast::local, coll: @ast::expr) { print_expr(s, coll); } -pub fn print_path(s: @ps, &&path: @ast::path, colons_before_params: bool) { +pub fn print_path(s: @ps, &&path: @ast::Path, colons_before_params: bool) { maybe_print_comment(s, path.span.lo); if path.global { word(s.s, ~"::"); } let mut first = true; diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index b20c5eeee1f04..c4c187bc4c7c4 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -265,7 +265,7 @@ pub fn visit_ty(t: @Ty, e: E, v: vt) { } } -pub fn visit_path(p: @path, e: E, v: vt) { +pub fn visit_path(p: @Path, e: E, v: vt) { for p.types.each |tp| { (v.visit_ty)(*tp, e, v); } } diff --git a/src/test/run-pass/by-val-and-by-move.rs b/src/test/run-pass/by-val-and-by-move.rs deleted file mode 100644 index 47d2f9e1df080..0000000000000 --- a/src/test/run-pass/by-val-and-by-move.rs +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2012 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// xfail-test #2443 -// exec-env:RUST_POISON_ON_FREE - -fn it_takes_two(x: @int, -y: @int) -> int { - free(y); - debug!("about to deref"); - *x -} - -fn free(-_t: T) { -} - -pub fn main() { - let z = @3; - assert!(3 == it_takes_two(z, z)); -}