Skip to content

Commit 79d05aa

Browse files
bors[bot]matklad
andauthored
Merge #3438
3438: Remove stray FIXME r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2 parents 437329d + 5095573 commit 79d05aa

File tree

8 files changed

+37
-7
lines changed

8 files changed

+37
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_ide/src/goto_definition.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub(crate) fn reference_definition(
9696

9797
#[cfg(test)]
9898
mod tests {
99-
use test_utils::assert_eq_text;
99+
use test_utils::{assert_eq_text, covers};
100100

101101
use crate::mock_analysis::analysis_and_position;
102102

@@ -208,6 +208,7 @@ mod tests {
208208

209209
#[test]
210210
fn goto_def_for_macros() {
211+
covers!(ra_ide_db::goto_def_for_macros);
211212
check_goto(
212213
"
213214
//- /lib.rs
@@ -224,6 +225,7 @@ mod tests {
224225

225226
#[test]
226227
fn goto_def_for_macros_from_other_crates() {
228+
covers!(ra_ide_db::goto_def_for_macros);
227229
check_goto(
228230
"
229231
//- /lib.rs
@@ -335,6 +337,7 @@ mod tests {
335337

336338
#[test]
337339
fn goto_def_for_methods() {
340+
covers!(ra_ide_db::goto_def_for_methods);
338341
check_goto(
339342
"
340343
//- /lib.rs
@@ -354,6 +357,7 @@ mod tests {
354357

355358
#[test]
356359
fn goto_def_for_fields() {
360+
covers!(ra_ide_db::goto_def_for_fields);
357361
check_goto(
358362
"
359363
//- /lib.rs
@@ -372,6 +376,7 @@ mod tests {
372376

373377
#[test]
374378
fn goto_def_for_record_fields() {
379+
covers!(ra_ide_db::goto_def_for_record_fields);
375380
check_goto(
376381
"
377382
//- /lib.rs
@@ -784,6 +789,7 @@ mod tests {
784789

785790
#[test]
786791
fn goto_def_for_field_init_shorthand() {
792+
covers!(ra_ide_db::goto_def_for_field_init_shorthand);
787793
check_goto(
788794
"
789795
//- /lib.rs

crates/ra_ide/src/references.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,9 +222,6 @@ fn process_definition(
222222
}
223223
};
224224

225-
// FIXME: reuse sb
226-
// See https://github.com/rust-lang/rust/pull/68198#issuecomment-574269098
227-
228225
if let Some(d) = classify_name_ref(&sema, &name_ref) {
229226
let d = d.definition();
230227
if &d == def {

crates/ra_ide_db/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ra_syntax = { path = "../ra_syntax" }
2121
ra_text_edit = { path = "../ra_text_edit" }
2222
ra_db = { path = "../ra_db" }
2323
ra_prof = { path = "../ra_prof" }
24+
test_utils = { path = "../test_utils" }
2425

2526
# ra_ide should depend only on the top-level `hir` package. if you need
2627
# something from some `hir_xxx` subpackage, reexport the API via `hir`.

crates/ra_ide_db/src/defs.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use ra_syntax::{
1414
ast::{self, AstNode, VisibilityOwner},
1515
match_ast,
1616
};
17+
use test_utils::tested_by;
1718

1819
use crate::RootDatabase;
1920

@@ -217,18 +218,22 @@ pub fn classify_name_ref(
217218
let parent = name_ref.syntax().parent()?;
218219

219220
if let Some(method_call) = ast::MethodCallExpr::cast(parent.clone()) {
221+
tested_by!(goto_def_for_methods; force);
220222
if let Some(func) = sema.resolve_method_call(&method_call) {
221223
return Some(NameRefClass::Definition(Definition::ModuleDef(func.into())));
222224
}
223225
}
224226

225227
if let Some(field_expr) = ast::FieldExpr::cast(parent.clone()) {
228+
tested_by!(goto_def_for_fields; force);
226229
if let Some(field) = sema.resolve_field(&field_expr) {
227230
return Some(NameRefClass::Definition(Definition::StructField(field)));
228231
}
229232
}
230233

231234
if let Some(record_field) = ast::RecordField::cast(parent.clone()) {
235+
tested_by!(goto_def_for_record_fields; force);
236+
tested_by!(goto_def_for_field_init_shorthand; force);
232237
if let Some((field, local)) = sema.resolve_record_field(&record_field) {
233238
let field = Definition::StructField(field);
234239
let res = match local {
@@ -240,6 +245,7 @@ pub fn classify_name_ref(
240245
}
241246

242247
if let Some(macro_call) = parent.ancestors().find_map(ast::MacroCall::cast) {
248+
tested_by!(goto_def_for_macros; force);
243249
if let Some(macro_def) = sema.resolve_macro_call(&macro_call) {
244250
return Some(NameRefClass::Definition(Definition::Macro(macro_def)));
245251
}

crates/ra_ide_db/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//!
33
//! It is mainly a `HirDatabase` for semantic analysis, plus a `SymbolsDatabase`, for fuzzy search.
44
5+
pub mod marks;
56
pub mod line_index;
67
pub mod line_index_utils;
78
pub mod feature_flags;

crates/ra_ide_db/src/marks.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//! See test_utils/src/marks.rs
2+
3+
test_utils::marks![
4+
goto_def_for_macros
5+
goto_def_for_methods
6+
goto_def_for_fields
7+
goto_def_for_record_fields
8+
goto_def_for_field_init_shorthand
9+
];

crates/test_utils/src/marks.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ use std::sync::atomic::{AtomicUsize, Ordering};
3030

3131
#[macro_export]
3232
macro_rules! tested_by {
33+
($ident:ident; force) => {{
34+
{
35+
// sic! use call-site crate
36+
crate::marks::$ident.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
37+
}
38+
}};
3339
($ident:ident) => {{
3440
#[cfg(test)]
3541
{
@@ -41,9 +47,12 @@ macro_rules! tested_by {
4147

4248
#[macro_export]
4349
macro_rules! covers {
50+
// sic! use call-site crate
4451
($ident:ident) => {
45-
// sic! use call-site crate
46-
let _checker = $crate::marks::MarkChecker::new(&crate::marks::$ident);
52+
$crate::covers!(crate::$ident)
53+
};
54+
($krate:ident :: $ident:ident) => {
55+
let _checker = $crate::marks::MarkChecker::new(&$krate::marks::$ident);
4756
};
4857
}
4958

@@ -52,7 +61,7 @@ macro_rules! marks {
5261
($($ident:ident)*) => {
5362
$(
5463
#[allow(bad_style)]
55-
pub(crate) static $ident: std::sync::atomic::AtomicUsize =
64+
pub static $ident: std::sync::atomic::AtomicUsize =
5665
std::sync::atomic::AtomicUsize::new(0);
5766
)*
5867
};

0 commit comments

Comments
 (0)