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 14 pull requests #36158

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 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
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
bdfcd78
Update E0318 to new format
acrrd Aug 28, 2016
8ca9fa1
add evocative examples for `BitOr` and `BitXor`
matthew-piziak Aug 23, 2016
507fe14
update E0265 to new format
mikhail-m1 Aug 30, 2016
d3a6ea5
Update compiler error E0076 to use new error format
abhiQmar Aug 27, 2016
268b3f5
Implement `Debug` for `std::path::Iter`.
frewsxcv Aug 30, 2016
56edae2
Fix typo in PartialOrd docs
fanzier Aug 31, 2016
69f0cee
Bonus fix for #35280. Part of #35233. Fixes #36057. Adding expanded n…
leikahing Aug 30, 2016
25067fc
Rollup merge of #35758 - matthew-piziak:vec-assert-over-println-remai…
Aug 31, 2016
f749281
Rollup merge of #35926 - matthew-piziak:bit-or-xor-examples, r=Guilla…
Aug 31, 2016
38a4007
Rollup merge of #36050 - abhiQmar:e0076-formatting, r=jonathandturner
Aug 31, 2016
ab85c10
Rollup merge of #36079 - acrrd:new_format_E0318, r=GuillaumeGomez
Aug 31, 2016
2cffabd
Rollup merge of #36085 - apasel422:issue-34053, r=brson
Aug 31, 2016
50deebc
Rollup merge of #36089 - apasel422:issue-24204, r=alexcrichton
Aug 31, 2016
fc80e7d
Rollup merge of #36101 - frewsxcv:debug-path-components, r=alexcrichton
Aug 31, 2016
9d2179c
Rollup merge of #36130 - frewsxcv:patch-32, r=steveklabnik
Aug 31, 2016
f7420d4
Rollup merge of #36134 - tshepang:more-simple, r=steveklabnik
Aug 31, 2016
7b40ad2
Rollup merge of #36135 - 0xmohit:pr/error-code-E0520, r=jonathandturner
Aug 31, 2016
5eb53d9
Rollup merge of #36136 - athulappadan:E0034, r=jonathandturner
Aug 31, 2016
d54d398
Rollup merge of #36140 - cristicbz:test-14875, r=nagisa
Aug 31, 2016
5123b38
Rollup merge of #36141 - GuillaumeGomez:err_codes, r=jonathandturner
Aug 31, 2016
441cb87
Rollup merge of #36147 - mikhail-m1:master, r=jonathandturner
Aug 31, 2016
e32adbb
Rollup merge of #36148 - birryree:E0194_bonus_format, r=jonathandturner
Aug 31, 2016
3f112a7
Rollup merge of #36165 - fanzier:fix-typo, r=GuillaumeGomez
Aug 31, 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
2 changes: 1 addition & 1 deletion src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ impl PartialOrd for Ordering {
/// }
/// ```
///
/// You may also find it useful to use `partial_cmp()` on your type`s fields. Here
/// You may also find it useful to use `partial_cmp()` on your type's fields. Here
/// is an example of `Person` types who have a floating-point `height` field that
/// is the only field to be used for sorting:
///
Expand Down
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
99 changes: 81 additions & 18 deletions src/libcore/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,25 +948,55 @@ bitand_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
///
/// # Examples
///
/// A trivial implementation of `BitOr`. When `Foo | Foo` happens, it ends up
/// calling `bitor`, and therefore, `main` prints `Bitwise Or-ing!`.
/// In this example, the `|` operator is lifted to a trivial `Scalar` type.
///
/// ```
/// use std::ops::BitOr;
///
/// struct Foo;
/// #[derive(Debug, PartialEq)]
/// struct Scalar(bool);
///
/// impl BitOr for Foo {
/// type Output = Foo;
/// impl BitOr for Scalar {
/// type Output = Self;
///
/// fn bitor(self, _rhs: Foo) -> Foo {
/// println!("Bitwise Or-ing!");
/// self
/// // rhs is the "right-hand side" of the expression `a | b`
/// fn bitor(self, rhs: Self) -> Self {
/// Scalar(self.0 | rhs.0)
/// }
/// }
///
/// fn main() {
/// assert_eq!(Scalar(true) | Scalar(true), Scalar(true));
/// assert_eq!(Scalar(true) | Scalar(false), Scalar(true));
/// assert_eq!(Scalar(false) | Scalar(true), Scalar(true));
/// assert_eq!(Scalar(false) | Scalar(false), Scalar(false));
/// }
/// ```
///
/// In this example, the `BitOr` trait is implemented for a `BooleanVector`
/// struct.
///
/// ```
/// use std::ops::BitOr;
///
/// #[derive(Debug, PartialEq)]
/// struct BooleanVector(Vec<bool>);
///
/// impl BitOr for BooleanVector {
/// type Output = Self;
///
/// fn bitor(self, BooleanVector(rhs): Self) -> Self {
/// let BooleanVector(lhs) = self;
/// assert_eq!(lhs.len(), rhs.len());
/// BooleanVector(lhs.iter().zip(rhs.iter()).map(|(x, y)| *x || *y).collect())
/// }
/// }
///
/// fn main() {
/// Foo | Foo;
/// let bv1 = BooleanVector(vec![true, true, false, false]);
/// let bv2 = BooleanVector(vec![true, false, true, false]);
/// let expected = BooleanVector(vec![true, true, true, false]);
/// assert_eq!(bv1 | bv2, expected);
/// }
/// ```
#[lang = "bitor"]
Expand Down Expand Up @@ -1001,25 +1031,58 @@ bitor_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
///
/// # Examples
///
/// A trivial implementation of `BitXor`. When `Foo ^ Foo` happens, it ends up
/// calling `bitxor`, and therefore, `main` prints `Bitwise Xor-ing!`.
/// In this example, the `^` operator is lifted to a trivial `Scalar` type.
///
/// ```
/// use std::ops::BitXor;
///
/// struct Foo;
/// #[derive(Debug, PartialEq)]
/// struct Scalar(bool);
///
/// impl BitXor for Foo {
/// type Output = Foo;
/// impl BitXor for Scalar {
/// type Output = Self;
///
/// fn bitxor(self, _rhs: Foo) -> Foo {
/// println!("Bitwise Xor-ing!");
/// self
/// // rhs is the "right-hand side" of the expression `a ^ b`
/// fn bitxor(self, rhs: Self) -> Self {
/// Scalar(self.0 ^ rhs.0)
/// }
/// }
///
/// fn main() {
/// assert_eq!(Scalar(true) ^ Scalar(true), Scalar(false));
/// assert_eq!(Scalar(true) ^ Scalar(false), Scalar(true));
/// assert_eq!(Scalar(false) ^ Scalar(true), Scalar(true));
/// assert_eq!(Scalar(false) ^ Scalar(false), Scalar(false));
/// }
/// ```
///
/// In this example, the `BitXor` trait is implemented for a `BooleanVector`
/// struct.
///
/// ```
/// use std::ops::BitXor;
///
/// #[derive(Debug, PartialEq)]
/// struct BooleanVector(Vec<bool>);
///
/// impl BitXor for BooleanVector {
/// type Output = Self;
///
/// fn bitxor(self, BooleanVector(rhs): Self) -> Self {
/// let BooleanVector(lhs) = self;
/// assert_eq!(lhs.len(), rhs.len());
/// BooleanVector(lhs.iter()
/// .zip(rhs.iter())
/// .map(|(x, y)| (*x || *y) && !(*x && *y))
/// .collect())
/// }
/// }
///
/// fn main() {
/// Foo ^ Foo;
/// let bv1 = BooleanVector(vec![true, true, false, false]);
/// let bv2 = BooleanVector(vec![true, false, true, false]);
/// let expected = BooleanVector(vec![false, true, true, false]);
/// assert_eq!(bv1 ^ bv2, expected);
/// }
/// ```
#[lang = "bitxor"]
Expand Down
14 changes: 8 additions & 6 deletions src/librustc_passes/static_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
idstack: Vec::new(),
}
}
fn with_item_id_pushed<F>(&mut self, id: ast::NodeId, f: F)
fn with_item_id_pushed<F>(&mut self, id: ast::NodeId, f: F, span: Span)
where F: Fn(&mut Self)
{
if self.idstack.iter().any(|&x| x == id) {
Expand All @@ -150,7 +150,9 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {
"recursive static");
}
} else {
span_err!(self.sess, *self.root_span, E0265, "recursive constant");
struct_span_err!(self.sess, span, E0265, "recursive constant")
.span_label(span, &format!("recursion not allowed in constant"))
.emit();
}
return;
}
Expand Down Expand Up @@ -203,7 +205,7 @@ impl<'a, 'ast: 'a> CheckItemRecursionVisitor<'a, 'ast> {

impl<'a, 'ast: 'a> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'ast> {
fn visit_item(&mut self, it: &'ast hir::Item) {
self.with_item_id_pushed(it.id, |v| intravisit::walk_item(v, it));
self.with_item_id_pushed(it.id, |v| intravisit::walk_item(v, it), it.span);
}

fn visit_enum_def(&mut self,
Expand Down Expand Up @@ -233,16 +235,16 @@ impl<'a, 'ast: 'a> Visitor<'ast> for CheckItemRecursionVisitor<'a, 'ast> {
// If `maybe_expr` is `None`, that's because no discriminant is
// specified that affects this variant. Thus, no risk of recursion.
if let Some(expr) = maybe_expr {
self.with_item_id_pushed(expr.id, |v| intravisit::walk_expr(v, expr));
self.with_item_id_pushed(expr.id, |v| intravisit::walk_expr(v, expr), expr.span);
}
}

fn visit_trait_item(&mut self, ti: &'ast hir::TraitItem) {
self.with_item_id_pushed(ti.id, |v| intravisit::walk_trait_item(v, ti));
self.with_item_id_pushed(ti.id, |v| intravisit::walk_trait_item(v, ti), ti.span);
}

fn visit_impl_item(&mut self, ii: &'ast hir::ImplItem) {
self.with_item_id_pushed(ii.id, |v| intravisit::walk_impl_item(v, ii));
self.with_item_id_pushed(ii.id, |v| intravisit::walk_impl_item(v, ii), ii.span);
}

fn visit_expr(&mut self, e: &'ast hir::Expr) {
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
16 changes: 11 additions & 5 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 Expand Up @@ -1204,7 +1208,9 @@ pub fn check_simd<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, id: ast::Node
}
let e = fields[0].ty(tcx, substs);
if !fields.iter().all(|f| f.ty(tcx, substs) == e) {
span_err!(tcx.sess, sp, E0076, "SIMD vector should be homogeneous");
struct_span_err!(tcx.sess, sp, E0076, "SIMD vector should be homogeneous")
.span_label(sp, &format!("SIMD elements must have the same type"))
.emit();
return;
}
match e.sty {
Expand Down
28 changes: 22 additions & 6 deletions src/librustc_typeck/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use middle::region::{CodeExtent};
use rustc::infer::TypeOrigin;
use rustc::traits;
use rustc::ty::{self, Ty, TyCtxt};
use rustc::util::nodemap::FnvHashSet;
use rustc::util::nodemap::{FnvHashSet, FnvHashMap};

use syntax::ast;
use syntax_pos::Span;
Expand Down Expand Up @@ -519,11 +519,26 @@ impl<'ccx, 'gcx> CheckTypeWellFormedVisitor<'ccx, 'gcx> {

fn reject_shadowing_type_parameters(tcx: TyCtxt, span: Span, generics: &ty::Generics) {
let parent = tcx.lookup_generics(generics.parent.unwrap());
let impl_params: FnvHashSet<_> = parent.types.iter().map(|tp| tp.name).collect();
let impl_params: FnvHashMap<_, _> = parent.types
.iter()
.map(|tp| (tp.name, tp.def_id))
.collect();

for method_param in &generics.types {
if impl_params.contains(&method_param.name) {
error_194(tcx, span, method_param.name);
if impl_params.contains_key(&method_param.name) {
// Tighten up the span to focus on only the shadowing type
let shadow_node_id = tcx.map.as_local_node_id(method_param.def_id).unwrap();
let type_span = match tcx.map.opt_span(shadow_node_id) {
Some(osp) => osp,
None => span
};

// The expectation here is that the original trait declaration is
// local so it should be okay to just unwrap everything.
let trait_def_id = impl_params.get(&method_param.name).unwrap();
let trait_node_id = tcx.map.as_local_node_id(*trait_def_id).unwrap();
let trait_decl_span = tcx.map.opt_span(trait_node_id).unwrap();
error_194(tcx, type_span, trait_decl_span, method_param.name);
}
}
}
Expand Down Expand Up @@ -630,10 +645,11 @@ fn error_392<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, span: Span, param_name: ast::N
err
}

fn error_194(tcx: TyCtxt, span: Span, name: ast::Name) {
fn error_194(tcx: TyCtxt, span: Span, trait_decl_span: Span, name: ast::Name) {
struct_span_err!(tcx.sess, span, E0194,
"type parameter `{}` shadows another type parameter of the same name",
name)
.span_label(span, &format!("`{}` shadows another type parameter", name))
.span_label(span, &format!("shadows another type parameter"))
.span_label(trait_decl_span, &format!("first `{}` declared here", name))
.emit();
}
Loading