Skip to content

Commit

Permalink
Rollup merge of rust-lang#40606 - oli-obk:interned_str_usability, r=j…
Browse files Browse the repository at this point in the history
…seyfried

Improve `InternedString` usability
  • Loading branch information
alexcrichton committed Mar 27, 2017
2 parents 76cc08b + eb447f4 commit 666bb19
Show file tree
Hide file tree
Showing 47 changed files with 160 additions and 126 deletions.
2 changes: 1 addition & 1 deletion src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ fn android_copy_libs(build: &Build, compiler: &Compiler, target: &str) {
.arg(ADB_TEST_DIR));

let target_dir = format!("{}/{}", ADB_TEST_DIR, target);
build.run(Command::new("adb").args(&["shell", "mkdir", &target_dir[..]]));
build.run(Command::new("adb").args(&["shell", "mkdir", &target_dir]));

for f in t!(build.sysroot_libdir(compiler, target).read_dir()) {
let f = t!(f);
Expand Down
6 changes: 3 additions & 3 deletions src/grammar/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ fn parse_antlr_token(s: &str, tokens: &HashMap<String, token::Token>, surrogate_
let toknum = &s[content_end + 3 .. toknum_end];

let not_found = format!("didn't find token {:?} in the map", toknum);
let proto_tok = tokens.get(toknum).expect(&not_found[..]);
let proto_tok = tokens.get(toknum).expect(&not_found);

let nm = Symbol::intern(content);

Expand Down Expand Up @@ -304,14 +304,14 @@ fn main() {
let mut token_file = File::open(&Path::new(&args.next().unwrap())).unwrap();
let mut token_list = String::new();
token_file.read_to_string(&mut token_list).unwrap();
let token_map = parse_token_list(&token_list[..]);
let token_map = parse_token_list(&token_list);

let stdin = std::io::stdin();
let lock = stdin.lock();
let lines = lock.lines();
let antlr_tokens = lines.map(|l| parse_antlr_token(l.unwrap().trim(),
&token_map,
&surrogate_pairs_pos[..],
&surrogate_pairs_pos,
has_bom));

for antlr_tok in antlr_tokens {
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1376,7 +1376,7 @@ mod tests {
thread::spawn(move || {
check_links(&n);
let a: &[_] = &[&1, &2, &3];
assert_eq!(a, &n.iter().collect::<Vec<_>>()[..]);
assert_eq!(a, &*n.iter().collect::<Vec<_>>());
})
.join()
.ok()
Expand Down
6 changes: 3 additions & 3 deletions src/libgraphviz/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ impl<'a> LabelText<'a> {
pub fn to_dot_string(&self) -> String {
match self {
&LabelStr(ref s) => format!("\"{}\"", s.escape_default()),
&EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(&s[..])),
&EscStr(ref s) => format!("\"{}\"", LabelText::escape_str(&s)),
&HtmlStr(ref s) => format!("<{}>", s),
}
}
Expand Down Expand Up @@ -587,7 +587,7 @@ impl<'a> LabelText<'a> {
let mut prefix = self.pre_escaped_content().into_owned();
let suffix = suffix.pre_escaped_content();
prefix.push_str(r"\n\n");
prefix.push_str(&suffix[..]);
prefix.push_str(&suffix);
EscStr(prefix.into_cow())
}
}
Expand Down Expand Up @@ -878,7 +878,7 @@ mod tests {
type Node = Node;
type Edge = &'a Edge;
fn graph_id(&'a self) -> Id<'a> {
Id::new(&self.name[..]).unwrap()
Id::new(self.name).unwrap()
}
fn node_id(&'a self, n: &Node) -> Id<'a> {
id_name(n)
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ich/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl Fingerprint {
impl Encodable for Fingerprint {
#[inline]
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
for &byte in &self.0[..] {
for &byte in &self.0 {
s.emit_u8(byte)?;
}
Ok(())
Expand All @@ -66,7 +66,7 @@ impl Decodable for Fingerprint {
#[inline]
fn decode<D: Decoder>(d: &mut D) -> Result<Fingerprint, D::Error> {
let mut result = Fingerprint([0u8; FINGERPRINT_LENGTH]);
for byte in &mut result.0[..] {
for byte in &mut result.0 {
*byte = d.read_u8()?;
}
Ok(result)
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ use std::cmp;
use std::default::Default as StdDefault;
use std::mem;
use std::fmt;
use std::ops::Deref;
use syntax::attr;
use syntax::ast;
use syntax::symbol::Symbol;
Expand Down Expand Up @@ -485,7 +484,7 @@ pub fn raw_struct_lint<'a, S>(sess: &'a Session,
Allow => bug!("earlier conditional return should handle Allow case")
};
let hyphen_case_lint_name = name.replace("_", "-");
if lint_flag_val.as_str().deref() == name {
if lint_flag_val.as_str() == name {
err.note(&format!("requested on the command line with `{} {}`",
flag, hyphen_case_lint_name));
} else {
Expand All @@ -496,7 +495,7 @@ pub fn raw_struct_lint<'a, S>(sess: &'a Session,
},
Node(lint_attr_name, src) => {
def = Some(src);
if lint_attr_name.as_str().deref() != name {
if lint_attr_name.as_str() != name {
let level_str = level.as_str();
err.note(&format!("#[{}({})] implied by #[{}({})]",
level_str, name, level_str, lint_attr_name));
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
if !self.stability.borrow().active_features.contains(feature) {
let msg = match *reason {
Some(ref r) => format!("use of unstable library feature '{}': {}",
&feature.as_str(), &r),
feature.as_str(), &r),
None => format!("use of unstable library feature '{}'", &feature)
};
emit_feature_err(&self.sess.parse_sess, &feature.as_str(), span,
Expand Down
24 changes: 12 additions & 12 deletions src/librustc_borrowck/borrowck/fragments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,11 @@ pub fn fixup_fragment_sets<'a, 'tcx>(this: &MoveData<'tcx>, tcx: TyCtxt<'a, 'tcx
// First, filter out duplicates
moved.sort();
moved.dedup();
debug!("fragments 1 moved: {:?}", path_lps(&moved[..]));
debug!("fragments 1 moved: {:?}", path_lps(&moved));

assigned.sort();
assigned.dedup();
debug!("fragments 1 assigned: {:?}", path_lps(&assigned[..]));
debug!("fragments 1 assigned: {:?}", path_lps(&assigned));

// Second, build parents from the moved and assigned.
for m in &moved {
Expand All @@ -291,14 +291,14 @@ pub fn fixup_fragment_sets<'a, 'tcx>(this: &MoveData<'tcx>, tcx: TyCtxt<'a, 'tcx

parents.sort();
parents.dedup();
debug!("fragments 2 parents: {:?}", path_lps(&parents[..]));
debug!("fragments 2 parents: {:?}", path_lps(&parents));

// Third, filter the moved and assigned fragments down to just the non-parents
moved.retain(|f| non_member(*f, &parents[..]));
debug!("fragments 3 moved: {:?}", path_lps(&moved[..]));
moved.retain(|f| non_member(*f, &parents));
debug!("fragments 3 moved: {:?}", path_lps(&moved));

assigned.retain(|f| non_member(*f, &parents[..]));
debug!("fragments 3 assigned: {:?}", path_lps(&assigned[..]));
assigned.retain(|f| non_member(*f, &parents));
debug!("fragments 3 assigned: {:?}", path_lps(&assigned));

// Fourth, build the leftover from the moved, assigned, and parents.
for m in &moved {
Expand All @@ -316,16 +316,16 @@ pub fn fixup_fragment_sets<'a, 'tcx>(this: &MoveData<'tcx>, tcx: TyCtxt<'a, 'tcx

unmoved.sort();
unmoved.dedup();
debug!("fragments 4 unmoved: {:?}", frag_lps(&unmoved[..]));
debug!("fragments 4 unmoved: {:?}", frag_lps(&unmoved));

// Fifth, filter the leftover fragments down to its core.
unmoved.retain(|f| match *f {
AllButOneFrom(_) => true,
Just(mpi) => non_member(mpi, &parents[..]) &&
non_member(mpi, &moved[..]) &&
non_member(mpi, &assigned[..])
Just(mpi) => non_member(mpi, &parents) &&
non_member(mpi, &moved) &&
non_member(mpi, &assigned)
});
debug!("fragments 5 unmoved: {:?}", frag_lps(&unmoved[..]));
debug!("fragments 5 unmoved: {:?}", frag_lps(&unmoved));

// Swap contents back in.
fragments.unmoved_fragments = unmoved;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_borrowck/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn borrowck_fn<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, body_id: hir::BodyId) {
&flowed_moves.move_data,
owner_id);

check_loans::check_loans(bccx, &loan_dfcx, &flowed_moves, &all_loans[..], body);
check_loans::check_loans(bccx, &loan_dfcx, &flowed_moves, &all_loans, body);
}

fn build_borrowck_dataflow_data<'a, 'tcx>(this: &mut BorrowckCtxt<'a, 'tcx>,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_borrowck/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl<'a, 'tcx> DataflowLabeller<'a, 'tcx> {
set.push_str(", ");
}
let loan_str = self.borrowck_ctxt.loan_path_to_string(&lp);
set.push_str(&loan_str[..]);
set.push_str(&loan_str);
saw_some = true;
true
});
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_const_eval/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,10 +680,10 @@ fn is_useful_specialized<'p, 'a:'p, 'tcx: 'a>(
}).collect();
let wild_patterns: Vec<_> = wild_patterns_owned.iter().collect();
let matrix = Matrix(m.iter().flat_map(|r| {
specialize(cx, &r[..], &ctor, &wild_patterns)
specialize(cx, &r, &ctor, &wild_patterns)
}).collect());
match specialize(cx, v, &ctor, &wild_patterns) {
Some(v) => match is_useful(cx, &matrix, &v[..], witness) {
Some(v) => match is_useful(cx, &matrix, &v, witness) {
UsefulWithWitness(witnesses) => UsefulWithWitness(
witnesses.into_iter()
.map(|witness| witness.apply_constructor(cx, &ctor, lty))
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_const_eval/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ fn check_arms<'a, 'tcx>(cx: &mut MatchCheckCtxt<'a, 'tcx>,
for &(pat, hir_pat) in pats {
let v = vec![pat];

match is_useful(cx, &seen, &v[..], LeaveOutWitness) {
match is_useful(cx, &seen, &v, LeaveOutWitness) {
NotUseful => {
match source {
hir::MatchSource::IfLetDesugar { .. } => {
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_data_structures/accumulate_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,17 @@ impl<A: Array> Deref for AccumulateVec<A> {
type Target = [A::Element];
fn deref(&self) -> &Self::Target {
match *self {
AccumulateVec::Array(ref v) => &v[..],
AccumulateVec::Heap(ref v) => &v[..],
AccumulateVec::Array(ref v) => v,
AccumulateVec::Heap(ref v) => v,
}
}
}

impl<A: Array> DerefMut for AccumulateVec<A> {
fn deref_mut(&mut self) -> &mut [A::Element] {
match *self {
AccumulateVec::Array(ref mut v) => &mut v[..],
AccumulateVec::Heap(ref mut v) => &mut v[..],
AccumulateVec::Array(ref mut v) => v,
AccumulateVec::Heap(ref mut v) => v,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_data_structures/base_n.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn encode(n: u64, base: u64) -> String {
#[test]
fn test_encode() {
fn test(n: u64, base: u64) {
assert_eq!(Ok(n), u64::from_str_radix(&encode(n, base)[..], base as u32));
assert_eq!(Ok(n), u64::from_str_radix(&encode(n, base), base as u32));
}

for base in 2..37 {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_data_structures/blake2b.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct Blake2bCtx {
impl ::std::fmt::Debug for Blake2bCtx {
fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> Result<(), ::std::fmt::Error> {
try!(write!(fmt, "hash: "));
for v in &self.h[..] {
for v in &self.h {
try!(write!(fmt, "{:x}", v));
}
Ok(())
Expand Down
8 changes: 4 additions & 4 deletions src/librustc_data_structures/indexed_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ impl<T: Idx> IdxSet<T> {
impl<T: Idx> Deref for IdxSetBuf<T> {
type Target = IdxSet<T>;
fn deref(&self) -> &IdxSet<T> {
unsafe { IdxSet::from_slice(&self.bits[..]) }
unsafe { IdxSet::from_slice(&self.bits) }
}
}

impl<T: Idx> DerefMut for IdxSetBuf<T> {
fn deref_mut(&mut self) -> &mut IdxSet<T> {
unsafe { IdxSet::from_slice_mut(&mut self.bits[..]) }
unsafe { IdxSet::from_slice_mut(&mut self.bits) }
}
}

Expand Down Expand Up @@ -135,11 +135,11 @@ impl<T: Idx> IdxSet<T> {
}

pub fn words(&self) -> &[Word] {
&self.bits[..]
&self.bits
}

pub fn words_mut(&mut self) -> &mut [Word] {
&mut self.bits[..]
&mut self.bits
}

pub fn clone_from(&mut self, other: &IdxSet<T>) {
Expand Down
10 changes: 5 additions & 5 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ fn make_output(matches: &getopts::Matches) -> (Option<PathBuf>, Option<PathBuf>)
// Extract input (string or file and optional path) from matches.
fn make_input(free_matches: &[String]) -> Option<(Input, Option<PathBuf>)> {
if free_matches.len() == 1 {
let ifile = &free_matches[0][..];
let ifile = &free_matches[0];
if ifile == "-" {
let mut src = String::new();
io::stdin().read_to_string(&mut src).unwrap();
Expand Down Expand Up @@ -800,7 +800,7 @@ Available lint options:
for lint in lints {
let name = lint.name_lower().replace("_", "-");
println!(" {} {:7.7} {}",
padded(&name[..]),
padded(&name),
lint.default_level.as_str(),
lint.desc);
}
Expand Down Expand Up @@ -838,7 +838,7 @@ Available lint options:
.map(|x| x.to_string().replace("_", "-"))
.collect::<Vec<String>>()
.join(", ");
println!(" {} {}", padded(&name[..]), desc);
println!(" {} {}", padded(&name), desc);
}
println!("\n");
};
Expand Down Expand Up @@ -945,7 +945,7 @@ pub fn handle_options(args: &[String]) -> Option<getopts::Matches> {
.into_iter()
.map(|x| x.opt_group)
.collect();
let matches = match getopts::getopts(&args[..], &all_groups) {
let matches = match getopts::getopts(&args, &all_groups) {
Ok(m) => m,
Err(f) => early_error(ErrorOutputType::default(), &f.to_string()),
};
Expand Down Expand Up @@ -1084,7 +1084,7 @@ pub fn monitor<F: FnOnce() + Send + 'static>(f: F) {
format!("we would appreciate a bug report: {}", BUG_REPORT_URL)];
for note in &xs {
handler.emit(&MultiSpan::new(),
&note[..],
&note,
errors::Level::Note);
}
if match env::var_os("RUST_BACKTRACE") {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_driver/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ impl UserIdentifiedItem {
-> NodesMatchingUII<'a, 'hir> {
match *self {
ItemViaNode(node_id) => NodesMatchingDirect(Some(node_id).into_iter()),
ItemViaPath(ref parts) => NodesMatchingSuffix(map.nodes_matching_suffix(&parts[..])),
ItemViaPath(ref parts) => NodesMatchingSuffix(map.nodes_matching_suffix(&parts)),
}
}

Expand All @@ -600,7 +600,7 @@ impl UserIdentifiedItem {
user_option,
self.reconstructed_input(),
is_wrong_because);
sess.fatal(&message[..])
sess.fatal(&message)
};

let mut saw_node = ast::DUMMY_NODE_ID;
Expand Down Expand Up @@ -771,7 +771,7 @@ fn print_flowgraph<'a, 'tcx, W: Write>(variants: Vec<borrowck_dot::Variant>,
fn expand_err_details(r: io::Result<()>) -> io::Result<()> {
r.map_err(|ioerr| {
io::Error::new(io::ErrorKind::Other,
&format!("graphviz::render failed: {}", ioerr)[..])
format!("graphviz::render failed: {}", ioerr))
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl<'a, 'gcx, 'tcx> Env<'a, 'gcx, 'tcx> {

pub fn t_param(&self, index: u32) -> Ty<'tcx> {
let name = format!("T{}", index);
self.infcx.tcx.mk_param(index, Symbol::intern(&name[..]))
self.infcx.tcx.mk_param(index, Symbol::intern(&name))
}

pub fn re_early_bound(&self, index: u32, name: &'static str) -> &'tcx ty::Region {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_incremental/persist/file_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ pub fn read_file(sess: &Session, path: &Path) -> io::Result<Option<Vec<u8>>> {
let rustc_version_str_len = rustc_version_str_len[0] as usize;
let mut buffer = Vec::with_capacity(rustc_version_str_len);
buffer.resize(rustc_version_str_len, 0);
file.read_exact(&mut buffer[..])?;
file.read_exact(&mut buffer)?;

if &buffer[..] != rustc_version().as_bytes() {
if buffer != rustc_version().as_bytes() {
report_format_mismatch(sess, path, "Different compiler version");
return Ok(None);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/bad_style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl NonCamelCaseTypes {
} else {
format!("{} `{}` should have a camel case name such as `{}`", sort, name, c)
};
cx.span_lint(NON_CAMEL_CASE_TYPES, span, &m[..]);
cx.span_lint(NON_CAMEL_CASE_TYPES, span, &m);
}
}
}
Expand Down
Loading

0 comments on commit 666bb19

Please sign in to comment.