From 2655c89549d08a8fa8e90cc53591f7dc4794513c Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Tue, 23 Aug 2016 21:27:20 -0400 Subject: [PATCH] Use idiomatic names for string-related methods names. --- src/librbml/lib.rs | 8 ++++---- src/librustc/lint/context.rs | 6 +++--- src/librustc/lint/mod.rs | 2 +- src/librustc_driver/lib.rs | 2 +- src/librustc_metadata/decoder.rs | 34 ++++++++++++++++---------------- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/librbml/lib.rs b/src/librbml/lib.rs index 4edbeab5dfb..1825a892cf5 100644 --- a/src/librbml/lib.rs +++ b/src/librbml/lib.rs @@ -173,12 +173,12 @@ pub fn is_empty(&self) -> bool { self.start == self.end } - pub fn as_str_slice(&self) -> &'doc str { + pub fn as_str(&self) -> &'doc str { str::from_utf8(&self.data[self.start..self.end]).unwrap() } - pub fn as_str(&self) -> String { - self.as_str_slice().to_string() + pub fn to_string(&self) -> String { + self.as_str().to_string() } } @@ -773,7 +773,7 @@ fn read_char(&mut self) -> DecodeResult { Ok(char::from_u32(doc_as_u32(self.next_doc(EsChar)?)).unwrap()) } fn read_str(&mut self) -> DecodeResult { - Ok(self.next_doc(EsStr)?.as_str()) + Ok(self.next_doc(EsStr)?.to_string()) } // Compound types: diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index daac315e14d..29bcc1257fd 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -601,7 +601,7 @@ fn with_lint_attrs(&mut self, for (lint_id, level, span) in v { let (now, now_source) = self.lints().get_level_source(lint_id); if now == Forbid && level != Forbid { - let lint_name = lint_id.as_str(); + let lint_name = lint_id.to_string(); let mut diag_builder = struct_span_err!(self.sess(), span, E0453, "{}({}) overruled by outer forbid({})", level.as_str(), lint_name, @@ -1216,7 +1216,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, for &(lint, span, ref msg) in v { span_bug!(span, "unprocessed lint {} at {}: {}", - lint.as_str(), tcx.map.node_to_string(*id), *msg) + lint.to_string(), tcx.map.node_to_string(*id), *msg) } } @@ -1252,7 +1252,7 @@ pub fn check_ast_crate(sess: &Session, krate: &ast::Crate) { // in the iteration code. for (_, v) in sess.lints.borrow().iter() { for &(lint, span, ref msg) in v { - span_bug!(span, "unprocessed lint {}: {}", lint.as_str(), *msg) + span_bug!(span, "unprocessed lint {}: {}", lint.to_string(), *msg) } } } diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index f34b14224f7..0938086b000 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -263,7 +263,7 @@ pub fn of(lint: &'static Lint) -> LintId { } /// Get the name of the lint. - pub fn as_str(&self) -> String { + pub fn to_string(&self) -> String { self.lint.name_lower() } } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 6f57ae29418..4e87c931cc1 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -861,7 +861,7 @@ fn sort_lint_groups(lints: Vec<(&'static str, Vec, bool)>) for (name, to) in lints { let name = name.to_lowercase().replace("_", "-"); let desc = to.into_iter() - .map(|x| x.as_str().replace("_", "-")) + .map(|x| x.to_string().replace("_", "-")) .collect::>() .join(", "); println!(" {} {}", padded(&name[..]), desc); diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index d63e0866a9d..ca7f81db692 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -86,7 +86,7 @@ pub fn load_index(data: &[u8]) -> index::Index { pub fn crate_rustc_version(data: &[u8]) -> Option { let doc = rbml::Doc::new(data); - reader::maybe_get_doc(doc, tag_rustc_version).map(|s| s.as_str()) + reader::maybe_get_doc(doc, tag_rustc_version).map(|s| s.to_string()) } pub fn load_xrefs(data: &[u8]) -> index::DenseIndex { @@ -207,7 +207,7 @@ fn item_defaultness(item: rbml::Doc) -> hir::Defaultness { fn item_sort(item: rbml::Doc) -> Option { reader::tagged_docs(item, tag_item_trait_item_sort).nth(0).map(|doc| { - doc.as_str_slice().as_bytes()[0] as char + doc.as_str().as_bytes()[0] as char }) } @@ -282,7 +282,7 @@ fn item_name(item: rbml::Doc) -> ast::Name { fn maybe_item_name(item: rbml::Doc) -> Option { reader::maybe_get_doc(item, tag_paths_data_name).map(|name| { - let string = name.as_str_slice(); + let string = name.as_str(); token::intern(string) }) } @@ -368,7 +368,7 @@ fn parse_polarity(item_doc: rbml::Doc) -> hir::ImplPolarity { fn parse_associated_type_names(item_doc: rbml::Doc) -> Vec { let names_doc = reader::get_doc(item_doc, tag_associated_type_names); reader::tagged_docs(names_doc, tag_associated_type_name) - .map(|name_doc| token::intern(name_doc.as_str_slice())) + .map(|name_doc| token::intern(name_doc.as_str())) .collect() } @@ -682,7 +682,7 @@ fn each_child_of_item_or_crate(cdata: Cmd, let name_doc = reader::get_doc(reexport_doc, tag_items_data_item_reexport_name); - let name = name_doc.as_str_slice(); + let name = name_doc.as_str(); // This reexport may be in yet another crate. let crate_data = if child_def_id.krate == cdata.cnum { @@ -869,7 +869,7 @@ fn get_mutability(ch: u8) -> hir::Mutability { } let explicit_self_doc = reader::get_doc(item, tag_item_trait_method_explicit_self); - let string = explicit_self_doc.as_str_slice(); + let string = explicit_self_doc.as_str(); let explicit_self_kind = string.as_bytes()[0]; match explicit_self_kind as char { @@ -1124,19 +1124,19 @@ pub fn get_struct_field_names(cdata: Cmd, id: DefIndex) -> Vec { fn get_meta_items(md: rbml::Doc) -> Vec> { reader::tagged_docs(md, tag_meta_item_word).map(|meta_item_doc| { let nd = reader::get_doc(meta_item_doc, tag_meta_item_name); - let n = token::intern_and_get_ident(nd.as_str_slice()); + let n = token::intern_and_get_ident(nd.as_str()); attr::mk_word_item(n) }).chain(reader::tagged_docs(md, tag_meta_item_name_value).map(|meta_item_doc| { let nd = reader::get_doc(meta_item_doc, tag_meta_item_name); let vd = reader::get_doc(meta_item_doc, tag_meta_item_value); - let n = token::intern_and_get_ident(nd.as_str_slice()); - let v = token::intern_and_get_ident(vd.as_str_slice()); + let n = token::intern_and_get_ident(nd.as_str()); + let v = token::intern_and_get_ident(vd.as_str()); // FIXME (#623): Should be able to decode MetaItemKind::NameValue variants, // but currently the encoder just drops them attr::mk_name_value_item_str(n, v) })).chain(reader::tagged_docs(md, tag_meta_item_list).map(|meta_item_doc| { let nd = reader::get_doc(meta_item_doc, tag_meta_item_name); - let n = token::intern_and_get_ident(nd.as_str_slice()); + let n = token::intern_and_get_ident(nd.as_str()); let subitems = get_meta_items(meta_item_doc); attr::mk_list_item(n, subitems) })).collect() @@ -1191,7 +1191,7 @@ pub fn get_crate_deps(data: &[u8]) -> Vec { fn docstr(doc: rbml::Doc, tag_: usize) -> String { let d = reader::get_doc(doc, tag_); - d.as_str_slice().to_string() + d.as_str().to_string() } reader::tagged_docs(depsdoc, tag_crate_dep).enumerate().map(|(crate_num, depdoc)| { @@ -1233,14 +1233,14 @@ pub fn get_crate_hash(data: &[u8]) -> Svh { pub fn maybe_get_crate_name(data: &[u8]) -> Option<&str> { let cratedoc = rbml::Doc::new(data); reader::maybe_get_doc(cratedoc, tag_crate_crate_name).map(|doc| { - doc.as_str_slice() + doc.as_str() }) } pub fn get_crate_disambiguator<'a>(data: &'a [u8]) -> &'a str { let crate_doc = rbml::Doc::new(data); let disambiguator_doc = reader::get_doc(crate_doc, tag_crate_disambiguator); - let slice: &'a str = disambiguator_doc.as_str_slice(); + let slice: &'a str = disambiguator_doc.as_str(); slice } @@ -1446,8 +1446,8 @@ pub fn get_dylib_dependency_formats(cdata: Cmd) tag_dylib_dependency_formats); let mut result = Vec::new(); - debug!("found dylib deps: {}", formats.as_str_slice()); - for spec in formats.as_str_slice().split(',') { + debug!("found dylib deps: {}", formats.as_str()); + for spec in formats.as_str().split(',') { if spec.is_empty() { continue } let cnum = spec.split(':').nth(0).unwrap(); let link = spec.split(':').nth(1).unwrap(); @@ -1476,7 +1476,7 @@ pub fn get_method_arg_names(cdata: Cmd, id: DefIndex) -> Vec { match reader::maybe_get_doc(method_doc, tag_method_argument_names) { Some(args_doc) => { reader::tagged_docs(args_doc, tag_method_argument_name).map(|name_doc| { - name_doc.as_str_slice().to_string() + name_doc.as_str().to_string() }).collect() }, None => vec![], @@ -1641,7 +1641,7 @@ fn item_def_key(item_doc: rbml::Doc) -> hir_map::DefKey { let mut decoder = reader::Decoder::new(def_key_doc); let simple_key = def_key::DefKey::decode(&mut decoder).unwrap(); let name = reader::maybe_get_doc(item_doc, tag_paths_data_name).map(|name| { - token::intern(name.as_str_slice()).as_str() + token::intern(name.as_str()).as_str() }); def_key::recover_def_key(simple_key, name) }