mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-24 15:54:15 +00:00
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:
parent
3316a0e6b2
commit
f079c94f72
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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()); }
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
}) {
|
||||
|
@ -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<Output, ~str> {
|
||||
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());
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ pub fn strip_hidden(krate: clean::Crate) -> plugins::PluginResult {
|
||||
fn fold_item(&mut self, i: Item) -> Option<Item> {
|
||||
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 {
|
||||
|
@ -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")
|
||||
}
|
||||
|
@ -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!()
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -25,9 +25,9 @@ impl read for int {
|
||||
|
||||
impl read for bool {
|
||||
fn readMaybe(s: ~str) -> Option<bool> {
|
||||
match s {
|
||||
~"true" => Some(true),
|
||||
~"false" => Some(false),
|
||||
match s.as_slice() {
|
||||
"true" => Some(true),
|
||||
"false" => Some(false),
|
||||
_ => None
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
_ => { }
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
@ -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!() }
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user