From f079c94f723f8c67319da8c727324b2011d7b36f Mon Sep 17 00:00:00 2001 From: Michael Darakananda Date: Fri, 7 Mar 2014 16:15:50 -0500 Subject: [PATCH] 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. --- src/compiletest/compiletest.rs | 14 ++++---- src/compiletest/runtest.rs | 16 ++++----- src/librustc/driver/driver.rs | 1 - src/librustdoc/clean.rs | 4 +-- src/librustdoc/html/format.rs | 3 +- src/librustdoc/html/render.rs | 12 +++---- src/librustdoc/lib.rs | 18 +++++----- src/librustdoc/passes.rs | 8 ++--- src/libstd/local_data.rs | 4 +-- src/libstd/task.rs | 4 +-- src/libsyntax/parse/parser.rs | 19 +--------- src/test/auxiliary/static-methods-crate.rs | 6 ++-- .../compile-fail/match-vec-unreachable.rs | 2 +- src/test/run-pass/borrowed-ptr-pattern-2.rs | 4 +-- src/test/run-pass/issue-4541.rs | 6 ++-- .../run-pass/match-drop-strs-issue-4541.rs | 36 ------------------- src/test/run-pass/match-str.rs | 10 +++--- 17 files changed, 57 insertions(+), 110 deletions(-) delete mode 100644 src/test/run-pass/match-drop-strs-issue-4541.rs diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index c5ec19813065c..5f8c63d60715a 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -191,13 +191,13 @@ pub fn opt_str2(maybestr: Option<~str>) -> ~str { } pub fn str_mode(s: ~str) -> mode { - match s { - ~"compile-fail" => mode_compile_fail, - ~"run-fail" => mode_run_fail, - ~"run-pass" => mode_run_pass, - ~"pretty" => mode_pretty, - ~"debug-info" => mode_debug_info, - ~"codegen" => mode_codegen, + match s.as_slice() { + "compile-fail" => mode_compile_fail, + "run-fail" => mode_run_fail, + "run-pass" => mode_run_pass, + "pretty" => mode_pretty, + "debug-info" => mode_debug_info, + "codegen" => mode_codegen, _ => fail!("invalid mode") } } diff --git a/src/compiletest/runtest.rs b/src/compiletest/runtest.rs index 47e1118459d67..b1c432ec50d57 100644 --- a/src/compiletest/runtest.rs +++ b/src/compiletest/runtest.rs @@ -38,9 +38,9 @@ use test::MetricMap; 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 { 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 mut proc_args; - match config.target { - ~"arm-linux-androideabi" => { + match config.target.as_slice() { + "arm-linux-androideabi" => { cmds = cmds.replace("run","continue"); @@ -682,9 +682,9 @@ fn exec_compiled_test(config: &config, props: &TestProps, 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) } @@ -735,9 +735,9 @@ fn compose_and_run_compiler( &auxres); } - match config.target { + match config.target.as_slice() { - ~"arm-linux-androideabi" => { + "arm-linux-androideabi" => { _arm_push_aux_shared_library(config, testfile); } diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 331677cf955d6..6f2934d9138a0 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -880,7 +880,6 @@ pub fn build_session_options(matches: &getopts::Matches) } }; let gc = debugging_opts & session::GC != 0; - let debuginfo = if matches.opt_present("g") { if matches.opt_present("debuginfo") { early_error("-g and --debuginfo both provided"); diff --git a/src/librustdoc/clean.rs b/src/librustdoc/clean.rs index 625cc5bc62346..d42a611053f91 100644 --- a/src/librustdoc/clean.rs +++ b/src/librustdoc/clean.rs @@ -137,7 +137,7 @@ impl Item { pub fn doc_list<'a>(&'a self) -> Option<&'a [Attribute]> { for attr in self.attrs.iter() { 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> { for attr in self.attrs.iter() { match *attr { - NameValue(~"doc", ref v) => { return Some(v.as_slice()); } + NameValue(ref x, ref v) if "doc" == *x => { return Some(v.as_slice()); } _ => {} } } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index a8b7e374a6ab9..9a7d00195d40d 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -357,7 +357,8 @@ impl fmt::Show for clean::Type { write!(f.buf, "{}{}fn{}{}", PuritySpace(decl.purity), match decl.abi { - ~"" | ~"\"Rust\"" => ~"", + ref x if "" == *x => ~"", + ref x if "\"Rust\"" == *x => ~"", ref s => " " + *s + " ", }, decl.generics, diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index b705e976e4656..ddacb9bdc0919 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -225,13 +225,13 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> { Some(attrs) => { for attr in attrs.iter() { 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(); } - clean::NameValue(~"html_logo_url", ref s) => { + clean::NameValue(ref x, ref s) if "html_logo_url" == *x => { cx.layout.logo = s.to_owned(); } - clean::Word(~"html_no_source") => { + clean::Word(ref x) if "html_no_source" == *x => { cx.include_sources = false; } _ => {} @@ -396,10 +396,10 @@ fn extern_location(e: &clean::ExternalCrate, dst: &Path) -> ExternalLocation { // external crate for attr in e.attrs.iter() { match *attr { - clean::List(~"doc", ref list) => { + clean::List(ref x, ref list) if "doc" == *x => { for attr in list.iter() { match *attr { - clean::NameValue(~"html_root_url", ref s) => { + clean::NameValue(ref x, ref s) if "html_root_url" == *x => { if s.ends_with("/") { return Remote(s.to_owned()); } @@ -666,7 +666,7 @@ impl DocFolder for Cache { // extract relevant documentation for this impl match attrs.move_iter().find(|a| { match *a { - clean::NameValue(~"doc", _) => true, + clean::NameValue(ref x, _) if "doc" == *x => true, _ => false } }) { diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 2d08dca97b986..e6b4e2c094308 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -195,14 +195,14 @@ pub fn main_args(args: &[~str]) -> int { info!("going to format"); let started = time::precise_time_ns(); - match matches.opt_str("w") { - Some(~"html") | None => { + match matches.opt_str("w").as_ref().map(|s| s.as_slice()) { + Some("html") | None => { match html::render::run(krate, output.unwrap_or(Path::new("doc"))) { Ok(()) => {} Err(e) => fail!("failed to generate documentation: {}", e), } } - Some(~"json") => { + Some("json") => { match json_output(krate, res, output.unwrap_or(Path::new("doc.json"))) { Ok(()) => {} 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. fn acquire_input(input: &str, matches: &getopts::Matches) -> Result { - match matches.opt_str("r") { - Some(~"rust") => Ok(rust_input(input, matches)), - Some(~"json") => json_input(input), + match matches.opt_str("r").as_ref().map(|s| s.as_slice()) { + Some("rust") => Ok(rust_input(input, matches)), + Some("json") => json_input(input), Some(s) => Err("unknown input format: " + s), None => { if input.ends_with(".json") { @@ -265,15 +265,15 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output { Some(nested) => { for inner in nested.iter() { match *inner { - clean::Word(~"no_default_passes") => { + clean::Word(ref x) if "no_default_passes" == *x => { default_passes = false; } - clean::NameValue(~"passes", ref value) => { + clean::NameValue(ref x, ref value) if "passes" == *x => { for pass in value.words() { passes.push(pass.to_owned()); } } - clean::NameValue(~"plugins", ref value) => { + clean::NameValue(ref x, ref value) if "plugins" == *x => { for p in value.words() { plugins.push(p.to_owned()); } diff --git a/src/librustdoc/passes.rs b/src/librustdoc/passes.rs index fdd637b1d0f78..3360e389c44a9 100644 --- a/src/librustdoc/passes.rs +++ b/src/librustdoc/passes.rs @@ -34,7 +34,7 @@ pub fn strip_hidden(krate: clean::Crate) -> plugins::PluginResult { fn fold_item(&mut self, i: Item) -> Option { for attr in i.attrs.iter() { match attr { - &clean::List(~"doc", ref l) => { + &clean::List(ref x, ref l) if "doc" == *x => { for innerattr in l.iter() { match innerattr { &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] = ~[]; for attr in i.attrs.iter() { 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))), x => avec.push(x.clone()) } @@ -245,7 +245,7 @@ pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult { let mut i = i; for attr in i.attrs.iter() { match *attr { - clean::NameValue(~"doc", ref s) => { + clean::NameValue(ref x, ref s) if "doc" == *x => { docstr.push_str(s.clone()); 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 { - &clean::NameValue(~"doc", _) => false, + &clean::NameValue(ref x, _) if "doc" == *x => false, _ => true }).map(|x| x.clone()).collect(); if "" != docstr { diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs index 6b854daabda85..9fc635647f335 100644 --- a/src/libstd/local_data.rs +++ b/src/libstd/local_data.rs @@ -398,8 +398,8 @@ mod tests { } }); modify(my_key, |data| { - match data { - Some(~"first data") => Some(~"next data"), + match data.as_ref().map(|s| s.as_slice()) { + Some("first data") => Some(~"next data"), Some(ref val) => fail!("wrong value: {}", *val), None => fail!("missing value") } diff --git a/src/libstd/task.rs b/src/libstd/task.rs index 1de5322b157ed..16ac46186df5a 100644 --- a/src/libstd/task.rs +++ b/src/libstd/task.rs @@ -387,8 +387,8 @@ fn test_back_to_the_future_result() { fn test_try_success() { match try(proc() { ~"Success!" - }) { - result::Ok(~"Success!") => (), + }).as_ref().map(|s| s.as_slice()) { + result::Ok("Success!") => (), _ => fail!() } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 7760ca89eb271..676db94cd7c82 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2838,24 +2838,7 @@ impl Parser { // parse ~pat self.bump(); let sub = self.parse_pat(); - hi = sub.span.hi; - // 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) - }; + pat = PatUniq(sub); hi = self.last_span.hi; return @ast::Pat { id: ast::DUMMY_NODE_ID, diff --git a/src/test/auxiliary/static-methods-crate.rs b/src/test/auxiliary/static-methods-crate.rs index bc028f972db9d..79d18596bf273 100644 --- a/src/test/auxiliary/static-methods-crate.rs +++ b/src/test/auxiliary/static-methods-crate.rs @@ -25,9 +25,9 @@ impl read for int { impl read for bool { fn readMaybe(s: ~str) -> Option { - match s { - ~"true" => Some(true), - ~"false" => Some(false), + match s.as_slice() { + "true" => Some(true), + "false" => Some(false), _ => None } } diff --git a/src/test/compile-fail/match-vec-unreachable.rs b/src/test/compile-fail/match-vec-unreachable.rs index e2a052bd2638e..e117e0a1c7a28 100644 --- a/src/test/compile-fail/match-vec-unreachable.rs +++ b/src/test/compile-fail/match-vec-unreachable.rs @@ -21,7 +21,7 @@ fn main() { let x: &[~str] = x; match x { [a, _, _, ..] => { println!("{}", a); } - [~"foo", ~"bar", ~"baz", ~"foo", ~"bar"] => { } //~ ERROR unreachable pattern + [_, _, _, _, _] => { } //~ ERROR unreachable pattern _ => { } } diff --git a/src/test/run-pass/borrowed-ptr-pattern-2.rs b/src/test/run-pass/borrowed-ptr-pattern-2.rs index b15f9e76234a7..fc14b60c532b8 100644 --- a/src/test/run-pass/borrowed-ptr-pattern-2.rs +++ b/src/test/run-pass/borrowed-ptr-pattern-2.rs @@ -9,8 +9,8 @@ // except according to those terms. fn foo(s: &~str) -> bool { - match s { - &~"kitty" => true, + match s.as_slice() { + "kitty" => true, _ => false } } diff --git a/src/test/run-pass/issue-4541.rs b/src/test/run-pass/issue-4541.rs index c1cab34f41cc7..a9ebdaa925fe2 100644 --- a/src/test/run-pass/issue-4541.rs +++ b/src/test/run-pass/issue-4541.rs @@ -13,10 +13,10 @@ fn parse_args() -> ~str { let mut n = 0; while n < args.len() { - match args[n].clone() { - ~"-v" => (), + match args[n].as_slice() { + "-v" => (), s => { - return s; + return s.into_owned(); } } n += 1; diff --git a/src/test/run-pass/match-drop-strs-issue-4541.rs b/src/test/run-pass/match-drop-strs-issue-4541.rs deleted file mode 100644 index 5fbe6b4aa6325..0000000000000 --- a/src/test/run-pass/match-drop-strs-issue-4541.rs +++ /dev/null @@ -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 or the MIT license -// , 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()); -} diff --git a/src/test/run-pass/match-str.rs b/src/test/run-pass/match-str.rs index 8bbcc507f184f..44fa2978716cb 100644 --- a/src/test/run-pass/match-str.rs +++ b/src/test/run-pass/match-str.rs @@ -11,21 +11,21 @@ // Issue #53 pub fn main() { - match ~"test" { ~"not-test" => fail!(), ~"test" => (), _ => fail!() } + match "test" { "not-test" => fail!(), "test" => (), _ => fail!() } enum t { tag1(~str), tag2, } match tag1(~"test") { tag2 => fail!(), - tag1(~"not-test") => fail!(), - tag1(~"test") => (), + tag1(ref s) if "test" != *s => fail!(), + tag1(ref s) if "test" == *s => (), _ => fail!() } - let x = match ~"a" { ~"a" => 1, ~"b" => 2, _ => fail!() }; + let x = match "a" { "a" => 1, "b" => 2, _ => fail!() }; assert_eq!(x, 1); - match ~"a" { ~"a" => { } ~"b" => { }, _ => fail!() } + match "a" { "a" => { } "b" => { }, _ => fail!() } }