Skip to content

Commit

Permalink
Fallout from deprecation
Browse files Browse the repository at this point in the history
This commit handles the fallout from deprecating `_with` and `_equiv` methods.
  • Loading branch information
aturon committed Nov 17, 2014
1 parent 80a2867 commit 7213de1
Show file tree
Hide file tree
Showing 21 changed files with 56 additions and 49 deletions.
2 changes: 1 addition & 1 deletion src/grammar/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn parse_antlr_token(s: &str, tokens: &HashMap<String, Token>) -> TokenAndSpan {
let toknum = m.name("toknum");
let content = m.name("content");

let proto_tok = tokens.find_equiv(&toknum).expect(format!("didn't find token {} in the map",
let proto_tok = tokens.get(&toknum).expect(format!("didn't find token {} in the map",
toknum).as_slice());

let nm = parse::token::intern(content);
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/tree/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
//! ```
pub mod map;
pub mod set;
pub mod set;
2 changes: 1 addition & 1 deletion src/libcollections/trie/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
//! `TrieMap` is ordered.
pub mod map;
pub mod set;
pub mod set;
2 changes: 1 addition & 1 deletion src/libregex/re.rs
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ impl<'t> Captures<'t> {
match self.named {
None => "",
Some(ref h) => {
match h.find_equiv(name) {
match h.get(name) {
None => "",
Some(i) => self.at(*i),
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ impl LintStore {
}

fn register_renamed(&mut self, old_name: &str, new_name: &str) {
let target = match self.by_name.find_equiv(new_name) {
let target = match self.by_name.get(new_name) {
Some(&Id(lint_id)) => lint_id.clone(),
_ => panic!("invalid lint renaming of {} to {}", old_name, new_name)
};
Expand Down Expand Up @@ -259,7 +259,7 @@ impl LintStore {
fn find_lint(&self, lint_name: &str, sess: &Session, span: Option<Span>)
-> Option<LintId>
{
match self.by_name.find_equiv(lint_name) {
match self.by_name.get(lint_name) {
Some(&Id(lint_id)) => Some(lint_id),
Some(&Renamed(ref new_name, lint_id)) => {
let warning = format!("lint {} has been renamed to {}",
Expand All @@ -282,7 +282,7 @@ impl LintStore {
match self.lint_groups.iter().map(|(&x, pair)| (x, pair.ref0().clone()))
.collect::<FnvHashMap<&'static str,
Vec<LintId>>>()
.find_equiv(lint_name.as_slice()) {
.get(lint_name.as_slice()) {
Some(v) => {
v.iter()
.map(|lint_id: &LintId|
Expand Down Expand Up @@ -489,7 +489,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
match self.lints.find_lint(lint_name.get(), &self.tcx.sess, Some(span)) {
Some(lint_id) => vec![(lint_id, level, span)],
None => {
match self.lints.lint_groups.find_equiv(lint_name.get()) {
match self.lints.lint_groups.get(lint_name.get()) {
Some(&(ref v, _)) => v.iter()
.map(|lint_id: &LintId|
(*lint_id, level, span))
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ fn existing_match(e: &Env, name: &str,
// `source` stores paths which are normalized which may be different
// from the strings on the command line.
let source = e.sess.cstore.get_used_crate_source(cnum).unwrap();
match e.sess.opts.externs.find_equiv(name) {
match e.sess.opts.externs.get(name) {
Some(locs) => {
let found = locs.iter().any(|l| {
let l = fs::realpath(&Path::new(l.as_slice())).ok();
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ fn item_path(item_doc: rbml::Doc) -> Vec<ast_map::PathElem> {
fn item_name(intr: &IdentInterner, item: rbml::Doc) -> ast::Name {
let name = reader::get_doc(item, tag_paths_data_name);
let string = name.as_str_slice();
match intr.find_equiv(string) {
match intr.find(string) {
None => token::intern(string),
Some(val) => val,
}
Expand Down Expand Up @@ -1449,4 +1449,3 @@ pub fn is_associated_type(cdata: Cmd, id: ast::NodeId) -> bool {
Some(item) => item_sort(item) == 't',
}
}

6 changes: 3 additions & 3 deletions src/librustc/metadata/filesearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'a> FileSearch<'a> {
debug!("filesearch: searching lib path");
let tlib_path = make_target_lib_path(self.sysroot,
self.triple);
if !visited_dirs.contains_equiv(tlib_path.as_vec()) {
if !visited_dirs.contains(tlib_path.as_vec()) {
match f(&tlib_path) {
FileMatches => found = true,
FileDoesntMatch => ()
Expand All @@ -69,9 +69,9 @@ impl<'a> FileSearch<'a> {
let tlib_path = make_rustpkg_lib_path(
self.sysroot, path, self.triple);
debug!("is {} in visited_dirs? {}", tlib_path.display(),
visited_dirs.contains_equiv(&tlib_path.as_vec().to_vec()));
visited_dirs.contains(&tlib_path.as_vec().to_vec()));

if !visited_dirs.contains_equiv(tlib_path.as_vec()) {
if !visited_dirs.contains(tlib_path.as_vec()) {
visited_dirs.insert(tlib_path.as_vec().to_vec());
// Don't keep searching the RUST_PATH if one match turns up --
// if we did, we'd get a "multiple matching crates" error
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ impl<'a> Context<'a> {
}

fn find_commandline_library(&mut self) -> Option<Library> {
let locs = match self.sess.opts.externs.find_equiv(self.crate_name) {
let locs = match self.sess.opts.externs.get(self.crate_name) {
Some(s) => s,
None => return None,
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl<'a, 'v> Visitor<'v> for LanguageItemCollector<'a> {
fn visit_item(&mut self, item: &ast::Item) {
match extract(item.attrs.as_slice()) {
Some(value) => {
let item_index = self.item_refs.find_equiv(&value).map(|x| *x);
let item_index = self.item_refs.get(value.get()).map(|x| *x);

match item_index {
Some(item_index) => {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ pub fn get_extern_fn(ccx: &CrateContext,
ty: Type,
output: ty::t)
-> ValueRef {
match externs.find_equiv(name) {
match externs.get(name) {
Some(n) => return *n,
None => {}
}
Expand All @@ -226,7 +226,7 @@ pub fn get_extern_fn(ccx: &CrateContext,
}

fn get_extern_rust_fn(ccx: &CrateContext, fn_ty: ty::t, name: &str, did: ast::DefId) -> ValueRef {
match ccx.externs().borrow().find_equiv(name) {
match ccx.externs().borrow().get(name) {
Some(n) => return *n,
None => ()
}
Expand Down Expand Up @@ -2983,7 +2983,7 @@ fn internalize_symbols(cx: &SharedCrateContext, reachable: &HashSet<String>) {

let name = CString::new(llvm::LLVMGetValueName(val), false);
if !declared.contains(&name) &&
!reachable.contains_equiv(name.as_str().unwrap()) {
!reachable.contains(name.as_str().unwrap()) {
llvm::SetLinkage(val, llvm::InternalLinkage);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,7 @@ fn declare_local(bcx: Block,
}

fn file_metadata(cx: &CrateContext, full_path: &str) -> DIFile {
match debug_context(cx).created_files.borrow().find_equiv(full_path) {
match debug_context(cx).created_files.borrow().get(full_path) {
Some(file_metadata) => return *file_metadata,
None => ()
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/trans/type_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ impl TypeNames {
}

pub fn find_type(&self, s: &str) -> Option<Type> {
self.named_types.borrow().find_equiv(s).map(|x| Type::from_ref(*x))
self.named_types.borrow().get(s).map(|x| Type::from_ref(*x))
}

pub fn type_to_string(&self, ty: Type) -> String {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2122,7 +2122,7 @@ impl<'a> fmt::Show for Sidebar<'a> {

fn block(w: &mut fmt::Formatter, short: &str, longty: &str,
cur: &clean::Item, cx: &Context) -> fmt::Result {
let items = match cx.sidebar.find_equiv(short) {
let items = match cx.sidebar.get(short) {
Some(items) => items.as_slice(),
None => return Ok(())
};
Expand Down
4 changes: 2 additions & 2 deletions src/libserialize/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@ impl Json {
/// Otherwise, returns None.
pub fn find<'a>(&'a self, key: &str) -> Option<&'a Json>{
match self {
&Object(ref map) => map.find_with(|s| key.cmp(s.as_slice())),
&Object(ref map) => map.get(key),
_ => None
}
}
Expand All @@ -926,7 +926,7 @@ impl Json {
pub fn search<'a>(&'a self, key: &str) -> Option<&'a Json> {
match self {
&Object(ref map) => {
match map.find_with(|s| key.cmp(s.as_slice())) {
match map.get(key) {
Some(json_value) => Some(json_value),
None => {
for (_, v) in map.iter() {
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1944,11 +1944,11 @@ mod test_map {
m.insert("baz".to_string(), baz);


assert_eq!(m.find_equiv("foo"), Some(&foo));
assert_eq!(m.find_equiv("bar"), Some(&bar));
assert_eq!(m.find_equiv("baz"), Some(&baz));
assert_eq!(m.get("foo"), Some(&foo));
assert_eq!(m.get("bar"), Some(&bar));
assert_eq!(m.get("baz"), Some(&baz));

assert_eq!(m.find_equiv("qux"), None);
assert_eq!(m.get("qux"), None);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/diagnostics/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ impl Registry {
}

pub fn find_description(&self, code: &str) -> Option<&'static str> {
self.descriptions.find_equiv(code).map(|desc| *desc)
self.descriptions.get(code).map(|desc| *desc)
}
}
6 changes: 3 additions & 3 deletions src/libsyntax/ext/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn parse_args(ecx: &mut ExtCtxt, sp: Span, allow_method: bool,
let name = interned_name.get();
p.expect(&token::Eq);
let e = p.parse_expr();
match names.find_equiv(name) {
match names.get(name) {
None => {}
Some(prev) => {
ecx.span_err(e.span,
Expand Down Expand Up @@ -366,7 +366,7 @@ impl<'a, 'b> Context<'a, 'b> {
self.ecx.expr_path(path)
}
parse::CountIsName(n) => {
let i = match self.name_positions.find_equiv(n) {
let i = match self.name_positions.get(n) {
Some(&i) => i,
None => 0, // error already emitted elsewhere
};
Expand Down Expand Up @@ -410,7 +410,7 @@ impl<'a, 'b> Context<'a, 'b> {
// Named arguments are converted to positional arguments at
// the end of the list of arguments
parse::ArgumentNamed(n) => {
let i = match self.name_positions.find_equiv(n) {
let i = match self.name_positions.get(n) {
Some(&i) => i,
None => 0, // error already emitted elsewhere
};
Expand Down
20 changes: 14 additions & 6 deletions src/libsyntax/util/interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use ast::Name;

use std::borrow::BorrowFrom;
use std::collections::HashMap;
use std::cell::RefCell;
use std::cmp::Equiv;
use std::fmt;
use std::hash::Hash;
use std::rc::Rc;
Expand Down Expand Up @@ -75,9 +75,10 @@ impl<T: Eq + Hash + Clone + 'static> Interner<T> {
(*vect).len()
}

pub fn find_equiv<Sized? Q: Hash + Equiv<T>>(&self, val: &Q) -> Option<Name> {
pub fn find<Sized? Q>(&self, val: &Q) -> Option<Name>
where Q: BorrowFrom<T> + Eq + Hash {
let map = self.map.borrow();
match (*map).find_equiv(val) {
match (*map).get(val) {
Some(v) => Some(*v),
None => None,
}
Expand Down Expand Up @@ -117,6 +118,12 @@ impl fmt::Show for RcStr {
}
}

impl BorrowFrom<RcStr> for str {
fn borrow_from(owned: &RcStr) -> &str {
owned.string.as_slice()
}
}

impl RcStr {
pub fn new(string: &str) -> RcStr {
RcStr {
Expand Down Expand Up @@ -149,7 +156,7 @@ impl StrInterner {

pub fn intern(&self, val: &str) -> Name {
let mut map = self.map.borrow_mut();
match map.find_equiv(val) {
match map.get(val) {
Some(&idx) => return idx,
None => (),
}
Expand Down Expand Up @@ -195,8 +202,9 @@ impl StrInterner {
self.vect.borrow().len()
}

pub fn find_equiv<Sized? Q:Hash + Equiv<RcStr>>(&self, val: &Q) -> Option<Name> {
match (*self.map.borrow()).find_equiv(val) {
pub fn find<Sized? Q>(&self, val: &Q) -> Option<Name>
where Q: BorrowFrom<RcStr> + Eq + Hash {
match (*self.map.borrow()).get(val) {
Some(v) => Some(*v),
None => None,
}
Expand Down
20 changes: 10 additions & 10 deletions src/libterm/terminfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<T: Writer+Send> Terminal<T> for TerminfoTerminal<T> {
if self.num_colors > color {
let s = expand(self.ti
.strings
.find_equiv("setaf")
.get("setaf")
.unwrap()
.as_slice(),
&[Number(color as int)], &mut Variables::new());
Expand All @@ -95,7 +95,7 @@ impl<T: Writer+Send> Terminal<T> for TerminfoTerminal<T> {
if self.num_colors > color {
let s = expand(self.ti
.strings
.find_equiv("setab")
.get("setab")
.unwrap()
.as_slice(),
&[Number(color as int)], &mut Variables::new());
Expand All @@ -113,7 +113,7 @@ impl<T: Writer+Send> Terminal<T> for TerminfoTerminal<T> {
attr::BackgroundColor(c) => self.bg(c),
_ => {
let cap = cap_for_attr(attr);
let parm = self.ti.strings.find_equiv(cap);
let parm = self.ti.strings.get(cap);
if parm.is_some() {
let s = expand(parm.unwrap().as_slice(),
&[],
Expand All @@ -135,19 +135,19 @@ impl<T: Writer+Send> Terminal<T> for TerminfoTerminal<T> {
}
_ => {
let cap = cap_for_attr(attr);
self.ti.strings.find_equiv(cap).is_some()
self.ti.strings.get(cap).is_some()
}
}
}

fn reset(&mut self) -> IoResult<()> {
let mut cap = self.ti.strings.find_equiv("sgr0");
let mut cap = self.ti.strings.get("sgr0");
if cap.is_none() {
// are there any terminals that have color/attrs and not sgr0?
// Try falling back to sgr, then op
cap = self.ti.strings.find_equiv("sgr");
cap = self.ti.strings.get("sgr");
if cap.is_none() {
cap = self.ti.strings.find_equiv("op");
cap = self.ti.strings.get("op");
}
}
let s = cap.map_or(Err("can't find terminfo capability `sgr0`".to_string()), |op| {
Expand Down Expand Up @@ -202,9 +202,9 @@ impl<T: Writer+Send> TerminfoTerminal<T> {
}

let inf = ti.unwrap();
let nc = if inf.strings.find_equiv("setaf").is_some()
&& inf.strings.find_equiv("setab").is_some() {
inf.numbers.find_equiv("colors").map_or(0, |&n| n)
let nc = if inf.strings.get("setaf").is_some()
&& inf.strings.get("setab").is_some() {
inf.numbers.get("colors").map_or(0, |&n| n)
} else { 0 };

return Some(box TerminfoTerminal {out: out,
Expand Down
2 changes: 1 addition & 1 deletion src/test/bench/shootout-k-nucleotide-pipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn sort_and_fmt(mm: &HashMap<Vec<u8> , uint>, total: uint) -> String {
// given a map, search for the frequency of a pattern
fn find(mm: &HashMap<Vec<u8> , uint>, key: String) -> uint {
let key = key.into_ascii().as_slice().to_lowercase().into_string();
match mm.find_equiv(key.as_bytes()) {
match mm.get(key.as_bytes()) {
option::None => { return 0u; }
option::Some(&num) => { return num; }
}
Expand Down

0 comments on commit 7213de1

Please sign in to comment.