mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
use subdiagnostic for message
This commit is contained in:
parent
2a973e2abc
commit
d2e5a929b9
5
compiler/rustc_error_messages/locales/en-US/expand.ftl
Normal file
5
compiler/rustc_error_messages/locales/en-US/expand.ftl
Normal file
@ -0,0 +1,5 @@
|
||||
expand-explain-doc-comment-outer =
|
||||
outer doc comments expand to `#[doc = "..."]`, which is what this macro attempted to match
|
||||
|
||||
expand-explain-doc-comment-inner =
|
||||
inner doc comments expand to `#![doc = "..."]`, which is what this macro attempted to match
|
@ -33,11 +33,12 @@ pub use unic_langid::{langid, LanguageIdentifier};
|
||||
fluent_messages! {
|
||||
borrowck => "../locales/en-US/borrowck.ftl",
|
||||
builtin_macros => "../locales/en-US/builtin_macros.ftl",
|
||||
const_eval => "../locales/en-US/const_eval.ftl",
|
||||
expand => "../locales/en-US/expand.ftl",
|
||||
lint => "../locales/en-US/lint.ftl",
|
||||
parser => "../locales/en-US/parser.ftl",
|
||||
privacy => "../locales/en-US/privacy.ftl",
|
||||
typeck => "../locales/en-US/typeck.ftl",
|
||||
const_eval => "../locales/en-US/const_eval.ftl",
|
||||
}
|
||||
|
||||
pub use fluent_generated::{self as fluent, DEFAULT_LOCALE_RESOURCES};
|
||||
|
@ -594,6 +594,20 @@ pub fn compile_declarative_macro(
|
||||
(mk_syn_ext(expander), rule_spans)
|
||||
}
|
||||
|
||||
#[derive(SessionSubdiagnostic)]
|
||||
enum ExplainDocComment {
|
||||
#[label(expand::explain_doc_comment_inner)]
|
||||
Inner {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
},
|
||||
#[label(expand::explain_doc_comment_outer)]
|
||||
Outer {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
},
|
||||
}
|
||||
|
||||
fn annotate_doc_comment(
|
||||
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
|
||||
sm: &SourceMap,
|
||||
@ -601,9 +615,9 @@ fn annotate_doc_comment(
|
||||
) {
|
||||
if let Ok(src) = sm.span_to_snippet(span) {
|
||||
if src.starts_with("///") || src.starts_with("/**") {
|
||||
err.span_label(span, "outer doc comments expand to `#[doc = \"...\"]`, which is what this macro attempted to match");
|
||||
err.subdiagnostic(ExplainDocComment::Outer { span });
|
||||
} else if src.starts_with("//!") || src.starts_with("/*!") {
|
||||
err.span_label(span, "inner doc comments expand to `#![doc = \"...\"]`, which is what this macro attempted to match");
|
||||
err.subdiagnostic(ExplainDocComment::Inner { span });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user