Skip to content

Commit 8913330

Browse files
authored
Auto merge of #35476 - jonathandturner:rollup, r=jonathandturner
Rollup of 6 pull requests - Successful merges: #35396, #35402, #35446, #35466, #35470, #35475 - Failed merges: #35395, #35415
2 parents 1744c46 + 09e2e04 commit 8913330

File tree

11 files changed

+72
-25
lines changed

11 files changed

+72
-25
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/librustc_typeck/astconv.rs

+15-7
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)
@@ -1584,9 +1590,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
15841590
return self.tcx().types.err;
15851591
}
15861592
_ => {
1587-
span_err!(tcx.sess, span, E0248,
1588-
"found value `{}` used as a type",
1589-
tcx.item_path_str(def.def_id()));
1593+
struct_span_err!(tcx.sess, span, E0248,
1594+
"found value `{}` used as a type",
1595+
tcx.item_path_str(def.def_id()))
1596+
.span_label(span, &format!("value used as a type"))
1597+
.emit();
15901598
return self.tcx().types.err;
15911599
}
15921600
}

src/librustc_typeck/check/_match.rs

+17-4
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
}

src/librustc_typeck/coherence/mod.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,17 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
330330
.emit()
331331
}
332332
Err(CopyImplementationError::NotAnAdt) => {
333-
span_err!(tcx.sess, span, E0206,
334-
"the trait `Copy` may not be implemented \
335-
for this type; type is not a structure or \
336-
enumeration")
333+
let item = tcx.map.expect_item(impl_node_id);
334+
let span = if let ItemImpl(_, _, _, _, ref ty, _) = item.node {
335+
ty.span
336+
} else {
337+
span
338+
};
339+
340+
struct_span_err!(tcx.sess, span, E0206,
341+
"the trait `Copy` may not be implemented for this type")
342+
.span_label(span, &format!("type is not a structure or enumeration"))
343+
.emit();
337344
}
338345
Err(CopyImplementationError::HasDestructor) => {
339346
span_err!(tcx.sess, span, E0184,

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/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/E0206.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,17 @@
1010

1111
type Foo = i32;
1212

13-
impl Copy for Foo { } //~ ERROR E0206
14-
//~^ ERROR E0117
13+
impl Copy for Foo { }
14+
//~^ ERROR the trait `Copy` may not be implemented for this type
15+
//~| NOTE type is not a structure or enumeration
16+
//~| ERROR E0117
1517

1618
#[derive(Copy, Clone)]
1719
struct Bar;
1820

19-
impl Copy for &'static Bar { } //~ ERROR E0206
21+
impl Copy for &'static Bar { }
22+
//~^ ERROR the trait `Copy` may not be implemented for this type
23+
//~| NOTE type is not a structure or enumeration
2024

2125
fn main() {
2226
}

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

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ fn dent_object<COLOR>(c: BoxCar<Color=COLOR>) {
3737
//~| ERROR the value of the associated type `Color` (from the trait `Vehicle`) must be specified
3838
//~| NOTE could derive from `Vehicle`
3939
//~| NOTE could derive from `Box`
40+
//~| NOTE missing associated type `Color` value
4041
}
4142

4243
fn paint<C:BoxCar>(c: C, d: C::Color) {

src/test/compile-fail/coherence-impls-copy.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,27 @@ impl Clone for TestE { fn clone(&self) -> Self { *self } }
2727
impl Copy for MyType {}
2828

2929
impl Copy for &'static mut MyType {}
30-
//~^ ERROR E0206
30+
//~^ ERROR the trait `Copy` may not be implemented for this type
31+
//~| NOTE type is not a structure or enumeration
3132
impl Clone for MyType { fn clone(&self) -> Self { *self } }
3233

3334
impl Copy for (MyType, MyType) {}
34-
//~^ ERROR E0206
35+
//~^ ERROR the trait `Copy` may not be implemented for this type
36+
//~| NOTE type is not a structure or enumeration
3537
//~| ERROR E0117
3638

3739
impl Copy for &'static NotSync {}
38-
//~^ ERROR E0206
40+
//~^ ERROR the trait `Copy` may not be implemented for this type
41+
//~| NOTE type is not a structure or enumeration
3942

4043
impl Copy for [MyType] {}
41-
//~^ ERROR E0206
44+
//~^ ERROR the trait `Copy` may not be implemented for this type
45+
//~| NOTE type is not a structure or enumeration
4246
//~| ERROR E0117
4347

4448
impl Copy for &'static [NotSync] {}
45-
//~^ ERROR E0206
49+
//~^ ERROR the trait `Copy` may not be implemented for this type
50+
//~| NOTE type is not a structure or enumeration
4651
//~| ERROR E0117
4752

4853
fn main() {

0 commit comments

Comments
 (0)