mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-12-27 16:07:46 +00:00
Test builtin derives expansions
Via a hack to disable their fast path.
This commit is contained in:
parent
bd934c08cf
commit
6ed7084fe8
File diff suppressed because it is too large
Load Diff
@ -53,6 +53,8 @@ use crate::{
|
||||
|
||||
#[track_caller]
|
||||
fn check_errors(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect) {
|
||||
crate::nameres::ENABLE_BUILTIN_DERIVE_FAST_PATH.set(false);
|
||||
|
||||
let db = TestDB::with_files(ra_fixture);
|
||||
let krate = db.fetch_test_crate();
|
||||
let def_map = crate_def_map(&db, krate);
|
||||
@ -80,10 +82,15 @@ fn check_errors(#[rust_analyzer::rust_fixture] ra_fixture: &str, expect: Expect)
|
||||
.sorted_unstable_by_key(|(range, _)| range.start())
|
||||
.format_with("\n", |(range, err), format| format(&format_args!("{range:?}: {err}")))
|
||||
.to_string();
|
||||
|
||||
crate::nameres::ENABLE_BUILTIN_DERIVE_FAST_PATH.set(true);
|
||||
|
||||
expect.assert_eq(&errors);
|
||||
}
|
||||
|
||||
fn check(#[rust_analyzer::rust_fixture] ra_fixture: &str, mut expect: Expect) {
|
||||
crate::nameres::ENABLE_BUILTIN_DERIVE_FAST_PATH.set(false);
|
||||
|
||||
let extra_proc_macros = vec![(
|
||||
r#"
|
||||
#[proc_macro_attribute]
|
||||
@ -246,6 +253,8 @@ pub fn identity_when_valid(_attr: TokenStream, item: TokenStream) -> TokenStream
|
||||
}
|
||||
}
|
||||
|
||||
crate::nameres::ENABLE_BUILTIN_DERIVE_FAST_PATH.set(true);
|
||||
|
||||
expect.indent(false);
|
||||
expect.assert_eq(&expanded_text);
|
||||
}
|
||||
|
||||
@ -87,6 +87,25 @@ use crate::{
|
||||
|
||||
pub use self::path_resolution::ResolvePathResultPrefixInfo;
|
||||
|
||||
#[cfg(test)]
|
||||
thread_local! {
|
||||
/// HACK: In order to test builtin derive expansion, we gate their fast path with this atomic when cfg(test).
|
||||
pub(crate) static ENABLE_BUILTIN_DERIVE_FAST_PATH: std::cell::Cell<bool> =
|
||||
const { std::cell::Cell::new(true) };
|
||||
}
|
||||
|
||||
#[inline]
|
||||
#[cfg(test)]
|
||||
fn enable_builtin_derive_fast_path() -> bool {
|
||||
ENABLE_BUILTIN_DERIVE_FAST_PATH.get()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(not(test))]
|
||||
fn enable_builtin_derive_fast_path() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
const PREDEFINED_TOOLS: &[SmolStr] = &[
|
||||
SmolStr::new_static("clippy"),
|
||||
SmolStr::new_static("rustfmt"),
|
||||
|
||||
@ -1526,8 +1526,9 @@ impl<'db> DefCollector<'db> {
|
||||
}
|
||||
}
|
||||
|
||||
if let MacroDefKind::BuiltInDerive(_, builtin_derive) =
|
||||
def_id.kind
|
||||
if super::enable_builtin_derive_fast_path()
|
||||
&& let MacroDefKind::BuiltInDerive(_, builtin_derive) =
|
||||
def_id.kind
|
||||
{
|
||||
self.deferred_builtin_derives
|
||||
.entry(ast_id.ast_id.upcast())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user