Skip to content

Commit f0d7e4e

Browse files
authored
Auto merge of #35430 - jonathandturner:rollup, r=jonathandturner
Rollup of 9 pull requests - Successful merges: #35362, #35393, #35394, #35402, #35410, #35411, #35413, #35419, #35421 - Failed merges: #35395, #35415
2 parents ddf92ff + 11022b4 commit f0d7e4e

29 files changed

+158
-70
lines changed

src/librustc_resolve/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3375,7 +3375,11 @@ impl<'a> Resolver<'a> {
33753375
(true, _) | (_, true) => struct_span_err!(self.session, span, E0260, "{}", msg),
33763376
_ => match (old_binding.is_import(), binding.is_import()) {
33773377
(false, false) => struct_span_err!(self.session, span, E0428, "{}", msg),
3378-
(true, true) => struct_span_err!(self.session, span, E0252, "{}", msg),
3378+
(true, true) => {
3379+
let mut e = struct_span_err!(self.session, span, E0252, "{}", msg);
3380+
e.span_label(span, &format!("already imported"));
3381+
e
3382+
},
33793383
_ => {
33803384
let mut e = struct_span_err!(self.session, span, E0255, "{}", msg);
33813385
e.span_label(span, &format!("`{}` was already imported", name));

src/librustc_typeck/astconv.rs

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,10 +1215,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
12151215
type_str: &str,
12161216
trait_str: &str,
12171217
name: &str) {
1218-
span_err!(self.tcx().sess, span, E0223,
1219-
"ambiguous associated type; specify the type using the syntax \
1220-
`<{} as {}>::{}`",
1221-
type_str, trait_str, name);
1218+
struct_span_err!(self.tcx().sess, span, E0223, "ambiguous associated type")
1219+
.span_label(span, &format!("ambiguous associated type"))
1220+
.note(&format!("specify the type using the syntax `<{} as {}>::{}`",
1221+
type_str, trait_str, name))
1222+
.emit();
1223+
12221224
}
12231225

12241226
// Search for a bound on a type parameter which includes the associated item
@@ -2095,8 +2097,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o {
20952097

20962098
if !trait_bounds.is_empty() {
20972099
let b = &trait_bounds[0];
2098-
span_err!(self.tcx().sess, b.trait_ref.path.span, E0225,
2099-
"only the builtin traits can be used as closure or object bounds");
2100+
let span = b.trait_ref.path.span;
2101+
struct_span_err!(self.tcx().sess, span, E0225,
2102+
"only the builtin traits can be used as closure or object bounds")
2103+
.span_label(span, &format!("non-builtin trait used as bounds"))
2104+
.emit();
21002105
}
21012106

21022107
let region_bound =
@@ -2255,20 +2260,27 @@ fn check_type_argument_count(tcx: TyCtxt, span: Span, supplied: usize,
22552260
} else {
22562261
"expected"
22572262
};
2258-
span_err!(tcx.sess, span, E0243,
2259-
"wrong number of type arguments: {} {}, found {}",
2260-
expected, required, supplied);
2263+
struct_span_err!(tcx.sess, span, E0243, "wrong number of type arguments")
2264+
.span_label(
2265+
span,
2266+
&format!("{} {} type arguments, found {}", expected, required, supplied)
2267+
)
2268+
.emit();
22612269
} else if supplied > accepted {
2262-
let expected = if required < accepted {
2263-
"expected at most"
2270+
let expected = if required == 0 {
2271+
"expected no".to_string()
2272+
} else if required < accepted {
2273+
format!("expected at most {}", accepted)
22642274
} else {
2265-
"expected"
2275+
format!("expected {}", accepted)
22662276
};
2267-
span_err!(tcx.sess, span, E0244,
2268-
"wrong number of type arguments: {} {}, found {}",
2269-
expected,
2270-
accepted,
2271-
supplied);
2277+
2278+
struct_span_err!(tcx.sess, span, E0244, "wrong number of type arguments")
2279+
.span_label(
2280+
span,
2281+
&format!("{} type arguments, found {}", expected, supplied)
2282+
)
2283+
.emit();
22722284
}
22732285
}
22742286

src/librustc_typeck/check/_match.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
9393
end.span
9494
};
9595

96-
// Note: spacing here is intentional, we want a space before "start" and "end".
97-
span_err!(tcx.sess, span, E0029,
98-
"only char and numeric types are allowed in range patterns\n \
99-
start type: {}\n end type: {}",
100-
self.ty_to_string(lhs_ty),
101-
self.ty_to_string(rhs_ty)
102-
);
96+
struct_span_err!(tcx.sess, span, E0029,
97+
"only char and numeric types are allowed in range patterns")
98+
.span_label(span, &format!("ranges require char or numeric types"))
99+
.note(&format!("start type: {}", self.ty_to_string(lhs_ty)))
100+
.note(&format!("end type: {}", self.ty_to_string(rhs_ty)))
101+
.emit();
103102
return;
104103
}
105104

@@ -700,9 +699,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
700699
for field in variant.fields
701700
.iter()
702701
.filter(|field| !used_fields.contains_key(&field.name)) {
703-
span_err!(tcx.sess, span, E0027,
704-
"pattern does not mention field `{}`",
705-
field.name);
702+
struct_span_err!(tcx.sess, span, E0027,
703+
"pattern does not mention field `{}`",
704+
field.name)
705+
.span_label(span, &format!("missing field `{}`", field.name))
706+
.emit();
706707
}
707708
}
708709
}

src/librustc_typeck/coherence/mod.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,17 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
325325
name)
326326
}
327327
Err(CopyImplementationError::NotAnAdt) => {
328-
span_err!(tcx.sess, span, E0206,
329-
"the trait `Copy` may not be implemented \
330-
for this type; type is not a structure or \
331-
enumeration")
328+
let item = tcx.map.expect_item(impl_node_id);
329+
let span = if let ItemImpl(_, _, _, _, ref ty, _) = item.node {
330+
ty.span
331+
} else {
332+
span
333+
};
334+
335+
struct_span_err!(tcx.sess, span, E0206,
336+
"the trait `Copy` may not be implemented for this type")
337+
.span_label(span, &format!("type is not a structure or enumeration"))
338+
.emit();
332339
}
333340
Err(CopyImplementationError::HasDestructor) => {
334341
span_err!(tcx.sess, span, E0184,

src/librustc_typeck/collect.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -770,9 +770,10 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
770770
let mut err = struct_span_err!(tcx.sess, impl_item.span, E0201,
771771
"duplicate definitions with name `{}`:",
772772
impl_item.name);
773-
span_note!(&mut err, *entry.get(),
774-
"previous definition of `{}` here",
775-
impl_item.name);
773+
err.span_label(*entry.get(),
774+
&format!("previous definition of `{}` here",
775+
impl_item.name));
776+
err.span_label(impl_item.span, &format!("duplicate definition"));
776777
err.emit();
777778
}
778779
Vacant(entry) => {

src/test/compile-fail/E0027.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ fn main() {
1717
let d = Dog { name: "Rusty".to_string(), age: 8 };
1818

1919
match d {
20-
Dog { age: x } => {} //~ ERROR E0027
20+
Dog { age: x } => {}
21+
//~^ ERROR pattern does not mention field `name`
22+
//~| NOTE missing field `name`
2123
}
2224
}

src/test/compile-fail/E0029.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ fn main() {
1212
let s = "hoho";
1313

1414
match s {
15-
"hello" ... "world" => {} //~ ERROR E0029
15+
"hello" ... "world" => {}
16+
//~^ ERROR only char and numeric types are allowed in range patterns
17+
//~| NOTE ranges require char or numeric types
18+
//~| NOTE start type: &'static str
19+
//~| NOTE end type: &'static str
1620
_ => {}
1721
}
1822
}

src/test/compile-fail/E0206.rs

Lines changed: 7 additions & 3 deletions
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/E0223.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
trait MyTrait { type X; }
1212

1313
fn main() {
14-
let foo: MyTrait::X; //~ ERROR E0223
14+
let foo: MyTrait::X;
15+
//~^ ERROR ambiguous associated type
16+
//~| NOTE ambiguous associated type
17+
//~| NOTE specify the type using the syntax `<Type as MyTrait>::X`
1518
}

src/test/compile-fail/E0225.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@
99
// except according to those terms.
1010

1111
fn main() {
12-
let _: Box<std::io::Read + std::io::Write>; //~ ERROR E0225
12+
let _: Box<std::io::Read + std::io::Write>;
13+
//~^ ERROR only the builtin traits can be used as closure or object bounds [E0225]
14+
//~| NOTE non-builtin trait used as bounds
1315
}

0 commit comments

Comments
 (0)