Skip to content

Commit 1f2ae38

Browse files
authored
Auto merge of #35525 - jonathandturner:rollup, r=jonathandturner
Rollup of 15 pull requests - Successful merges: #35371, #35396, #35446, #35449, #35452, #35458, #35465, #35466, #35470, #35475, #35477, #35484, #35504, #35507, #35524 - Failed merges: #35395, #35415
2 parents ae77410 + fb1c6ac commit 1f2ae38

File tree

20 files changed

+133
-56
lines changed

20 files changed

+133
-56
lines changed

src/doc/book/crates-and-modules.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ As an example, let’s make a *phrases* crate, which will give us various phrase
2222
in different languages. To keep things simple, we’ll stick to ‘greetings’ and
2323
‘farewells’ as two kinds of phrases, and use English and Japanese (日本語) as
2424
two languages for those phrases to be in. We’ll use this module layout:
25+
2526
```text
2627
+-----------+
2728
+---| greetings |

src/doc/book/patterns.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@ struct Point {
109109
y: i32,
110110
}
111111

112-
let origin = Point { x: 0, y: 0 };
112+
let point = Point { x: 2, y: 3 };
113113

114-
match origin {
114+
match point {
115115
Point { x, .. } => println!("x is {}", x),
116116
}
117117
```
118118

119-
This prints `x is 0`.
119+
This prints `x is 2`.
120120

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

@@ -126,14 +126,14 @@ struct Point {
126126
y: i32,
127127
}
128128

129-
let origin = Point { x: 0, y: 0 };
129+
let point = Point { x: 2, y: 3 };
130130

131-
match origin {
131+
match point {
132132
Point { y, .. } => println!("y is {}", y),
133133
}
134134
```
135135

136-
This prints `y is 0`.
136+
This prints `y is 3`.
137137

138138
This ‘destructuring’ behavior works on any compound data type, like
139139
[tuples][tuples] or [enums][enums].

src/doc/reference.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -3039,7 +3039,7 @@ The precedence of Rust binary operators is ordered as follows, going from
30393039
strong to weak:
30403040

30413041
```{.text .precedence}
3042-
as
3042+
as :
30433043
* / %
30443044
+ -
30453045
<< >>
@@ -3050,6 +3050,7 @@ as
30503050
&&
30513051
||
30523052
.. ...
3053+
<-
30533054
=
30543055
```
30553056

src/librustc_const_eval/check_match.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,10 @@ fn check_arms(cx: &MatchCheckCtxt,
316316
let &(ref first_arm_pats, _) = &arms[0];
317317
let first_pat = &first_arm_pats[0];
318318
let span = first_pat.span;
319-
span_err!(cx.tcx.sess, span, E0162, "irrefutable if-let pattern");
319+
struct_span_err!(cx.tcx.sess, span, E0162,
320+
"irrefutable if-let pattern")
321+
.span_label(span, &format!("irrefutable pattern"))
322+
.emit();
320323
printed_if_let_err = true;
321324
}
322325
},

src/librustc_typeck/astconv.rs

+21-11
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
360360
self.convert_angle_bracketed_parameters(rscope, span, decl_generics, data)
361361
}
362362
hir::ParenthesizedParameters(..) => {
363-
span_err!(tcx.sess, span, E0214,
364-
"parenthesized parameters may only be used with a trait");
363+
struct_span_err!(tcx.sess, span, E0214,
364+
"parenthesized parameters may only be used with a trait")
365+
.span_label(span, &format!("only traits may use parentheses"))
366+
.emit();
367+
365368
let ty_param_defs = decl_generics.types.get_slice(TypeSpace);
366369
(Substs::empty(),
367370
ty_param_defs.iter().map(|_| tcx.types.err).collect(),
@@ -1201,10 +1204,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
12011204
}
12021205

12031206
for (trait_def_id, name) in associated_types {
1204-
span_err!(tcx.sess, span, E0191,
1207+
struct_span_err!(tcx.sess, span, E0191,
12051208
"the value of the associated type `{}` (from the trait `{}`) must be specified",
12061209
name,
1207-
tcx.item_path_str(trait_def_id));
1210+
tcx.item_path_str(trait_def_id))
1211+
.span_label(span, &format!(
1212+
"missing associated type `{}` value", name))
1213+
.emit();
12081214
}
12091215

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

12831289
if bounds.len() > 1 {
1284-
let mut err = struct_span_err!(self.tcx().sess, span, E0221,
1285-
"ambiguous associated type `{}` in bounds of `{}`",
1286-
assoc_name,
1287-
ty_param_name);
1290+
let mut err = struct_span_err!(
1291+
self.tcx().sess, span, E0221,
1292+
"ambiguous associated type `{}` in bounds of `{}`",
1293+
assoc_name,
1294+
ty_param_name);
1295+
err.span_label(span, &format!("ambiguous associated type `{}`", assoc_name));
12881296

12891297
for bound in &bounds {
12901298
span_note!(&mut err, span,
@@ -1584,9 +1592,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
15841592
return self.tcx().types.err;
15851593
}
15861594
_ => {
1587-
span_err!(tcx.sess, span, E0248,
1588-
"found value `{}` used as a type",
1589-
tcx.item_path_str(def.def_id()));
1595+
struct_span_err!(tcx.sess, span, E0248,
1596+
"found value `{}` used as a type",
1597+
tcx.item_path_str(def.def_id()))
1598+
.span_label(span, &format!("value used as a type"))
1599+
.emit();
15901600
return self.tcx().types.err;
15911601
}
15921602
}

src/librustc_typeck/check/_match.rs

+27-8
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,23 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
633633
self.check_pat(&subpat, field_ty);
634634
}
635635
} else {
636-
span_err!(tcx.sess, pat.span, E0023,
637-
"this pattern has {} field{s}, but the corresponding {} has {} field{s}",
638-
subpats.len(), def.kind_name(), variant.fields.len(),
639-
s = if variant.fields.len() == 1 {""} else {"s"});
636+
let subpats_ending = if subpats.len() == 1 {
637+
""
638+
} else {
639+
"s"
640+
};
641+
let fields_ending = if variant.fields.len() == 1 {
642+
""
643+
} else {
644+
"s"
645+
};
646+
struct_span_err!(tcx.sess, pat.span, E0023,
647+
"this pattern has {} field{}, but the corresponding {} has {} field{}",
648+
subpats.len(), subpats_ending, def.kind_name(),
649+
variant.fields.len(), fields_ending)
650+
.span_label(pat.span, &format!("expected {} field{}, found {}",
651+
variant.fields.len(), fields_ending, subpats.len()))
652+
.emit();
640653
on_error();
641654
}
642655
}
@@ -682,10 +695,16 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
682695
field_map.get(&field.name)
683696
.map(|f| self.field_ty(span, f, substs))
684697
.unwrap_or_else(|| {
685-
span_err!(tcx.sess, span, E0026,
686-
"struct `{}` does not have a field named `{}`",
687-
tcx.item_path_str(variant.did),
688-
field.name);
698+
struct_span_err!(tcx.sess, span, E0026,
699+
"struct `{}` does not have a field named `{}`",
700+
tcx.item_path_str(variant.did),
701+
field.name)
702+
.span_label(span,
703+
&format!("struct `{}` does not have field `{}`",
704+
tcx.item_path_str(variant.did),
705+
field.name))
706+
.emit();
707+
689708
tcx.types.err
690709
})
691710
}

src/librustc_typeck/check/mod.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -4372,14 +4372,17 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
43724372
if i < type_count {
43734373
substs.types.push(space, t);
43744374
} else if i == type_count {
4375-
span_err!(self.tcx.sess, typ.span, E0087,
4376-
"too many type parameters provided: \
4377-
expected at most {} parameter{}, \
4378-
found {} parameter{}",
4379-
type_count,
4380-
if type_count == 1 {""} else {"s"},
4381-
data.types.len(),
4382-
if data.types.len() == 1 {""} else {"s"});
4375+
struct_span_err!(self.tcx.sess, typ.span, E0087,
4376+
"too many type parameters provided: \
4377+
expected at most {} parameter{}, \
4378+
found {} parameter{}",
4379+
type_count,
4380+
if type_count == 1 {""} else {"s"},
4381+
data.types.len(),
4382+
if data.types.len() == 1 {""} else {"s"})
4383+
.span_label(typ.span , &format!("expected {} parameter{}",
4384+
type_count,
4385+
if type_count == 1 {""} else {"s"})).emit();
43834386
substs.types.truncate(space, 0);
43844387
break;
43854388
}

src/librustc_typeck/coherence/mod.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -321,13 +321,18 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
321321

322322
}
323323
Err(CopyImplementationError::InfrigingVariant(name)) => {
324-
struct_span_err!(tcx.sess, span, E0205,
325-
"the trait `Copy` may not be \
326-
implemented for this type")
327-
.span_label(span, &format!("variant \
328-
`{}` does not implement `Copy`",
329-
name))
330-
.emit()
324+
let item = tcx.map.expect_item(impl_node_id);
325+
let span = if let ItemImpl(_, _, _, Some(ref tr), _, _) = item.node {
326+
tr.path.span
327+
} else {
328+
span
329+
};
330+
331+
struct_span_err!(tcx.sess, span, E0205,
332+
"the trait `Copy` may not be implemented for this type")
333+
.span_label(span, &format!("variant `{}` does not implement `Copy`",
334+
name))
335+
.emit()
331336
}
332337
Err(CopyImplementationError::NotAnAdt) => {
333338
let item = tcx.map.expect_item(impl_node_id);

src/librustc_typeck/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,10 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
262262
match it.node {
263263
hir::ItemFn(_,_,_,_,ref ps,_)
264264
if ps.is_parameterized() => {
265-
struct_span_err!(tcx.sess, start_span, E0132,
265+
let sp = if let Some(sp) = ps.span() { sp } else { start_span };
266+
struct_span_err!(tcx.sess, sp, E0132,
266267
"start function is not allowed to have type parameters")
267-
.span_label(ps.span().unwrap(),
268+
.span_label(sp,
268269
&format!("start function cannot have type parameters"))
269270
.emit();
270271
return;

src/libstd/collections/hash/map.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,12 @@ fn test_resize_policy() {
199199
/// A hash map implementation which uses linear probing with Robin
200200
/// Hood bucket stealing.
201201
///
202-
/// The hashes are all keyed by the thread-local random number generator
203-
/// on creation by default. This means that the ordering of the keys is
204-
/// randomized, but makes the tables more resistant to
205-
/// denial-of-service attacks (Hash DoS). No guarantees are made to the
206-
/// quality of the random data. The implementation uses the best available
207-
/// random data from your platform at the time of creation. This behavior
208-
/// can be overridden with one of the constructors.
202+
/// By default, HashMap uses a somewhat slow hashing algorithm which can provide resistance
203+
/// to DoS attacks. Rust makes a best attempt at acquiring random numbers without IO
204+
/// blocking from your system. Because of this HashMap is not guaranteed to provide
205+
/// DoS resistance since the numbers generated might not be truly random. If you do
206+
/// require this behavior you can create your own hashing function using
207+
/// [BuildHasherDefault](../hash/struct.BuildHasherDefault.html).
209208
///
210209
/// It is required that the keys implement the `Eq` and `Hash` traits, although
211210
/// this can frequently be achieved by using `#[derive(PartialEq, Eq, Hash)]`.

src/test/compile-fail/E0023.rs

+5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ enum Fruit {
1313
Pear(u32),
1414
}
1515

16+
1617
fn main() {
1718
let x = Fruit::Apple(String::new(), String::new());
1819
match x {
1920
Fruit::Apple(a) => {}, //~ ERROR E0023
21+
//~| NOTE expected 2 fields, found 1
2022
Fruit::Apple(a, b, c) => {}, //~ ERROR E0023
23+
//~| NOTE expected 2 fields, found 3
24+
Fruit::Pear(1, 2) => {}, //~ ERROR E0023
25+
//~| NOTE expected 1 field, found 2
2126
}
2227
}

src/test/compile-fail/E0026.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ struct Thing {
1616
fn main() {
1717
let thing = Thing { x: 0, y: 0 };
1818
match thing {
19-
Thing { x, y, z } => {} //~ ERROR E0026
19+
Thing { x, y, z } => {}
20+
//~^ ERROR struct `Thing` does not have a field named `z` [E0026]
21+
//~| NOTE struct `Thing` does not have field `z`
2022
}
2123
}

src/test/compile-fail/E0087.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ fn foo<T>() {}
1212

1313
fn main() {
1414
foo::<f64, bool>(); //~ ERROR E0087
15+
//~^ NOTE expected
1516
}

src/test/compile-fail/E0162.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct Irrefutable(i32);
1313
fn main() {
1414
let irr = Irrefutable(0);
1515
if let Irrefutable(x) = irr { //~ ERROR E0162
16+
//~| NOTE irrefutable pattern
1617
println!("{}", x);
1718
}
1819
}

src/test/compile-fail/E0191.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ trait Trait {
1313
}
1414

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

1718
fn main() {
1819
}

src/test/compile-fail/E0205.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ enum Foo {
1414
}
1515

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

2020
#[derive(Copy)]
21-
//~^ ERROR E0205
21+
//~^ ERROR the trait `Copy` may not be implemented for this type
2222
//~| NOTE variant `Bar` does not implement `Copy`
2323
//~| NOTE in this expansion of #[derive(Copy)]
2424
enum Foo2<'a> {

src/test/compile-fail/E0214.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
let v: Vec(&str) = vec!["foo"]; //~ ERROR E0214
12+
let v: Vec(&str) = vec!["foo"];
13+
//~^ ERROR E0214
14+
//~| NOTE only traits may use parentheses
1315
}

src/test/compile-fail/E0248.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ enum Foo {
1313
}
1414

1515
fn do_something(x: Foo::Bar) { } //~ ERROR E0248
16-
16+
//~| NOTE value used as a type
1717
fn main() {
1818
}

src/test/compile-fail/associated-type-projection-from-multiple-supertraits.rs

+4
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,23 @@ pub trait BoxCar : Box + Vehicle {
2828

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

3536
fn dent_object<COLOR>(c: BoxCar<Color=COLOR>) {
3637
//~^ ERROR ambiguous associated type
3738
//~| ERROR the value of the associated type `Color` (from the trait `Vehicle`) must be specified
39+
//~| NOTE ambiguous associated type `Color`
3840
//~| NOTE could derive from `Vehicle`
3941
//~| NOTE could derive from `Box`
42+
//~| NOTE missing associated type `Color` value
4043
}
4144

4245
fn paint<C:BoxCar>(c: C, d: C::Color) {
4346
//~^ ERROR ambiguous associated type `Color` in bounds of `C`
47+
//~| NOTE ambiguous associated type `Color`
4448
//~| NOTE could derive from `Vehicle`
4549
//~| NOTE could derive from `Box`
4650
}

src/test/run-pass/issue-33498.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub fn main() {
12+
let x = (0, 2);
13+
14+
match x {
15+
(0, ref y) => {}
16+
(y, 0) => {}
17+
_ => (),
18+
}
19+
}

0 commit comments

Comments
 (0)