Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3f1dd5e

Browse files
authoredJun 6, 2024
Rollup merge of rust-lang#126035 - oli-obk:query_macro_errors, r=fmease
Some minor query system cleanups * Improves diagnostics on conflicting query flags * removes unnecessary impls * `track_caller` pulled out of rust-lang#115613
2 parents 29446f2 + c7ced1b commit 3f1dd5e

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed
 

‎compiler/rustc_macros/src/query.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,17 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
314314
let mut query_description_stream = quote! {};
315315
let mut query_cached_stream = quote! {};
316316
let mut feedable_queries = quote! {};
317+
let mut errors = quote! {};
318+
319+
macro_rules! assert {
320+
( $cond:expr, $span:expr, $( $tt:tt )+ ) => {
321+
if !$cond {
322+
errors.extend(
323+
Error::new($span, format!($($tt)+)).into_compile_error(),
324+
);
325+
}
326+
}
327+
}
317328

318329
for query in queries.0 {
319330
let Query { name, arg, modifiers, .. } = &query;
@@ -369,10 +380,15 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
369380
[#attribute_stream] fn #name(#arg) #result,
370381
});
371382

372-
if modifiers.feedable.is_some() {
373-
assert!(modifiers.anon.is_none(), "Query {name} cannot be both `feedable` and `anon`.");
383+
if let Some(feedable) = &modifiers.feedable {
384+
assert!(
385+
modifiers.anon.is_none(),
386+
feedable.span(),
387+
"Query {name} cannot be both `feedable` and `anon`."
388+
);
374389
assert!(
375390
modifiers.eval_always.is_none(),
391+
feedable.span(),
376392
"Query {name} cannot be both `feedable` and `eval_always`."
377393
);
378394
feedable_queries.extend(quote! {
@@ -407,5 +423,6 @@ pub fn rustc_queries(input: TokenStream) -> TokenStream {
407423
use super::*;
408424
#query_cached_stream
409425
}
426+
#errors
410427
})
411428
}

‎compiler/rustc_query_system/src/dep_graph/graph.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ pub struct MarkFrame<'a> {
6464
parent: Option<&'a MarkFrame<'a>>,
6565
}
6666

67-
#[derive(PartialEq)]
6867
enum DepNodeColor {
6968
Red,
7069
Green(DepNodeIndex),
@@ -925,7 +924,7 @@ impl<D: Deps> DepGraph<D> {
925924
/// Returns true if the given node has been marked as red during the
926925
/// current compilation session. Used in various assertions
927926
pub fn is_red(&self, dep_node: &DepNode) -> bool {
928-
self.node_color(dep_node) == Some(DepNodeColor::Red)
927+
matches!(self.node_color(dep_node), Some(DepNodeColor::Red))
929928
}
930929

931930
/// Returns true if the given node has been marked as green during the

‎src/tools/compiletest/src/runtest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2469,6 +2469,7 @@ impl<'test> TestCx<'test> {
24692469
}
24702470
}
24712471

2472+
#[track_caller]
24722473
fn fatal(&self, err: &str) -> ! {
24732474
self.error(err);
24742475
error!("fatal error, panic: {:?}", err);

0 commit comments

Comments
 (0)
Failed to load comments.