rustc: Remove matching on ~str from the language

The `~str` type is not long for this world as it will be superseded by the
soon-to-come DST changes for the language. The new type will be
`~Str`, and matching over the allocation will no longer be supported.
Matching on `&str` will continue to work, in both a pre and post DST world.
This commit is contained in:
Michael Darakananda 2014-03-07 16:15:50 -05:00
parent 3316a0e6b2
commit f079c94f72
17 changed files with 57 additions and 110 deletions

View file

@ -191,13 +191,13 @@ pub fn opt_str2(maybestr: Option<~str>) -> ~str {
} }
pub fn str_mode(s: ~str) -> mode { pub fn str_mode(s: ~str) -> mode {
match s { match s.as_slice() {
~"compile-fail" => mode_compile_fail, "compile-fail" => mode_compile_fail,
~"run-fail" => mode_run_fail, "run-fail" => mode_run_fail,
~"run-pass" => mode_run_pass, "run-pass" => mode_run_pass,
~"pretty" => mode_pretty, "pretty" => mode_pretty,
~"debug-info" => mode_debug_info, "debug-info" => mode_debug_info,
~"codegen" => mode_codegen, "codegen" => mode_codegen,
_ => fail!("invalid mode") _ => fail!("invalid mode")
} }
} }

View file

@ -38,9 +38,9 @@ use test::MetricMap;
pub fn run(config: config, testfile: ~str) { pub fn run(config: config, testfile: ~str) {
match config.target { match config.target.as_slice() {
~"arm-linux-androideabi" => { "arm-linux-androideabi" => {
if !config.adb_device_status { if !config.adb_device_status {
fail!("android device not available"); fail!("android device not available");
} }
@ -277,8 +277,8 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
let exe_file = make_exe_name(config, testfile); let exe_file = make_exe_name(config, testfile);
let mut proc_args; let mut proc_args;
match config.target { match config.target.as_slice() {
~"arm-linux-androideabi" => { "arm-linux-androideabi" => {
cmds = cmds.replace("run","continue"); cmds = cmds.replace("run","continue");
@ -682,9 +682,9 @@ fn exec_compiled_test(config: &config, props: &TestProps,
let env = props.exec_env.clone(); let env = props.exec_env.clone();
match config.target { match config.target.as_slice() {
~"arm-linux-androideabi" => { "arm-linux-androideabi" => {
_arm_exec_compiled_test(config, props, testfile, env) _arm_exec_compiled_test(config, props, testfile, env)
} }
@ -735,9 +735,9 @@ fn compose_and_run_compiler(
&auxres); &auxres);
} }
match config.target { match config.target.as_slice() {
~"arm-linux-androideabi" => { "arm-linux-androideabi" => {
_arm_push_aux_shared_library(config, testfile); _arm_push_aux_shared_library(config, testfile);
} }

View file

@ -880,7 +880,6 @@ pub fn build_session_options(matches: &getopts::Matches)
} }
}; };
let gc = debugging_opts & session::GC != 0; let gc = debugging_opts & session::GC != 0;
let debuginfo = if matches.opt_present("g") { let debuginfo = if matches.opt_present("g") {
if matches.opt_present("debuginfo") { if matches.opt_present("debuginfo") {
early_error("-g and --debuginfo both provided"); early_error("-g and --debuginfo both provided");

View file

@ -137,7 +137,7 @@ impl Item {
pub fn doc_list<'a>(&'a self) -> Option<&'a [Attribute]> { pub fn doc_list<'a>(&'a self) -> Option<&'a [Attribute]> {
for attr in self.attrs.iter() { for attr in self.attrs.iter() {
match *attr { match *attr {
List(~"doc", ref list) => { return Some(list.as_slice()); } List(ref x, ref list) if "doc" == *x => { return Some(list.as_slice()); }
_ => {} _ => {}
} }
} }
@ -149,7 +149,7 @@ impl Item {
pub fn doc_value<'a>(&'a self) -> Option<&'a str> { pub fn doc_value<'a>(&'a self) -> Option<&'a str> {
for attr in self.attrs.iter() { for attr in self.attrs.iter() {
match *attr { match *attr {
NameValue(~"doc", ref v) => { return Some(v.as_slice()); } NameValue(ref x, ref v) if "doc" == *x => { return Some(v.as_slice()); }
_ => {} _ => {}
} }
} }

View file

@ -357,7 +357,8 @@ impl fmt::Show for clean::Type {
write!(f.buf, "{}{}fn{}{}", write!(f.buf, "{}{}fn{}{}",
PuritySpace(decl.purity), PuritySpace(decl.purity),
match decl.abi { match decl.abi {
~"" | ~"\"Rust\"" => ~"", ref x if "" == *x => ~"",
ref x if "\"Rust\"" == *x => ~"",
ref s => " " + *s + " ", ref s => " " + *s + " ",
}, },
decl.generics, decl.generics,

View file

@ -225,13 +225,13 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
Some(attrs) => { Some(attrs) => {
for attr in attrs.iter() { for attr in attrs.iter() {
match *attr { match *attr {
clean::NameValue(~"html_favicon_url", ref s) => { clean::NameValue(ref x, ref s) if "html_favicon_url" == *x => {
cx.layout.favicon = s.to_owned(); cx.layout.favicon = s.to_owned();
} }
clean::NameValue(~"html_logo_url", ref s) => { clean::NameValue(ref x, ref s) if "html_logo_url" == *x => {
cx.layout.logo = s.to_owned(); cx.layout.logo = s.to_owned();
} }
clean::Word(~"html_no_source") => { clean::Word(ref x) if "html_no_source" == *x => {
cx.include_sources = false; cx.include_sources = false;
} }
_ => {} _ => {}
@ -396,10 +396,10 @@ fn extern_location(e: &clean::ExternalCrate, dst: &Path) -> ExternalLocation {
// external crate // external crate
for attr in e.attrs.iter() { for attr in e.attrs.iter() {
match *attr { match *attr {
clean::List(~"doc", ref list) => { clean::List(ref x, ref list) if "doc" == *x => {
for attr in list.iter() { for attr in list.iter() {
match *attr { match *attr {
clean::NameValue(~"html_root_url", ref s) => { clean::NameValue(ref x, ref s) if "html_root_url" == *x => {
if s.ends_with("/") { if s.ends_with("/") {
return Remote(s.to_owned()); return Remote(s.to_owned());
} }
@ -666,7 +666,7 @@ impl DocFolder for Cache {
// extract relevant documentation for this impl // extract relevant documentation for this impl
match attrs.move_iter().find(|a| { match attrs.move_iter().find(|a| {
match *a { match *a {
clean::NameValue(~"doc", _) => true, clean::NameValue(ref x, _) if "doc" == *x => true,
_ => false _ => false
} }
}) { }) {

View file

@ -195,14 +195,14 @@ pub fn main_args(args: &[~str]) -> int {
info!("going to format"); info!("going to format");
let started = time::precise_time_ns(); let started = time::precise_time_ns();
match matches.opt_str("w") { match matches.opt_str("w").as_ref().map(|s| s.as_slice()) {
Some(~"html") | None => { Some("html") | None => {
match html::render::run(krate, output.unwrap_or(Path::new("doc"))) { match html::render::run(krate, output.unwrap_or(Path::new("doc"))) {
Ok(()) => {} Ok(()) => {}
Err(e) => fail!("failed to generate documentation: {}", e), Err(e) => fail!("failed to generate documentation: {}", e),
} }
} }
Some(~"json") => { Some("json") => {
match json_output(krate, res, output.unwrap_or(Path::new("doc.json"))) { match json_output(krate, res, output.unwrap_or(Path::new("doc.json"))) {
Ok(()) => {} Ok(()) => {}
Err(e) => fail!("failed to write json: {}", e), Err(e) => fail!("failed to write json: {}", e),
@ -223,9 +223,9 @@ pub fn main_args(args: &[~str]) -> int {
/// and files and then generates the necessary rustdoc output for formatting. /// and files and then generates the necessary rustdoc output for formatting.
fn acquire_input(input: &str, fn acquire_input(input: &str,
matches: &getopts::Matches) -> Result<Output, ~str> { matches: &getopts::Matches) -> Result<Output, ~str> {
match matches.opt_str("r") { match matches.opt_str("r").as_ref().map(|s| s.as_slice()) {
Some(~"rust") => Ok(rust_input(input, matches)), Some("rust") => Ok(rust_input(input, matches)),
Some(~"json") => json_input(input), Some("json") => json_input(input),
Some(s) => Err("unknown input format: " + s), Some(s) => Err("unknown input format: " + s),
None => { None => {
if input.ends_with(".json") { if input.ends_with(".json") {
@ -265,15 +265,15 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
Some(nested) => { Some(nested) => {
for inner in nested.iter() { for inner in nested.iter() {
match *inner { match *inner {
clean::Word(~"no_default_passes") => { clean::Word(ref x) if "no_default_passes" == *x => {
default_passes = false; default_passes = false;
} }
clean::NameValue(~"passes", ref value) => { clean::NameValue(ref x, ref value) if "passes" == *x => {
for pass in value.words() { for pass in value.words() {
passes.push(pass.to_owned()); passes.push(pass.to_owned());
} }
} }
clean::NameValue(~"plugins", ref value) => { clean::NameValue(ref x, ref value) if "plugins" == *x => {
for p in value.words() { for p in value.words() {
plugins.push(p.to_owned()); plugins.push(p.to_owned());
} }

View file

@ -34,7 +34,7 @@ pub fn strip_hidden(krate: clean::Crate) -> plugins::PluginResult {
fn fold_item(&mut self, i: Item) -> Option<Item> { fn fold_item(&mut self, i: Item) -> Option<Item> {
for attr in i.attrs.iter() { for attr in i.attrs.iter() {
match attr { match attr {
&clean::List(~"doc", ref l) => { &clean::List(ref x, ref l) if "doc" == *x => {
for innerattr in l.iter() { for innerattr in l.iter() {
match innerattr { match innerattr {
&clean::Word(ref s) if "hidden" == *s => { &clean::Word(ref s) if "hidden" == *s => {
@ -223,7 +223,7 @@ pub fn unindent_comments(krate: clean::Crate) -> plugins::PluginResult {
let mut avec: ~[clean::Attribute] = ~[]; let mut avec: ~[clean::Attribute] = ~[];
for attr in i.attrs.iter() { for attr in i.attrs.iter() {
match attr { match attr {
&clean::NameValue(~"doc", ref s) => avec.push( &clean::NameValue(ref x, ref s) if "doc" == *x => avec.push(
clean::NameValue(~"doc", unindent(*s))), clean::NameValue(~"doc", unindent(*s))),
x => avec.push(x.clone()) x => avec.push(x.clone())
} }
@ -245,7 +245,7 @@ pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult {
let mut i = i; let mut i = i;
for attr in i.attrs.iter() { for attr in i.attrs.iter() {
match *attr { match *attr {
clean::NameValue(~"doc", ref s) => { clean::NameValue(ref x, ref s) if "doc" == *x => {
docstr.push_str(s.clone()); docstr.push_str(s.clone());
docstr.push_char('\n'); docstr.push_char('\n');
}, },
@ -253,7 +253,7 @@ pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult {
} }
} }
let mut a: ~[clean::Attribute] = i.attrs.iter().filter(|&a| match a { let mut a: ~[clean::Attribute] = i.attrs.iter().filter(|&a| match a {
&clean::NameValue(~"doc", _) => false, &clean::NameValue(ref x, _) if "doc" == *x => false,
_ => true _ => true
}).map(|x| x.clone()).collect(); }).map(|x| x.clone()).collect();
if "" != docstr { if "" != docstr {

View file

@ -398,8 +398,8 @@ mod tests {
} }
}); });
modify(my_key, |data| { modify(my_key, |data| {
match data { match data.as_ref().map(|s| s.as_slice()) {
Some(~"first data") => Some(~"next data"), Some("first data") => Some(~"next data"),
Some(ref val) => fail!("wrong value: {}", *val), Some(ref val) => fail!("wrong value: {}", *val),
None => fail!("missing value") None => fail!("missing value")
} }

View file

@ -387,8 +387,8 @@ fn test_back_to_the_future_result() {
fn test_try_success() { fn test_try_success() {
match try(proc() { match try(proc() {
~"Success!" ~"Success!"
}) { }).as_ref().map(|s| s.as_slice()) {
result::Ok(~"Success!") => (), result::Ok("Success!") => (),
_ => fail!() _ => fail!()
} }
} }

View file

@ -2838,24 +2838,7 @@ impl Parser {
// parse ~pat // parse ~pat
self.bump(); self.bump();
let sub = self.parse_pat(); let sub = self.parse_pat();
hi = sub.span.hi; pat = PatUniq(sub);
// HACK: parse ~"..." as a literal of a vstore ~str
pat = match sub.node {
PatLit(e) => {
match e.node {
ExprLit(lit) if lit_is_str(lit) => {
let vst = @Expr {
id: ast::DUMMY_NODE_ID,
node: ExprVstore(e, ExprVstoreUniq),
span: mk_sp(lo, hi),
};
PatLit(vst)
}
_ => PatUniq(sub)
}
}
_ => PatUniq(sub)
};
hi = self.last_span.hi; hi = self.last_span.hi;
return @ast::Pat { return @ast::Pat {
id: ast::DUMMY_NODE_ID, id: ast::DUMMY_NODE_ID,

View file

@ -25,9 +25,9 @@ impl read for int {
impl read for bool { impl read for bool {
fn readMaybe(s: ~str) -> Option<bool> { fn readMaybe(s: ~str) -> Option<bool> {
match s { match s.as_slice() {
~"true" => Some(true), "true" => Some(true),
~"false" => Some(false), "false" => Some(false),
_ => None _ => None
} }
} }

View file

@ -21,7 +21,7 @@ fn main() {
let x: &[~str] = x; let x: &[~str] = x;
match x { match x {
[a, _, _, ..] => { println!("{}", a); } [a, _, _, ..] => { println!("{}", a); }
[~"foo", ~"bar", ~"baz", ~"foo", ~"bar"] => { } //~ ERROR unreachable pattern [_, _, _, _, _] => { } //~ ERROR unreachable pattern
_ => { } _ => { }
} }

View file

@ -9,8 +9,8 @@
// except according to those terms. // except according to those terms.
fn foo(s: &~str) -> bool { fn foo(s: &~str) -> bool {
match s { match s.as_slice() {
&~"kitty" => true, "kitty" => true,
_ => false _ => false
} }
} }

View file

@ -13,10 +13,10 @@ fn parse_args() -> ~str {
let mut n = 0; let mut n = 0;
while n < args.len() { while n < args.len() {
match args[n].clone() { match args[n].as_slice() {
~"-v" => (), "-v" => (),
s => { s => {
return s; return s.into_owned();
} }
} }
n += 1; n += 1;

View file

@ -1,36 +0,0 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Tests a tricky scenario involving string matching,
// copying, and moving to ensure that we don't segfault
// or double-free, as we were wont to do in the past.
use std::os;
fn parse_args() -> ~str {
let args = os::args();
let mut n = 0;
while n < args.len() {
match args[n].clone() {
~"-v" => (),
s => {
return s;
}
}
n += 1;
}
return ~""
}
pub fn main() {
println!("{}", parse_args());
}

View file

@ -11,21 +11,21 @@
// Issue #53 // Issue #53
pub fn main() { pub fn main() {
match ~"test" { ~"not-test" => fail!(), ~"test" => (), _ => fail!() } match "test" { "not-test" => fail!(), "test" => (), _ => fail!() }
enum t { tag1(~str), tag2, } enum t { tag1(~str), tag2, }
match tag1(~"test") { match tag1(~"test") {
tag2 => fail!(), tag2 => fail!(),
tag1(~"not-test") => fail!(), tag1(ref s) if "test" != *s => fail!(),
tag1(~"test") => (), tag1(ref s) if "test" == *s => (),
_ => fail!() _ => fail!()
} }
let x = match ~"a" { ~"a" => 1, ~"b" => 2, _ => fail!() }; let x = match "a" { "a" => 1, "b" => 2, _ => fail!() };
assert_eq!(x, 1); assert_eq!(x, 1);
match ~"a" { ~"a" => { } ~"b" => { }, _ => fail!() } match "a" { "a" => { } "b" => { }, _ => fail!() }
} }