rust/compiler/rustc_builtin_macros/src/compile_error.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

28 lines
992 B
Rust
Raw Normal View History

2017-05-06 23:26:45 -04:00
// The compiler code necessary to support the compile_error! extension.
use rustc_ast::tokenstream::TokenStream;
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacroExpanderResult};
use rustc_span::Span;
2017-05-06 23:26:45 -04:00
use crate::util::get_single_str_from_tts;
2024-04-26 07:56:48 +10:00
pub(crate) fn expand_compile_error<'cx>(
2019-02-04 21:49:54 +09:00
cx: &'cx mut ExtCtxt<'_>,
2017-05-06 23:26:45 -04:00
sp: Span,
tts: TokenStream,
) -> MacroExpanderResult<'cx> {
let ExpandResult::Ready(mac) = get_single_str_from_tts(cx, sp, tts, "compile_error!") else {
return ExpandResult::Retry(());
};
let var = match mac {
Ok(var) => var,
Err(guar) => return ExpandResult::Ready(DummyResult::any(sp, guar)),
2017-05-06 23:26:45 -04:00
};
#[expect(rustc::diagnostic_outside_of_impl, reason = "diagnostic message is specified by user")]
#[expect(rustc::untranslatable_diagnostic, reason = "diagnostic message is specified by user")]
let guar = cx.dcx().span_err(sp, var.to_string());
2017-05-06 23:26:45 -04:00
ExpandResult::Ready(DummyResult::any(sp, guar))
2017-05-06 23:26:45 -04:00
}