Skip to content

Commit d2e5a92

Browse files
use subdiagnostic for message
1 parent 2a973e2 commit d2e5a92

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
expand-explain-doc-comment-outer =
2+
outer doc comments expand to `#[doc = "..."]`, which is what this macro attempted to match
3+
4+
expand-explain-doc-comment-inner =
5+
inner doc comments expand to `#![doc = "..."]`, which is what this macro attempted to match

compiler/rustc_error_messages/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ pub use unic_langid::{langid, LanguageIdentifier};
3333
fluent_messages! {
3434
borrowck => "../locales/en-US/borrowck.ftl",
3535
builtin_macros => "../locales/en-US/builtin_macros.ftl",
36+
const_eval => "../locales/en-US/const_eval.ftl",
37+
expand => "../locales/en-US/expand.ftl",
3638
lint => "../locales/en-US/lint.ftl",
3739
parser => "../locales/en-US/parser.ftl",
3840
privacy => "../locales/en-US/privacy.ftl",
3941
typeck => "../locales/en-US/typeck.ftl",
40-
const_eval => "../locales/en-US/const_eval.ftl",
4142
}
4243

4344
pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES};

compiler/rustc_expand/src/mbe/macro_rules.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,16 +594,30 @@ pub fn compile_declarative_macro(
594594
(mk_syn_ext(expander), rule_spans)
595595
}
596596

597+
#[derive(SessionSubdiagnostic)]
598+
enum ExplainDocComment {
599+
#[label(expand::explain_doc_comment_inner)]
600+
Inner {
601+
#[primary_span]
602+
span: Span,
603+
},
604+
#[label(expand::explain_doc_comment_outer)]
605+
Outer {
606+
#[primary_span]
607+
span: Span,
608+
},
609+
}
610+
597611
fn annotate_doc_comment(
598612
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
599613
sm: &SourceMap,
600614
span: Span,
601615
) {
602616
if let Ok(src) = sm.span_to_snippet(span) {
603617
if src.starts_with("///") || src.starts_with("/**") {
604-
err.span_label(span, "outer doc comments expand to `#[doc = \"...\"]`, which is what this macro attempted to match");
618+
err.subdiagnostic(ExplainDocComment::Outer { span });
605619
} else if src.starts_with("//!") || src.starts_with("/*!") {
606-
err.span_label(span, "inner doc comments expand to `#![doc = \"...\"]`, which is what this macro attempted to match");
620+
err.subdiagnostic(ExplainDocComment::Inner { span });
607621
}
608622
}
609623
}

0 commit comments

Comments
 (0)