From fd90470b0fa6b0571e78ffda22cbfaf7cb27c146 Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Tue, 27 Oct 2015 23:23:20 +1300 Subject: [PATCH 1/8] Add dependencies to generated llvmdeps.rs Previously the file was not regenrated upon modification of src/rustllvm or others. Now it will be rebuilt if `src/llvm` or `src/rustllvm` is touched. Also added *.rs rule to 'clean' rule so that it is removed upon 'make clean'. --- mk/clean.mk | 1 + mk/llvm.mk | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/mk/clean.mk b/mk/clean.mk index bb79e2186ae15..19a8c3b180663 100644 --- a/mk/clean.mk +++ b/mk/clean.mk @@ -66,6 +66,7 @@ clean-generic-$(2)-$(1): -name '*.py' -o \ -name '*.pyc' -o \ -name '*.bc' \ + -name '*.rs' \ \) \ | xargs rm -f $(Q)find $(1) \ diff --git a/mk/llvm.mk b/mk/llvm.mk index 1cbf4a9fb841c..213453a93aa40 100644 --- a/mk/llvm.mk +++ b/mk/llvm.mk @@ -81,7 +81,7 @@ endif # LLVM linkage: LLVM_LINKAGE_PATH_$(1):=$$(abspath $$(RT_OUTPUT_DIR_$(1))/llvmdeps.rs) -$$(LLVM_LINKAGE_PATH_$(1)): $(S)src/etc/mklldeps.py $$(LLVM_CONFIG_$(1)) +$$(LLVM_LINKAGE_PATH_$(1)): $(S)src/etc/mklldeps.py $(S)src/llvm $(S)src/rustllvm $$(LLVM_CONFIG_$(1)) $(Q)$(CFG_PYTHON) "$$<" "$$@" "$$(LLVM_COMPONENTS)" "$$(CFG_ENABLE_LLVM_STATIC_STDCPP)" \ $$(LLVM_CONFIG_$(1)) "$(CFG_STDCPP_NAME)" endef From 5e9314da18eac9e5de7d5ea68df901b1beaa6ea5 Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Tue, 27 Oct 2015 23:47:53 +1300 Subject: [PATCH 2/8] Added missing argument to 'find' --- mk/clean.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mk/clean.mk b/mk/clean.mk index 19a8c3b180663..ac34ac506bb17 100644 --- a/mk/clean.mk +++ b/mk/clean.mk @@ -65,7 +65,7 @@ clean-generic-$(2)-$(1): -name '*.def' -o \ -name '*.py' -o \ -name '*.pyc' -o \ - -name '*.bc' \ + -name '*.bc' -o \ -name '*.rs' \ \) \ | xargs rm -f From 9c1dad7b91dd077c7763010e50cb0cdc862849c4 Mon Sep 17 00:00:00 2001 From: Dylan McKay Date: Wed, 28 Oct 2015 13:11:55 +1300 Subject: [PATCH 3/8] Remove llvmdeps.rs make dependencies on src/llvm and src/rustllvm --- mk/llvm.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mk/llvm.mk b/mk/llvm.mk index 213453a93aa40..1cbf4a9fb841c 100644 --- a/mk/llvm.mk +++ b/mk/llvm.mk @@ -81,7 +81,7 @@ endif # LLVM linkage: LLVM_LINKAGE_PATH_$(1):=$$(abspath $$(RT_OUTPUT_DIR_$(1))/llvmdeps.rs) -$$(LLVM_LINKAGE_PATH_$(1)): $(S)src/etc/mklldeps.py $(S)src/llvm $(S)src/rustllvm $$(LLVM_CONFIG_$(1)) +$$(LLVM_LINKAGE_PATH_$(1)): $(S)src/etc/mklldeps.py $$(LLVM_CONFIG_$(1)) $(Q)$(CFG_PYTHON) "$$<" "$$@" "$$(LLVM_COMPONENTS)" "$$(CFG_ENABLE_LLVM_STATIC_STDCPP)" \ $$(LLVM_CONFIG_$(1)) "$(CFG_STDCPP_NAME)" endef From c5971a29da58f28901d2958b155e0f2cdb537690 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Thu, 19 Nov 2015 16:00:54 +0000 Subject: [PATCH 4/8] Remove unneeded `#[derive(Copy)]` It was introduced with the change that made copy opt-in. The implementation gives a warning, because the struct contains a raw pointer. --- src/librustc_llvm/diagnostic.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/librustc_llvm/diagnostic.rs b/src/librustc_llvm/diagnostic.rs index c09048d677e81..acb47516150cf 100644 --- a/src/librustc_llvm/diagnostic.rs +++ b/src/librustc_llvm/diagnostic.rs @@ -37,7 +37,6 @@ impl OptimizationDiagnosticKind { } } -#[derive(Copy, Clone)] pub struct OptimizationDiagnostic { pub kind: OptimizationDiagnosticKind, pub pass_name: *const c_char, @@ -94,7 +93,6 @@ impl InlineAsmDiagnostic { } } -#[derive(Copy, Clone)] pub enum Diagnostic { Optimization(OptimizationDiagnostic), InlineAsm(InlineAsmDiagnostic), From 3be1d8ca7d9d9df60a38106d6c8f5d12597cbafc Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Mon, 23 Nov 2015 15:59:36 +0100 Subject: [PATCH 5/8] Avoid some code duplication around getting names of numeric types. --- src/librustc/util/ppaux.rs | 50 ++----------------- .../trans/debuginfo/metadata.rs | 29 ++++------- .../trans/debuginfo/type_names.rs | 23 +++------ src/libsyntax/ast.rs | 4 +- src/libsyntax/ast_util.rs | 42 +++++++--------- src/libsyntax/print/pprust.rs | 6 +-- 6 files changed, 44 insertions(+), 110 deletions(-) diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 67ced5d32594d..9db34eef91fd1 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -24,8 +24,7 @@ use middle::ty::{self, TypeAndMut, Ty, HasTypeFlags}; use middle::ty::fold::TypeFoldable; use std::fmt; -use syntax::abi; -use syntax::ast; +use syntax::{abi, ast_util}; use syntax::parse::token; use syntax::ast::CRATE_NODE_ID; use rustc_front::hir; @@ -774,55 +773,14 @@ impl<'tcx> fmt::Display for ty::TraitRef<'tcx> { } } -pub fn int_ty_to_string(t: ast::IntTy, val: Option) -> String { - let s = match t { - ast::TyIs => "isize", - ast::TyI8 => "i8", - ast::TyI16 => "i16", - ast::TyI32 => "i32", - ast::TyI64 => "i64" - }; - - match val { - // cast to a u64 so we can correctly print INT64_MIN. All integral types - // are parsed as u64, so we wouldn't want to print an extra negative - // sign. - Some(n) => format!("{}{}", n as u64, s), - None => s.to_string() - } -} - -pub fn uint_ty_to_string(t: ast::UintTy, val: Option) -> String { - let s = match t { - ast::TyUs => "usize", - ast::TyU8 => "u8", - ast::TyU16 => "u16", - ast::TyU32 => "u32", - ast::TyU64 => "u64" - }; - - match val { - Some(n) => format!("{}{}", n, s), - None => s.to_string() - } -} - - -pub fn float_ty_to_string(t: ast::FloatTy) -> String { - match t { - ast::TyF32 => "f32".to_string(), - ast::TyF64 => "f64".to_string(), - } -} - impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { TyBool => write!(f, "bool"), TyChar => write!(f, "char"), - TyInt(t) => write!(f, "{}", int_ty_to_string(t, None)), - TyUint(t) => write!(f, "{}", uint_ty_to_string(t, None)), - TyFloat(t) => write!(f, "{}", float_ty_to_string(t)), + TyInt(t) => write!(f, "{}", ast_util::int_ty_to_string(t)), + TyUint(t) => write!(f, "{}", ast_util::uint_ty_to_string(t)), + TyFloat(t) => write!(f, "{}", ast_util::float_ty_to_string(t)), TyBox(typ) => write!(f, "Box<{}>", typ), TyRawPtr(ref tm) => { write!(f, "*{} {}", match tm.mutbl { diff --git a/src/librustc_trans/trans/debuginfo/metadata.rs b/src/librustc_trans/trans/debuginfo/metadata.rs index addac528aa25c..11b8a6a5faa14 100644 --- a/src/librustc_trans/trans/debuginfo/metadata.rs +++ b/src/librustc_trans/trans/debuginfo/metadata.rs @@ -46,7 +46,7 @@ use std::rc::Rc; use syntax; use syntax::util::interner::Interner; use syntax::codemap::Span; -use syntax::{ast, codemap}; +use syntax::{ast, ast_util, codemap}; use syntax::parse::token; @@ -932,26 +932,17 @@ fn basic_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, let (name, encoding) = match t.sty { ty::TyTuple(ref elements) if elements.is_empty() => - ("()".to_string(), DW_ATE_unsigned), - ty::TyBool => ("bool".to_string(), DW_ATE_boolean), - ty::TyChar => ("char".to_string(), DW_ATE_unsigned_char), - ty::TyInt(int_ty) => match int_ty { - ast::TyIs => ("isize".to_string(), DW_ATE_signed), - ast::TyI8 => ("i8".to_string(), DW_ATE_signed), - ast::TyI16 => ("i16".to_string(), DW_ATE_signed), - ast::TyI32 => ("i32".to_string(), DW_ATE_signed), - ast::TyI64 => ("i64".to_string(), DW_ATE_signed) + ("()", DW_ATE_unsigned), + ty::TyBool => ("bool", DW_ATE_boolean), + ty::TyChar => ("char", DW_ATE_unsigned_char), + ty::TyInt(int_ty) => { + (ast_util::int_ty_to_string(int_ty), DW_ATE_signed) }, - ty::TyUint(uint_ty) => match uint_ty { - ast::TyUs => ("usize".to_string(), DW_ATE_unsigned), - ast::TyU8 => ("u8".to_string(), DW_ATE_unsigned), - ast::TyU16 => ("u16".to_string(), DW_ATE_unsigned), - ast::TyU32 => ("u32".to_string(), DW_ATE_unsigned), - ast::TyU64 => ("u64".to_string(), DW_ATE_unsigned) + ty::TyUint(uint_ty) => { + (ast_util::uint_ty_to_string(uint_ty), DW_ATE_unsigned) }, - ty::TyFloat(float_ty) => match float_ty { - ast::TyF32 => ("f32".to_string(), DW_ATE_float), - ast::TyF64 => ("f64".to_string(), DW_ATE_float), + ty::TyFloat(float_ty) => { + (ast_util::float_ty_to_string(float_ty), DW_ATE_float) }, _ => cx.sess().bug("debuginfo::basic_type_metadata - t is invalid type") }; diff --git a/src/librustc_trans/trans/debuginfo/type_names.rs b/src/librustc_trans/trans/debuginfo/type_names.rs index c6b5ce436835f..6769c010435aa 100644 --- a/src/librustc_trans/trans/debuginfo/type_names.rs +++ b/src/librustc_trans/trans/debuginfo/type_names.rs @@ -19,7 +19,7 @@ use middle::subst::{self, Substs}; use middle::ty::{self, Ty}; use rustc_front::hir; -use syntax::ast; +use syntax::ast_util; // Compute the name of the type as it should be stored in debuginfo. Does not do // any caching, i.e. calling the function twice with the same type will also do @@ -41,21 +41,12 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, qualified: bool, output: &mut String) { match t.sty { - ty::TyBool => output.push_str("bool"), - ty::TyChar => output.push_str("char"), - ty::TyStr => output.push_str("str"), - ty::TyInt(ast::TyIs) => output.push_str("isize"), - ty::TyInt(ast::TyI8) => output.push_str("i8"), - ty::TyInt(ast::TyI16) => output.push_str("i16"), - ty::TyInt(ast::TyI32) => output.push_str("i32"), - ty::TyInt(ast::TyI64) => output.push_str("i64"), - ty::TyUint(ast::TyUs) => output.push_str("usize"), - ty::TyUint(ast::TyU8) => output.push_str("u8"), - ty::TyUint(ast::TyU16) => output.push_str("u16"), - ty::TyUint(ast::TyU32) => output.push_str("u32"), - ty::TyUint(ast::TyU64) => output.push_str("u64"), - ty::TyFloat(ast::TyF32) => output.push_str("f32"), - ty::TyFloat(ast::TyF64) => output.push_str("f64"), + ty::TyBool => output.push_str("bool"), + ty::TyChar => output.push_str("char"), + ty::TyStr => output.push_str("str"), + ty::TyInt(int_ty) => output.push_str(ast_util::int_ty_to_string(int_ty)), + ty::TyUint(uint_ty) => output.push_str(ast_util::uint_ty_to_string(uint_ty)), + ty::TyFloat(float_ty) => output.push_str(ast_util::float_ty_to_string(float_ty)), ty::TyStruct(def, substs) | ty::TyEnum(def, substs) => { push_item_name(cx, def.did, qualified, output); diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index e4697a7fd9149..ab62c8d9421ae 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1258,7 +1258,7 @@ impl fmt::Debug for IntTy { impl fmt::Display for IntTy { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", ast_util::int_ty_to_string(*self, None)) + write!(f, "{}", ast_util::int_ty_to_string(*self)) } } @@ -1303,7 +1303,7 @@ impl fmt::Debug for UintTy { impl fmt::Display for UintTy { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", ast_util::uint_ty_to_string(*self, None)) + write!(f, "{}", ast_util::uint_ty_to_string(*self)) } } diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 44334762d9022..489c61b83da75 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -111,26 +111,23 @@ pub fn is_path(e: P) -> bool { match e.node { ExprPath(..) => true, _ => false } } -/// Get a string representation of a signed int type, with its value. -/// We want to avoid "45int" and "-3int" in favor of "45" and "-3" -pub fn int_ty_to_string(t: IntTy, val: Option) -> String { - let s = match t { +pub fn int_ty_to_string(t: IntTy) -> &'static str { + match t { TyIs => "isize", TyI8 => "i8", TyI16 => "i16", TyI32 => "i32", TyI64 => "i64" - }; - - match val { - // cast to a u64 so we can correctly print INT64_MIN. All integral types - // are parsed as u64, so we wouldn't want to print an extra negative - // sign. - Some(n) => format!("{}{}", n as u64, s), - None => s.to_string() } } +pub fn int_val_to_string(t: IntTy, val: i64) -> String { + // cast to a u64 so we can correctly print INT64_MIN. All integral types + // are parsed as u64, so we wouldn't want to print an extra negative + // sign. + format!("{}{}", val as u64, int_ty_to_string(t)) +} + pub fn int_ty_max(t: IntTy) -> u64 { match t { TyI8 => 0x80, @@ -140,23 +137,20 @@ pub fn int_ty_max(t: IntTy) -> u64 { } } -/// Get a string representation of an unsigned int type, with its value. -/// We want to avoid "42u" in favor of "42us". "42uint" is right out. -pub fn uint_ty_to_string(t: UintTy, val: Option) -> String { - let s = match t { +pub fn uint_ty_to_string(t: UintTy) -> &'static str { + match t { TyUs => "usize", TyU8 => "u8", TyU16 => "u16", TyU32 => "u32", TyU64 => "u64" - }; - - match val { - Some(n) => format!("{}{}", n, s), - None => s.to_string() } } +pub fn uint_val_to_string(t: UintTy, val: u64) -> String { + format!("{}{}", val, uint_ty_to_string(t)) +} + pub fn uint_ty_max(t: UintTy) -> u64 { match t { TyU8 => 0xff, @@ -166,10 +160,10 @@ pub fn uint_ty_max(t: UintTy) -> u64 { } } -pub fn float_ty_to_string(t: FloatTy) -> String { +pub fn float_ty_to_string(t: FloatTy) -> &'static str { match t { - TyF32 => "f32".to_string(), - TyF64 => "f64".to_string(), + TyF32 => "f32", + TyF64 => "f64", } } diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index e9c716017c0b3..6de86de9c54eb 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -651,15 +651,15 @@ pub trait PrintState<'a> { match t { ast::SignedIntLit(st, ast::Plus) => { word(self.writer(), - &ast_util::int_ty_to_string(st, Some(i as i64))) + &ast_util::int_val_to_string(st, i as i64)) } ast::SignedIntLit(st, ast::Minus) => { - let istr = ast_util::int_ty_to_string(st, Some(-(i as i64))); + let istr = ast_util::int_val_to_string(st, -(i as i64)); word(self.writer(), &format!("-{}", istr)) } ast::UnsignedIntLit(ut) => { - word(self.writer(), &ast_util::uint_ty_to_string(ut, Some(i))) + word(self.writer(), &ast_util::uint_val_to_string(ut, i)) } ast::UnsuffixedIntLit(ast::Plus) => { word(self.writer(), &format!("{}", i)) From 3f36ce82389952b1c4d760c008881a720278535d Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 23 Nov 2015 22:09:40 +0100 Subject: [PATCH 6/8] Add TRACE to the known log levels The `log` crate on crates.io already knows TRACE, but the internal liblog doesn't, which causes it to spew errors when a TRACE level is defined. --- src/liblog/directive.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/liblog/directive.rs b/src/liblog/directive.rs index 3958969cfca32..59e5b72d9612c 100644 --- a/src/liblog/directive.rs +++ b/src/liblog/directive.rs @@ -17,7 +17,7 @@ pub struct LogDirective { pub level: u32, } -pub const LOG_LEVEL_NAMES: [&'static str; 4] = ["ERROR", "WARN", "INFO", "DEBUG"]; +pub const LOG_LEVEL_NAMES: [&'static str; 5] = ["ERROR", "WARN", "INFO", "DEBUG", "TRACE"]; /// Parse an individual log level that is either a number or a symbolic log level fn parse_log_level(level: &str) -> Option { From 563adbbea593bc1a81e2d920d9ebac13e2b5e6c0 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Tue, 24 Nov 2015 01:24:27 -0500 Subject: [PATCH 7/8] fixed inconsistent indentation in book example looks like a case of mixed tabs and spaces --- src/doc/book/error-handling.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/book/error-handling.md b/src/doc/book/error-handling.md index 600019bcceb0a..e37360a457b7b 100644 --- a/src/doc/book/error-handling.md +++ b/src/doc/book/error-handling.md @@ -1643,7 +1643,7 @@ fn main() { let matches = match opts.parse(&args[1..]) { Ok(m) => { m } - Err(e) => { panic!(e.to_string()) } + Err(e) => { panic!(e.to_string()) } }; if matches.opt_present("h") { From c3600114cc29bd015847fcb208af55a2e2d3a5b8 Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Tue, 24 Nov 2015 11:56:27 +0530 Subject: [PATCH 8/8] Update reference.md --- src/doc/reference.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 900d1306e050c..97be9a36ed63d 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -649,8 +649,8 @@ apply to the crate as a whole. ``` A crate that contains a `main` function can be compiled to an executable. If a -`main` function is present, its return type must be [`unit`](#tuple-types) -and it must take no arguments. +`main` function is present, its return type must be `()` +("[unit](#tuple-types)") and it must take no arguments. # Items and attributes