mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
parent
e81c310b62
commit
aad911fb0c
2 changed files with 40 additions and 7 deletions
|
@ -8,7 +8,7 @@ mod method_resolution;
|
||||||
mod macros;
|
mod macros;
|
||||||
mod display_source_code;
|
mod display_source_code;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::{env, sync::Arc};
|
||||||
|
|
||||||
use base_db::{fixture::WithFixture, FileRange, SourceDatabase, SourceDatabaseExt};
|
use base_db::{fixture::WithFixture, FileRange, SourceDatabase, SourceDatabaseExt};
|
||||||
use expect::Expect;
|
use expect::Expect;
|
||||||
|
@ -22,12 +22,14 @@ use hir_def::{
|
||||||
AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId,
|
AssocItemId, DefWithBodyId, LocalModuleId, Lookup, ModuleDefId,
|
||||||
};
|
};
|
||||||
use hir_expand::{db::AstDatabase, InFile};
|
use hir_expand::{db::AstDatabase, InFile};
|
||||||
use stdx::format_to;
|
use stdx::{format_to, RacyFlag};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
algo,
|
algo,
|
||||||
ast::{self, AstNode},
|
ast::{self, AstNode},
|
||||||
SyntaxNode,
|
SyntaxNode,
|
||||||
};
|
};
|
||||||
|
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
|
||||||
|
use tracing_tree::HierarchicalLayer;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
db::HirDatabase, display::HirDisplay, infer::TypeMismatch, test_db::TestDB, InferenceResult, Ty,
|
db::HirDatabase, display::HirDisplay, infer::TypeMismatch, test_db::TestDB, InferenceResult, Ty,
|
||||||
|
@ -37,9 +39,12 @@ use crate::{
|
||||||
// against snapshots of the expected results using expect. Use
|
// against snapshots of the expected results using expect. Use
|
||||||
// `env UPDATE_EXPECT=1 cargo test -p hir_ty` to update the snapshots.
|
// `env UPDATE_EXPECT=1 cargo test -p hir_ty` to update the snapshots.
|
||||||
|
|
||||||
fn setup_tracing() -> tracing::subscriber::DefaultGuard {
|
fn setup_tracing() -> Option<tracing::subscriber::DefaultGuard> {
|
||||||
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
|
static ENABLE: RacyFlag = RacyFlag::new();
|
||||||
use tracing_tree::HierarchicalLayer;
|
if !ENABLE.get(|| env::var("CHALK_DEBUG").is_ok()) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
let filter = EnvFilter::from_env("CHALK_DEBUG");
|
let filter = EnvFilter::from_env("CHALK_DEBUG");
|
||||||
let layer = HierarchicalLayer::default()
|
let layer = HierarchicalLayer::default()
|
||||||
.with_indent_lines(true)
|
.with_indent_lines(true)
|
||||||
|
@ -47,7 +52,7 @@ fn setup_tracing() -> tracing::subscriber::DefaultGuard {
|
||||||
.with_indent_amount(2)
|
.with_indent_amount(2)
|
||||||
.with_writer(std::io::stderr);
|
.with_writer(std::io::stderr);
|
||||||
let subscriber = Registry::default().with(filter).with(layer);
|
let subscriber = Registry::default().with(filter).with(layer);
|
||||||
tracing::subscriber::set_default(subscriber)
|
Some(tracing::subscriber::set_default(subscriber))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_types(ra_fixture: &str) {
|
fn check_types(ra_fixture: &str) {
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
//! Missing batteries for standard libraries.
|
//! Missing batteries for standard libraries.
|
||||||
use std::time::Instant;
|
use std::{
|
||||||
|
sync::atomic::{AtomicUsize, Ordering},
|
||||||
|
time::Instant,
|
||||||
|
};
|
||||||
|
|
||||||
mod macros;
|
mod macros;
|
||||||
|
|
||||||
|
@ -134,6 +137,31 @@ where
|
||||||
left
|
left
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct RacyFlag(AtomicUsize);
|
||||||
|
|
||||||
|
impl RacyFlag {
|
||||||
|
pub const fn new() -> RacyFlag {
|
||||||
|
RacyFlag(AtomicUsize::new(0))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get(&self, init: impl FnMut() -> bool) -> bool {
|
||||||
|
let mut init = Some(init);
|
||||||
|
self.get_impl(&mut || init.take().map_or(false, |mut f| f()))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_impl(&self, init: &mut dyn FnMut() -> bool) -> bool {
|
||||||
|
match self.0.load(Ordering::Relaxed) {
|
||||||
|
0 => false,
|
||||||
|
1 => true,
|
||||||
|
_ => {
|
||||||
|
let res = init();
|
||||||
|
self.0.store(if res { 1 } else { 0 }, Ordering::Relaxed);
|
||||||
|
res
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
Loading…
Reference in a new issue