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

Lines changed: 7 additions & 7 deletions
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

Lines changed: 8 additions & 8 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 9 additions & 9 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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
}

0 commit comments

Comments
 (0)