File tree Expand file tree Collapse file tree 4 files changed +44
-6
lines changed
compiler/rustc_trait_selection/src/traits/error_reporting
tests/ui/diagnostic_namespace Expand file tree Collapse file tree 4 files changed +44
-6
lines changed Original file line number Diff line number Diff line change @@ -499,12 +499,14 @@ impl<'tcx> OnUnimplementedDirective {
499499 }
500500
501501 if is_diagnostic_namespace_variant {
502- tcx. emit_node_span_lint (
503- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
504- tcx. local_def_id_to_hir_id ( item_def_id. expect_local ( ) ) ,
505- vec ! [ item. span( ) ] ,
506- MalformedOnUnimplementedAttrLint :: new ( item. span ( ) ) ,
507- ) ;
502+ if let Some ( def_id) = item_def_id. as_local ( ) {
503+ tcx. emit_node_span_lint (
504+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
505+ tcx. local_def_id_to_hir_id ( def_id) ,
506+ vec ! [ item. span( ) ] ,
507+ MalformedOnUnimplementedAttrLint :: new ( item. span ( ) ) ,
508+ ) ;
509+ }
508510 } else {
509511 // nothing found
510512 tcx. dcx ( ) . emit_err ( NoValueInOnUnimplemented { span : item. span ( ) } ) ;
Original file line number Diff line number Diff line change 1+ #[ diagnostic:: on_unimplemented( aa = "broken" ) ]
2+ pub trait Test { }
Original file line number Diff line number Diff line change 1+ //@ edition:2021
2+ //@ compile-flags:--test
3+ //@ aux-build:bad_on_unimplemented.rs
4+
5+ // Do not ICE when encountering a malformed `#[diagnostic::on_unimplemented]` annotation in a
6+ // dependency when incorrectly used (#124651).
7+
8+ extern crate bad_on_unimplemented;
9+
10+ use bad_on_unimplemented:: Test ;
11+
12+ fn breakage < T : Test > ( _: T ) { }
13+
14+ #[ test]
15+ fn test ( ) {
16+ breakage ( 1 ) ; //~ ERROR E0277
17+ }
Original file line number Diff line number Diff line change 1+ error[E0277]: the trait bound `{integer}: Test` is not satisfied
2+ --> $DIR/on_unimplemented_ice.rs:16:14
3+ |
4+ LL | breakage(1);
5+ | -------- ^ the trait `Test` is not implemented for `{integer}`
6+ | |
7+ | required by a bound introduced by this call
8+ |
9+ note: required by a bound in `breakage`
10+ --> $DIR/on_unimplemented_ice.rs:12:16
11+ |
12+ LL | fn breakage<T: Test>(_: T) {}
13+ | ^^^^ required by this bound in `breakage`
14+
15+ error: aborting due to 1 previous error
16+
17+ For more information about this error, try `rustc --explain E0277`.
You can’t perform that action at this time.
0 commit comments