Skip to content

Commit e3481d2

Browse files
Rollup merge of rust-lang#35298 - Keats:err-120, r=jonathandturner
Update error message E0120 Fixes rust-lang#35253 as part of rust-lang#35233. r? @jonathandturner
2 parents 4b170d5 + 3b2f184 commit e3481d2

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Diff for: src/librustc_typeck/coherence/mod.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -249,16 +249,25 @@ impl<'a, 'gcx, 'tcx> CoherenceChecker<'a, 'gcx, 'tcx> {
249249
if let Some(impl_node_id) = tcx.map.as_local_node_id(impl_did) {
250250
match tcx.map.find(impl_node_id) {
251251
Some(hir_map::NodeItem(item)) => {
252-
span_err!(tcx.sess, item.span, E0120,
253-
"the Drop trait may only be implemented on structures");
252+
let span = match item.node {
253+
ItemImpl(_, _, _, _, ref ty, _) => {
254+
ty.span
255+
},
256+
_ => item.span
257+
};
258+
struct_span_err!(tcx.sess, span, E0120,
259+
"the Drop trait may only be implemented on structures")
260+
.span_label(span,
261+
&format!("implementing Drop requires a struct"))
262+
.emit();
254263
}
255264
_ => {
256265
bug!("didn't find impl in ast map");
257266
}
258267
}
259268
} else {
260269
bug!("found external impl of Drop trait on \
261-
:omething other than a struct");
270+
something other than a struct");
262271
}
263272
}
264273
}

Diff for: src/test/compile-fail/E0120.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
trait MyTrait {}
1212

13-
impl Drop for MyTrait { //~ ERROR E0120
13+
impl Drop for MyTrait {
14+
//~^ ERROR E0120
15+
//~| NOTE implementing Drop requires a struct
1416
fn drop(&mut self) {}
1517
}
1618

0 commit comments

Comments
 (0)