From ab92ea526d455b402efbccc7160c8aec0237c88f Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 28 Apr 2014 20:36:08 -0700 Subject: std: Modernize the local_data api This commit brings the local_data api up to modern rust standards with a few key improvements: * The `pop` and `set` methods have been combined into one method, `replace` * The `get_mut` method has been removed. All interior mutability should be done through `RefCell`. * All functionality is now exposed as a method on the keys themselves. Instead of importing std::local_data, you now use "key.replace()" and "key.get()". * All closures have been removed in favor of RAII functionality. This means that get() and get_mut() no long require closures, but rather return Option where the smart pointer takes care of relinquishing the borrow and also implements the necessary Deref traits * The modify() function was removed to cut the local_data interface down to its bare essentials (similarly to how RefCell removed set/get). [breaking-change] --- src/libsyntax/parse/token.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index e4e71baad44..131e744d83d 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -19,7 +19,6 @@ use util::interner; use serialize::{Decodable, Decoder, Encodable, Encoder}; use std::cast; use std::fmt; -use std::local_data; use std::path::BytesContainer; use std::rc::Rc; use std::strbuf::StrBuf; @@ -529,11 +528,11 @@ pub type IdentInterner = StrInterner; // FIXME(eddyb) #8726 This should probably use a task-local reference. pub fn get_ident_interner() -> Rc { local_data_key!(key: Rc<::parse::token::IdentInterner>) - match local_data::get(key, |k| k.map(|k| k.clone())) { - Some(interner) => interner, + match key.get() { + Some(interner) => interner.clone(), None => { let interner = Rc::new(mk_fresh_ident_interner()); - local_data::set(key, interner.clone()); + key.replace(Some(interner.clone())); interner } } -- cgit 1.4.1-3-g733a5