Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 11 pull requests #36145

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
50e0fbc
accumulate vector and assert for RangeFrom and RangeInclusive examples
matthew-piziak Aug 17, 2016
da566ae
Add test for #34053
apasel422 Aug 28, 2016
91bfa2c
Add test for #24204
apasel422 Aug 28, 2016
89f7e92
demonstrate `RHS != Self` use cases for `Add` and `Sub`
matthew-piziak Aug 18, 2016
10b8e0e
rustbook chapters/sections should be an ordered list.
frewsxcv Aug 30, 2016
c36ccf7
doc: make TcpListener example more simple
tshepang Aug 30, 2016
fb65fe9
Update compiler error 0034 to use new format.
athulappadan Aug 30, 2016
34e1817
add test for #14875
cristicbz Aug 30, 2016
77cd09a
Update E0520 to new error format
0xmohit Aug 30, 2016
150599d
Add E0530 error explanation
GuillaumeGomez Aug 30, 2016
37bf449
Add new error code tests
GuillaumeGomez Aug 30, 2016
f48d385
Implement `Debug` for `std::path::Components`.
frewsxcv Aug 29, 2016
e118d4c
Implement `Debug` for `std::path::Iter`.
frewsxcv Aug 30, 2016
40ef965
Rollup merge of #35758 - matthew-piziak:vec-assert-over-println-remai…
Aug 30, 2016
dcbcdc7
Rollup merge of #35793 - matthew-piziak:add-rhs-example, r=steveklabnik
Aug 30, 2016
7edaf55
Rollup merge of #36085 - apasel422:issue-34053, r=brson
Aug 30, 2016
3b6f713
Rollup merge of #36089 - apasel422:issue-24204, r=alexcrichton
Aug 30, 2016
1404423
Rollup merge of #36101 - frewsxcv:debug-path-components, r=alexcrichton
Aug 30, 2016
a5332d0
Rollup merge of #36130 - frewsxcv:patch-32, r=steveklabnik
Aug 30, 2016
e8369c6
Rollup merge of #36134 - tshepang:more-simple, r=steveklabnik
Aug 30, 2016
fb574b2
Rollup merge of #36135 - 0xmohit:pr/error-code-E0520, r=jonathandturner
Aug 30, 2016
a1a3474
Rollup merge of #36136 - athulappadan:E0034, r=jonathandturner
Aug 30, 2016
78fc44f
Rollup merge of #36140 - cristicbz:test-14875, r=nagisa
Aug 30, 2016
251697b
Rollup merge of #36141 - GuillaumeGomez:err_codes, r=jonathandturner
Aug 30, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 10 additions & 22 deletions src/libcore/iter/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,12 @@ impl<A: Step> ops::RangeFrom<A> {
/// # 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<A, Self> {
Expand All @@ -291,8 +289,10 @@ impl<A: Step> ops::Range<A> {
///
/// ```
/// #![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")]
Expand All @@ -315,20 +315,8 @@ impl<A: Step> ops::RangeInclusive<A> {
/// ```
/// #![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")]
Expand Down
12 changes: 12 additions & 0 deletions src/libcore/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Duration>`, 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<RHS=Self> {
Expand Down Expand Up @@ -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<Duration>`, 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<RHS=Self> {
Expand Down
38 changes: 36 additions & 2 deletions src/librustc_resolve/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!
}
```
"##,

}

Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 8 additions & 4 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
9 changes: 1 addition & 8 deletions src/libstd/net/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
///
Expand All @@ -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);
Expand Down
80 changes: 80 additions & 0 deletions src/libstd/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -818,6 +837,25 @@ impl<'a> AsRef<OsStr> 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")]
Expand Down Expand Up @@ -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);
}
}
14 changes: 11 additions & 3 deletions src/test/compile-fail/E0034.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 5 additions & 1 deletion src/test/compile-fail/E0520.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ impl<T> SpaceLlama for T {
}

impl<T: Clone> 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() {
Expand Down
19 changes: 19 additions & 0 deletions src/test/compile-fail/E0528.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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
}
}
}
19 changes: 19 additions & 0 deletions src/test/compile-fail/E0529.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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
}
}
}
18 changes: 18 additions & 0 deletions src/test/compile-fail/E0530.rs
Original file line number Diff line number Diff line change
@@ -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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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
}
}
Loading