Skip to content

Commit f079c94

Browse files
committed
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.
1 parent 3316a0e commit f079c94

File tree

17 files changed

+57
-110
lines changed

17 files changed

+57
-110
lines changed

src/compiletest/compiletest.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ pub fn opt_str2(maybestr: Option<~str>) -> ~str {
191191
}
192192

193193
pub fn str_mode(s: ~str) -> mode {
194-
match s {
195-
~"compile-fail" => mode_compile_fail,
196-
~"run-fail" => mode_run_fail,
197-
~"run-pass" => mode_run_pass,
198-
~"pretty" => mode_pretty,
199-
~"debug-info" => mode_debug_info,
200-
~"codegen" => mode_codegen,
194+
match s.as_slice() {
195+
"compile-fail" => mode_compile_fail,
196+
"run-fail" => mode_run_fail,
197+
"run-pass" => mode_run_pass,
198+
"pretty" => mode_pretty,
199+
"debug-info" => mode_debug_info,
200+
"codegen" => mode_codegen,
201201
_ => fail!("invalid mode")
202202
}
203203
}

src/compiletest/runtest.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ use test::MetricMap;
3838

3939
pub fn run(config: config, testfile: ~str) {
4040

41-
match config.target {
41+
match config.target.as_slice() {
4242

43-
~"arm-linux-androideabi" => {
43+
"arm-linux-androideabi" => {
4444
if !config.adb_device_status {
4545
fail!("android device not available");
4646
}
@@ -277,8 +277,8 @@ fn run_debuginfo_test(config: &config, props: &TestProps, testfile: &Path) {
277277
let exe_file = make_exe_name(config, testfile);
278278
279279
let mut proc_args;
280-
match config.target {
281-
~"arm-linux-androideabi" => {
280+
match config.target.as_slice() {
281+
"arm-linux-androideabi" => {
282282

283283
cmds = cmds.replace("run","continue");
284284

@@ -682,9 +682,9 @@ fn exec_compiled_test(config: &config, props: &TestProps,
682682

683683
let env = props.exec_env.clone();
684684

685-
match config.target {
685+
match config.target.as_slice() {
686686

687-
~"arm-linux-androideabi" => {
687+
"arm-linux-androideabi" => {
688688
_arm_exec_compiled_test(config, props, testfile, env)
689689
}
690690

@@ -735,9 +735,9 @@ fn compose_and_run_compiler(
735735
&auxres);
736736
}
737737

738-
match config.target {
738+
match config.target.as_slice() {
739739

740-
~"arm-linux-androideabi" => {
740+
"arm-linux-androideabi" => {
741741
_arm_push_aux_shared_library(config, testfile);
742742
}
743743

src/librustc/driver/driver.rs

-1
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,6 @@ pub fn build_session_options(matches: &getopts::Matches)
880880
}
881881
};
882882
let gc = debugging_opts & session::GC != 0;
883-
884883
let debuginfo = if matches.opt_present("g") {
885884
if matches.opt_present("debuginfo") {
886885
early_error("-g and --debuginfo both provided");

src/librustdoc/clean.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl Item {
137137
pub fn doc_list<'a>(&'a self) -> Option<&'a [Attribute]> {
138138
for attr in self.attrs.iter() {
139139
match *attr {
140-
List(~"doc", ref list) => { return Some(list.as_slice()); }
140+
List(ref x, ref list) if "doc" == *x => { return Some(list.as_slice()); }
141141
_ => {}
142142
}
143143
}
@@ -149,7 +149,7 @@ impl Item {
149149
pub fn doc_value<'a>(&'a self) -> Option<&'a str> {
150150
for attr in self.attrs.iter() {
151151
match *attr {
152-
NameValue(~"doc", ref v) => { return Some(v.as_slice()); }
152+
NameValue(ref x, ref v) if "doc" == *x => { return Some(v.as_slice()); }
153153
_ => {}
154154
}
155155
}

src/librustdoc/html/format.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ impl fmt::Show for clean::Type {
357357
write!(f.buf, "{}{}fn{}{}",
358358
PuritySpace(decl.purity),
359359
match decl.abi {
360-
~"" | ~"\"Rust\"" => ~"",
360+
ref x if "" == *x => ~"",
361+
ref x if "\"Rust\"" == *x => ~"",
361362
ref s => " " + *s + " ",
362363
},
363364
decl.generics,

src/librustdoc/html/render.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,13 @@ pub fn run(mut krate: clean::Crate, dst: Path) -> io::IoResult<()> {
225225
Some(attrs) => {
226226
for attr in attrs.iter() {
227227
match *attr {
228-
clean::NameValue(~"html_favicon_url", ref s) => {
228+
clean::NameValue(ref x, ref s) if "html_favicon_url" == *x => {
229229
cx.layout.favicon = s.to_owned();
230230
}
231-
clean::NameValue(~"html_logo_url", ref s) => {
231+
clean::NameValue(ref x, ref s) if "html_logo_url" == *x => {
232232
cx.layout.logo = s.to_owned();
233233
}
234-
clean::Word(~"html_no_source") => {
234+
clean::Word(ref x) if "html_no_source" == *x => {
235235
cx.include_sources = false;
236236
}
237237
_ => {}
@@ -396,10 +396,10 @@ fn extern_location(e: &clean::ExternalCrate, dst: &Path) -> ExternalLocation {
396396
// external crate
397397
for attr in e.attrs.iter() {
398398
match *attr {
399-
clean::List(~"doc", ref list) => {
399+
clean::List(ref x, ref list) if "doc" == *x => {
400400
for attr in list.iter() {
401401
match *attr {
402-
clean::NameValue(~"html_root_url", ref s) => {
402+
clean::NameValue(ref x, ref s) if "html_root_url" == *x => {
403403
if s.ends_with("/") {
404404
return Remote(s.to_owned());
405405
}
@@ -666,7 +666,7 @@ impl DocFolder for Cache {
666666
// extract relevant documentation for this impl
667667
match attrs.move_iter().find(|a| {
668668
match *a {
669-
clean::NameValue(~"doc", _) => true,
669+
clean::NameValue(ref x, _) if "doc" == *x => true,
670670
_ => false
671671
}
672672
}) {

src/librustdoc/lib.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,14 @@ pub fn main_args(args: &[~str]) -> int {
195195

196196
info!("going to format");
197197
let started = time::precise_time_ns();
198-
match matches.opt_str("w") {
199-
Some(~"html") | None => {
198+
match matches.opt_str("w").as_ref().map(|s| s.as_slice()) {
199+
Some("html") | None => {
200200
match html::render::run(krate, output.unwrap_or(Path::new("doc"))) {
201201
Ok(()) => {}
202202
Err(e) => fail!("failed to generate documentation: {}", e),
203203
}
204204
}
205-
Some(~"json") => {
205+
Some("json") => {
206206
match json_output(krate, res, output.unwrap_or(Path::new("doc.json"))) {
207207
Ok(()) => {}
208208
Err(e) => fail!("failed to write json: {}", e),
@@ -223,9 +223,9 @@ pub fn main_args(args: &[~str]) -> int {
223223
/// and files and then generates the necessary rustdoc output for formatting.
224224
fn acquire_input(input: &str,
225225
matches: &getopts::Matches) -> Result<Output, ~str> {
226-
match matches.opt_str("r") {
227-
Some(~"rust") => Ok(rust_input(input, matches)),
228-
Some(~"json") => json_input(input),
226+
match matches.opt_str("r").as_ref().map(|s| s.as_slice()) {
227+
Some("rust") => Ok(rust_input(input, matches)),
228+
Some("json") => json_input(input),
229229
Some(s) => Err("unknown input format: " + s),
230230
None => {
231231
if input.ends_with(".json") {
@@ -265,15 +265,15 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
265265
Some(nested) => {
266266
for inner in nested.iter() {
267267
match *inner {
268-
clean::Word(~"no_default_passes") => {
268+
clean::Word(ref x) if "no_default_passes" == *x => {
269269
default_passes = false;
270270
}
271-
clean::NameValue(~"passes", ref value) => {
271+
clean::NameValue(ref x, ref value) if "passes" == *x => {
272272
for pass in value.words() {
273273
passes.push(pass.to_owned());
274274
}
275275
}
276-
clean::NameValue(~"plugins", ref value) => {
276+
clean::NameValue(ref x, ref value) if "plugins" == *x => {
277277
for p in value.words() {
278278
plugins.push(p.to_owned());
279279
}

src/librustdoc/passes.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub fn strip_hidden(krate: clean::Crate) -> plugins::PluginResult {
3434
fn fold_item(&mut self, i: Item) -> Option<Item> {
3535
for attr in i.attrs.iter() {
3636
match attr {
37-
&clean::List(~"doc", ref l) => {
37+
&clean::List(ref x, ref l) if "doc" == *x => {
3838
for innerattr in l.iter() {
3939
match innerattr {
4040
&clean::Word(ref s) if "hidden" == *s => {
@@ -223,7 +223,7 @@ pub fn unindent_comments(krate: clean::Crate) -> plugins::PluginResult {
223223
let mut avec: ~[clean::Attribute] = ~[];
224224
for attr in i.attrs.iter() {
225225
match attr {
226-
&clean::NameValue(~"doc", ref s) => avec.push(
226+
&clean::NameValue(ref x, ref s) if "doc" == *x => avec.push(
227227
clean::NameValue(~"doc", unindent(*s))),
228228
x => avec.push(x.clone())
229229
}
@@ -245,15 +245,15 @@ pub fn collapse_docs(krate: clean::Crate) -> plugins::PluginResult {
245245
let mut i = i;
246246
for attr in i.attrs.iter() {
247247
match *attr {
248-
clean::NameValue(~"doc", ref s) => {
248+
clean::NameValue(ref x, ref s) if "doc" == *x => {
249249
docstr.push_str(s.clone());
250250
docstr.push_char('\n');
251251
},
252252
_ => ()
253253
}
254254
}
255255
let mut a: ~[clean::Attribute] = i.attrs.iter().filter(|&a| match a {
256-
&clean::NameValue(~"doc", _) => false,
256+
&clean::NameValue(ref x, _) if "doc" == *x => false,
257257
_ => true
258258
}).map(|x| x.clone()).collect();
259259
if "" != docstr {

src/libstd/local_data.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,8 @@ mod tests {
398398
}
399399
});
400400
modify(my_key, |data| {
401-
match data {
402-
Some(~"first data") => Some(~"next data"),
401+
match data.as_ref().map(|s| s.as_slice()) {
402+
Some("first data") => Some(~"next data"),
403403
Some(ref val) => fail!("wrong value: {}", *val),
404404
None => fail!("missing value")
405405
}

src/libstd/task.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -387,8 +387,8 @@ fn test_back_to_the_future_result() {
387387
fn test_try_success() {
388388
match try(proc() {
389389
~"Success!"
390-
}) {
391-
result::Ok(~"Success!") => (),
390+
}).as_ref().map(|s| s.as_slice()) {
391+
result::Ok("Success!") => (),
392392
_ => fail!()
393393
}
394394
}

src/libsyntax/parse/parser.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -2838,24 +2838,7 @@ impl Parser {
28382838
// parse ~pat
28392839
self.bump();
28402840
let sub = self.parse_pat();
2841-
hi = sub.span.hi;
2842-
// HACK: parse ~"..." as a literal of a vstore ~str
2843-
pat = match sub.node {
2844-
PatLit(e) => {
2845-
match e.node {
2846-
ExprLit(lit) if lit_is_str(lit) => {
2847-
let vst = @Expr {
2848-
id: ast::DUMMY_NODE_ID,
2849-
node: ExprVstore(e, ExprVstoreUniq),
2850-
span: mk_sp(lo, hi),
2851-
};
2852-
PatLit(vst)
2853-
}
2854-
_ => PatUniq(sub)
2855-
}
2856-
}
2857-
_ => PatUniq(sub)
2858-
};
2841+
pat = PatUniq(sub);
28592842
hi = self.last_span.hi;
28602843
return @ast::Pat {
28612844
id: ast::DUMMY_NODE_ID,

src/test/auxiliary/static-methods-crate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ impl read for int {
2525

2626
impl read for bool {
2727
fn readMaybe(s: ~str) -> Option<bool> {
28-
match s {
29-
~"true" => Some(true),
30-
~"false" => Some(false),
28+
match s.as_slice() {
29+
"true" => Some(true),
30+
"false" => Some(false),
3131
_ => None
3232
}
3333
}

src/test/compile-fail/match-vec-unreachable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn main() {
2121
let x: &[~str] = x;
2222
match x {
2323
[a, _, _, ..] => { println!("{}", a); }
24-
[~"foo", ~"bar", ~"baz", ~"foo", ~"bar"] => { } //~ ERROR unreachable pattern
24+
[_, _, _, _, _] => { } //~ ERROR unreachable pattern
2525
_ => { }
2626
}
2727

src/test/run-pass/borrowed-ptr-pattern-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
// except according to those terms.
1010

1111
fn foo(s: &~str) -> bool {
12-
match s {
13-
&~"kitty" => true,
12+
match s.as_slice() {
13+
"kitty" => true,
1414
_ => false
1515
}
1616
}

src/test/run-pass/issue-4541.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ fn parse_args() -> ~str {
1313
let mut n = 0;
1414

1515
while n < args.len() {
16-
match args[n].clone() {
17-
~"-v" => (),
16+
match args[n].as_slice() {
17+
"-v" => (),
1818
s => {
19-
return s;
19+
return s.into_owned();
2020
}
2121
}
2222
n += 1;

src/test/run-pass/match-drop-strs-issue-4541.rs

-36
This file was deleted.

src/test/run-pass/match-str.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@
1111
// Issue #53
1212

1313
pub fn main() {
14-
match ~"test" { ~"not-test" => fail!(), ~"test" => (), _ => fail!() }
14+
match "test" { "not-test" => fail!(), "test" => (), _ => fail!() }
1515

1616
enum t { tag1(~str), tag2, }
1717

1818

1919
match tag1(~"test") {
2020
tag2 => fail!(),
21-
tag1(~"not-test") => fail!(),
22-
tag1(~"test") => (),
21+
tag1(ref s) if "test" != *s => fail!(),
22+
tag1(ref s) if "test" == *s => (),
2323
_ => fail!()
2424
}
2525

26-
let x = match ~"a" { ~"a" => 1, ~"b" => 2, _ => fail!() };
26+
let x = match "a" { "a" => 1, "b" => 2, _ => fail!() };
2727
assert_eq!(x, 1);
2828

29-
match ~"a" { ~"a" => { } ~"b" => { }, _ => fail!() }
29+
match "a" { "a" => { } "b" => { }, _ => fail!() }
3030

3131
}

0 commit comments

Comments
 (0)