From a4c133777e33754137d8a097a0c932cfc45ec8a5 Mon Sep 17 00:00:00 2001 From: Jannis Redmann Date: Wed, 29 Apr 2015 17:55:14 +0200 Subject: [PATCH 01/35] link to .editorconfig for Rust files I've written a small [EditorConfig](http://editorconfig.org) file for Rust development. --- src/etc/CONFIGS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/etc/CONFIGS.md b/src/etc/CONFIGS.md index 036a2f7d4365b..def5ab05fe2f1 100644 --- a/src/etc/CONFIGS.md +++ b/src/etc/CONFIGS.md @@ -2,6 +2,7 @@ Here are some links to repos with configs which ease the use of rust: +* [.editorconfig](https://gist.github.com/derhuerst/c9d1b9309e308d9851fa) ([what is this?](http://editorconfig.org/)) * [rust.vim](https://github.com/rust-lang/rust.vim) * [emacs rust-mode](https://github.com/rust-lang/rust-mode) * [gedit-config](https://github.com/rust-lang/gedit-config) From 6f3641de83b2b3a5c52557b424489bc9fc350571 Mon Sep 17 00:00:00 2001 From: Jannis Redmann Date: Wed, 29 Apr 2015 18:53:36 +0200 Subject: [PATCH 02/35] distinction between official and community plugins --- src/etc/CONFIGS.md | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/etc/CONFIGS.md b/src/etc/CONFIGS.md index def5ab05fe2f1..74837a06faecd 100644 --- a/src/etc/CONFIGS.md +++ b/src/etc/CONFIGS.md @@ -1,11 +1,16 @@ # Configs -Here are some links to repos with configs which ease the use of rust: +These are some links to repos with configs which ease the use of rust. + +## Officially Maintained Configs -* [.editorconfig](https://gist.github.com/derhuerst/c9d1b9309e308d9851fa) ([what is this?](http://editorconfig.org/)) * [rust.vim](https://github.com/rust-lang/rust.vim) * [emacs rust-mode](https://github.com/rust-lang/rust-mode) * [gedit-config](https://github.com/rust-lang/gedit-config) * [kate-config](https://github.com/rust-lang/kate-config) * [nano-config](https://github.com/rust-lang/nano-config) * [zsh-config](https://github.com/rust-lang/zsh-config) + +## Community-maintained Configs + +* [.editorconfig](https://gist.github.com/derhuerst/c9d1b9309e308d9851fa) ([what is this?](http://editorconfig.org/)) From 7ec81722250efc7798d9163574e01eec5cde85ca Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Sat, 2 May 2015 16:25:49 -0400 Subject: [PATCH 03/35] Update old uses of ~ in comments and debugging statements --- src/librustc/middle/expr_use_visitor.rs | 2 +- src/librustc/middle/traits/coherence.rs | 2 +- src/librustc/middle/traits/select.rs | 6 +++--- src/librustc/util/ppaux.rs | 2 +- src/librustc_borrowck/borrowck/check_loans.rs | 2 +- src/librustc_privacy/lib.rs | 2 +- src/librustc_trans/back/link.rs | 2 +- src/librustc_trans/save/span_utils.rs | 6 +++--- src/librustc_trans/trans/attributes.rs | 4 ++-- src/librustc_typeck/check/mod.rs | 2 +- src/librustc_typeck/variance.rs | 4 ++-- src/librustdoc/clean/mod.rs | 2 +- src/libsyntax/ext/deriving/generic/mod.rs | 4 ++-- src/libsyntax/ext/expand.rs | 2 +- src/libsyntax/print/pp.rs | 18 +++++++++--------- src/libtest/lib.rs | 4 ++-- src/test/compile-fail/kindck-copy.rs | 2 +- src/test/debuginfo/issue11600.rs | 2 +- src/test/run-pass/const-bound.rs | 2 +- src/test/run-pass/issue-3556.rs | 4 ---- 20 files changed, 35 insertions(+), 39 deletions(-) diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index d740d24e23672..359ea02c1d74f 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -1125,7 +1125,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { // that case we can adjust the length of the // original vec accordingly, but we'd have to // make trans do the right thing, and it would - // only work for `~` vectors. It seems simpler + // only work for `Vec`s. It seems simpler // to just require that people call // `vec.pop()` or `vec.unshift()`. let slice_bk = ty::BorrowKind::from_mutbl(slice_mutbl); diff --git a/src/librustc/middle/traits/coherence.rs b/src/librustc/middle/traits/coherence.rs index d9f8a88fddca3..222da6d7c3e5e 100644 --- a/src/librustc/middle/traits/coherence.rs +++ b/src/librustc/middle/traits/coherence.rs @@ -323,7 +323,7 @@ fn ty_is_local_constructor<'tcx>(tcx: &ty::ctxt<'tcx>, def_id.krate == ast::LOCAL_CRATE } - ty::ty_uniq(_) => { // treat ~T like Box + ty::ty_uniq(_) => { // Box let krate = tcx.lang_items.owned_box().map(|d| d.krate); krate == Some(ast::LOCAL_CRATE) } diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs index 49371eae2652d..9a5e7219aaa8c 100644 --- a/src/librustc/middle/traits/select.rs +++ b/src/librustc/middle/traits/select.rs @@ -2441,10 +2441,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { /// `match_impl()`. For example, if `impl_def_id` is declared /// as: /// - /// impl Foo for ~T { ... } + /// impl Foo for Box { ... } /// - /// and `obligation_self_ty` is `int`, we'd back an `Err(_)` - /// result. But if `obligation_self_ty` were `~int`, we'd get + /// and `obligation_self_ty` is `int`, we'd get back an `Err(_)` + /// result. But if `obligation_self_ty` were `Box`, we'd get /// back `Ok(T=int)`. fn match_inherent_impl(&mut self, impl_def_id: ast::DefId, diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index aa89c1943a2e3..32ec70c487887 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -637,7 +637,7 @@ impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for OwnedSlice { } } -// This is necessary to handle types like Option<~[T]>, for which +// This is necessary to handle types like Option>, for which // autoderef cannot convert the &[T] handler impl<'tcx, T:Repr<'tcx>> Repr<'tcx> for Vec { fn repr(&self, tcx: &ctxt<'tcx>) -> String { diff --git a/src/librustc_borrowck/borrowck/check_loans.rs b/src/librustc_borrowck/borrowck/check_loans.rs index 9776538de3fed..839b39a8ca003 100644 --- a/src/librustc_borrowck/borrowck/check_loans.rs +++ b/src/librustc_borrowck/borrowck/check_loans.rs @@ -732,7 +732,7 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> { /// let p: Point; /// p.x = 22; // ok, even though `p` is uninitialized /// - /// let p: ~Point; + /// let p: Box; /// (*p).x = 22; // not ok, p is uninitialized, can't deref /// ``` fn check_if_assigned_path_is_moved(&self, diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 128e29ee76e7d..9a8bbc5ea0bc0 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -1314,7 +1314,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for VisiblePrivateTypesVisitor<'a, 'tcx> { // `impl [... for] Private` is never visible. let self_contains_private; // impl [... for] Public<...>, but not `impl [... for] - // ~[Public]` or `(Public,)` etc. + // Vec` or `(Public,)` etc. let self_is_public_path; // check the properties of the Self type: diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 92c9549b37727..49e336c670078 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -288,7 +288,7 @@ pub fn mangle>(path: PI, // when using unix's linker. Perhaps one day when we just use a linker from LLVM // we won't need to do this name mangling. The problem with name mangling is // that it seriously limits the available characters. For example we can't - // have things like &T or ~[T] in symbol names when one would theoretically + // have things like &T or Vec in symbol names when one would theoretically // want them for things like impls of traits on that type. // // To be able to work on all platforms and get *some* reasonable output, we diff --git a/src/librustc_trans/save/span_utils.rs b/src/librustc_trans/save/span_utils.rs index 84a7678959d3e..504663571f533 100644 --- a/src/librustc_trans/save/span_utils.rs +++ b/src/librustc_trans/save/span_utils.rs @@ -230,8 +230,8 @@ impl<'a> SpanUtils<'a> { // Reparse span and return an owned vector of sub spans of the first limit // identifier tokens in the given nesting level. // example with Foo, Bar> - // Nesting = 0: all idents outside of brackets: ~[Foo] - // Nesting = 1: idents within one level of brackets: ~[Bar, Bar] + // Nesting = 0: all idents outside of brackets: Vec + // Nesting = 1: idents within one level of brackets: Vec pub fn spans_with_brackets(&self, span: Span, nesting: isize, limit: isize) -> Vec { let mut result: Vec = vec!(); @@ -352,7 +352,7 @@ impl<'a> SpanUtils<'a> { return vec!(); } // Type params are nested within one level of brackets: - // i.e. we want ~[A, B] from Foo> + // i.e. we want Vec from Foo> self.spans_with_brackets(span, 1, number) } diff --git a/src/librustc_trans/trans/attributes.rs b/src/librustc_trans/trans/attributes.rs index b44ccec0127bd..8086f88deeee9 100644 --- a/src/librustc_trans/trans/attributes.rs +++ b/src/librustc_trans/trans/attributes.rs @@ -196,7 +196,7 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx // The `noalias` attribute on the return value is useful to a // function ptr caller. match ret_ty.sty { - // `~` pointer return values never alias because ownership + // `Box` pointer return values never alias because ownership // is transferred ty::ty_uniq(it) if common::type_is_sized(ccx.tcx(), it) => { attrs.ret(llvm::Attribute::NoAliasAttribute); @@ -239,7 +239,7 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx attrs.arg(idx, llvm::Attribute::ZExtAttribute); } - // `~` pointer parameters never alias because ownership is transferred + // `Box` pointer parameters never alias because ownership is transferred ty::ty_uniq(inner) => { let llsz = machine::llsize_of_real(ccx, type_of::type_of(ccx, inner)); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index c05c1c6b08523..3769e9fa0f36a 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2458,7 +2458,7 @@ fn check_expr_with_lvalue_pref<'a,'tcx>(fcx: &FnCtxt<'a,'tcx>, expr: &'tcx ast:: } // determine the `self` type, using fresh variables for all variables -// declared on the impl declaration e.g., `impl for ~[(A,B)]` +// declared on the impl declaration e.g., `impl for Vec<(A,B)>` // would return ($0, $1) where $0 and $1 are freshly instantiated type // variables. pub fn impl_self_ty<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, diff --git a/src/librustc_typeck/variance.rs b/src/librustc_typeck/variance.rs index 9e8c23734e3c8..7c062d354d395 100644 --- a/src/librustc_typeck/variance.rs +++ b/src/librustc_typeck/variance.rs @@ -178,8 +178,8 @@ //! further that for whatever reason I specifically supply the value of //! `String` for the type parameter `T`: //! -//! let mut vector = ~["string", ...]; -//! convertAll::(v); +//! let mut vector = vec!["string", ...]; +//! convertAll::(vector); //! //! Is this legal? To put another way, can we apply the `impl` for //! `Object` to the type `String`? The answer is yes, but to see why diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 1e6e9a7562a7c..8f78841ef792a 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -897,7 +897,7 @@ impl<'tcx> Clean for ty::ProjectionTy<'tcx> { } } -// maybe use a Generic enum and use ~[Generic]? +// maybe use a Generic enum and use Vec? #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Debug)] pub struct Generics { pub lifetimes: Vec, diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs index 339e535cdcd9f..eb6d0c0285f75 100644 --- a/src/libsyntax/ext/deriving/generic/mod.rs +++ b/src/libsyntax/ext/deriving/generic/mod.rs @@ -896,8 +896,8 @@ impl<'a> MethodDef<'a> { nonself_args: &[P]) -> P { - let mut raw_fields = Vec::new(); // ~[[fields of self], - // [fields of next Self arg], [etc]] + let mut raw_fields = Vec::new(); // Vec<[fields of self], + // [fields of next Self arg], [etc]> let mut patterns = Vec::new(); for i in 0..self_args.len() { let struct_path= cx.path(DUMMY_SP, vec!( type_ident )); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 4ea2d4e5c686c..b471e06492d44 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1691,7 +1691,7 @@ mod tests { // induced by visit. Each of these arrays contains a list of indexes, // interpreted as the varrefs in the varref traversal that this binding // should match. So, for instance, in a program with two bindings and - // three varrefs, the array ~[~[1,2],~[0]] would indicate that the first + // three varrefs, the array [[1, 2], [0]] would indicate that the first // binding should match the second two varrefs, and the second binding // should match the first varref. // diff --git a/src/libsyntax/print/pp.rs b/src/libsyntax/print/pp.rs index 15aaf9cf390fd..ed9937c53f4af 100644 --- a/src/libsyntax/print/pp.rs +++ b/src/libsyntax/print/pp.rs @@ -312,7 +312,7 @@ impl<'a> Printer<'a> { self.token[self.right] = t; } pub fn pretty_print(&mut self, token: Token) -> io::Result<()> { - debug!("pp ~[{},{}]", self.left, self.right); + debug!("pp Vec<{},{}>", self.left, self.right); match token { Token::Eof => { if !self.scan_stack_empty { @@ -329,7 +329,7 @@ impl<'a> Printer<'a> { self.left = 0; self.right = 0; } else { self.advance_right(); } - debug!("pp Begin({})/buffer ~[{},{}]", + debug!("pp Begin({})/buffer Vec<{},{}>", b.offset, self.left, self.right); self.token[self.right] = token; self.size[self.right] = -self.right_total; @@ -339,10 +339,10 @@ impl<'a> Printer<'a> { } Token::End => { if self.scan_stack_empty { - debug!("pp End/print ~[{},{}]", self.left, self.right); + debug!("pp End/print Vec<{},{}>", self.left, self.right); self.print(token, 0) } else { - debug!("pp End/buffer ~[{},{}]", self.left, self.right); + debug!("pp End/buffer Vec<{},{}>", self.left, self.right); self.advance_right(); self.token[self.right] = token; self.size[self.right] = -1; @@ -358,7 +358,7 @@ impl<'a> Printer<'a> { self.left = 0; self.right = 0; } else { self.advance_right(); } - debug!("pp Break({})/buffer ~[{},{}]", + debug!("pp Break({})/buffer Vec<{},{}>", b.offset, self.left, self.right); self.check_stack(0); let right = self.right; @@ -370,11 +370,11 @@ impl<'a> Printer<'a> { } Token::String(s, len) => { if self.scan_stack_empty { - debug!("pp String('{}')/print ~[{},{}]", + debug!("pp String('{}')/print Vec<{},{}>", s, self.left, self.right); self.print(Token::String(s, len), len) } else { - debug!("pp String('{}')/buffer ~[{},{}]", + debug!("pp String('{}')/buffer Vec<{},{}>", s, self.left, self.right); self.advance_right(); self.token[self.right] = Token::String(s, len); @@ -386,7 +386,7 @@ impl<'a> Printer<'a> { } } pub fn check_stream(&mut self) -> io::Result<()> { - debug!("check_stream ~[{}, {}] with left_total={}, right_total={}", + debug!("check_stream Vec<{}, {}> with left_total={}, right_total={}", self.left, self.right, self.left_total, self.right_total); if self.right_total - self.left_total > self.space { debug!("scan window is {}, longer than space on line ({})", @@ -446,7 +446,7 @@ impl<'a> Printer<'a> { assert!((self.right != self.left)); } pub fn advance_left(&mut self) -> io::Result<()> { - debug!("advance_left ~[{},{}], sizeof({})={}", self.left, self.right, + debug!("advance_left Vec<{},{}>, sizeof({})={}", self.left, self.right, self.left, self.size[self.left]); let mut left_size = self.size[self.left]; diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 9cbfe283cbddc..31eb9b7fa2768 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -259,8 +259,8 @@ pub fn test_main(args: &[String], tests: Vec ) { // This will panic (intentionally) when fed any dynamic tests, because // it is copying the static values out into a dynamic vector and cannot // copy dynamic values. It is doing this because from this point on -// a ~[TestDescAndFn] is used in order to effect ownership-transfer -// semantics into parallel test runners, which in turn requires a ~[] +// a Vec is used in order to effect ownership-transfer +// semantics into parallel test runners, which in turn requires a Vec<> // rather than a &[]. pub fn test_main_static(args: env::Args, tests: &[TestDescAndFn]) { let args = args.collect::>(); diff --git a/src/test/compile-fail/kindck-copy.rs b/src/test/compile-fail/kindck-copy.rs index d43ddff6b9500..95ab2bbab14a3 100644 --- a/src/test/compile-fail/kindck-copy.rs +++ b/src/test/compile-fail/kindck-copy.rs @@ -37,7 +37,7 @@ fn test<'a,T,U:Copy>(_: &'a isize) { assert_copy::<&'static mut isize>(); //~ ERROR `core::marker::Copy` is not implemented assert_copy::<&'a mut isize>(); //~ ERROR `core::marker::Copy` is not implemented - // ~ pointers are not ok + // owned pointers are not ok assert_copy::>(); //~ ERROR `core::marker::Copy` is not implemented assert_copy::(); //~ ERROR `core::marker::Copy` is not implemented assert_copy:: >(); //~ ERROR `core::marker::Copy` is not implemented diff --git a/src/test/debuginfo/issue11600.rs b/src/test/debuginfo/issue11600.rs index e93704cac34c2..b79cba7aa6971 100644 --- a/src/test/debuginfo/issue11600.rs +++ b/src/test/debuginfo/issue11600.rs @@ -25,6 +25,6 @@ fn main() { // compile-flags:-g // gdb-command:list // gdb-check:1[...]fn main() { -// gdb-check:2[...]let args : ~[String] = ::std::os::args(); +// gdb-check:2[...]let args : Vec = ::std::os::args(); // gdb-check:3[...]::std::io::println(args[0]); // gdb-check:4[...]} diff --git a/src/test/run-pass/const-bound.rs b/src/test/run-pass/const-bound.rs index 5c2985ffa777d..72a23b998e5a1 100644 --- a/src/test/run-pass/const-bound.rs +++ b/src/test/run-pass/const-bound.rs @@ -20,7 +20,7 @@ struct F { field: isize } pub fn main() { /*foo(1); foo("hi".to_string()); - foo(~[1, 2, 3]); + foo(vec![1, 2, 3]); foo(F{field: 42}); foo((1, 2)); foo(@1);*/ diff --git a/src/test/run-pass/issue-3556.rs b/src/test/run-pass/issue-3556.rs index 0efa85e232bae..e6b577ada0c86 100644 --- a/src/test/run-pass/issue-3556.rs +++ b/src/test/run-pass/issue-3556.rs @@ -32,10 +32,6 @@ fn check_strs(actual: &str, expected: &str) -> bool pub fn main() { -// assert!(check_strs(fmt!("%?", Text(@"foo".to_string())), "Text(@~\"foo\")")); -// assert!(check_strs(fmt!("%?", ETag(@~["foo".to_string()], @"bar".to_string())), -// "ETag(@~[ ~\"foo\" ], @~\"bar\")")); - let t = Token::Text("foo".to_string()); let u = Token::Section(vec!["alpha".to_string()], true, From 232b2022b515fdba7e06354c635998cbc0d76114 Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Sat, 2 May 2015 16:26:45 -0400 Subject: [PATCH 04/35] Update debuginfo metadata to use Box instead of ~ Also remove comments that reference the unique_type_id HEAP_VEC_BOX metadata, which was removed in 3e62637 and the unique_type_id GC_BOX metadata, which was removed in 8a91d33. --- .../trans/debuginfo/metadata.rs | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/librustc_trans/trans/debuginfo/metadata.rs b/src/librustc_trans/trans/debuginfo/metadata.rs index 9ff69e7f9dd29..29c22c8c9f712 100644 --- a/src/librustc_trans/trans/debuginfo/metadata.rs +++ b/src/librustc_trans/trans/debuginfo/metadata.rs @@ -142,26 +142,24 @@ impl<'tcx> TypeMap<'tcx> { fn get_unique_type_id_of_type<'a>(&mut self, cx: &CrateContext<'a, 'tcx>, type_: Ty<'tcx>) -> UniqueTypeId { - // basic type -> {:name of the type:} - // tuple -> {tuple_(:param-uid:)*} - // struct -> {struct_:svh: / :node-id:_<(:param-uid:),*> } - // enum -> {enum_:svh: / :node-id:_<(:param-uid:),*> } - // enum variant -> {variant_:variant-name:_:enum-uid:} - // reference (&) -> {& :pointee-uid:} - // mut reference (&mut) -> {&mut :pointee-uid:} - // ptr (*) -> {* :pointee-uid:} - // mut ptr (*mut) -> {*mut :pointee-uid:} - // unique ptr (~) -> {~ :pointee-uid:} - // @-ptr (@) -> {@ :pointee-uid:} - // sized vec ([T; x]) -> {[:size:] :element-uid:} - // unsized vec ([T]) -> {[] :element-uid:} - // trait (T) -> {trait_:svh: / :node-id:_<(:param-uid:),*> } - // closure -> { :store-sigil: |(:param-uid:),* <,_...>| -> \ + // basic type -> {:name of the type:} + // tuple -> {tuple_(:param-uid:)*} + // struct -> {struct_:svh: / :node-id:_<(:param-uid:),*> } + // enum -> {enum_:svh: / :node-id:_<(:param-uid:),*> } + // enum variant -> {variant_:variant-name:_:enum-uid:} + // reference (&) -> {& :pointee-uid:} + // mut reference (&mut) -> {&mut :pointee-uid:} + // ptr (*) -> {* :pointee-uid:} + // mut ptr (*mut) -> {*mut :pointee-uid:} + // unique ptr (Box) -> {Box :pointee-uid:} + // @-ptr (@) -> {@ :pointee-uid:} + // sized vec ([T; x]) -> {[:size:] :element-uid:} + // unsized vec ([T]) -> {[] :element-uid:} + // trait (T) -> {trait_:svh: / :node-id:_<(:param-uid:),*> } + // closure -> { :store-sigil: |(:param-uid:),* <,_...>| -> \ // :return-type-uid: : (:bounds:)*} - // function -> { fn( (:param-uid:)* <,_...> ) -> \ + // function -> { fn( (:param-uid:)* <,_...> ) -> \ // :return-type-uid:} - // unique vec box (~[]) -> {HEAP_VEC_BOX<:pointee-uid:>} - // gc box -> {GC_BOX<:pointee-uid:>} match self.type_to_unique_id.get(&type_).cloned() { Some(unique_type_id) => return unique_type_id, @@ -202,7 +200,7 @@ impl<'tcx> TypeMap<'tcx> { } }, ty::ty_uniq(inner_type) => { - unique_type_id.push('~'); + unique_type_id.push_str("Box "); let inner_type_id = self.get_unique_type_id_of_type(cx, inner_type); let inner_type_id = self.get_unique_type_id_as_string(inner_type_id); unique_type_id.push_str(&inner_type_id[..]); From d3667746d417228f551a91886b7215c9e3038056 Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Sat, 2 May 2015 16:28:53 -0400 Subject: [PATCH 05/35] Update tests to not use old ~ syntax --- src/test/debuginfo/issue11600.rs | 2 +- src/test/run-pass/issue-4241.rs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/test/debuginfo/issue11600.rs b/src/test/debuginfo/issue11600.rs index b79cba7aa6971..dea2a0c5a23f8 100644 --- a/src/test/debuginfo/issue11600.rs +++ b/src/test/debuginfo/issue11600.rs @@ -13,7 +13,7 @@ // ignore-test fn main() { - let args : ~[String] = ::std::os::args(); + let args : Vec = ::std::os::args(); ::std::io::println(args[0]); } diff --git a/src/test/run-pass/issue-4241.rs b/src/test/run-pass/issue-4241.rs index c9b684fd65694..ab75c2064a403 100644 --- a/src/test/run-pass/issue-4241.rs +++ b/src/test/run-pass/issue-4241.rs @@ -22,8 +22,8 @@ use std::io::{ReaderUtil,WriterUtil}; enum Result { Nil, Int(isize), - Data(~[u8]), - List(~[Result]), + Data(Vec), + List(Vec), Error(String), Status(String) } @@ -35,7 +35,7 @@ fn parse_data(len: usize, io: @io::Reader) -> Result { assert_eq!(bytes.len(), len); Data(bytes) } else { - Data(~[]) + Data(vec![]) }; assert_eq!(io.read_char(), '\r'); assert_eq!(io.read_char(), '\n'); @@ -43,7 +43,7 @@ fn parse_data(len: usize, io: @io::Reader) -> Result { } fn parse_list(len: usize, io: @io::Reader) -> Result { - let mut list: ~[Result] = ~[]; + let mut list: Vec = vec![]; for _ in 0..len { let v = match io.read_char() { '$' => parse_bulk(io), @@ -72,7 +72,7 @@ fn parse_multi(io: @io::Reader) -> Result { match from_str::(chop(io.read_line())) { None => panic!(), Some(-1) => Nil, - Some(0) => List(~[]), + Some(0) => List(vec![]), Some(len) if len >= 0 => parse_list(len as usize, io), Some(_) => panic!() } @@ -96,7 +96,7 @@ fn parse_response(io: @io::Reader) -> Result { } } -fn cmd_to_string(cmd: ~[String]) -> String { +fn cmd_to_string(cmd: Vec) -> String { let mut res = "*".to_string(); res.push_str(cmd.len().to_string()); res.push_str("\r\n"); @@ -107,7 +107,7 @@ fn cmd_to_string(cmd: ~[String]) -> String { res } -fn query(cmd: ~[String], sb: TcpSocketBuf) -> Result { +fn query(cmd: Vec, sb: TcpSocketBuf) -> Result { let cmd = cmd_to_string(cmd); //println!("{}", cmd); sb.write_str(cmd); @@ -115,7 +115,7 @@ fn query(cmd: ~[String], sb: TcpSocketBuf) -> Result { res } -fn query2(cmd: ~[String]) -> Result { +fn query2(cmd: Vec) -> Result { let _cmd = cmd_to_string(cmd); io::with_str_reader("$3\r\nXXX\r\n".to_string())(|sb| { let res = parse_response(@sb as @io::Reader); From 55e7f9b7d680d8085765c7c659351d3efe09ffb8 Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Mon, 4 May 2015 21:33:51 -0400 Subject: [PATCH 06/35] Changing Vec to Box<[T]> --- src/librustc/middle/expr_use_visitor.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 359ea02c1d74f..0458bd70346c1 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -1125,7 +1125,7 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> { // that case we can adjust the length of the // original vec accordingly, but we'd have to // make trans do the right thing, and it would - // only work for `Vec`s. It seems simpler + // only work for `Box<[T]>`s. It seems simpler // to just require that people call // `vec.pop()` or `vec.unshift()`. let slice_bk = ty::BorrowKind::from_mutbl(slice_mutbl); From 77acf7b4ee533bf0d84ee5097dfb6676e2f4360e Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Mon, 4 May 2015 21:43:11 -0400 Subject: [PATCH 07/35] Use the lowercase version of the box syntax --- src/librustc_trans/trans/debuginfo/metadata.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_trans/trans/debuginfo/metadata.rs b/src/librustc_trans/trans/debuginfo/metadata.rs index 29c22c8c9f712..bd04bd7a75460 100644 --- a/src/librustc_trans/trans/debuginfo/metadata.rs +++ b/src/librustc_trans/trans/debuginfo/metadata.rs @@ -151,7 +151,7 @@ impl<'tcx> TypeMap<'tcx> { // mut reference (&mut) -> {&mut :pointee-uid:} // ptr (*) -> {* :pointee-uid:} // mut ptr (*mut) -> {*mut :pointee-uid:} - // unique ptr (Box) -> {Box :pointee-uid:} + // unique ptr (box) -> {box :pointee-uid:} // @-ptr (@) -> {@ :pointee-uid:} // sized vec ([T; x]) -> {[:size:] :element-uid:} // unsized vec ([T]) -> {[] :element-uid:} @@ -200,7 +200,7 @@ impl<'tcx> TypeMap<'tcx> { } }, ty::ty_uniq(inner_type) => { - unique_type_id.push_str("Box "); + unique_type_id.push_str("box "); let inner_type_id = self.get_unique_type_id_of_type(cx, inner_type); let inner_type_id = self.get_unique_type_id_as_string(inner_type_id); unique_type_id.push_str(&inner_type_id[..]); From abc0017f3b2308c3bff2a975d4e33b53c2f52bdb Mon Sep 17 00:00:00 2001 From: Carol Nichols Date: Mon, 4 May 2015 21:44:22 -0400 Subject: [PATCH 08/35] Remove an obsolete example in a comment --- src/librustc_trans/back/link.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 49e336c670078..e97f8d9be1274 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -288,7 +288,7 @@ pub fn mangle>(path: PI, // when using unix's linker. Perhaps one day when we just use a linker from LLVM // we won't need to do this name mangling. The problem with name mangling is // that it seriously limits the available characters. For example we can't - // have things like &T or Vec in symbol names when one would theoretically + // have things like &T in symbol names when one would theoretically // want them for things like impls of traits on that type. // // To be able to work on all platforms and get *some* reasonable output, we From 4d1e48e37610f421f30e098f2ae9ef98b85b66eb Mon Sep 17 00:00:00 2001 From: Tincan Date: Thu, 7 May 2015 20:23:47 +0200 Subject: [PATCH 09/35] Typo in ownership.md --- src/doc/trpl/ownership.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/ownership.md b/src/doc/trpl/ownership.md index 3003156f875aa..a70f03739f773 100644 --- a/src/doc/trpl/ownership.md +++ b/src/doc/trpl/ownership.md @@ -3,7 +3,7 @@ This guide is one of three presenting Rust’s ownership system. This is one of Rust’s most unique and compelling features, with which Rust developers should become quite acquainted. Ownership is how Rust achieves its largest goal, -memory safety. The there are a few distinct concepts, each with its own +memory safety. There are a few distinct concepts, each with its own chapter: * ownership, which you’re reading now. From ae1b2f4bf3a5d9cee9227528b6df24decc20b977 Mon Sep 17 00:00:00 2001 From: Tincan Date: Thu, 7 May 2015 21:31:10 +0200 Subject: [PATCH 10/35] Another typo --- src/doc/trpl/ownership.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/ownership.md b/src/doc/trpl/ownership.md index a70f03739f773..d994c1772755b 100644 --- a/src/doc/trpl/ownership.md +++ b/src/doc/trpl/ownership.md @@ -173,7 +173,7 @@ fn foo(v: Vec) -> Vec { } ``` -This would get very tedius. It gets worse the more things we want to take ownership of: +This would get very tedious. It gets worse the more things we want to take ownership of: ```rust fn foo(v1: Vec, v2: Vec) -> (Vec, Vec, i32) { From 96229e82985054a7b1f95732605eeeda69bf71b9 Mon Sep 17 00:00:00 2001 From: llogiq Date: Fri, 8 May 2015 13:26:45 +0200 Subject: [PATCH 11/35] fixed ICE issue #25180 --- src/librustc/middle/check_const.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 8bb83c54da8a3..195f4f4b69568 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -251,9 +251,13 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> { b: &'v ast::Block, s: Span, fn_id: ast::NodeId) { - assert!(self.mode == Mode::Var); - self.with_euv(Some(fn_id), |euv| euv.walk_fn(fd, b)); - visit::walk_fn(self, fk, fd, b, s); + let (old_mode, old_qualif) = (self.mode, self.qualif); + self.mode = Mode::Var; + self.qualif = ConstQualif::empty(); + self.with_euv(Some(fn_id), |euv| euv.walk_fn(fd, b)); + visit::walk_fn(self, fk, fd, b, s); + self.mode = old_mode; + self.qualif = old_qualif; } fn visit_pat(&mut self, p: &ast::Pat) { @@ -275,7 +279,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> { let node_ty = ty::node_id_to_type(self.tcx, ex.id); check_expr(self, ex, node_ty); - + // Special-case some expressions to avoid certain flags bubbling up. match ex.node { ast::ExprCall(ref callee, ref args) => { From 29daa29981e89ba7f71dcbba06166f8c54f4682d Mon Sep 17 00:00:00 2001 From: llogiq Date: Fri, 8 May 2015 13:56:14 +0200 Subject: [PATCH 12/35] formatting correction --- src/librustc/middle/check_const.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 195f4f4b69568..2322b97de1487 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -254,10 +254,10 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> { let (old_mode, old_qualif) = (self.mode, self.qualif); self.mode = Mode::Var; self.qualif = ConstQualif::empty(); - self.with_euv(Some(fn_id), |euv| euv.walk_fn(fd, b)); - visit::walk_fn(self, fk, fd, b, s); - self.mode = old_mode; - self.qualif = old_qualif; + self.with_euv(Some(fn_id), |euv| euv.walk_fn(fd, b)); + visit::walk_fn(self, fk, fd, b, s); + self.mode = old_mode; + self.qualif = old_qualif; } fn visit_pat(&mut self, p: &ast::Pat) { @@ -279,7 +279,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> { let node_ty = ty::node_id_to_type(self.tcx, ex.id); check_expr(self, ex, node_ty); - + // Special-case some expressions to avoid certain flags bubbling up. match ex.node { ast::ExprCall(ref callee, ref args) => { From 1434715550c372f83ab3a138d66674d5b303d429 Mon Sep 17 00:00:00 2001 From: llogiq Date: Fri, 8 May 2015 17:07:03 +0200 Subject: [PATCH 13/35] crossed the i-s and dotted the t-s ;-) Also added a run-pass test and removed the with_mode copy, thanks to eddyb --- src/librustc/middle/check_const.rs | 8 ++------ src/test/run-pass/issue-25180.rs | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 src/test/run-pass/issue-25180.rs diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index 2322b97de1487..d48d2abc660f6 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -251,13 +251,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> { b: &'v ast::Block, s: Span, fn_id: ast::NodeId) { - let (old_mode, old_qualif) = (self.mode, self.qualif); - self.mode = Mode::Var; - self.qualif = ConstQualif::empty(); - self.with_euv(Some(fn_id), |euv| euv.walk_fn(fd, b)); + self.with_mode(Mode::Var, |v| v.with_euv(Some(fn_id), + |euv| euv.walk_fn(fd, b))); visit::walk_fn(self, fk, fd, b, s); - self.mode = old_mode; - self.qualif = old_qualif; } fn visit_pat(&mut self, p: &ast::Pat) { diff --git a/src/test/run-pass/issue-25180.rs b/src/test/run-pass/issue-25180.rs new file mode 100644 index 0000000000000..3955e451639fd --- /dev/null +++ b/src/test/run-pass/issue-25180.rs @@ -0,0 +1,16 @@ +// Copyright 2015 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. + +// pretty-expanded FIXME #25180 + +const x: &'static Fn() = &|| println!("ICE here"); + +fn main() {} + From 715f7c3cd2af3d54ef79d75fe7b1e820853f08ea Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 8 May 2015 23:54:24 +0200 Subject: [PATCH 14/35] Add a precision for references --- src/doc/trpl/references-and-borrowing.md | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/doc/trpl/references-and-borrowing.md b/src/doc/trpl/references-and-borrowing.md index 21feff73342ce..06ff9bfbc55d9 100644 --- a/src/doc/trpl/references-and-borrowing.md +++ b/src/doc/trpl/references-and-borrowing.md @@ -334,3 +334,35 @@ In other words, `y` is only valid for the scope where `x` exists. As soon as `x` goes away, it becomes invalid to refer to it. As such, the error says that the borrow ‘doesn’t live long enough’ because it’s not valid for the right amount of time. + +The same problem occurs when the reference is declared _before_ the variable it refers to: + +```rust,ignore +let y: &i32; +let x = 5; +y = &x; + +println!("{}", y); +``` + +We get this error: + +error: `x` does not live long enough +y = &x; + ^ +note: reference must be valid for the block suffix following statement 0 at +2:16... + let y: &i32; + let x = 5; + y = &x; + + println!("{}", y); +} + +note: ...but borrowed value is only valid for the block suffix following +statement 1 at 3:14 + let x = 5; + y = &x; + + println!("{}", y); +} From 7a91fe845c7ee6e78f6b9f5846541fdc1785687a Mon Sep 17 00:00:00 2001 From: Sindre Johansen Date: Sat, 9 May 2015 12:59:24 +0200 Subject: [PATCH 15/35] Fixed a typo. Removed an extra s --- src/doc/trpl/primitive-types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/primitive-types.md b/src/doc/trpl/primitive-types.md index e017e222c7417..f0f57c3ab5858 100644 --- a/src/doc/trpl/primitive-types.md +++ b/src/doc/trpl/primitive-types.md @@ -176,7 +176,7 @@ Slices have type `&[T]`. We’ll talk about that `T` when we cover [generics]: generics.html -You can find more documentation for `slices`s [in the standard library +You can find more documentation for `slices` [in the standard library documentation][slice]. [slice]: ../std/primitive.slice.html From 1e9ce0d50564b872d12457da59911838eb21b760 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Sat, 9 May 2015 13:27:23 +0200 Subject: [PATCH 16/35] std: Add example for HashMap::entry() --- src/libstd/collections/hash/map.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index eedda3cf4371a..ae75de2086b77 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -916,6 +916,24 @@ impl HashMap } /// Gets the given key's corresponding entry in the map for in-place manipulation. + /// + /// # Examples + /// + /// ``` + /// use std::collections::HashMap; + /// + /// let mut letters = HashMap::new(); + /// + /// for ch in "a short treatise on fungi".chars() { + /// let counter = letters.entry(ch).or_insert(0); + /// *counter += 1; + /// } + /// + /// assert_eq!(letters[&'s'], 2); + /// assert_eq!(letters[&'t'], 3); + /// assert_eq!(letters[&'u'], 1); + /// assert_eq!(letters.get(&'y'), None); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn entry(&mut self, key: K) -> Entry { // Gotta resize now. From 7a2ac0cd5ae44e84a15264888427f007f895946e Mon Sep 17 00:00:00 2001 From: Sindre Johansen Date: Sat, 9 May 2015 13:34:49 +0200 Subject: [PATCH 17/35] Added start of last text block The start of the last text block in references was missing, I added it. --- src/doc/trpl/references-and-borrowing.md | 1 + 1 file changed, 1 insertion(+) diff --git a/src/doc/trpl/references-and-borrowing.md b/src/doc/trpl/references-and-borrowing.md index 8bb3f94760bc9..f428107ffc0ca 100644 --- a/src/doc/trpl/references-and-borrowing.md +++ b/src/doc/trpl/references-and-borrowing.md @@ -312,6 +312,7 @@ println!("{}", y); We get this error: +```text error: `x` does not live long enough y = &x; ^ From ca5c694f439fdb86bd7314b7daaa56994e33c761 Mon Sep 17 00:00:00 2001 From: llogiq Date: Sun, 10 May 2015 04:39:51 +0200 Subject: [PATCH 18/35] Pulled walk_fn() into Var mode, extended test --- src/librustc/middle/check_const.rs | 7 ++++--- src/test/run-pass/issue-25180.rs | 4 +++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index d48d2abc660f6..89a93f990df63 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -251,9 +251,10 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> { b: &'v ast::Block, s: Span, fn_id: ast::NodeId) { - self.with_mode(Mode::Var, |v| v.with_euv(Some(fn_id), - |euv| euv.walk_fn(fd, b))); - visit::walk_fn(self, fk, fd, b, s); + self.with_mode(Mode::Var, |v| { + v.with_euv(Some(fn_id), |euv| euv.walk_fn(fd, b)); + visit::walk_fn(v, fk, fd, b, s); + }) } fn visit_pat(&mut self, p: &ast::Pat) { diff --git a/src/test/run-pass/issue-25180.rs b/src/test/run-pass/issue-25180.rs index 3955e451639fd..d63c50192426b 100644 --- a/src/test/run-pass/issue-25180.rs +++ b/src/test/run-pass/issue-25180.rs @@ -12,5 +12,7 @@ const x: &'static Fn() = &|| println!("ICE here"); -fn main() {} +fn main() { + x() +} From f8888af412b517c55deed84f851b3dc3c93d81d0 Mon Sep 17 00:00:00 2001 From: Don Petersen Date: Sat, 9 May 2015 20:25:09 -0700 Subject: [PATCH 19/35] Add omitted word to mutability docs. --- src/doc/trpl/mutability.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/mutability.md b/src/doc/trpl/mutability.md index 435407a8a967d..9b386acdca214 100644 --- a/src/doc/trpl/mutability.md +++ b/src/doc/trpl/mutability.md @@ -78,8 +78,8 @@ When we call `clone()`, the `Arc` needs to update the reference count. Yet we’ve not used any `mut`s here, `x` is an immutable binding, and we didn’t take `&mut 5` or anything. So what gives? -To this, we have to go back to the core of Rust’s guiding philosophy, memory -safety, and the mechanism by which Rust guarantees it, the +To understand this, we have to go back to the core of Rust’s guiding +philosophy, memory safety, and the mechanism by which Rust guarantees it, the [ownership][ownership] system, and more specifically, [borrowing][borrowing]: > You may have one or the other of these two kinds of borrows, but not both at From ae1b64ff7376859b3582441cd41218b5445da148 Mon Sep 17 00:00:00 2001 From: Don Petersen Date: Sat, 9 May 2015 22:10:34 -0700 Subject: [PATCH 20/35] Fix typo in Match document. --- src/doc/trpl/match.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/match.md b/src/doc/trpl/match.md index 2c0c8ea73c03c..86b9445338966 100644 --- a/src/doc/trpl/match.md +++ b/src/doc/trpl/match.md @@ -50,7 +50,7 @@ side of a `let` binding or directly where an expression is used: ```rust let x = 5; -let numer = match x { +let number = match x { 1 => "one", 2 => "two", 3 => "three", From 2cc4d822dfada7395b67d83368a5bee44b50a5e2 Mon Sep 17 00:00:00 2001 From: Franziska Hinkelmann Date: Sun, 10 May 2015 08:02:06 +0200 Subject: [PATCH 21/35] Fix small typos in documentation --- src/doc/trpl/guessing-game.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/guessing-game.md b/src/doc/trpl/guessing-game.md index 57479a21e47a8..fc3927380fadb 100644 --- a/src/doc/trpl/guessing-game.md +++ b/src/doc/trpl/guessing-game.md @@ -711,7 +711,7 @@ variety of numbers, we need to give Rust a hint as to the exact type of number we want. Hence, `let guess: u32`. The colon (`:`) after `guess` tells Rust we’re going to annotate its type. `u32` is an unsigned, thirty-two bit integer. Rust has [a number of built-in number types][number], but we’ve -chosen `u32`. It’s a good default choice for a small positive numer. +chosen `u32`. It’s a good default choice for a small positive number. [parse]: ../std/primitive.str.html#method.parse [number]: primitive-types.html#numeric-types @@ -920,7 +920,7 @@ failure. Each contains more information: the successful parsed integer, or an error type. In this case, we `match` on `Ok(num)`, which sets the inner value of the `Ok` to the name `num`, and then we just return it on the right-hand side. In the `Err` case, we don’t care what kind of error it is, so we just -use `_` intead of a name. This ignores the error, and `continue` causes us +use `_` instead of a name. This ignores the error, and `continue` causes us to go to the next iteration of the `loop`. Now we should be good! Let’s try: From 8ad1c90db0670c763fec0f1d5cfc0303bc28fb77 Mon Sep 17 00:00:00 2001 From: Sindre Johansen Date: Sun, 10 May 2015 11:16:32 +0200 Subject: [PATCH 22/35] Removed the backticks on slices --- src/doc/trpl/primitive-types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/primitive-types.md b/src/doc/trpl/primitive-types.md index f0f57c3ab5858..bb2bf028700d2 100644 --- a/src/doc/trpl/primitive-types.md +++ b/src/doc/trpl/primitive-types.md @@ -176,7 +176,7 @@ Slices have type `&[T]`. We’ll talk about that `T` when we cover [generics]: generics.html -You can find more documentation for `slices` [in the standard library +You can find more documentation for slices [in the standard library documentation][slice]. [slice]: ../std/primitive.slice.html From 6e19cfacf42e2de001de4c2133a4321b5286f523 Mon Sep 17 00:00:00 2001 From: llogiq Date: Sun, 10 May 2015 11:57:52 +0200 Subject: [PATCH 23/35] more tests --- src/test/run-pass/issue-25180.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/test/run-pass/issue-25180.rs b/src/test/run-pass/issue-25180.rs index d63c50192426b..0ad5fd87e9566 100644 --- a/src/test/run-pass/issue-25180.rs +++ b/src/test/run-pass/issue-25180.rs @@ -10,9 +10,21 @@ // pretty-expanded FIXME #25180 -const x: &'static Fn() = &|| println!("ICE here"); +const empty: &'static Fn() = &|| println!("ICE here"); -fn main() { - x() +const one_argument: &'static Fn(u32) = &|y| println("{}", y); + +const plus_21: &'static Fn(u32) -> u32 = |y| y + 21; + +const multi_and_local: &'static Fn(u32, u32) -> u32 = |x, y| { + let tmp = x + y; + tmp * 2; +}; + +pub fn main() { + empty(); + one_argument(42); + assert!(plus_21(21) == 42); + assert!(multi_and_local(1, 2) == 6); } From a18ce4d47979260001e9be0a92f887e3abd4eb88 Mon Sep 17 00:00:00 2001 From: llogiq Date: Sun, 10 May 2015 12:30:06 +0200 Subject: [PATCH 24/35] fixed errors in test code --- src/test/run-pass/issue-25180.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/test/run-pass/issue-25180.rs b/src/test/run-pass/issue-25180.rs index 0ad5fd87e9566..9d2d51264e6fa 100644 --- a/src/test/run-pass/issue-25180.rs +++ b/src/test/run-pass/issue-25180.rs @@ -10,21 +10,21 @@ // pretty-expanded FIXME #25180 -const empty: &'static Fn() = &|| println!("ICE here"); +const EMPTY: &'static Fn() = &|| println!("ICE here"); -const one_argument: &'static Fn(u32) = &|y| println("{}", y); +const ONE_ARGUMENT: &'static Fn(u32) = &|y| println!("{}", y); -const plus_21: &'static Fn(u32) -> u32 = |y| y + 21; +const PLUS_21: &'static (Fn(u32) -> u32) = &|y| y + 21; -const multi_and_local: &'static Fn(u32, u32) -> u32 = |x, y| { +const MULTI_AND_LOCAL: &'static (Fn(u32, u32) -> u32) = &|x, y| { let tmp = x + y; - tmp * 2; + tmp * 2 }; pub fn main() { - empty(); - one_argument(42); - assert!(plus_21(21) == 42); - assert!(multi_and_local(1, 2) == 6); + EMPTY(); + ONE_ARGUMENT(42); + assert!(PLUS_21(21) == 42); + assert!(MULTI_AND_LOCAL(1, 2) == 6); } From a168dbad15e108fce02a996fc8f72803460b7a55 Mon Sep 17 00:00:00 2001 From: Jan Bujak Date: Sun, 10 May 2015 14:06:41 +0200 Subject: [PATCH 25/35] Add #[inline] to AsRef::as_ref for String and str. --- src/libcollections/string.rs | 1 + src/libcore/convert.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index 3c668f7fe9bc6..bb5345917e713 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -1052,6 +1052,7 @@ impl ToString for T { #[stable(feature = "rust1", since = "1.0.0")] impl AsRef for String { + #[inline] fn as_ref(&self) -> &str { self } diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index d3de77a9241e3..da6ac6bd752bf 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -173,6 +173,7 @@ impl AsMut<[T]> for [T] { #[stable(feature = "rust1", since = "1.0.0")] impl AsRef for str { + #[inline] fn as_ref(&self) -> &str { self } From 5613502a4f3476e5db2c68bdf203104556796630 Mon Sep 17 00:00:00 2001 From: Nick Platt Date: Sat, 9 May 2015 23:18:28 -0400 Subject: [PATCH 26/35] Add long diagnostic for E0067 --- src/librustc_typeck/diagnostics.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 0e6386618f17b..2cc1b23e03ec3 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -46,6 +46,23 @@ enum variant, one of the fields was not provided. Each field should be specified exactly once. "##, +E0067: r##" +The left-hand side of an assignment operator must be an lvalue expression. An +lvalue expression represents a memory location and includes item paths (ie, +namespaced variables), dereferences, indexing expressions, and field references. + +``` +use std::collections::LinkedList; + +// Good +let mut list = LinkedList::new(); + + +// Bad: assignment to non-lvalue expression +LinkedList::new() += 1; +``` +"##, + E0081: r##" Enum discriminants are used to differentiate enum variants stored in memory. This error indicates that the same value was used for two or more variants, @@ -149,7 +166,6 @@ register_diagnostics! { E0060, E0061, E0066, - E0067, E0068, E0069, E0070, From ffc0d0448917c1f225a3500bf3a1dc6fc40029d7 Mon Sep 17 00:00:00 2001 From: Nick Platt Date: Sat, 9 May 2015 23:20:14 -0400 Subject: [PATCH 27/35] Add long diagnostic for E0131, E0132 --- src/librustc_typeck/diagnostics.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 2cc1b23e03ec3..026ba3d08b42b 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -136,6 +136,20 @@ construct an instance of the following type using only safe code: ``` enum Empty {} ``` +"##, + +E0131: r##" +It is not possible to define `main` with type parameters, or even with function +parameters. When `main` is present, it must take no arguments and return `()`. +"##, + +E0132: r##" +It is not possible to declare type parameters on a function that has the `start` +attribute. Such a function must have the following type signature: + +``` +fn(isize, *const *const u8) -> isize +``` "## } @@ -205,8 +219,6 @@ register_diagnostics! { E0128, E0129, E0130, - E0131, - E0132, E0141, E0159, E0163, From 25543f38e437f959298238790a3737ff44ab5baf Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sun, 10 May 2015 21:05:04 +0200 Subject: [PATCH 28/35] Add missing backticks --- src/doc/trpl/references-and-borrowing.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/doc/trpl/references-and-borrowing.md b/src/doc/trpl/references-and-borrowing.md index 06ff9bfbc55d9..82533becef342 100644 --- a/src/doc/trpl/references-and-borrowing.md +++ b/src/doc/trpl/references-and-borrowing.md @@ -312,6 +312,7 @@ println!("{}", y); We get this error: +```text error: `x` does not live long enough y = &x; ^ @@ -347,6 +348,7 @@ println!("{}", y); We get this error: +```text error: `x` does not live long enough y = &x; ^ @@ -366,3 +368,4 @@ statement 1 at 3:14 println!("{}", y); } +``` \ No newline at end of file From 0c390d2f8e1cc2f29d9c1088387d375a929356a5 Mon Sep 17 00:00:00 2001 From: Alexander Polakov Date: Sun, 10 May 2015 22:37:06 +0300 Subject: [PATCH 29/35] point supposed to be immutable in this example --- src/doc/trpl/mutability.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/mutability.md b/src/doc/trpl/mutability.md index 435407a8a967d..3e910aff9eafc 100644 --- a/src/doc/trpl/mutability.md +++ b/src/doc/trpl/mutability.md @@ -169,7 +169,7 @@ struct Point { y: Cell, } -let mut point = Point { x: 5, y: Cell::new(6) }; +let point = Point { x: 5, y: Cell::new(6) }; point.y.set(7); From 685f557729e3bb2691a81ac10074bddf4f61a0b6 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 10 May 2015 16:32:18 -0400 Subject: [PATCH 30/35] Update docs to stop referencing `BufReadExt` --- src/libstd/io/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 9089b417fcb99..e7b2b01d09f35 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -844,7 +844,7 @@ impl fmt::Display for CharsError { /// An iterator over the contents of an instance of `BufRead` split on a /// particular byte. /// -/// See `BufReadExt::split` for more information. +/// See `BufRead::split` for more information. #[stable(feature = "rust1", since = "1.0.0")] pub struct Split { buf: B, @@ -873,7 +873,7 @@ impl Iterator for Split { /// An iterator over the lines of an instance of `BufRead` split on a newline /// byte. /// -/// See `BufReadExt::lines` for more information. +/// See `BufRead::lines` for more information. #[stable(feature = "rust1", since = "1.0.0")] pub struct Lines { buf: B, From 6d410132dcbe7a83f3276b6eac4c0baa0f6a3930 Mon Sep 17 00:00:00 2001 From: Pete Hunt Date: Sun, 10 May 2015 15:11:40 -0700 Subject: [PATCH 31/35] Fix typo in guessing-game docs --- src/doc/trpl/guessing-game.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/trpl/guessing-game.md b/src/doc/trpl/guessing-game.md index 50767b603c46c..86158e716d2f2 100644 --- a/src/doc/trpl/guessing-game.md +++ b/src/doc/trpl/guessing-game.md @@ -273,7 +273,7 @@ information’. Why throw it away? Well, for a basic program, we just want to print a generic error, as basically any issue means we can’t continue. The [`ok()` method][ok] returns a value which has another method defined on it: `expect()`. The [`expect()` method][expect] takes a value it’s called on, and -if it isn’t a successful one, [`panic!`][panic]s with a message you passed you +if it isn’t a successful one, [`panic!`][panic]s with a message you passed it. A `panic!` like this will cause our program to crash, displaying the message. From a168a15008e5a5ac50a3914e8d15c6ee8fbc92ce Mon Sep 17 00:00:00 2001 From: Pete Hunt Date: Sun, 10 May 2015 16:10:02 -0700 Subject: [PATCH 32/35] Fix typo in references-and-borrowing docs --- src/doc/trpl/references-and-borrowing.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/doc/trpl/references-and-borrowing.md b/src/doc/trpl/references-and-borrowing.md index da416e994c4c5..c434371ce59d3 100644 --- a/src/doc/trpl/references-and-borrowing.md +++ b/src/doc/trpl/references-and-borrowing.md @@ -6,7 +6,7 @@ become quite acquainted. Ownership is how Rust achieves its largest goal, memory safety. There are a few distinct concepts, each with its own chapter: -* [ownership][ownership], ownership, the key concept +* [ownership][ownership], the key concept * borrowing, which you’re reading now * [lifetimes][lifetimes], an advanced concept of borrowing @@ -368,4 +368,4 @@ statement 1 at 3:14 println!("{}", y); } -``` \ No newline at end of file +``` From 295b62dfb9ae53cb14518664ddaaf71348b20f18 Mon Sep 17 00:00:00 2001 From: Johann Hofmann Date: Mon, 11 May 2015 00:53:24 +0200 Subject: [PATCH 33/35] Docs: Compile-time bounds check in index expression The reference was claiming all vectors all bounds-checked at run-time, when constant vectors are usually checked at compile-time. For the changed example see http://is.gd/28ak9E --- src/doc/reference.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 16fdcfa301392..fe5a6d9be49d3 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -842,7 +842,7 @@ module declarations should be at the crate root if direct usage of the declared modules within `use` items is desired. It is also possible to use `self` and `super` at the beginning of a `use` item to refer to the current and direct parent modules respectively. All rules regarding accessing declared modules in -`use` declarations applies to both module declarations and `extern crate` +`use` declarations apply to both module declarations and `extern crate` declarations. An example of what will and will not work for `use` items: @@ -2564,12 +2564,19 @@ array is mutable, the resulting [lvalue](#lvalues,-rvalues-and-temporaries) can be assigned to. Indices are zero-based, and may be of any integral type. Vector access is -bounds-checked at run-time. When the check fails, it will put the thread in a -_panicked state_. +bounds-checked at compile-time for constant arrays being accessed with a constant index value. +Otherwise a check will be performed at run-time that will put the thread in a _panicked state_ if it fails. ```{should-fail} ([1, 2, 3, 4])[0]; -(["a", "b"])[10]; // panics + +let x = (["a", "b"])[10]; // compiler error: const index-expr is out of bounds + +let n = 10; +let y = (["a", "b"])[n]; // panics + +let arr = ["a", "b"]; +arr[10]; // panics ``` ### Range expressions From 770f0e95a189e84491845ab1378eb3bc3c896f62 Mon Sep 17 00:00:00 2001 From: Johann Hofmann Date: Mon, 11 May 2015 02:03:37 +0200 Subject: [PATCH 34/35] Add if let expressions example --- src/doc/reference.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/doc/reference.md b/src/doc/reference.md index 16fdcfa301392..89f74d8d87afa 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -3064,6 +3064,17 @@ of a condition expression it expects a refutable let statement. If the value of expression on the right hand side of the let statement matches the pattern, the corresponding block will execute, otherwise flow proceeds to the first `else` block that follows. +``` +let dish = ("Ham", "Eggs"); +if let ("Bacon", b) = dish { // will not execute because let is refuted + println!("Bacon is served with {}", b); +} + +if let ("Ham", b) = dish { // will execute + println!("Ham is served with {}", b); +} +``` + ### While let loops A `while let` loop is semantically identical to a `while` loop but in place of a From 6a19046423b49672bc71eb07149ae9ef32bc8af5 Mon Sep 17 00:00:00 2001 From: Johann Date: Mon, 11 May 2015 02:40:02 +0200 Subject: [PATCH 35/35] Four spaces indent, rephrasing --- src/doc/reference.md | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 89f74d8d87afa..e6afa695b2c68 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -3066,12 +3066,15 @@ block will execute, otherwise flow proceeds to the first `else` block that follo ``` let dish = ("Ham", "Eggs"); -if let ("Bacon", b) = dish { // will not execute because let is refuted - println!("Bacon is served with {}", b); + +// this body will be skipped because the pattern is refuted +if let ("Bacon", b) = dish { + println!("Bacon is served with {}", b); } -if let ("Ham", b) = dish { // will execute - println!("Ham is served with {}", b); +// this body will execute +if let ("Ham", b) = dish { + println!("Ham is served with {}", b); } ```