@@ -25,9 +25,8 @@ use syntax_pos::{self, Span, FileName};
2525use tokenstream:: { TokenStream , TokenTree } ;
2626use tokenstream;
2727
28- use std:: cell:: Cell ;
2928use std:: { cmp, fmt} ;
30- use rustc_data_structures:: sync:: Lrc ;
29+ use rustc_data_structures:: sync:: { Lrc , Lock } ;
3130
3231#[ derive( Clone , RustcEncodable , RustcDecodable , PartialEq , Eq , Hash , Debug , Copy ) ]
3332pub enum BinOpToken {
@@ -614,15 +613,8 @@ pub fn is_op(tok: &Token) -> bool {
614613 }
615614}
616615
617- pub struct LazyTokenStream ( Cell < Option < TokenStream > > ) ;
618-
619- impl Clone for LazyTokenStream {
620- fn clone ( & self ) -> Self {
621- let opt_stream = self . 0 . take ( ) ;
622- self . 0 . set ( opt_stream. clone ( ) ) ;
623- LazyTokenStream ( Cell :: new ( opt_stream) )
624- }
625- }
616+ #[ derive( Clone ) ]
617+ pub struct LazyTokenStream ( Lock < Option < TokenStream > > ) ;
626618
627619impl cmp:: Eq for LazyTokenStream { }
628620impl PartialEq for LazyTokenStream {
@@ -639,15 +631,14 @@ impl fmt::Debug for LazyTokenStream {
639631
640632impl LazyTokenStream {
641633 pub fn new ( ) -> Self {
642- LazyTokenStream ( Cell :: new ( None ) )
634+ LazyTokenStream ( Lock :: new ( None ) )
643635 }
644636
645637 pub fn force < F : FnOnce ( ) -> TokenStream > ( & self , f : F ) -> TokenStream {
646- let mut opt_stream = self . 0 . take ( ) ;
638+ let mut opt_stream = self . 0 . lock ( ) ;
647639 if opt_stream. is_none ( ) {
648- opt_stream = Some ( f ( ) ) ;
640+ * opt_stream = Some ( f ( ) ) ;
649641 }
650- self . 0 . set ( opt_stream. clone ( ) ) ;
651642 opt_stream. clone ( ) . unwrap ( )
652643 }
653644}
0 commit comments