Skip to content

Commit b351e11

Browse files
Move cfg attrs up to the mod definitions to disable sourcegen
1 parent 0bffdf2 commit b351e11

File tree

8 files changed

+7
-32
lines changed

8 files changed

+7
-32
lines changed

crates/ide-assists/src/tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
mod sourcegen;
21
mod generated;
2+
#[cfg(not(feature = "in-rust-tree"))]
3+
mod sourcegen;
34

45
use expect_test::expect;
56
use hir::{db::DefDatabase, Semantics};

crates/ide-assists/src/tests/sourcegen.rs

-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
//! Generates `assists.md` documentation.
22
3-
#[cfg(not(feature = "in-rust-tree"))]
43
use std::{fmt, fs, path::Path};
54

6-
#[cfg(not(feature = "in-rust-tree"))]
75
use test_utils::project_root;
86

9-
#[cfg(not(feature = "in-rust-tree"))]
107
#[test]
118
fn sourcegen_assists_docs() {
129
let assists = Assist::collect();
@@ -63,23 +60,20 @@ r#####"
6360
}
6461
}
6562

66-
#[cfg(not(feature = "in-rust-tree"))]
6763
#[derive(Debug)]
6864
struct Section {
6965
doc: String,
7066
before: String,
7167
after: String,
7268
}
7369

74-
#[cfg(not(feature = "in-rust-tree"))]
7570
#[derive(Debug)]
7671
struct Assist {
7772
id: String,
7873
location: sourcegen::Location,
7974
sections: Vec<Section>,
8075
}
8176

82-
#[cfg(not(feature = "in-rust-tree"))]
8377
impl Assist {
8478
fn collect() -> Vec<Assist> {
8579
let handlers_dir = project_root().join("crates/ide-assists/src/handlers");
@@ -144,7 +138,6 @@ impl Assist {
144138
}
145139
}
146140

147-
#[cfg(not(feature = "in-rust-tree"))]
148141
impl fmt::Display for Assist {
149142
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
150143
let _ = writeln!(
@@ -179,15 +172,13 @@ impl fmt::Display for Assist {
179172
}
180173
}
181174

182-
#[cfg(not(feature = "in-rust-tree"))]
183175
fn hide_hash_comments(text: &str) -> String {
184176
text.split('\n') // want final newline
185177
.filter(|&it| !(it.starts_with("# ") || it == "#"))
186178
.map(|it| format!("{}\n", it))
187179
.collect()
188180
}
189181

190-
#[cfg(not(feature = "in-rust-tree"))]
191182
fn reveal_hash_comments(text: &str) -> String {
192183
text.split('\n') // want final newline
193184
.map(|it| {

crates/ide-diagnostics/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(not(feature = "in-rust-tree"))]
12
mod sourcegen;
23

34
use expect_test::Expect;

crates/ide-diagnostics/src/tests/sourcegen.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
//! Generates `assists.md` documentation.
22
3-
#[cfg(not(feature = "in-rust-tree"))]
43
use std::{fmt, fs, io, path::PathBuf};
54

6-
#[cfg(not(feature = "in-rust-tree"))]
75
use sourcegen::project_root;
86

9-
#[cfg(not(feature = "in-rust-tree"))]
107
#[test]
118
fn sourcegen_diagnostic_docs() {
129
let diagnostics = Diagnostic::collect().unwrap();
@@ -17,15 +14,13 @@ fn sourcegen_diagnostic_docs() {
1714
fs::write(&dst, &contents).unwrap();
1815
}
1916

20-
#[cfg(not(feature = "in-rust-tree"))]
2117
#[derive(Debug)]
2218
struct Diagnostic {
2319
id: String,
2420
location: sourcegen::Location,
2521
doc: String,
2622
}
2723

28-
#[cfg(not(feature = "in-rust-tree"))]
2924
impl Diagnostic {
3025
fn collect() -> io::Result<Vec<Diagnostic>> {
3126
let handlers_dir = project_root().join("crates/ide-diagnostics/src/handlers");
@@ -56,7 +51,6 @@ impl Diagnostic {
5651
}
5752
}
5853

59-
#[cfg(not(feature = "in-rust-tree"))]
6054
fn is_valid_diagnostic_name(diagnostic: &str) -> Result<(), String> {
6155
let diagnostic = diagnostic.trim();
6256
if diagnostic.find(char::is_whitespace).is_some() {
@@ -72,7 +66,6 @@ fn is_valid_diagnostic_name(diagnostic: &str) -> Result<(), String> {
7266
Ok(())
7367
}
7468

75-
#[cfg(not(feature = "in-rust-tree"))]
7669
impl fmt::Display for Diagnostic {
7770
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7871
writeln!(f, "=== {}\n**Source:** {}\n{}", self.id, self.location, self.doc)

crates/rust-analyzer/tests/slow-tests/main.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
1111
#![warn(rust_2018_idioms, unused_lifetimes, semicolon_in_expressions_from_macros)]
1212

13+
#[cfg(not(feature = "in-rust-tree"))]
1314
mod sourcegen;
14-
mod tidy;
15-
mod testdir;
1615
mod support;
16+
mod testdir;
17+
mod tidy;
1718

1819
use std::{collections::HashMap, path::PathBuf, time::Instant};
1920

crates/rust-analyzer/tests/slow-tests/sourcegen.rs

-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
//! Generates `assists.md` documentation.
22
3-
#[cfg(not(feature = "in-rust-tree"))]
43
use std::{fmt, fs, io, path::PathBuf};
54

6-
#[cfg(not(feature = "in-rust-tree"))]
75
#[test]
86
fn sourcegen_feature_docs() {
97
let features = Feature::collect().unwrap();
@@ -19,15 +17,13 @@ fn sourcegen_feature_docs() {
1917
fs::write(&dst, &contents).unwrap();
2018
}
2119

22-
#[cfg(not(feature = "in-rust-tree"))]
2320
#[derive(Debug)]
2421
struct Feature {
2522
id: String,
2623
location: sourcegen::Location,
2724
doc: String,
2825
}
2926

30-
#[cfg(not(feature = "in-rust-tree"))]
3127
impl Feature {
3228
fn collect() -> io::Result<Vec<Feature>> {
3329
let crates_dir = sourcegen::project_root().join("crates");
@@ -58,7 +54,6 @@ impl Feature {
5854
}
5955
}
6056

61-
#[cfg(not(feature = "in-rust-tree"))]
6257
fn is_valid_feature_name(feature: &str) -> Result<(), String> {
6358
'word: for word in feature.split_whitespace() {
6459
for short in ["to", "and"] {
@@ -78,7 +73,6 @@ fn is_valid_feature_name(feature: &str) -> Result<(), String> {
7873
Ok(())
7974
}
8075

81-
#[cfg(not(feature = "in-rust-tree"))]
8276
impl fmt::Display for Feature {
8377
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
8478
writeln!(f, "=== {}\n**Source:** {}\n{}", self.id, self.location, self.doc)

crates/syntax/src/tests.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(not(feature = "in-rust-tree"))]
12
mod ast_src;
23
#[cfg(not(feature = "in-rust-tree"))]
34
mod sourcegen_ast;

crates/syntax/src/tests/ast_src.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//! Defines input for code generation process.
22
3-
#[cfg(not(feature = "in-rust-tree"))]
43
pub(crate) struct KindsSrc<'a> {
54
pub(crate) punct: &'a [(&'a str, &'a str)],
65
pub(crate) keywords: &'a [&'a str],
@@ -10,7 +9,6 @@ pub(crate) struct KindsSrc<'a> {
109
pub(crate) nodes: &'a [&'a str],
1110
}
1211

13-
#[cfg(not(feature = "in-rust-tree"))]
1412
pub(crate) const KINDS_SRC: KindsSrc<'_> = KindsSrc {
1513
punct: &[
1614
(";", "SEMICOLON"),
@@ -218,15 +216,13 @@ pub(crate) const KINDS_SRC: KindsSrc<'_> = KindsSrc {
218216
],
219217
};
220218

221-
#[cfg(not(feature = "in-rust-tree"))]
222219
#[derive(Default, Debug)]
223220
pub(crate) struct AstSrc {
224221
pub(crate) tokens: Vec<String>,
225222
pub(crate) nodes: Vec<AstNodeSrc>,
226223
pub(crate) enums: Vec<AstEnumSrc>,
227224
}
228225

229-
#[cfg(not(feature = "in-rust-tree"))]
230226
#[derive(Debug)]
231227
pub(crate) struct AstNodeSrc {
232228
pub(crate) doc: Vec<String>,
@@ -235,21 +231,18 @@ pub(crate) struct AstNodeSrc {
235231
pub(crate) fields: Vec<Field>,
236232
}
237233

238-
#[cfg(not(feature = "in-rust-tree"))]
239234
#[derive(Debug, Eq, PartialEq)]
240235
pub(crate) enum Field {
241236
Token(String),
242237
Node { name: String, ty: String, cardinality: Cardinality },
243238
}
244239

245-
#[cfg(not(feature = "in-rust-tree"))]
246240
#[derive(Debug, Eq, PartialEq)]
247241
pub(crate) enum Cardinality {
248242
Optional,
249243
Many,
250244
}
251245

252-
#[cfg(not(feature = "in-rust-tree"))]
253246
#[derive(Debug)]
254247
pub(crate) struct AstEnumSrc {
255248
pub(crate) doc: Vec<String>,

0 commit comments

Comments
 (0)