Skip to content

Commit 236c089

Browse files
author
Jonathan Turner
authored
Rollup merge of #35454 - Detegr:master, r=jonathandturner
New error message format for E0117 and E0118 Part of #35233 r? @jonathandturner
2 parents db04c10 + e91f3f6 commit 236c089

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/librustc_typeck/coherence/orphan.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
6666
fn check_item(&self, item: &hir::Item) {
6767
let def_id = self.tcx.map.local_def_id(item.id);
6868
match item.node {
69-
hir::ItemImpl(_, _, _, None, _, _) => {
69+
hir::ItemImpl(_, _, _, None, ref ty, _) => {
7070
// For inherent impls, self type must be a nominal type
7171
// defined in this crate.
7272
debug!("coherence2::orphan check: inherent impl {}",
@@ -209,11 +209,11 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
209209
return;
210210
}
211211
_ => {
212-
struct_span_err!(self.tcx.sess, item.span, E0118,
212+
struct_span_err!(self.tcx.sess, ty.span, E0118,
213213
"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")
214+
.span_label(ty.span, &format!("impl requires a base type"))
215+
.note(&format!("either implement a trait on it or create a newtype \
216+
to wrap it instead"))
217217
.emit();
218218
return;
219219
}
@@ -228,12 +228,14 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> {
228228
match traits::orphan_check(self.tcx, def_id) {
229229
Ok(()) => { }
230230
Err(traits::OrphanCheckErr::NoLocalInputType) => {
231-
span_err!(
231+
struct_span_err!(
232232
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");
233+
"only traits defined in the current crate can be \
234+
implemented for arbitrary types")
235+
.span_label(item.span, &format!("impl doesn't use types inside crate"))
236+
.note(&format!("the impl does not reference any \
237+
types defined in this crate"))
238+
.emit();
237239
return;
238240
}
239241
Err(traits::OrphanCheckErr::UncoveredTy(param_ty)) => {

src/test/compile-fail/E0117.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
// except according to those terms.
1010

1111
impl Drop for u32 {} //~ ERROR E0117
12+
//~^ NOTE impl doesn't use types inside crate
13+
//~| NOTE the impl does not reference any types defined in this crate
1214

1315
fn main() {
1416
}

src/test/compile-fail/E0118.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
// except according to those terms.
1010

1111
impl (u8, u8) { //~ ERROR E0118
12+
//~^ NOTE impl requires a base type
13+
//~| NOTE either implement a trait on it or create a newtype to wrap it instead
1214
fn get_state(&self) -> String {
1315
String::new()
1416
}

0 commit comments

Comments
 (0)