Unnamed repository; edit this file 'description' to name the repository.
Review comments - some cleanups to get_failed_obligations, including returning a list
jackh726 4 months ago
parent 0dd3fe0 · commit f870ae8
-rw-r--r--crates/hir/src/semantics.rs19
-rw-r--r--crates/rust-analyzer/tests/slow-tests/main.rs6
2 files changed, 16 insertions, 9 deletions
diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs
index 60418b1dad..fcb97ab34e 100644
--- a/crates/hir/src/semantics.rs
+++ b/crates/hir/src/semantics.rs
@@ -8,7 +8,6 @@ use std::{
convert::Infallible,
fmt, iter, mem,
ops::{self, ControlFlow, Not},
- sync::Mutex,
};
use base_db::FxIndexSet;
@@ -34,7 +33,10 @@ use hir_ty::{
InferenceResult,
diagnostics::{unsafe_operations, unsafe_operations_for_body},
infer_query_with_inspect,
- next_solver::{DbInterner, Span, format_proof_tree::dump_proof_tree_structured},
+ next_solver::{
+ DbInterner, Span,
+ format_proof_tree::{ProofTreeData, dump_proof_tree_structured},
+ },
};
use intern::{Interned, Symbol, sym};
use itertools::Itertools;
@@ -2322,7 +2324,9 @@ impl<'db> SemanticsImpl<'db> {
match container {
ChildContainer::DefWithBodyId(def) => {
- static RESULT: Mutex<String> = Mutex::new(String::new());
+ thread_local! {
+ static RESULT: RefCell<Vec<ProofTreeData>> = const { RefCell::new(Vec::new()) };
+ }
infer_query_with_inspect(
self.db,
def,
@@ -2331,13 +2335,14 @@ impl<'db> SemanticsImpl<'db> {
&& let Some(tree) = proof_tree
{
let data = dump_proof_tree_structured(tree, Span::dummy(), infer_ctxt);
- let data = serde_json::to_string_pretty(&data)
- .unwrap_or_else(|_| "{}".to_string());
- *RESULT.lock().unwrap() = data;
+ RESULT.with(|ctx| ctx.borrow_mut().push(data));
}
}),
);
- RESULT.lock().ok().map(|s| (*s).clone())
+ let data: Vec<ProofTreeData> =
+ RESULT.with(|data| data.borrow_mut().drain(..).collect());
+ let data = serde_json::to_string_pretty(&data).unwrap_or_else(|_| "[]".to_owned());
+ Some(data)
}
_ => None,
}
diff --git a/crates/rust-analyzer/tests/slow-tests/main.rs b/crates/rust-analyzer/tests/slow-tests/main.rs
index 0754e80b15..eb1b8c5dd0 100644
--- a/crates/rust-analyzer/tests/slow-tests/main.rs
+++ b/crates/rust-analyzer/tests/slow-tests/main.rs
@@ -1522,6 +1522,8 @@ fn test() {
},
);
- expect![[r#""{\n \"goal\": \"Goal { param_env: ParamEnv { clauses: [] }, predicate: Binder { value: TraitPredicate(usize: Trait, polarity:Positive), bound_vars: [] } }\",\n \"result\": \"Err(NoSolution)\",\n \"depth\": 0,\n \"candidates\": []\n}""#]]
- .assert_eq(&res.to_string());
+ let res: serde_json::Value = serde_json::from_str(res.as_str().unwrap()).unwrap();
+ let arr = res.as_array().unwrap();
+ assert_eq!(arr.len(), 2);
+ expect![[r#"{"goal":"Goal { param_env: ParamEnv { clauses: [] }, predicate: Binder { value: TraitPredicate(usize: Trait, polarity:Positive), bound_vars: [] } }","result":"Err(NoSolution)","depth":0,"candidates":[]}"#]].assert_eq(&arr[0].to_string());
}