From e38cb972dcfc0fdab44270257eac3405a39bd996 Mon Sep 17 00:00:00 2001 From: John Clements Date: Mon, 30 Jun 2014 18:02:14 -0700 Subject: Simplify PatIdent to contain an Ident rather than a Path Rationale: for what appear to be historical reasons only, the PatIdent contains a Path rather than an Ident. This means that there are many places in the code where an ident is artificially promoted to a path, and---much more problematically--- a bunch of elements from a path are simply thrown away, which seems like an invitation to some really nasty bugs. This commit replaces the Path in a PatIdent with a SpannedIdent, which just contains an ident and a span. --- src/libsyntax/ext/build.rs | 3 +-- src/libsyntax/ext/deriving/generic/mod.rs | 27 +++++++++------------------ src/libsyntax/ext/expand.rs | 16 ++-------------- 3 files changed, 12 insertions(+), 34 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 8d48401f9c2..46bc4ec11ce 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -759,8 +759,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { span: Span, ident: ast::Ident, bm: ast::BindingMode) -> Gc { - let path = self.path_ident(span, ident); - let pat = ast::PatIdent(bm, path, None); + let pat = ast::PatIdent(bm, Spanned{span: span, node: ident}, None); self.pat(span, pat) } fn pat_enum(&self, span: Span, path: ast::Path, subpats: Vec> ) -> Gc { diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 2b97687dbf8..b9bc5009337 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -1049,7 +1049,7 @@ impl<'a> TraitDef<'a> { fn create_subpatterns(&self, cx: &mut ExtCtxt, - field_paths: Vec , + field_paths: Vec , mutbl: ast::Mutability) -> Vec> { field_paths.iter().map(|path| { @@ -1095,15 +1095,10 @@ impl<'a> TraitDef<'a> { cx.span_bug(sp, "a struct with named and unnamed fields in `deriving`"); } }; - let path = - cx.path_ident(sp, - cx.ident_of(format!("{}_{}", - prefix, - i).as_slice())); - paths.push(path.clone()); + let ident = cx.ident_of(format!("{}_{}", prefix, i).as_slice()); + paths.push(codemap::Spanned{span: sp, node: ident}); let val = cx.expr( - sp, ast::ExprParen( - cx.expr_deref(sp, cx.expr_path(path)))); + sp, ast::ExprParen(cx.expr_deref(sp, cx.expr_path(cx.path_ident(sp,ident))))); ident_expr.push((sp, opt_id, val)); } @@ -1145,15 +1140,11 @@ impl<'a> TraitDef<'a> { let mut ident_expr = Vec::new(); for (i, va) in variant_args.iter().enumerate() { let sp = self.set_expn_info(cx, va.ty.span); - let path = - cx.path_ident(sp, - cx.ident_of(format!("{}_{}", - prefix, - i).as_slice())); - - paths.push(path.clone()); - let val = cx.expr( - sp, ast::ExprParen(cx.expr_deref(sp, cx.expr_path(path)))); + let ident = cx.ident_of(format!("{}_{}", prefix, i).as_slice()); + let path1 = codemap::Spanned{span: sp, node: ident}; + paths.push(path1); + let expr_path = cx.expr_path(cx.path_ident(sp, ident)); + let val = cx.expr(sp, ast::ExprParen(cx.expr_deref(sp, expr_path))); ident_expr.push((sp, None, val)); } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index b9cedb7a779..d1eb0147b9c 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -705,22 +705,10 @@ impl Visitor<()> for NameFinderContext { // we found a pat_ident! ast::Pat { id: _, - node: ast::PatIdent(_, ref path, ref inner), + node: ast::PatIdent(_, ref path1, ref inner), span: _ } => { - match path { - // a path of length one: - &ast::Path { - global: false, - span: _, - segments: ref segments - } if segments.len() == 1 => { - self.ident_accumulator.push(segments.get(0) - .identifier) - } - // I believe these must be enums... - _ => () - } + self.ident_accumulator.push(path1.node); // visit optional subpattern of pat_ident: for subpat in inner.iter() { self.visit_pat(&**subpat, ()) -- cgit 1.4.1-3-g733a5 From e3fa23bcb64064d50c2a9e3b5870bc82081359d9 Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Wed, 2 Jul 2014 21:27:07 -0400 Subject: Fix spelling errors. --- src/liballoc/arc.rs | 2 +- src/libgreen/stack.rs | 2 +- src/liblog/lib.rs | 2 +- src/libnative/io/net.rs | 2 +- src/libnative/io/pipe_win32.rs | 2 +- src/librlibc/lib.rs | 2 +- src/librustc/back/link.rs | 2 +- src/librustc/lint/builtin.rs | 2 +- src/librustc/middle/mem_categorization.rs | 2 +- src/librustc/middle/privacy.rs | 2 +- src/librustc/middle/save/mod.rs | 6 +++--- src/librustc/middle/typeck/infer/unify.rs | 8 ++++---- src/librustdoc/clean/mod.rs | 2 +- src/librustrt/c_str.rs | 2 +- src/librustrt/libunwind.rs | 2 +- src/librustrt/task.rs | 4 ++-- src/librustrt/thread.rs | 2 +- src/librustuv/lib.rs | 2 +- src/librustuv/stream.rs | 2 +- src/librustuv/timer.rs | 2 +- src/libstd/io/net/ip.rs | 2 +- src/libstd/os.rs | 2 +- src/libstd/rt/backtrace.rs | 2 +- src/libsync/comm/oneshot.rs | 2 +- src/libsync/comm/shared.rs | 4 ++-- src/libsync/mutex.rs | 2 +- src/libsyntax/ext/base.rs | 2 +- src/libsyntax/ext/deriving/generic/mod.rs | 2 +- src/libsyntax/ext/expand.rs | 2 +- 29 files changed, 36 insertions(+), 36 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs index 38ed511c458..9b4f879e61e 100644 --- a/src/liballoc/arc.rs +++ b/src/liballoc/arc.rs @@ -185,7 +185,7 @@ impl Drop for Arc { // deletion of the data. Because it is marked `Release`, the // decreasing of the reference count synchronizes with this `Acquire` // fence. This means that use of the data happens before decreasing - // the refernce count, which happens before this fence, which + // the reference count, which happens before this fence, which // happens before the deletion of the data. // // As explained in the [Boost documentation][1], diff --git a/src/libgreen/stack.rs b/src/libgreen/stack.rs index c4885edb7d3..5faa9cfe6f6 100644 --- a/src/libgreen/stack.rs +++ b/src/libgreen/stack.rs @@ -124,7 +124,7 @@ impl Drop for Stack { } pub struct StackPool { - // Ideally this would be some datastructure that preserved ordering on + // Ideally this would be some data structure that preserved ordering on // Stack.min_size. stacks: Vec, } diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index ba102a85c1b..17349f41b98 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -288,7 +288,7 @@ pub fn mod_enabled(level: u32, module: &str) -> bool { unsafe { INIT.doit(init); } // It's possible for many threads are in this function, only one of them - // will peform the global initialization, but all of them will need to check + // will perform the global initialization, but all of them will need to check // again to whether they should really be here or not. Hence, despite this // check being expanded manually in the logging macro, this function checks // the log level again. diff --git a/src/libnative/io/net.rs b/src/libnative/io/net.rs index dfc2c55cde7..f052826d303 100644 --- a/src/libnative/io/net.rs +++ b/src/libnative/io/net.rs @@ -877,7 +877,7 @@ pub fn write(fd: sock_t, } // Also as with read(), we use MSG_DONTWAIT to guard ourselves - // against unforseen circumstances. + // against unforeseen circumstances. let _guard = lock(); let ptr = buf.slice_from(written).as_ptr(); let len = buf.len() - written; diff --git a/src/libnative/io/pipe_win32.rs b/src/libnative/io/pipe_win32.rs index da713e3f2a9..e5e8cdeffd7 100644 --- a/src/libnative/io/pipe_win32.rs +++ b/src/libnative/io/pipe_win32.rs @@ -376,7 +376,7 @@ impl rtio::RtioPipe for UnixStream { if ret != 0 { return Ok(bytes_read as uint) } // If our errno doesn't say that the I/O is pending, then we hit some - // legitimate error and reeturn immediately. + // legitimate error and return immediately. if os::errno() != libc::ERROR_IO_PENDING as uint { return Err(super::last_error()) } diff --git a/src/librlibc/lib.rs b/src/librlibc/lib.rs index c85e0099ab8..4423ab62f0d 100644 --- a/src/librlibc/lib.rs +++ b/src/librlibc/lib.rs @@ -31,7 +31,7 @@ #![no_std] #![experimental] -// This library is definining the builtin functions, so it would be a shame for +// This library defines the builtin functions, so it would be a shame for // LLVM to optimize these function calls to themselves! #![no_builtins] diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 17f29639601..a190d9309cc 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -119,7 +119,7 @@ pub mod write { // get all hardware potential via VFP3 (hardware floating point) // and NEON (SIMD) instructions supported by LLVM. // Note that without those flags various linking errors might - // arise as some of intrinsicts are converted into function calls + // arise as some of intrinsics are converted into function calls // and nobody provides implementations those functions fn target_feature<'a>(sess: &'a Session) -> &'a str { match sess.targ_cfg.os { diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 3e7c4912527..a8f778934ae 100644 --- a/src/librustc/lint/builtin.rs +++ b/src/librustc/lint/builtin.rs @@ -985,7 +985,7 @@ impl UnnecessaryParens { _ => {} } - /// Expressions that syntatically contain an "exterior" struct + /// Expressions that syntactically contain an "exterior" struct /// literal i.e. not surrounded by any parens or other /// delimiters, e.g. `X { y: 1 }`, `X { y: 1 }.method()`, `foo /// == X { y: 1 }` and `X { y: 1 } == foo` all do, but `(X { diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index e1a2a5741fb..54cca082e0d 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -383,7 +383,7 @@ impl<'t,TYPER:Typer> MemCategorizationContext<'t,TYPER> { Some(adjustment) => { match *adjustment { ty::AutoObject(..) => { - // Implicity cast a concrete object to trait object. + // Implicitly cast a concrete object to trait object. // Result is an rvalue. let expr_ty = if_ok!(self.expr_ty_adjusted(expr)); Ok(self.cat_rvalue_node(expr.id(), expr.span(), expr_ty)) diff --git a/src/librustc/middle/privacy.rs b/src/librustc/middle/privacy.rs index 414aac47cdc..76e962a3bc4 100644 --- a/src/librustc/middle/privacy.rs +++ b/src/librustc/middle/privacy.rs @@ -1267,7 +1267,7 @@ impl<'a> Visitor<()> for VisiblePrivateTypesVisitor<'a> { // error messages without (too many) false positives // (i.e. we could just return here to not check them at // all, or some worse estimation of whether an impl is - // publically visible. + // publicly visible. ast::ItemImpl(ref g, ref trait_ref, self_, ref methods) => { // `impl [... for] Private` is never visible. let self_contains_private; diff --git a/src/librustc/middle/save/mod.rs b/src/librustc/middle/save/mod.rs index 56894ad3e5c..bdb7d30339d 100644 --- a/src/librustc/middle/save/mod.rs +++ b/src/librustc/middle/save/mod.rs @@ -484,7 +484,7 @@ impl <'l> DxrVisitor<'l> { { let qualname = self.analysis.ty_cx.map.path_to_str(item.id); - // If the variable is immutable, save the initialising expresion. + // If the variable is immutable, save the initialising expression. let value = match mt { ast::MutMutable => String::from_str(""), ast::MutImmutable => self.span.snippet(expr.span), @@ -845,7 +845,7 @@ impl <'l> DxrVisitor<'l> { let decl_id = ty::trait_method_of_method(&self.analysis.ty_cx, def_id); // This incantation is required if the method referenced is a trait's - // defailt implementation. + // default implementation. let def_id = ty::method(&self.analysis.ty_cx, def_id).provided_source .unwrap_or(def_id); (Some(def_id), decl_id) @@ -1403,7 +1403,7 @@ pub fn process_crate(sess: &Session, info!("Writing output to {}", disp); } - // Create ouput file. + // Create output file. let mut out_name = cratename.clone(); out_name.push_str(".csv"); root_path.push(out_name); diff --git a/src/librustc/middle/typeck/infer/unify.rs b/src/librustc/middle/typeck/infer/unify.rs index f106ce18a4a..44afc04d3f0 100644 --- a/src/librustc/middle/typeck/infer/unify.rs +++ b/src/librustc/middle/typeck/infer/unify.rs @@ -93,7 +93,7 @@ pub struct UnificationTable { /** * At any time, users may snapshot a unification table. The changes - * made during the snapshot may either be *commited* or *rolled back*. + * made during the snapshot may either be *committed* or *rolled back*. */ pub struct Snapshot { // Ensure that this snapshot is keyed to the table type. @@ -152,7 +152,7 @@ impl> UnificationTable { /** * Starts a new snapshot. Each snapshot must be either - * rolled back or commited in a "LIFO" (stack) order. + * rolled back or committed in a "LIFO" (stack) order. */ pub fn snapshot(&mut self) -> Snapshot { let length = self.undo_log.len(); @@ -188,12 +188,12 @@ impl> UnificationTable { match self.undo_log.pop().unwrap() { OpenSnapshot => { // This indicates a failure to obey the stack discipline. - tcx.sess.bug("Cannot rollback an uncommited snapshot"); + tcx.sess.bug("Cannot rollback an uncommitted snapshot"); } CommittedSnapshot => { // This occurs when there are nested snapshots and - // the inner is commited but outer is rolled back. + // the inner is committed but outer is rolled back. } NewVar(i) => { diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 58985f832ce..d0873d4c66a 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1737,7 +1737,7 @@ pub struct ViewItem { impl Clean> for ast::ViewItem { fn clean(&self) -> Vec { - // We consider inlining the documentation of `pub use` statments, but we + // We consider inlining the documentation of `pub use` statements, but we // forcefully don't inline if this is not public or if the // #[doc(no_inline)] attribute is present. let denied = self.vis != ast::Public || self.attrs.iter().any(|a| { diff --git a/src/librustrt/c_str.rs b/src/librustrt/c_str.rs index 9734ba2d751..161d3ed5e65 100644 --- a/src/librustrt/c_str.rs +++ b/src/librustrt/c_str.rs @@ -376,7 +376,7 @@ pub trait ToCStr { // (without forcing an additional & around &str). So we are instead // temporarily adding an instance for ~str and String, so that we can // take ToCStr as owned. When DST lands, the string instances should -// be revisted, and arguments bound by ToCStr should be passed by +// be revisited, and arguments bound by ToCStr should be passed by // reference. impl<'a> ToCStr for &'a str { diff --git a/src/librustrt/libunwind.rs b/src/librustrt/libunwind.rs index 6811a62c74f..f018b3fc16b 100644 --- a/src/librustrt/libunwind.rs +++ b/src/librustrt/libunwind.rs @@ -97,7 +97,7 @@ extern {} extern "C" { // iOS on armv7 uses SjLj exceptions and requires to link - // agains corresponding routine (..._SjLj_...) + // against corresponding routine (..._SjLj_...) #[cfg(not(target_os = "ios", target_arch = "arm"))] pub fn _Unwind_RaiseException(exception: *mut _Unwind_Exception) -> _Unwind_Reason_Code; diff --git a/src/librustrt/task.rs b/src/librustrt/task.rs index 891d0d5a8e3..59401a8b666 100644 --- a/src/librustrt/task.rs +++ b/src/librustrt/task.rs @@ -170,7 +170,7 @@ impl Task { /// This function can be used as an emulated "try/catch" to interoperate /// with the rust runtime at the outermost boundary. It is not possible to /// use this function in a nested fashion (a try/catch inside of another - /// try/catch). Invoking this funciton is quite cheap. + /// try/catch). Invoking this function is quite cheap. /// /// If the closure `f` succeeds, then the returned task can be used again /// for another invocation of `run`. If the closure `f` fails then `self` @@ -276,7 +276,7 @@ impl Task { // 1. If TLD destruction fails, heap destruction will be attempted. // There is a test for this at fail-during-tld-destroy.rs. Sadly the // other way can't be tested due to point 2 above. Note that we must - // immortalize the heap first becuase if any deallocations are + // immortalize the heap first because if any deallocations are // attempted while TLD is being dropped it will attempt to free the // allocation from the wrong heap (because the current one has been // replaced). diff --git a/src/librustrt/thread.rs b/src/librustrt/thread.rs index 9908e87e86a..59784328cdb 100644 --- a/src/librustrt/thread.rs +++ b/src/librustrt/thread.rs @@ -243,7 +243,7 @@ mod imp { // EINVAL means |stack_size| is either too small or not a // multiple of the system page size. Because it's definitely // >= PTHREAD_STACK_MIN, it must be an alignment issue. - // Round up to the neareast page and try again. + // Round up to the nearest page and try again. let page_size = libc::sysconf(libc::_SC_PAGESIZE) as uint; let stack_size = (stack_size + page_size - 1) & (-(page_size as int - 1) as uint - 1); diff --git a/src/librustuv/lib.rs b/src/librustuv/lib.rs index 968a283995b..a1712394634 100644 --- a/src/librustuv/lib.rs +++ b/src/librustuv/lib.rs @@ -234,7 +234,7 @@ impl ForbidUnwind { impl Drop for ForbidUnwind { fn drop(&mut self) { assert!(self.failing_before == task::failing(), - "didnt want an unwind during: {}", self.msg); + "didn't want an unwind during: {}", self.msg); } } diff --git a/src/librustuv/stream.rs b/src/librustuv/stream.rs index f6b9226588c..875c2dee46b 100644 --- a/src/librustuv/stream.rs +++ b/src/librustuv/stream.rs @@ -87,7 +87,7 @@ impl StreamWatcher { // immediately as part of the call to alloc_cb. What this means is that // we must be ready for this to happen (by setting the data in the uv // handle). In theory this otherwise doesn't need to happen until after - // the read is succesfully started. + // the read is successfully started. unsafe { uvll::set_data_for_uv_handle(self.handle, &mut rcx) } // Send off the read request, but don't block until we're sure that the diff --git a/src/librustuv/timer.rs b/src/librustuv/timer.rs index 9d0a56b3c85..f6c1cdd2977 100644 --- a/src/librustuv/timer.rs +++ b/src/librustuv/timer.rs @@ -77,7 +77,7 @@ impl RtioTimer for TimerWatcher { fn sleep(&mut self, msecs: u64) { // As with all of the below functions, we must be extra careful when // destroying the previous action. If the previous action was a channel, - // destroying it could invoke a context switch. For these situtations, + // destroying it could invoke a context switch. For these situations, // we must temporarily un-home ourselves, then destroy the action, and // then re-home again. let missile = self.fire_homing_missile(); diff --git a/src/libstd/io/net/ip.rs b/src/libstd/io/net/ip.rs index 2c54bd895e9..ca59849202b 100644 --- a/src/libstd/io/net/ip.rs +++ b/src/libstd/io/net/ip.rs @@ -410,7 +410,7 @@ mod test { // colon after v4 let none: Option = FromStr::from_str("::127.0.0.1:"); assert_eq!(None, none); - // not enought groups + // not enough groups let none: Option = FromStr::from_str("1.2.3.4.5:127.0.0.1"); assert_eq!(None, none); // too many groups diff --git a/src/libstd/os.rs b/src/libstd/os.rs index c69209acbdd..4388de43f20 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -469,7 +469,7 @@ pub fn unsetenv(n: &str) { /// println!("'{}'", path.display()); /// } /// } -/// None => println!("{} is not defined in the environnement.", key) +/// None => println!("{} is not defined in the environment.", key) /// } /// ``` pub fn split_paths(unparsed: T) -> Vec { diff --git a/src/libstd/rt/backtrace.rs b/src/libstd/rt/backtrace.rs index 8f51e834c6a..2e0dcdd8eb6 100644 --- a/src/libstd/rt/backtrace.rs +++ b/src/libstd/rt/backtrace.rs @@ -266,7 +266,7 @@ mod imp { } // while it doesn't requires lock for work as everything is - // local, it still displays much nicier backtraces when a + // local, it still displays much nicer backtraces when a // couple of tasks fail simultaneously static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT; let _g = unsafe { LOCK.lock() }; diff --git a/src/libsync/comm/oneshot.rs b/src/libsync/comm/oneshot.rs index bf2d9aa52fd..742686069e2 100644 --- a/src/libsync/comm/oneshot.rs +++ b/src/libsync/comm/oneshot.rs @@ -354,7 +354,7 @@ impl Packet { } // We woke ourselves up from select. Assert that the task should be - // trashed and returne that we don't have any data. + // trashed and returned that we don't have any data. n => { let t = unsafe { BlockedTask::cast_from_uint(n) }; t.trash(); diff --git a/src/libsync/comm/shared.rs b/src/libsync/comm/shared.rs index a50a6bbc8d3..5ad4dea5d2a 100644 --- a/src/libsync/comm/shared.rs +++ b/src/libsync/comm/shared.rs @@ -81,7 +81,7 @@ impl Packet { // This function should be used after newly created Packet // was wrapped with an Arc - // In other case mutex data will be duplicated while clonning + // In other case mutex data will be duplicated while cloning // and that could cause problems on platforms where it is // represented by opaque data structure pub fn postinit_lock(&mut self) { @@ -140,7 +140,7 @@ impl Packet { // See Port::drop for what's going on if self.port_dropped.load(atomics::SeqCst) { return Err(t) } - // Note that the multiple sender case is a little tricker + // Note that the multiple sender case is a little trickier // semantically than the single sender case. The logic for // incrementing is "add and if disconnected store disconnected". // This could end up leading some senders to believe that there diff --git a/src/libsync/mutex.rs b/src/libsync/mutex.rs index ef558d3f924..a10ec745869 100644 --- a/src/libsync/mutex.rs +++ b/src/libsync/mutex.rs @@ -215,7 +215,7 @@ impl StaticMutex { None => {} } - // After we've failed the fast path, then we delegate to the differnet + // After we've failed the fast path, then we delegate to the different // locking protocols for green/native tasks. This will select two tasks // to continue further (one native, one green). let t: Box = Local::take(); diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 0d8373eac3c..ab5d7021746 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -472,7 +472,7 @@ impl<'a> ExtCtxt<'a> { } /// Emit `msg` attached to `sp`, and stop compilation immediately. /// - /// `span_err` should be strongly prefered where-ever possible: + /// `span_err` should be strongly preferred where-ever possible: /// this should *only* be used when /// - continuing has a high risk of flow-on errors (e.g. errors in /// declaring a macro would cause all uses of that macro to diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index b9bc5009337..157b64fb47c 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -834,7 +834,7 @@ impl<'a> MethodDef<'a> { generic `deriving`"); } - // `ref` inside let matches is buggy. Causes havoc wih rusc. + // `ref` inside let matches is buggy. Causes havoc with rusc. // let (variant_index, ref self_vec) = matches_so_far[0]; let (variant, self_vec) = match matches_so_far.get(0) { &(_, v, ref s) => (v, s) diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index d1eb0147b9c..c3413293e52 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1295,7 +1295,7 @@ mod test { } // create a really evil test case where a $x appears inside a binding of $x - // but *shouldnt* bind because it was inserted by a different macro.... + // but *shouldn't* bind because it was inserted by a different macro.... // can't write this test case until we have macro-generating macros. // FIXME #9383 : lambda var hygiene -- cgit 1.4.1-3-g733a5 From 2f355b79ddb49c45fb3396352f464458ad867234 Mon Sep 17 00:00:00 2001 From: Piotr Jawniak Date: Thu, 3 Jul 2014 11:42:24 +0200 Subject: Simplify creating a parser from a token tree Closes #15306 --- src/libfourcc/lib.rs | 7 +------ src/libhexfloat/lib.rs | 7 +------ src/libregex_macros/lib.rs | 4 +--- src/libsyntax/ext/asm.rs | 8 +------- src/libsyntax/ext/base.rs | 12 +++++++----- src/libsyntax/ext/cfg.rs | 8 +------- src/libsyntax/ext/format.rs | 7 +------ src/libsyntax/ext/quote.rs | 7 +------ 8 files changed, 14 insertions(+), 46 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libfourcc/lib.rs b/src/libfourcc/lib.rs index a5880f32472..848509cbab2 100644 --- a/src/libfourcc/lib.rs +++ b/src/libfourcc/lib.rs @@ -59,7 +59,6 @@ use syntax::codemap::{Span, mk_sp}; use syntax::ext::base; use syntax::ext::base::{ExtCtxt, MacExpr}; use syntax::ext::build::AstBuilder; -use syntax::parse; use syntax::parse::token; use syntax::parse::token::InternedString; use rustc::plugin::Registry; @@ -135,11 +134,7 @@ struct Ident { fn parse_tts(cx: &ExtCtxt, tts: &[ast::TokenTree]) -> (Gc, Option) { - let p = &mut parse::new_parser_from_tts(cx.parse_sess(), - cx.cfg(), - tts.iter() - .map(|x| (*x).clone()) - .collect()); + let p = &mut cx.new_parser_from_tts(tts); let ex = p.parse_expr(); let id = if p.token == token::EOF { None diff --git a/src/libhexfloat/lib.rs b/src/libhexfloat/lib.rs index 1b43f236e69..369de484e8e 100644 --- a/src/libhexfloat/lib.rs +++ b/src/libhexfloat/lib.rs @@ -54,7 +54,6 @@ use syntax::codemap::{Span, mk_sp}; use syntax::ext::base; use syntax::ext::base::{ExtCtxt, MacExpr}; use syntax::ext::build::AstBuilder; -use syntax::parse; use syntax::parse::token; use rustc::plugin::Registry; @@ -167,11 +166,7 @@ struct Ident { fn parse_tts(cx: &ExtCtxt, tts: &[ast::TokenTree]) -> (Gc, Option) { - let p = &mut parse::new_parser_from_tts(cx.parse_sess(), - cx.cfg(), - tts.iter() - .map(|x| (*x).clone()) - .collect()); + let p = &mut cx.new_parser_from_tts(tts); let ex = p.parse_expr(); let id = if p.token == token::EOF { None diff --git a/src/libregex_macros/lib.rs b/src/libregex_macros/lib.rs index ff5cada05ea..4108388e776 100644 --- a/src/libregex_macros/lib.rs +++ b/src/libregex_macros/lib.rs @@ -32,7 +32,6 @@ use syntax::ast; use syntax::codemap; use syntax::ext::build::AstBuilder; use syntax::ext::base::{ExtCtxt, MacResult, MacExpr, DummyResult}; -use syntax::parse; use syntax::parse::token; use syntax::print::pprust; @@ -615,8 +614,7 @@ fn exec<'t>(which: ::regex::native::MatchKind, input: &'t str, /// Looks for a single string literal and returns it. /// Otherwise, logs an error with cx.span_err and returns None. fn parse(cx: &mut ExtCtxt, tts: &[ast::TokenTree]) -> Option { - let mut parser = parse::new_parser_from_tts(cx.parse_sess(), cx.cfg(), - Vec::from_slice(tts)); + let mut parser = cx.new_parser_from_tts(tts); let entry = cx.expand_expr(parser.parse_expr()); let regex = match entry.node { ast::ExprLit(lit) => { diff --git a/src/libsyntax/ext/asm.rs b/src/libsyntax/ext/asm.rs index 50b1639484d..f0494e18120 100644 --- a/src/libsyntax/ext/asm.rs +++ b/src/libsyntax/ext/asm.rs @@ -16,7 +16,6 @@ use ast; use codemap::Span; use ext::base; use ext::base::*; -use parse; use parse::token::InternedString; use parse::token; @@ -48,12 +47,7 @@ static OPTIONS: &'static [&'static str] = &["volatile", "alignstack", "intel"]; pub fn expand_asm(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> Box { - let mut p = parse::new_parser_from_tts(cx.parse_sess(), - cx.cfg(), - tts.iter() - .map(|x| (*x).clone()) - .collect()); - + let mut p = cx.new_parser_from_tts(tts); let mut asm = InternedString::new(""); let mut asm_str_style = None; let mut outputs = Vec::new(); diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index ab5d7021746..d2e69204d33 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -15,6 +15,7 @@ use codemap::{CodeMap, Span, ExpnInfo}; use ext; use ext::expand; use parse; +use parse::parser; use parse::token; use parse::token::{InternedString, intern, str_to_ident}; use util::small_vector::SmallVector; @@ -433,6 +434,11 @@ impl<'a> ExtCtxt<'a> { } } + pub fn new_parser_from_tts(&self, tts: &[ast::TokenTree]) + -> parser::Parser<'a> { + parse::tts_to_parser(self.parse_sess, Vec::from_slice(tts), self.cfg()) + } + pub fn codemap(&self) -> &'a CodeMap { &self.parse_sess.span_diagnostic.cm } pub fn parse_sess(&self) -> &'a parse::ParseSess { self.parse_sess } pub fn cfg(&self) -> ast::CrateConfig { self.cfg.clone() } @@ -586,11 +592,7 @@ pub fn get_single_str_from_tts(cx: &ExtCtxt, pub fn get_exprs_from_tts(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> Option>> { - let mut p = parse::new_parser_from_tts(cx.parse_sess(), - cx.cfg(), - tts.iter() - .map(|x| (*x).clone()) - .collect()); + let mut p = cx.new_parser_from_tts(tts); let mut es = Vec::new(); while p.token != token::EOF { es.push(cx.expand_expr(p.parse_expr())); diff --git a/src/libsyntax/ext/cfg.rs b/src/libsyntax/ext/cfg.rs index 3e74b2680e0..c2930662bc4 100644 --- a/src/libsyntax/ext/cfg.rs +++ b/src/libsyntax/ext/cfg.rs @@ -24,17 +24,11 @@ use attr::*; use parse::attr::ParserAttr; use parse::token::InternedString; use parse::token; -use parse; pub fn expand_cfg(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) -> Box { - let mut p = parse::new_parser_from_tts(cx.parse_sess(), - cx.cfg(), - tts.iter() - .map(|x| (*x).clone()) - .collect()); - + let mut p = cx.new_parser_from_tts(tts); let mut cfgs = Vec::new(); // parse `cfg!(meta_item, meta_item(x,y), meta_item="foo", ...)` while p.token != token::EOF { diff --git a/src/libsyntax/ext/format.rs b/src/libsyntax/ext/format.rs index 857eadfe57c..f39e50ad131 100644 --- a/src/libsyntax/ext/format.rs +++ b/src/libsyntax/ext/format.rs @@ -16,7 +16,6 @@ use ext::base; use ext::build::AstBuilder; use parse::token::InternedString; use parse::token; -use rsparse = parse; use parse = fmt_macros; use std::collections::HashMap; @@ -81,11 +80,7 @@ fn parse_args(ecx: &mut ExtCtxt, sp: Span, allow_method: bool, let mut names = HashMap::>::new(); let mut order = Vec::new(); - let mut p = rsparse::new_parser_from_tts(ecx.parse_sess(), - ecx.cfg(), - tts.iter() - .map(|x| (*x).clone()) - .collect()); + let mut p = ecx.new_parser_from_tts(tts); // Parse the leading function expression (maybe a block, maybe a path) let invocation = if allow_method { let e = p.parse_expr(); diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 35702b1b3cd..7b24b97d5da 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -15,7 +15,6 @@ use ext::base; use ext::build::AstBuilder; use parse::token::*; use parse::token; -use parse; use std::gc::Gc; @@ -583,11 +582,7 @@ fn expand_tts(cx: &ExtCtxt, sp: Span, tts: &[ast::TokenTree]) // it has to do with transition away from supporting old-style macros, so // try removing it when enough of them are gone. - let mut p = parse::new_parser_from_tts(cx.parse_sess(), - cx.cfg(), - tts.iter() - .map(|x| (*x).clone()) - .collect()); + let mut p = cx.new_parser_from_tts(tts); p.quote_depth += 1u; let cx_expr = p.parse_expr(); -- cgit 1.4.1-3-g733a5