Make the panic info more useful

This commit is contained in:
Oli Scherer 2023-09-06 10:46:54 +00:00
parent 2b6a34273d
commit c7ced1ba53
3 changed files with 21 additions and 4 deletions

View File

@ -314,6 +314,17 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
let mut query_description_stream = quote! {}; let mut query_description_stream = quote! {};
let mut query_cached_stream = quote! {}; let mut query_cached_stream = quote! {};
let mut feedable_queries = quote! {}; let mut feedable_queries = quote! {};
let mut errors = quote! {};
macro_rules! assert {
( $cond:expr, $span:expr, $( $tt:tt )+ ) => {
if !$cond {
errors.extend(
Error::new($span, format!($($tt)+)).into_compile_error(),
);
}
}
}
for query in queries.0 { for query in queries.0 {
let Query { name, arg, modifiers, .. } = &query; let Query { name, arg, modifiers, .. } = &query;
@ -369,10 +380,15 @@ macro_rules! passthrough {
[#attribute_stream] fn #name(#arg) #result, [#attribute_stream] fn #name(#arg) #result,
}); });
if modifiers.feedable.is_some() { if let Some(feedable) = &modifiers.feedable {
assert!(modifiers.anon.is_none(), "Query {name} cannot be both `feedable` and `anon`."); assert!(
modifiers.anon.is_none(),
feedable.span(),
"Query {name} cannot be both `feedable` and `anon`."
);
assert!( assert!(
modifiers.eval_always.is_none(), modifiers.eval_always.is_none(),
feedable.span(),
"Query {name} cannot be both `feedable` and `eval_always`." "Query {name} cannot be both `feedable` and `eval_always`."
); );
feedable_queries.extend(quote! { feedable_queries.extend(quote! {
@ -407,5 +423,6 @@ pub mod cached {
use super::*; use super::*;
#query_cached_stream #query_cached_stream
} }
#errors
}) })
} }

View File

@ -64,7 +64,6 @@ pub struct MarkFrame<'a> {
parent: Option<&'a MarkFrame<'a>>, parent: Option<&'a MarkFrame<'a>>,
} }
#[derive(PartialEq)]
enum DepNodeColor { enum DepNodeColor {
Red, Red,
Green(DepNodeIndex), Green(DepNodeIndex),
@ -925,7 +924,7 @@ impl<D: Deps> DepGraph<D> {
/// Returns true if the given node has been marked as red during the /// Returns true if the given node has been marked as red during the
/// current compilation session. Used in various assertions /// current compilation session. Used in various assertions
pub fn is_red(&self, dep_node: &DepNode) -> bool { pub fn is_red(&self, dep_node: &DepNode) -> bool {
self.node_color(dep_node) == Some(DepNodeColor::Red) matches!(self.node_color(dep_node), Some(DepNodeColor::Red))
} }
/// Returns true if the given node has been marked as green during the /// Returns true if the given node has been marked as green during the

View File

@ -2469,6 +2469,7 @@ fn error(&self, err: &str) {
} }
} }
#[track_caller]
fn fatal(&self, err: &str) -> ! { fn fatal(&self, err: &str) -> ! {
self.error(err); self.error(err);
error!("fatal error, panic: {:?}", err); error!("fatal error, panic: {:?}", err);