From 91362bd22021e15e4f220863e6e3070af6db911e Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Fri, 21 Jun 2013 01:07:05 +1000 Subject: [PATCH 1/4] extra: Add a testcase for #7256. --- src/libextra/time.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/libextra/time.rs b/src/libextra/time.rs index 50592d5f7309d..973aa58921c6f 100644 --- a/src/libextra/time.rs +++ b/src/libextra/time.rs @@ -1138,6 +1138,9 @@ mod tests { assert!(result::unwrap(strptime("-0800", "%z")).tm_gmtoff == 0); assert!(test("%", "%%")); + + // Test for #7256 + assert_eq!(strptime("360", "%Y-%m-%d"), Err(~"Invalid year")) } fn test_ctime() { From 31b4b53797337a3750bcb63b19b78642816f76de Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Thu, 20 Jun 2013 19:14:57 -0400 Subject: [PATCH 2/4] librustc: Don't allow enum struct variants to shadow structs. --- src/librustc/middle/resolve.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/librustc/middle/resolve.rs b/src/librustc/middle/resolve.rs index 3e656b3e59405..a91ee34f2985e 100644 --- a/src/librustc/middle/resolve.rs +++ b/src/librustc/middle/resolve.rs @@ -1415,24 +1415,26 @@ impl Resolver { (ReducedGraphParent, vt)) { let ident = variant.node.name; - let (child, _) = self.add_child(ident, parent, ForbidDuplicateValues, - variant.span); - - let privacy; - match variant.node.vis { - public => privacy = Public, - private => privacy = Private, - inherited => privacy = parent_privacy - } + + let privacy = + match variant.node.vis { + public => Public, + private => Private, + inherited => parent_privacy + }; match variant.node.kind { tuple_variant_kind(_) => { + let (child, _) = self.add_child(ident, parent, ForbidDuplicateValues, + variant.span); child.define_value(privacy, def_variant(item_id, local_def(variant.node.id)), variant.span); } struct_variant_kind(_) => { + let (child, _) = self.add_child(ident, parent, ForbidDuplicateTypesAndValues, + variant.span); child.define_type(privacy, def_variant(item_id, local_def(variant.node.id)), From 41e90f2156236d8b4a0ab74e3ed9aadaa7d11d58 Mon Sep 17 00:00:00 2001 From: Luqman Aden Date: Thu, 20 Jun 2013 19:23:31 -0400 Subject: [PATCH 3/4] Add test for duplicate definitions of structs and enum struct variants. --- .../dup-struct-enum-struct-variant.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 src/test/compile-fail/dup-struct-enum-struct-variant.rs diff --git a/src/test/compile-fail/dup-struct-enum-struct-variant.rs b/src/test/compile-fail/dup-struct-enum-struct-variant.rs new file mode 100644 index 0000000000000..69e6b5c6856a8 --- /dev/null +++ b/src/test/compile-fail/dup-struct-enum-struct-variant.rs @@ -0,0 +1,17 @@ +// Copyright 2013 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. + +enum Foo { C { a: int, b: int } } +struct C { a: int, b: int } //~ ERROR error: duplicate definition of type `C` + +struct A { x: int } +enum Bar { A { x: int } } //~ ERROR error: duplicate definition of type `A` + +fn main() {} From ce4847e50f1b0421bcd96fd55d456e834befbf74 Mon Sep 17 00:00:00 2001 From: maikklein Date: Sun, 23 Jun 2013 20:06:21 +0200 Subject: [PATCH 4/4] Added format to rust --- src/librust/rust.rc | 49 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/librust/rust.rc b/src/librust/rust.rc index 68427745ff592..b07dba48a6ddd 100644 --- a/src/librust/rust.rc +++ b/src/librust/rust.rc @@ -118,6 +118,13 @@ static commands: &'static [Command<'static>] = &[ usage_line: "run a rust interpreter", usage_full: UsgStr("\nUsage:\trusti"), }, + Command{cmd: "format", + action: Call(format_source_code), + usage_line: "Formats and overwrites the specified files", + usage_full: + UsgStr("usage: \"rust format file1.rs file2.rs\" aborts on error. Do + \"rust format --force file1.rs file2.rs\" if you want to contiue + formating even if an error is thrown")}, Command{ cmd: "help", action: Call(cmd_help), @@ -129,6 +136,48 @@ static commands: &'static [Command<'static>] = &[ ) } ]; +pub fn format_source_code(args: &[~str]) -> ValidUsage { + let mut args = args.to_owned(); + + // true if all specified files are formatable + fn check_for_error(args: &[~str]) -> bool { + for args.iter().advance |p| { + let source_code = + core::run::process_output("rustc", &[copy *p, ~"--pretty"]); + if (source_code.output.is_empty()) { return false; } + } + true + } + + fn write_output(args: &[~str]) { + + + // If we have a writer in our result then we write the source code to it. + for args.iter().advance |path| { + let source_code = + core::run::process_output("rustc", &[copy *path, ~"--pretty"]); + let path = core::path::Path(*path); + // We overwrite the input file. + let writer_result = io::buffered_file_writer(&path); + match writer_result { + core::result::Ok(writer) => writer.write(source_code.output), + core::result::Err(u) => () + }; + } + } + + // rust format --force file1 file2 + if (*args.head() == ~"--force") { + args.shift(); + write_output(args); + // rust format file1 file2 --format_source_code + } else if (*args.last() == ~"--force") { + args.pop(); + write_output(args); + + } else if (check_for_error(args)) { write_output(args); } else { return Invalid } + Valid(0) +} fn rustc_help() { rustc::usage(copy os::args()[0])