diff options
| author | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2017-06-05 01:41:33 +0000 |
|---|---|---|
| committer | Jeffrey Seyfried <jeffrey.seyfried@gmail.com> | 2017-06-26 02:06:34 +0000 |
| commit | 71d4a860a1797300f976b45d7b7a41815eca6207 (patch) | |
| tree | b96df67fc15071360fa03403d9c89a1c561e4b35 /src/libsyntax/parse | |
| parent | 1e32a3f15e35075b537741cdfef40f29bb856582 (diff) | |
| download | rust-71d4a860a1797300f976b45d7b7a41815eca6207.tar.gz rust-71d4a860a1797300f976b45d7b7a41815eca6207.zip | |
Address review comments.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 44 |
2 files changed, 33 insertions, 13 deletions
diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index afc1e583d69..66775d8c43d 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -483,7 +483,7 @@ impl<'a> StringReader<'a> { self.with_str_from(start, |string| { if string == "_" { self.sess.span_diagnostic - .struct_span_warn(mk_sp(start, self.pos), + .struct_span_warn(self.mk_sp(start, self.pos), "underscore literal suffix is not allowed") .warn("this was previously accepted by the compiler but is \ being phased out; it will become a hard error in \ diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 189a18f4420..d4198261d3f 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -20,8 +20,8 @@ use serialize::{Decodable, Decoder, Encodable, Encoder}; use symbol::keywords; use tokenstream::{TokenStream, TokenTree}; -use std::cell::RefCell; -use std::fmt; +use std::cell::Cell; +use std::{cmp, fmt}; use std::rc::Rc; #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)] @@ -169,7 +169,8 @@ pub enum Token { Underscore, Lifetime(ast::Ident), - /* For interpolation */ + // The `LazyTokenStream` is a pure function of the `Nonterminal`, + // and so the `LazyTokenStream` can be ignored by Eq, Hash, etc. Interpolated(Rc<(Nonterminal, LazyTokenStream)>), // Can be expanded into several tokens. /// Doc comment @@ -468,19 +469,40 @@ pub fn is_op(tok: &Token) -> bool { } } -#[derive(Clone, Eq, PartialEq, Debug)] -pub struct LazyTokenStream(RefCell<Option<TokenStream>>); +pub struct LazyTokenStream(Cell<Option<TokenStream>>); + +impl Clone for LazyTokenStream { + fn clone(&self) -> Self { + let opt_stream = self.0.take(); + self.0.set(opt_stream.clone()); + LazyTokenStream(Cell::new(opt_stream)) + } +} + +impl cmp::Eq for LazyTokenStream {} +impl PartialEq for LazyTokenStream { + fn eq(&self, _other: &LazyTokenStream) -> bool { + true + } +} + +impl fmt::Debug for LazyTokenStream { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.clone().0.into_inner(), f) + } +} impl LazyTokenStream { pub fn new() -> Self { - LazyTokenStream(RefCell::new(None)) + LazyTokenStream(Cell::new(None)) } pub fn force<F: FnOnce() -> TokenStream>(&self, f: F) -> TokenStream { - let mut opt_stream = self.0.borrow_mut(); + let mut opt_stream = self.0.take(); if opt_stream.is_none() { - *opt_stream = Some(f()); - }; + opt_stream = Some(f()); + } + self.0.set(opt_stream.clone()); opt_stream.clone().unwrap() } } @@ -498,7 +520,5 @@ impl Decodable for LazyTokenStream { } impl ::std::hash::Hash for LazyTokenStream { - fn hash<H: ::std::hash::Hasher>(&self, hasher: &mut H) { - self.0.borrow().hash(hasher); - } + fn hash<H: ::std::hash::Hasher>(&self, _hasher: &mut H) {} } |
