Skip to content

Use idiomatic names for string-related methods names. #35955

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/librbml/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,12 @@ impl<'doc> Doc<'doc> {
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()
}
}

Expand Down Expand Up @@ -773,7 +773,7 @@ pub mod reader {
Ok(char::from_u32(doc_as_u32(self.next_doc(EsChar)?)).unwrap())
}
fn read_str(&mut self) -> DecodeResult<String> {
Ok(self.next_doc(EsStr)?.as_str())
Ok(self.next_doc(EsStr)?.to_string())
}

// Compound types:
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ pub trait LintContext: Sized {
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,
Expand Down Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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)
}
}
}
2 changes: 1 addition & 1 deletion src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ impl LintId {
}

/// Get the name of the lint.
pub fn as_str(&self) -> String {
pub fn to_string(&self) -> String {
self.lint.name_lower()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ Available lint options:
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::<Vec<String>>()
.join(", ");
println!(" {} {}", padded(&name[..]), desc);
Expand Down
39 changes: 20 additions & 19 deletions src/librustc_metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ pub fn load_index(data: &[u8]) -> index::Index {

pub fn crate_rustc_version(data: &[u8]) -> Option<String> {
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 {
Expand Down Expand Up @@ -207,7 +207,7 @@ fn item_defaultness(item: rbml::Doc) -> hir::Defaultness {

fn item_sort(item: rbml::Doc) -> Option<char> {
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
})
}

Expand Down Expand Up @@ -282,7 +282,7 @@ fn item_name(item: rbml::Doc) -> ast::Name {

fn maybe_item_name(item: rbml::Doc) -> Option<ast::Name> {
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)
})
}
Expand Down Expand Up @@ -368,7 +368,7 @@ fn parse_polarity(item_doc: rbml::Doc) -> hir::ImplPolarity {
fn parse_associated_type_names(item_doc: rbml::Doc) -> Vec<ast::Name> {
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()
}

Expand Down Expand Up @@ -682,7 +682,7 @@ fn each_child_of_item_or_crate<F, G>(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 {
Expand Down Expand Up @@ -869,7 +869,7 @@ fn get_explicit_self(item: rbml::Doc) -> ty::ExplicitSelfCategory {
}

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 {
Expand Down Expand Up @@ -1124,19 +1124,19 @@ pub fn get_struct_field_names(cdata: Cmd, id: DefIndex) -> Vec<ast::Name> {
fn get_meta_items(md: rbml::Doc) -> Vec<P<ast::MetaItem>> {
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()
Expand Down Expand Up @@ -1191,7 +1191,7 @@ pub fn get_crate_deps(data: &[u8]) -> Vec<CrateDep> {

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)| {
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -1446,11 +1446,12 @@ 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();
let mut split = spec.split(':');
let cnum = split.next().unwrap();
let link = split.next().unwrap();
let cnum: ast::CrateNum = cnum.parse().unwrap();
let cnum = cdata.cnum_map.borrow()[cnum];
result.push((cnum, if link == "d" {
Expand All @@ -1476,7 +1477,7 @@ pub fn get_method_arg_names(cdata: Cmd, id: DefIndex) -> Vec<String> {
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![],
Expand Down Expand Up @@ -1641,7 +1642,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)
}
Expand Down