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 15 pull requests #35525

Merged
merged 33 commits into from
Aug 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2683e84
Update HashMap docs regarding DoS protection
mgattozzi Aug 4, 2016
b79e15d
Update E0191 to the new error format
munyari Aug 5, 2016
2c563c6
Update E0023 to the new format
pcn Aug 7, 2016
7c1bb9a
Finish fixing the operator precedence tables
ubsan Aug 7, 2016
56eba5a
Add run-pass test for issue 33498
GuillaumeGomez Aug 7, 2016
98c6770
Fix formatting of module layout example
Aug 7, 2016
f07f093
Update E0214 to the new error format
munyari Aug 7, 2016
4a99a9d
E0248 Change in issue format
shyamsundarb-arch Aug 7, 2016
a848f11
E0248 Change in issue format
shyamsundarb-arch Aug 7, 2016
8b111a7
Updated E0087 to new format
Aug 7, 2016
e40df1c
Fix E0132 error display
GuillaumeGomez Aug 7, 2016
c6e17ec
Shrink E0205 span label to the trait being implemented
KiChjang Aug 8, 2016
18565c6
book: update example patterns to be more clear
cardoe Aug 7, 2016
a403ddf
Updated E0221 message to new format!
hank-der-hafenarbeiter Aug 8, 2016
6eb0218
updated unit test!
hank-der-hafenarbeiter Aug 8, 2016
ee38609
Updated E0026 to new format.
razielgn Aug 8, 2016
daf7c60
Update E0162 to the new format
krzysztofgarczynski Aug 8, 2016
75efffe
Rollup merge of #35371 - mgattozzi:master, r=steveklabnik
Aug 8, 2016
dd38172
Rollup merge of #35396 - munyari:e0191, r=jonathandturner
Aug 8, 2016
7979da0
Rollup merge of #35446 - pcn:update-E0023-to-new-format, r=jonathandt…
Aug 8, 2016
c479f02
Rollup merge of #35449 - poveda-ruiz:master, r=jonathandturner
Aug 8, 2016
936a6df
Rollup merge of #35452 - ubsan:precedence, r=steveklabnik
Aug 8, 2016
732e8f2
Rollup merge of #35458 - GuillaumeGomez:test_string_ICE, r=alexcrichton
Aug 8, 2016
39a26c5
Rollup merge of #35465 - cardoe:pattern-book-update, r=steveklabnik
Aug 8, 2016
3d2d5c4
Rollup merge of #35466 - xitep:master, r=steveklabnik
Aug 8, 2016
0e4e8e9
Rollup merge of #35470 - munyari:e0214, r=jonathandturner
Aug 8, 2016
bbbac59
Rollup merge of #35475 - shyaamsundhar:patch-1, r=jonathandturner
Aug 8, 2016
8a7edc0
Rollup merge of #35477 - GuillaumeGomez:fix_E0132, r=jonathandturner
Aug 8, 2016
a72891e
Rollup merge of #35484 - KiChjang:e0205-bonus, r=GuillaumeGomez
Aug 8, 2016
0a3766a
Rollup merge of #35504 - razielgn:updated-e0026-to-new-format, r=jona…
Aug 8, 2016
7db3f86
Rollup merge of #35507 - hank-der-hafenarbeiter:master, r=jonathandtu…
Aug 8, 2016
f835b38
Rollup merge of #35524 - garekkream:update-E0162-new-error-format, r=…
Aug 8, 2016
fb1c6ac
Update E0087.rs
Aug 9, 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
1 change: 1 addition & 0 deletions src/doc/book/crates-and-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ As an example, let’s make a *phrases* crate, which will give us various phrase
in different languages. To keep things simple, we’ll stick to ‘greetings’ and
‘farewells’ as two kinds of phrases, and use English and Japanese (日本語) as
two languages for those phrases to be in. We’ll use this module layout:

```text
+-----------+
+---| greetings |
Expand Down
12 changes: 6 additions & 6 deletions src/doc/book/patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ struct Point {
y: i32,
}

let origin = Point { x: 0, y: 0 };
let point = Point { x: 2, y: 3 };

match origin {
match point {
Point { x, .. } => println!("x is {}", x),
}
```

This prints `x is 0`.
This prints `x is 2`.

You can do this kind of match on any member, not only the first:

Expand All @@ -126,14 +126,14 @@ struct Point {
y: i32,
}

let origin = Point { x: 0, y: 0 };
let point = Point { x: 2, y: 3 };

match origin {
match point {
Point { y, .. } => println!("y is {}", y),
}
```

This prints `y is 0`.
This prints `y is 3`.

This ‘destructuring’ behavior works on any compound data type, like
[tuples][tuples] or [enums][enums].
Expand Down
3 changes: 2 additions & 1 deletion src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -3039,7 +3039,7 @@ The precedence of Rust binary operators is ordered as follows, going from
strong to weak:

```{.text .precedence}
as
as :
* / %
+ -
<< >>
Expand All @@ -3050,6 +3050,7 @@ as
&&
||
.. ...
<-
=
```

Expand Down
5 changes: 4 additions & 1 deletion src/librustc_const_eval/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,10 @@ fn check_arms(cx: &MatchCheckCtxt,
let &(ref first_arm_pats, _) = &arms[0];
let first_pat = &first_arm_pats[0];
let span = first_pat.span;
span_err!(cx.tcx.sess, span, E0162, "irrefutable if-let pattern");
struct_span_err!(cx.tcx.sess, span, E0162,
"irrefutable if-let pattern")
.span_label(span, &format!("irrefutable pattern"))
.emit();
printed_if_let_err = true;
}
},
Expand Down
32 changes: 21 additions & 11 deletions src/librustc_typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
self.convert_angle_bracketed_parameters(rscope, span, decl_generics, data)
}
hir::ParenthesizedParameters(..) => {
span_err!(tcx.sess, span, E0214,
"parenthesized parameters may only be used with a trait");
struct_span_err!(tcx.sess, span, E0214,
"parenthesized parameters may only be used with a trait")
.span_label(span, &format!("only traits may use parentheses"))
.emit();

let ty_param_defs = decl_generics.types.get_slice(TypeSpace);
(Substs::empty(),
ty_param_defs.iter().map(|_| tcx.types.err).collect(),
Expand Down Expand Up @@ -1201,10 +1204,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
}

for (trait_def_id, name) in associated_types {
span_err!(tcx.sess, span, E0191,
struct_span_err!(tcx.sess, span, E0191,
"the value of the associated type `{}` (from the trait `{}`) must be specified",
name,
tcx.item_path_str(trait_def_id));
tcx.item_path_str(trait_def_id))
.span_label(span, &format!(
"missing associated type `{}` value", name))
.emit();
}

tcx.mk_trait(object.principal, object.bounds)
Expand Down Expand Up @@ -1281,10 +1287,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
}

if bounds.len() > 1 {
let mut err = struct_span_err!(self.tcx().sess, span, E0221,
"ambiguous associated type `{}` in bounds of `{}`",
assoc_name,
ty_param_name);
let mut err = struct_span_err!(
self.tcx().sess, span, E0221,
"ambiguous associated type `{}` in bounds of `{}`",
assoc_name,
ty_param_name);
err.span_label(span, &format!("ambiguous associated type `{}`", assoc_name));

for bound in &bounds {
span_note!(&mut err, span,
Expand Down Expand Up @@ -1584,9 +1592,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
return self.tcx().types.err;
}
_ => {
span_err!(tcx.sess, span, E0248,
"found value `{}` used as a type",
tcx.item_path_str(def.def_id()));
struct_span_err!(tcx.sess, span, E0248,
"found value `{}` used as a type",
tcx.item_path_str(def.def_id()))
.span_label(span, &format!("value used as a type"))
.emit();
return self.tcx().types.err;
}
}
Expand Down
35 changes: 27 additions & 8 deletions src/librustc_typeck/check/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
self.check_pat(&subpat, field_ty);
}
} else {
span_err!(tcx.sess, pat.span, E0023,
"this pattern has {} field{s}, but the corresponding {} has {} field{s}",
subpats.len(), def.kind_name(), variant.fields.len(),
s = if variant.fields.len() == 1 {""} else {"s"});
let subpats_ending = if subpats.len() == 1 {
""
} else {
"s"
};
let fields_ending = if variant.fields.len() == 1 {
""
} else {
"s"
};
struct_span_err!(tcx.sess, pat.span, E0023,
"this pattern has {} field{}, but the corresponding {} has {} field{}",
subpats.len(), subpats_ending, def.kind_name(),
variant.fields.len(), fields_ending)
.span_label(pat.span, &format!("expected {} field{}, found {}",
variant.fields.len(), fields_ending, subpats.len()))
.emit();
on_error();
}
}
Expand Down Expand Up @@ -682,10 +695,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
field_map.get(&field.name)
.map(|f| self.field_ty(span, f, substs))
.unwrap_or_else(|| {
span_err!(tcx.sess, span, E0026,
"struct `{}` does not have a field named `{}`",
tcx.item_path_str(variant.did),
field.name);
struct_span_err!(tcx.sess, span, E0026,
"struct `{}` does not have a field named `{}`",
tcx.item_path_str(variant.did),
field.name)
.span_label(span,
&format!("struct `{}` does not have field `{}`",
tcx.item_path_str(variant.did),
field.name))
.emit();

tcx.types.err
})
}
Expand Down
19 changes: 11 additions & 8 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4372,14 +4372,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
if i < type_count {
substs.types.push(space, t);
} else if i == type_count {
span_err!(self.tcx.sess, typ.span, E0087,
"too many type parameters provided: \
expected at most {} parameter{}, \
found {} parameter{}",
type_count,
if type_count == 1 {""} else {"s"},
data.types.len(),
if data.types.len() == 1 {""} else {"s"});
struct_span_err!(self.tcx.sess, typ.span, E0087,
"too many type parameters provided: \
expected at most {} parameter{}, \
found {} parameter{}",
type_count,
if type_count == 1 {""} else {"s"},
data.types.len(),
if data.types.len() == 1 {""} else {"s"})
.span_label(typ.span , &format!("expected {} parameter{}",
type_count,
if type_count == 1 {""} else {"s"})).emit();
substs.types.truncate(space, 0);
break;
}
Expand Down
19 changes: 12 additions & 7 deletions src/librustc_typeck/coherence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,18 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {

}
Err(CopyImplementationError::InfrigingVariant(name)) => {
struct_span_err!(tcx.sess, span, E0205,
"the trait `Copy` may not be \
implemented for this type")
.span_label(span, &format!("variant \
`{}` does not implement `Copy`",
name))
.emit()
let item = tcx.map.expect_item(impl_node_id);
let span = if let ItemImpl(_, _, _, Some(ref tr), _, _) = item.node {
tr.path.span
} else {
span
};

struct_span_err!(tcx.sess, span, E0205,
"the trait `Copy` may not be implemented for this type")
.span_label(span, &format!("variant `{}` does not implement `Copy`",
name))
.emit()
}
Err(CopyImplementationError::NotAnAdt) => {
let item = tcx.map.expect_item(impl_node_id);
Expand Down
5 changes: 3 additions & 2 deletions src/librustc_typeck/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,10 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
match it.node {
hir::ItemFn(_,_,_,_,ref ps,_)
if ps.is_parameterized() => {
struct_span_err!(tcx.sess, start_span, E0132,
let sp = if let Some(sp) = ps.span() { sp } else { start_span };
struct_span_err!(tcx.sess, sp, E0132,
"start function is not allowed to have type parameters")
.span_label(ps.span().unwrap(),
.span_label(sp,
&format!("start function cannot have type parameters"))
.emit();
return;
Expand Down
13 changes: 6 additions & 7 deletions src/libstd/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,12 @@ fn test_resize_policy() {
/// A hash map implementation which uses linear probing with Robin
/// Hood bucket stealing.
///
/// The hashes are all keyed by the thread-local random number generator
/// on creation by default. This means that the ordering of the keys is
/// randomized, but makes the tables more resistant to
/// denial-of-service attacks (Hash DoS). No guarantees are made to the
/// quality of the random data. The implementation uses the best available
/// random data from your platform at the time of creation. This behavior
/// can be overridden with one of the constructors.
/// By default, HashMap uses a somewhat slow hashing algorithm which can provide resistance
/// to DoS attacks. Rust makes a best attempt at acquiring random numbers without IO
/// blocking from your system. Because of this HashMap is not guaranteed to provide
/// DoS resistance since the numbers generated might not be truly random. If you do
/// require this behavior you can create your own hashing function using
/// [BuildHasherDefault](../hash/struct.BuildHasherDefault.html).
///
/// It is required that the keys implement the `Eq` and `Hash` traits, although
/// this can frequently be achieved by using `#[derive(PartialEq, Eq, Hash)]`.
Expand Down
5 changes: 5 additions & 0 deletions src/test/compile-fail/E0023.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ enum Fruit {
Pear(u32),
}


fn main() {
let x = Fruit::Apple(String::new(), String::new());
match x {
Fruit::Apple(a) => {}, //~ ERROR E0023
//~| NOTE expected 2 fields, found 1
Fruit::Apple(a, b, c) => {}, //~ ERROR E0023
//~| NOTE expected 2 fields, found 3
Fruit::Pear(1, 2) => {}, //~ ERROR E0023
//~| NOTE expected 1 field, found 2
}
}
4 changes: 3 additions & 1 deletion src/test/compile-fail/E0026.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ struct Thing {
fn main() {
let thing = Thing { x: 0, y: 0 };
match thing {
Thing { x, y, z } => {} //~ ERROR E0026
Thing { x, y, z } => {}
//~^ ERROR struct `Thing` does not have a field named `z` [E0026]
//~| NOTE struct `Thing` does not have field `z`
}
}
1 change: 1 addition & 0 deletions src/test/compile-fail/E0087.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ fn foo<T>() {}

fn main() {
foo::<f64, bool>(); //~ ERROR E0087
//~^ NOTE expected
}
1 change: 1 addition & 0 deletions src/test/compile-fail/E0162.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct Irrefutable(i32);
fn main() {
let irr = Irrefutable(0);
if let Irrefutable(x) = irr { //~ ERROR E0162
//~| NOTE irrefutable pattern
println!("{}", x);
}
}
1 change: 1 addition & 0 deletions src/test/compile-fail/E0191.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ trait Trait {
}

type Foo = Trait; //~ ERROR E0191
//~| NOTE missing associated type `Bar` value

fn main() {
}
4 changes: 2 additions & 2 deletions src/test/compile-fail/E0205.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ enum Foo {
}

impl Copy for Foo { }
//~^ ERROR E0205
//~^ ERROR the trait `Copy` may not be implemented for this type
//~| NOTE variant `Bar` does not implement `Copy`

#[derive(Copy)]
//~^ ERROR E0205
//~^ ERROR the trait `Copy` may not be implemented for this type
//~| NOTE variant `Bar` does not implement `Copy`
//~| NOTE in this expansion of #[derive(Copy)]
enum Foo2<'a> {
Expand Down
4 changes: 3 additions & 1 deletion src/test/compile-fail/E0214.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@
// except according to those terms.

fn main() {
let v: Vec(&str) = vec!["foo"]; //~ ERROR E0214
let v: Vec(&str) = vec!["foo"];
//~^ ERROR E0214
//~| NOTE only traits may use parentheses
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/E0248.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ enum Foo {
}

fn do_something(x: Foo::Bar) { } //~ ERROR E0248

//~| NOTE value used as a type
fn main() {
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,23 @@ pub trait BoxCar : Box + Vehicle {

fn dent<C:BoxCar>(c: C, color: C::Color) {
//~^ ERROR ambiguous associated type `Color` in bounds of `C`
//~| NOTE ambiguous associated type `Color`
//~| NOTE could derive from `Vehicle`
//~| NOTE could derive from `Box`
}

fn dent_object<COLOR>(c: BoxCar<Color=COLOR>) {
//~^ ERROR ambiguous associated type
//~| ERROR the value of the associated type `Color` (from the trait `Vehicle`) must be specified
//~| NOTE ambiguous associated type `Color`
//~| NOTE could derive from `Vehicle`
//~| NOTE could derive from `Box`
//~| NOTE missing associated type `Color` value
}

fn paint<C:BoxCar>(c: C, d: C::Color) {
//~^ ERROR ambiguous associated type `Color` in bounds of `C`
//~| NOTE ambiguous associated type `Color`
//~| NOTE could derive from `Vehicle`
//~| NOTE could derive from `Box`
}
Expand Down
19 changes: 19 additions & 0 deletions src/test/run-pass/issue-33498.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.

pub fn main() {
let x = (0, 2);

match x {
(0, ref y) => {}
(y, 0) => {}
_ => (),
}
}