Skip to content

Commit 1744c46

Browse files
authored
Auto merge of #35469 - jonathandturner:rollup, r=jonathandturner
Rollup of 21 pull requests - Successful merges: #35314, #35355, #35357, #35366, #35394, #35410, #35411, #35413, #35417, #35419, #35421, #35429, #35433, #35434, #35436, #35439, #35443, #35454, #35455, #35467, #35468 - Failed merges: #35395, #35415
2 parents f5e7a59 + 995eeb0 commit 1744c46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+345
-126
lines changed

src/libcore/iter/traits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ pub trait ExactSizeIterator: Iterator {
548548
/// assert_eq!(one_element.next(), None);
549549
/// ```
550550
#[inline]
551-
#[unstable(feature = "exact_size_is_empty", issue = "0")]
551+
#[unstable(feature = "exact_size_is_empty", issue = "35428")]
552552
fn is_empty(&self) -> bool {
553553
self.len() == 0
554554
}

src/librustc/traits/error_reporting.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -870,10 +870,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
870870

871871

872872
fn need_type_info(&self, span: Span, ty: Ty<'tcx>) {
873-
span_err!(self.tcx.sess, span, E0282,
874-
"unable to infer enough type information about `{}`; \
875-
type annotations or generic parameter binding required",
876-
ty);
873+
let mut err = struct_span_err!(self.tcx.sess, span, E0282,
874+
"unable to infer enough type information about `{}`",
875+
ty);
876+
err.note("type annotations or generic parameter binding required");
877+
err.span_label(span, &format!("cannot infer type for `{}`", ty));
878+
err.emit()
877879
}
878880

879881
fn note_obligation_cause<T>(&self,

src/librustc_mir/transform/qualify_consts.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -686,8 +686,10 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
686686
Rvalue::Box(_) => {
687687
self.add(Qualif::NOT_CONST);
688688
if self.mode != Mode::Fn {
689-
span_err!(self.tcx.sess, self.span, E0010,
690-
"allocations are not allowed in {}s", self.mode);
689+
struct_span_err!(self.tcx.sess, self.span, E0010,
690+
"allocations are not allowed in {}s", self.mode)
691+
.span_label(self.span, &format!("allocation not allowed in {}s", self.mode))
692+
.emit();
691693
}
692694
}
693695

src/librustc_typeck/astconv.rs

+29-17
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

+11-10
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/check/callee.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ use rustc::hir;
2828
/// method that is called)
2929
pub fn check_legal_trait_for_method_call(ccx: &CrateCtxt, span: Span, trait_id: DefId) {
3030
if ccx.tcx.lang_items.drop_trait() == Some(trait_id) {
31-
span_err!(ccx.tcx.sess, span, E0040, "explicit use of destructor method");
31+
struct_span_err!(ccx.tcx.sess, span, E0040, "explicit use of destructor method")
32+
.span_label(span, &format!("call to destructor method"))
33+
.emit();
3234
}
3335
}
3436

src/librustc_typeck/check/compare_method.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -59,19 +59,33 @@ pub fn compare_impl_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
5959
(&ty::ExplicitSelfCategory::Static,
6060
&ty::ExplicitSelfCategory::Static) => {}
6161
(&ty::ExplicitSelfCategory::Static, _) => {
62-
span_err!(tcx.sess, impl_m_span, E0185,
62+
let mut err = struct_span_err!(tcx.sess, impl_m_span, E0185,
6363
"method `{}` has a `{}` declaration in the impl, \
6464
but not in the trait",
6565
trait_m.name,
6666
impl_m.explicit_self);
67+
err.span_label(impl_m_span, &format!("`{}` used in impl",
68+
impl_m.explicit_self));
69+
if let Some(span) = tcx.map.span_if_local(trait_m.def_id) {
70+
err.span_label(span, &format!("trait declared without `{}`",
71+
impl_m.explicit_self));
72+
}
73+
err.emit();
6774
return;
6875
}
6976
(_, &ty::ExplicitSelfCategory::Static) => {
70-
span_err!(tcx.sess, impl_m_span, E0186,
77+
let mut err = struct_span_err!(tcx.sess, impl_m_span, E0186,
7178
"method `{}` has a `{}` declaration in the trait, \
7279
but not in the impl",
7380
trait_m.name,
7481
trait_m.explicit_self);
82+
err.span_label(impl_m_span, &format!("expected `{}` in impl",
83+
trait_m.explicit_self));
84+
if let Some(span) = tcx.map.span_if_local(trait_m.def_id) {
85+
err.span_label(span, & format!("`{}` used in trait",
86+
trait_m.explicit_self));
87+
}
88+
err.emit();
7589
return;
7690
}
7791
_ => {

src/librustc_typeck/check/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1136,11 +1136,16 @@ fn check_impl_items_against_trait<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
11361136
}
11371137

11381138
if !missing_items.is_empty() {
1139-
span_err!(tcx.sess, impl_span, E0046,
1139+
struct_span_err!(tcx.sess, impl_span, E0046,
11401140
"not all trait items implemented, missing: `{}`",
11411141
missing_items.iter()
11421142
.map(|name| name.to_string())
11431143
.collect::<Vec<_>>().join("`, `"))
1144+
.span_label(impl_span, &format!("missing `{}` in implementation",
1145+
missing_items.iter()
1146+
.map(|name| name.to_string())
1147+
.collect::<Vec<_>>().join("`, `"))
1148+
).emit();
11441149
}
11451150

11461151
if !invalidated_items.is_empty() {

src/librustc_typeck/check/writeback.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -441,13 +441,19 @@ impl<'cx, 'gcx, 'tcx> Resolver<'cx, 'gcx, 'tcx> {
441441
if !self.tcx.sess.has_errors() {
442442
match self.reason {
443443
ResolvingExpr(span) => {
444-
span_err!(self.tcx.sess, span, E0101,
445-
"cannot determine a type for this expression: {}", e);
444+
struct_span_err!(
445+
self.tcx.sess, span, E0101,
446+
"cannot determine a type for this expression: {}", e)
447+
.span_label(span, &format!("cannot resolve type of expression"))
448+
.emit();
446449
}
447450

448451
ResolvingLocal(span) => {
449-
span_err!(self.tcx.sess, span, E0102,
450-
"cannot determine a type for this local variable: {}", e);
452+
struct_span_err!(
453+
self.tcx.sess, span, E0102,
454+
"cannot determine a type for this local variable: {}", e)
455+
.span_label(span, &format!("cannot resolve type of variable"))
456+
.emit();
451457
}
452458

453459
ResolvingPattern(span) => {

src/librustc_typeck/coherence/mod.rs

+13-8
Original file line numberDiff line numberDiff line change
@@ -311,18 +311,23 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
311311
match param_env.can_type_implement_copy(tcx, self_type, span) {
312312
Ok(()) => {}
313313
Err(CopyImplementationError::InfrigingField(name)) => {
314-
span_err!(tcx.sess, span, E0204,
315-
"the trait `Copy` may not be \
316-
implemented for this type; field \
317-
`{}` does not implement `Copy`",
318-
name)
314+
struct_span_err!(tcx.sess, span, E0204,
315+
"the trait `Copy` may not be implemented for \
316+
this type")
317+
.span_label(span, &format!(
318+
"field `{}` does not implement `Copy`", name)
319+
)
320+
.emit()
321+
319322
}
320323
Err(CopyImplementationError::InfrigingVariant(name)) => {
321-
span_err!(tcx.sess, span, E0205,
324+
struct_span_err!(tcx.sess, span, E0205,
322325
"the trait `Copy` may not be \
323-
implemented for this type; variant \
326+
implemented for this type")
327+
.span_label(span, &format!("variant \
324328
`{}` does not implement `Copy`",
325-
name)
329+
name))
330+
.emit()
326331
}
327332
Err(CopyImplementationError::NotAnAdt) => {
328333
span_err!(tcx.sess, span, E0206,

src/librustc_typeck/coherence/orphan.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ struct OrphanChecker<'cx, 'tcx:'cx> {
3333
impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
3434
fn check_def_id(&self, item: &hir::Item, def_id: DefId) {
3535
if def_id.krate != LOCAL_CRATE {
36-
span_err!(self.tcx.sess, item.span, E0116,
36+
struct_span_err!(self.tcx.sess, item.span, E0116,
3737
"cannot define inherent `impl` for a type outside of the \
38-
crate where the type is defined; define and implement \
39-
a trait or new type instead");
38+
crate where the type is defined")
39+
.span_label(item.span, &format!("impl for type defined outside of crate."))
40+
.span_note(item.span, &format!("define and implement a trait or new type instead"))
41+
.emit();
4042
}
4143
}
4244

@@ -66,7 +68,7 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
6668
fn check_item(&self, item: &hir::Item) {
6769
let def_id = self.tcx.map.local_def_id(item.id);
6870
match item.node {
69-
hir::ItemImpl(_, _, _, None, _, _) => {
71+
hir::ItemImpl(_, _, _, None, ref ty, _) => {
7072
// For inherent impls, self type must be a nominal type
7173
// defined in this crate.
7274
debug!("coherence2::orphan check: inherent impl {}",
@@ -209,11 +211,11 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
209211
return;
210212
}
211213
_ => {
212-
struct_span_err!(self.tcx.sess, item.span, E0118,
214+
struct_span_err!(self.tcx.sess, ty.span, E0118,
213215
"no base type found for inherent implementation")
214-
.span_help(item.span,
215-
"either implement a trait on it or create a newtype to wrap it \
216-
instead")
216+
.span_label(ty.span, &format!("impl requires a base type"))
217+
.note(&format!("either implement a trait on it or create a newtype \
218+
to wrap it instead"))
217219
.emit();
218220
return;
219221
}
@@ -228,12 +230,14 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
228230
match traits::orphan_check(self.tcx, def_id) {
229231
Ok(()) => { }
230232
Err(traits::OrphanCheckErr::NoLocalInputType) => {
231-
span_err!(
233+
struct_span_err!(
232234
self.tcx.sess, item.span, E0117,
233-
"the impl does not reference any \
234-
types defined in this crate; \
235-
only traits defined in the current crate can be \
236-
implemented for arbitrary types");
235+
"only traits defined in the current crate can be \
236+
implemented for arbitrary types")
237+
.span_label(item.span, &format!("impl doesn't use types inside crate"))
238+
.note(&format!("the impl does not reference any \
239+
types defined in this crate"))
240+
.emit();
237241
return;
238242
}
239243
Err(traits::OrphanCheckErr::UncoveredTy(param_ty)) => {

src/librustc_typeck/collect.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,13 @@ impl<'a, 'tcx> AstConv<'tcx, 'tcx> for ItemCtxt<'a, 'tcx> {
367367
_substs: Option<&mut Substs<'tcx>>,
368368
_space: Option<ParamSpace>,
369369
span: Span) -> Ty<'tcx> {
370-
span_err!(self.tcx().sess, span, E0121,
371-
"the type placeholder `_` is not allowed within types on item signatures");
370+
struct_span_err!(
371+
self.tcx().sess,
372+
span,
373+
E0121,
374+
"the type placeholder `_` is not allowed within types on item signatures"
375+
).span_label(span, &format!("not allowed in type signatures"))
376+
.emit();
372377
self.tcx().types.err
373378
}
374379

@@ -770,9 +775,10 @@ fn convert_item(ccx: &CrateCtxt, it: &hir::Item) {
770775
let mut err = struct_span_err!(tcx.sess, impl_item.span, E0201,
771776
"duplicate definitions with name `{}`:",
772777
impl_item.name);
773-
span_note!(&mut err, *entry.get(),
774-
"previous definition of `{}` here",
775-
impl_item.name);
778+
err.span_label(*entry.get(),
779+
&format!("previous definition of `{}` here",
780+
impl_item.name));
781+
err.span_label(impl_item.span, &format!("duplicate definition"));
776782
err.emit();
777783
}
778784
Vacant(entry) => {

src/librustc_typeck/lib.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,15 @@ fn check_main_fn_ty(ccx: &CrateCtxt,
211211
match tcx.map.find(main_id) {
212212
Some(hir_map::NodeItem(it)) => {
213213
match it.node {
214-
hir::ItemFn(_, _, _, _, ref ps, _)
215-
if ps.is_parameterized() => {
216-
span_err!(ccx.tcx.sess, main_span, E0131,
217-
"main function is not allowed to have type parameters");
218-
return;
214+
hir::ItemFn(_, _, _, _, ref generics, _) => {
215+
if let Some(gen_span) = generics.span() {
216+
struct_span_err!(ccx.tcx.sess, gen_span, E0131,
217+
"main function is not allowed to have type parameters")
218+
.span_label(gen_span,
219+
&format!("main cannot have type parameters"))
220+
.emit();
221+
return;
222+
}
219223
}
220224
_ => ()
221225
}

src/libstd/ffi/c_str.rs

+9
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,15 @@ impl NulError {
373373

374374
/// Consumes this error, returning the underlying vector of bytes which
375375
/// generated the error in the first place.
376+
///
377+
/// # Examples
378+
///
379+
/// ```
380+
/// use std::ffi::CString;
381+
///
382+
/// let nul_error = CString::new("foo\0bar").unwrap_err();
383+
/// assert_eq!(nul_error.into_vec(), b"foo\0bar");
384+
/// ```
376385
#[stable(feature = "rust1", since = "1.0.0")]
377386
pub fn into_vec(self) -> Vec<u8> { self.1 }
378387
}

0 commit comments

Comments
 (0)