From ba052bd8de1459acb6809215b0bedf4ea476ef9a Mon Sep 17 00:00:00 2001 From: Esteban Küber Date: Sat, 17 Jul 2021 11:13:50 -0700 Subject: Various diagnostics clean ups/tweaks * Always point at macros, including derive macros * Point at non-local items that introduce a trait requirement * On private associated item, point at definition --- compiler/rustc_builtin_macros/src/derive.rs | 5 ++++- compiler/rustc_builtin_macros/src/deriving/clone.rs | 6 +----- 2 files changed, 5 insertions(+), 6 deletions(-) (limited to 'compiler/rustc_builtin_macros/src') diff --git a/compiler/rustc_builtin_macros/src/derive.rs b/compiler/rustc_builtin_macros/src/derive.rs index 60d6bae38b5..e0389f448eb 100644 --- a/compiler/rustc_builtin_macros/src/derive.rs +++ b/compiler/rustc_builtin_macros/src/derive.rs @@ -84,8 +84,10 @@ fn report_bad_target(sess: &Session, item: &Annotatable, span: Span) -> bool { sess, span, E0774, - "`derive` may only be applied to structs, enums and unions", + "`derive` may only be applied to `struct`s, `enum`s and `union`s", ) + .span_label(span, "not applicable here") + .span_label(item.span(), "not a `struct`, `enum` or `union`") .emit(); } bad_target @@ -99,6 +101,7 @@ fn report_unexpected_literal(sess: &Session, lit: &ast::Lit) { _ => "for example, write `#[derive(Debug)]` for `Debug`".to_string(), }; struct_span_err!(sess, lit.span, E0777, "expected path to a trait, found literal",) + .span_label(lit.span, "not a trait") .help(&help_msg) .emit(); } diff --git a/compiler/rustc_builtin_macros/src/deriving/clone.rs b/compiler/rustc_builtin_macros/src/deriving/clone.rs index ca1226b445d..4ff9a301717 100644 --- a/compiler/rustc_builtin_macros/src/deriving/clone.rs +++ b/compiler/rustc_builtin_macros/src/deriving/clone.rs @@ -148,11 +148,7 @@ fn cs_clone_shallow( } _ => cx.span_bug( trait_span, - &format!( - "unexpected substructure in \ - shallow `derive({})`", - name - ), + &format!("unexpected substructure in shallow `derive({})`", name), ), } } -- cgit 1.4.1-3-g733a5