diff --git a/src/libcore/iter/range.rs b/src/libcore/iter/range.rs index 8408e5d88b4cb..66d05d81d80cd 100644 --- a/src/libcore/iter/range.rs +++ b/src/libcore/iter/range.rs @@ -263,14 +263,12 @@ impl ops::RangeFrom { /// # Examples /// /// ``` - /// # #![feature(step_by)] - /// - /// for i in (0u8..).step_by(2).take(10) { - /// println!("{}", i); + /// #![feature(step_by)] + /// fn main() { + /// let result: Vec<_> = (0..).step_by(2).take(5).collect(); + /// assert_eq!(result, vec![0, 2, 4, 6, 8]); /// } /// ``` - /// - /// This prints the first ten even natural integers (0 to 18). #[unstable(feature = "step_by", reason = "recent addition", issue = "27741")] pub fn step_by(self, by: A) -> StepBy { @@ -291,8 +289,10 @@ impl ops::Range { /// /// ``` /// #![feature(step_by)] - /// let result: Vec<_> = (0..10).step_by(2).collect(); - /// assert_eq!(result, vec![0, 2, 4, 6, 8]); + /// fn main() { + /// let result: Vec<_> = (0..10).step_by(2).collect(); + /// assert_eq!(result, vec![0, 2, 4, 6, 8]); + /// } /// ``` #[unstable(feature = "step_by", reason = "recent addition", issue = "27741")] @@ -315,20 +315,8 @@ impl ops::RangeInclusive { /// ``` /// #![feature(step_by, inclusive_range_syntax)] /// - /// for i in (0...10).step_by(2) { - /// println!("{}", i); - /// } - /// ``` - /// - /// This prints: - /// - /// ```text - /// 0 - /// 2 - /// 4 - /// 6 - /// 8 - /// 10 + /// let result: Vec<_> = (0...10).step_by(2).collect(); + /// assert_eq!(result, vec![0, 2, 4, 6, 8, 10]); /// ``` #[unstable(feature = "step_by", reason = "recent addition", issue = "27741")] diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 14aa2ba3bd429..1f9902abcb2f0 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -282,6 +282,12 @@ macro_rules! forward_ref_binop { /// Point { x: 3, y: 3 }); /// } /// ``` +/// +/// Note that `RHS = Self` by default, but this is not mandatory. For example, +/// [std::time::SystemTime] implements `Add`, which permits +/// operations of the form `SystemTime = SystemTime + Duration`. +/// +/// [std::time::SystemTime]: ../time/struct.SystemTime.html #[lang = "add"] #[stable(feature = "rust1", since = "1.0.0")] pub trait Add { @@ -349,6 +355,12 @@ add_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// Point { x: 1, y: 0 }); /// } /// ``` +/// +/// Note that `RHS = Self` by default, but this is not mandatory. For example, +/// [std::time::SystemTime] implements `Sub`, which permits +/// operations of the form `SystemTime = SystemTime - Duration`. +/// +/// [std::time::SystemTime]: ../time/struct.SystemTime.html #[lang = "sub"] #[stable(feature = "rust1", since = "1.0.0")] pub trait Sub { diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 5183d68065c7d..f8f90bdb4e7f5 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -1270,7 +1270,42 @@ trait Foo {} impl Foo for i32 {} ``` -"## +"##, + +E0530: r##" +A binding shadowed something it shouldn't. + +Erroneous code example: + +```compile_fail,E0530 +static TEST: i32 = 0; + +let r: (i32, i32) = (0, 0); +match r { + TEST => {} // error: match bindings cannot shadow statics +} +``` + +To fix this error, just change the binding's name in order to avoid shadowing +one of the following: + +* struct name +* struct/enum variant +* static +* const +* associated const + +Fixed example: + +``` +static TEST: i32 = 0; + +let r: (i32, i32) = (0, 0); +match r { + something => {} // ok! +} +``` +"##, } @@ -1289,7 +1324,6 @@ register_diagnostics! { // E0419, merged into 531 // E0420, merged into 532 // E0421, merged into 531 - E0530, // X bindings cannot shadow Ys E0531, // unresolved pattern path kind `name` E0532, // expected pattern path kind, found another pattern path kind // E0427, merged into 530 diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs index f9699a55f5068..46b3f503b6e76 100644 --- a/src/librustc_typeck/check/method/suggest.rs +++ b/src/librustc_typeck/check/method/suggest.rs @@ -242,6 +242,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { MethodError::Ambiguity(sources) => { let mut err = struct_span_err!(self.sess(), span, E0034, "multiple applicable items in scope"); + err.span_label(span, &format!("multiple `{}` found", item_name)); report_candidates(&mut err, sources); err.emit(); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index ddb4d7c7012a0..dcd37805c8758 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -903,14 +903,18 @@ fn report_forbidden_specialization<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, { let mut err = struct_span_err!( tcx.sess, impl_item.span, E0520, - "item `{}` is provided by an `impl` that specializes \ - another, but the item in the parent `impl` is not \ - marked `default` and so it cannot be specialized.", + "`{}` specializes an item from a parent `impl`, but \ + neither that item nor the `impl` are marked `default`", impl_item.name); + err.span_label(impl_item.span, &format!("cannot specialize default item `{}`", + impl_item.name)); match tcx.span_of_impl(parent_impl) { Ok(span) => { - err.span_note(span, "parent implementation is here:"); + err.span_label(span, &"parent `impl` is here"); + err.note(&format!("to specialize, either the parent `impl` or `{}` \ + in the parent `impl` must be marked `default`", + impl_item.name)); } Err(cname) => { err.note(&format!("parent implementation is in crate `{}`", cname)); diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index dcd3652af876b..3c5f07c3e33a6 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -45,7 +45,6 @@ pub struct TcpStream(net_imp::TcpStream); /// /// ```no_run /// use std::net::{TcpListener, TcpStream}; -/// use std::thread; /// /// let listener = TcpListener::bind("127.0.0.1:80").unwrap(); /// @@ -57,17 +56,11 @@ pub struct TcpStream(net_imp::TcpStream); /// for stream in listener.incoming() { /// match stream { /// Ok(stream) => { -/// thread::spawn(move|| { -/// // connection succeeded -/// handle_client(stream) -/// }); +/// handle_client(stream); /// } /// Err(e) => { /* connection failed */ } /// } /// } -/// -/// // close the socket server -/// drop(listener); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub struct TcpListener(net_imp::TcpListener); diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 67219b6fd1b9c..92ebec03b364b 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -639,6 +639,25 @@ pub struct Iter<'a> { inner: Components<'a>, } +#[stable(feature = "path_components_debug", since = "1.13.0")] +impl<'a> fmt::Debug for Components<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + struct DebugHelper<'a>(&'a Path); + + impl<'a> fmt::Debug for DebugHelper<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_list() + .entries(self.0.components()) + .finish() + } + } + + f.debug_tuple("Components") + .field(&DebugHelper(self.as_path())) + .finish() + } +} + impl<'a> Components<'a> { // how long is the prefix, if any? #[inline] @@ -818,6 +837,25 @@ impl<'a> AsRef for Components<'a> { } } +#[stable(feature = "path_iter_debug", since = "1.13.0")] +impl<'a> fmt::Debug for Iter<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + struct DebugHelper<'a>(&'a Path); + + impl<'a> fmt::Debug for DebugHelper<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.debug_list() + .entries(self.0.iter()) + .finish() + } + } + + f.debug_tuple("Iter") + .field(&DebugHelper(self.as_path())) + .finish() + } +} + impl<'a> Iter<'a> { /// Extracts a slice corresponding to the portion of the path remaining for iteration. #[stable(feature = "rust1", since = "1.0.0")] @@ -3483,4 +3521,46 @@ mod tests { ); } } + + #[test] + fn test_components_debug() { + let path = Path::new("/tmp"); + + let mut components = path.components(); + + let expected = "Components([RootDir, Normal(\"tmp\")])"; + let actual = format!("{:?}", components); + assert_eq!(expected, actual); + + let _ = components.next().unwrap(); + let expected = "Components([Normal(\"tmp\")])"; + let actual = format!("{:?}", components); + assert_eq!(expected, actual); + + let _ = components.next().unwrap(); + let expected = "Components([])"; + let actual = format!("{:?}", components); + assert_eq!(expected, actual); + } + + #[test] + fn test_iter_debug() { + let path = Path::new("/tmp"); + + let mut iter = path.iter(); + + let expected = "Iter([\"/\", \"tmp\"])"; + let actual = format!("{:?}", iter); + assert_eq!(expected, actual); + + let _ = iter.next().unwrap(); + let expected = "Iter([\"tmp\"])"; + let actual = format!("{:?}", iter); + assert_eq!(expected, actual); + + let _ = iter.next().unwrap(); + let expected = "Iter([])"; + let actual = format!("{:?}", iter); + assert_eq!(expected, actual); + } } diff --git a/src/test/compile-fail/E0034.rs b/src/test/compile-fail/E0034.rs index 669bece0f7d17..136a74f7a8b74 100644 --- a/src/test/compile-fail/E0034.rs +++ b/src/test/compile-fail/E0034.rs @@ -18,9 +18,17 @@ trait Trait2 { fn foo(); } -impl Trait1 for Test { fn foo() {} } -impl Trait2 for Test { fn foo() {} } +impl Trait1 for Test { + fn foo() {} + //~^ NOTE candidate #1 is defined in an impl of the trait `Trait1` for the type `Test` +} + +impl Trait2 for Test { + fn foo() {} + //~^ NOTE candidate #2 is defined in an impl of the trait `Trait2` for the type `Test` +} fn main() { - Test::foo() //~ ERROR E0034 + Test::foo() //~ ERROR multiple applicable items in scope + //~| NOTE multiple `foo` found } diff --git a/src/test/compile-fail/E0520.rs b/src/test/compile-fail/E0520.rs index bb52843ee7835..0bb8faea62e1e 100644 --- a/src/test/compile-fail/E0520.rs +++ b/src/test/compile-fail/E0520.rs @@ -19,11 +19,15 @@ impl SpaceLlama for T { } impl SpaceLlama for T { +//~^ NOTE parent `impl` is here fn fly(&self) {} } impl SpaceLlama for i32 { - default fn fly(&self) {} //~ ERROR E0520 + default fn fly(&self) {} + //~^ ERROR E0520 + //~| NOTE cannot specialize default item `fly` + //~| NOTE either the parent `impl` or `fly` in the parent `impl` must be marked `default` } fn main() { diff --git a/src/test/compile-fail/E0528.rs b/src/test/compile-fail/E0528.rs new file mode 100644 index 0000000000000..27187bb5aba08 --- /dev/null +++ b/src/test/compile-fail/E0528.rs @@ -0,0 +1,19 @@ +// Copyright 2016 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. + +#![feature(slice_patterns)] + +fn main() { + let r = &[1, 2]; + match r { + &[a, b, c, rest..] => { //~ ERROR E0528 + } + } +} diff --git a/src/test/compile-fail/E0529.rs b/src/test/compile-fail/E0529.rs new file mode 100644 index 0000000000000..488fe7c7763ae --- /dev/null +++ b/src/test/compile-fail/E0529.rs @@ -0,0 +1,19 @@ +// Copyright 2016 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. + +#![feature(slice_patterns)] + +fn main() { + let r: f32 = 1.0; + match r { + [a, b] => { //~ ERROR E0529 + } + } +} diff --git a/src/test/compile-fail/E0530.rs b/src/test/compile-fail/E0530.rs new file mode 100644 index 0000000000000..4f674d0e67106 --- /dev/null +++ b/src/test/compile-fail/E0530.rs @@ -0,0 +1,18 @@ +// Copyright 2016 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. + +fn main() { + static TEST: i32 = 0; + + let r: (i32, i32) = (0, 0); + match r { + TEST => {} //~ ERROR E0530 + } +} diff --git a/src/test/compile-fail/E0534.rs b/src/test/compile-fail/E0534.rs new file mode 100644 index 0000000000000..8c036e6076d1d --- /dev/null +++ b/src/test/compile-fail/E0534.rs @@ -0,0 +1,14 @@ +// Copyright 2016 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. + +#[inline()] //~ ERROR E0534 +pub fn something() {} + +fn main() {} diff --git a/src/test/compile-fail/E0535.rs b/src/test/compile-fail/E0535.rs new file mode 100644 index 0000000000000..17558cc05c612 --- /dev/null +++ b/src/test/compile-fail/E0535.rs @@ -0,0 +1,14 @@ +// Copyright 2016 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. + +#[inline(unknown)] //~ ERROR E0535 +pub fn something() {} + +fn main() {} diff --git a/src/test/compile-fail/E0536.rs b/src/test/compile-fail/E0536.rs new file mode 100644 index 0000000000000..127bdc258d947 --- /dev/null +++ b/src/test/compile-fail/E0536.rs @@ -0,0 +1,14 @@ +// Copyright 2016 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. + +#[cfg(not())] //~ ERROR E0536 +pub fn something() {} + +pub fn main() {} diff --git a/src/test/compile-fail/E0537.rs b/src/test/compile-fail/E0537.rs new file mode 100644 index 0000000000000..497936fbcd28e --- /dev/null +++ b/src/test/compile-fail/E0537.rs @@ -0,0 +1,14 @@ +// Copyright 2016 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. + +#[cfg(unknown())] //~ ERROR E0537 +pub fn something() {} + +pub fn main() {} diff --git a/src/test/compile-fail/E0558.rs b/src/test/compile-fail/E0558.rs new file mode 100644 index 0000000000000..4ab0506a9c0cd --- /dev/null +++ b/src/test/compile-fail/E0558.rs @@ -0,0 +1,14 @@ +// Copyright 2016 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. + +#[export_name] //~ ERROR E0558 +pub fn something() {} + +fn main() {} diff --git a/src/test/compile-fail/E0559.rs b/src/test/compile-fail/E0559.rs new file mode 100644 index 0000000000000..80eeb203a850e --- /dev/null +++ b/src/test/compile-fail/E0559.rs @@ -0,0 +1,17 @@ +// Copyright 2016 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 Field { + Fool { x: u32 }, +} + +fn main() { + let s = Field::Fool { joke: 0 }; //~ ERROR E0559 +} diff --git a/src/test/compile-fail/E560.rs b/src/test/compile-fail/E560.rs new file mode 100644 index 0000000000000..ec9b86ee1f00f --- /dev/null +++ b/src/test/compile-fail/E560.rs @@ -0,0 +1,17 @@ +// Copyright 2016 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. + +struct Simba { + mother: u32, +} + +fn main() { + let s = Simba { mother: 1, father: 0 }; //~ ERROR E0560 +} diff --git a/src/test/compile-fail/issue-24204.rs b/src/test/compile-fail/issue-24204.rs new file mode 100644 index 0000000000000..2a012da0083bc --- /dev/null +++ b/src/test/compile-fail/issue-24204.rs @@ -0,0 +1,27 @@ +// Copyright 2016 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. + +#![allow(dead_code)] + +trait MultiDispatch { + type O; +} + +trait Trait: Sized { + type A: MultiDispatch; + type B; + + fn new(u: U) -> >::O where Self::A : MultiDispatch; +} + +fn test>(b: i32) -> T where T::A: MultiDispatch { T::new(b) } +//~^ ERROR type mismatch resolving + +fn main() {} diff --git a/src/test/run-pass/issue-14875.rs b/src/test/run-pass/issue-14875.rs new file mode 100644 index 0000000000000..ad19a9be76f88 --- /dev/null +++ b/src/test/run-pass/issue-14875.rs @@ -0,0 +1,43 @@ +// Copyright 2016 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. + +// Check that values are not leaked when a dtor panics (#14875) + +use std::panic::{self, UnwindSafe}; + +struct SetInnerOnDrop<'a>(&'a mut bool); + +impl<'a> UnwindSafe for SetInnerOnDrop<'a> {} + +impl<'a> Drop for SetInnerOnDrop<'a> { + fn drop(&mut self) { + *self.0 = true; + } +} + +struct PanicOnDrop; +impl Drop for PanicOnDrop { + fn drop(&mut self) { + panic!("test panic"); + } +} + + +fn main() { + let mut set_on_drop = false; + { + let set_inner_on_drop = SetInnerOnDrop(&mut set_on_drop); + let _ = panic::catch_unwind(|| { + let _set_inner_on_drop = set_inner_on_drop; + let _panic_on_drop = PanicOnDrop; + }); + } + assert!(set_on_drop); +} diff --git a/src/test/run-pass/issue-34053.rs b/src/test/run-pass/issue-34053.rs new file mode 100644 index 0000000000000..7f8a4941494a9 --- /dev/null +++ b/src/test/run-pass/issue-34053.rs @@ -0,0 +1,23 @@ +// Copyright 2016 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. + +#![feature(drop_types_in_const)] + +struct A(i32); + +impl Drop for A { + fn drop(&mut self) {} +} + +static FOO: A = A(123); + +fn main() { + println!("{}", &FOO.0); +} diff --git a/src/tools/rustbook/build.rs b/src/tools/rustbook/build.rs index 6014439fafcf9..09c2d2510e317 100644 --- a/src/tools/rustbook/build.rs +++ b/src/tools/rustbook/build.rs @@ -61,9 +61,9 @@ fn write_toc(book: &Book, current_page: &BookItem, out: &mut Write) -> io::Resul section, item.title)?; if !item.children.is_empty() { - writeln!(out, "
    ")?; + writeln!(out, "
      ")?; let _ = walk_items(&item.children[..], section, current_page, out); - writeln!(out, "
")?; + writeln!(out, "")?; } writeln!(out, "")?; @@ -71,9 +71,9 @@ fn write_toc(book: &Book, current_page: &BookItem, out: &mut Write) -> io::Resul } writeln!(out, "
")?; - writeln!(out, "
    ")?; + writeln!(out, "
      ")?; walk_items(&book.chapters[..], "", ¤t_page, out)?; - writeln!(out, "
")?; + writeln!(out, "")?; writeln!(out, "
")?; Ok(())