2019-10-22 15:46:53 -05:00
|
|
|
//! This module implements a reference search.
|
|
|
|
//! First, the element at the cursor position must be either an `ast::Name`
|
2021-08-22 09:45:58 -05:00
|
|
|
//! or `ast::NameRef`. If it's an `ast::NameRef`, at the classification step we
|
2019-10-22 15:46:53 -05:00
|
|
|
//! try to resolve the direct tree parent of this element, otherwise we
|
|
|
|
//! already have a definition and just need to get its HIR together with
|
2021-01-08 08:46:48 -06:00
|
|
|
//! some information that is needed for further steps of searching.
|
2019-10-22 15:46:53 -05:00
|
|
|
//! After that, we collect files that might contain references and look
|
|
|
|
//! for text occurrences of the identifier. If there's an `ast::NameRef`
|
|
|
|
//! at the index that the match starts at and its tree parent is
|
|
|
|
//! resolved to the search element definition, we get a reference.
|
2019-09-30 03:58:53 -05:00
|
|
|
|
2021-09-01 11:17:32 -05:00
|
|
|
use std::iter;
|
|
|
|
|
|
|
|
use either::Either;
|
2021-02-12 14:30:55 -06:00
|
|
|
use hir::{PathResolution, Semantics};
|
2020-08-13 09:39:16 -05:00
|
|
|
use ide_db::{
|
2021-02-07 11:38:12 -06:00
|
|
|
base_db::FileId,
|
2020-10-15 10:27:50 -05:00
|
|
|
defs::{Definition, NameClass, NameRefClass},
|
2021-10-02 04:18:18 -05:00
|
|
|
search::{ReferenceCategory, SearchScope, UsageSearchResult},
|
2020-03-03 11:54:39 -06:00
|
|
|
RootDatabase,
|
|
|
|
};
|
2021-02-07 11:38:12 -06:00
|
|
|
use rustc_hash::FxHashMap;
|
2020-08-12 11:26:51 -05:00
|
|
|
use syntax::{
|
2020-01-10 13:56:58 -06:00
|
|
|
algo::find_node_at_offset,
|
2021-09-27 05:54:24 -05:00
|
|
|
ast::{self, HasName},
|
2021-06-23 07:56:40 -05:00
|
|
|
match_ast, AstNode, SyntaxNode, TextRange, TextSize, T,
|
2020-01-03 09:30:45 -06:00
|
|
|
};
|
2019-10-12 10:47:17 -05:00
|
|
|
|
2021-01-18 14:10:01 -06:00
|
|
|
use crate::{display::TryToNav, FilePosition, NavigationTarget};
|
2019-10-12 10:47:17 -05:00
|
|
|
|
2019-02-17 05:38:32 -06:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct ReferenceSearchResult {
|
2021-03-15 03:32:06 -05:00
|
|
|
pub declaration: Option<Declaration>,
|
2021-10-02 04:18:18 -05:00
|
|
|
pub references: FxHashMap<FileId, Vec<(TextRange, Option<ReferenceCategory>)>>,
|
2020-01-03 09:30:45 -06:00
|
|
|
}
|
|
|
|
|
2020-01-09 15:27:10 -06:00
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct Declaration {
|
2021-02-07 11:38:12 -06:00
|
|
|
pub nav: NavigationTarget,
|
2021-10-02 05:02:06 -05:00
|
|
|
pub is_mut: bool,
|
2019-02-17 05:38:32 -06:00
|
|
|
}
|
|
|
|
|
2021-03-01 04:07:15 -06:00
|
|
|
// Feature: Find All References
|
|
|
|
//
|
|
|
|
// Shows all references of the item at the cursor location
|
|
|
|
//
|
|
|
|
// |===
|
|
|
|
// | Editor | Shortcut
|
|
|
|
//
|
|
|
|
// | VS Code | kbd:[Shift+Alt+F12]
|
|
|
|
// |===
|
2021-03-30 18:08:10 -05:00
|
|
|
//
|
|
|
|
// image::https://user-images.githubusercontent.com/48062697/113020670-b7c34f00-917a-11eb-8003-370ac5f2b3cb.gif[]
|
2019-02-17 05:38:32 -06:00
|
|
|
pub(crate) fn find_all_refs(
|
2020-07-01 07:11:34 -05:00
|
|
|
sema: &Semantics<RootDatabase>,
|
2020-01-18 06:17:34 -06:00
|
|
|
position: FilePosition,
|
2019-10-24 06:01:02 -05:00
|
|
|
search_scope: Option<SearchScope>,
|
2021-09-01 11:17:32 -05:00
|
|
|
) -> Option<Vec<ReferenceSearchResult>> {
|
2020-08-12 09:32:36 -05:00
|
|
|
let _p = profile::span("find_all_refs");
|
2020-02-18 11:35:10 -06:00
|
|
|
let syntax = sema.parse(position.file_id).syntax().clone();
|
2020-01-03 09:30:45 -06:00
|
|
|
|
2021-07-15 14:28:30 -05:00
|
|
|
let mut is_literal_search = false;
|
2021-09-01 11:17:32 -05:00
|
|
|
let defs = match name_for_constructor_search(&syntax, position) {
|
|
|
|
Some(name) => {
|
|
|
|
is_literal_search = true;
|
|
|
|
let def = match NameClass::classify(sema, &name)? {
|
|
|
|
NameClass::Definition(it) | NameClass::ConstReference(it) => it,
|
|
|
|
NameClass::PatFieldShorthand { local_def: _, field_ref } => {
|
|
|
|
Definition::Field(field_ref)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Either::Left(iter::once(def))
|
2021-02-12 14:30:55 -06:00
|
|
|
}
|
2021-09-01 11:17:32 -05:00
|
|
|
None => Either::Right(find_defs(sema, &syntax, position.offset)),
|
2021-07-15 14:28:30 -05:00
|
|
|
};
|
|
|
|
|
2021-09-01 11:17:32 -05:00
|
|
|
Some(
|
|
|
|
defs.into_iter()
|
|
|
|
.map(|def| {
|
|
|
|
let mut usages =
|
|
|
|
def.usages(sema).set_scope(search_scope.clone()).include_self_refs().all();
|
|
|
|
let declaration = match def {
|
|
|
|
Definition::ModuleDef(hir::ModuleDef::Module(module)) => {
|
|
|
|
Some(NavigationTarget::from_module_to_decl(sema.db, module))
|
|
|
|
}
|
|
|
|
def => def.try_to_nav(sema.db),
|
|
|
|
}
|
|
|
|
.map(|nav| {
|
|
|
|
let decl_range = nav.focus_or_full_range();
|
2021-09-12 16:12:08 -05:00
|
|
|
Declaration {
|
2021-10-02 05:02:06 -05:00
|
|
|
is_mut: decl_mutability(&def, sema.parse(nav.file_id).syntax(), decl_range),
|
2021-09-12 16:12:08 -05:00
|
|
|
nav,
|
|
|
|
}
|
2021-09-01 11:17:32 -05:00
|
|
|
});
|
|
|
|
if is_literal_search {
|
|
|
|
retain_adt_literal_usages(&mut usages, def, sema);
|
|
|
|
}
|
2020-11-14 12:11:09 -06:00
|
|
|
|
2021-09-01 11:17:32 -05:00
|
|
|
let references = usages
|
|
|
|
.into_iter()
|
|
|
|
.map(|(file_id, refs)| {
|
|
|
|
(
|
|
|
|
file_id,
|
|
|
|
refs.into_iter()
|
2021-10-02 04:18:18 -05:00
|
|
|
.map(|file_ref| (file_ref.range, file_ref.category))
|
2021-09-01 11:17:32 -05:00
|
|
|
.collect(),
|
|
|
|
)
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
ReferenceSearchResult { declaration, references }
|
|
|
|
})
|
|
|
|
.collect(),
|
|
|
|
)
|
2020-03-03 11:22:52 -06:00
|
|
|
}
|
|
|
|
|
2021-09-01 11:17:32 -05:00
|
|
|
pub(crate) fn find_defs<'a>(
|
|
|
|
sema: &'a Semantics<RootDatabase>,
|
2020-03-04 05:07:44 -06:00
|
|
|
syntax: &SyntaxNode,
|
2021-06-23 07:56:40 -05:00
|
|
|
offset: TextSize,
|
2021-09-01 11:17:32 -05:00
|
|
|
) -> impl Iterator<Item = Definition> + 'a {
|
|
|
|
sema.find_nodes_at_offset_with_descend(syntax, offset).filter_map(move |node| {
|
|
|
|
Some(match node {
|
|
|
|
ast::NameLike::NameRef(name_ref) => match NameRefClass::classify(sema, &name_ref)? {
|
|
|
|
NameRefClass::Definition(def) => def,
|
|
|
|
NameRefClass::FieldShorthand { local_ref, field_ref: _ } => {
|
|
|
|
Definition::Local(local_ref)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
ast::NameLike::Name(name) => match NameClass::classify(sema, &name)? {
|
|
|
|
NameClass::Definition(it) | NameClass::ConstReference(it) => it,
|
|
|
|
NameClass::PatFieldShorthand { local_def, field_ref: _ } => {
|
|
|
|
Definition::Local(local_def)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
ast::NameLike::Lifetime(lifetime) => NameRefClass::classify_lifetime(sema, &lifetime)
|
|
|
|
.and_then(|class| match class {
|
|
|
|
NameRefClass::Definition(it) => Some(it),
|
|
|
|
_ => None,
|
|
|
|
})
|
|
|
|
.or_else(|| {
|
|
|
|
NameClass::classify_lifetime(sema, &lifetime).and_then(NameClass::defined)
|
|
|
|
})?,
|
|
|
|
})
|
|
|
|
})
|
2020-03-04 05:07:44 -06:00
|
|
|
}
|
|
|
|
|
2021-10-02 05:02:06 -05:00
|
|
|
pub(crate) fn decl_mutability(def: &Definition, syntax: &SyntaxNode, range: TextRange) -> bool {
|
2020-02-19 07:56:22 -06:00
|
|
|
match def {
|
2020-04-25 07:23:34 -05:00
|
|
|
Definition::Local(_) | Definition::Field(_) => {}
|
2021-10-02 05:02:06 -05:00
|
|
|
_ => return false,
|
2020-01-10 13:56:58 -06:00
|
|
|
};
|
|
|
|
|
2021-10-02 05:02:06 -05:00
|
|
|
match find_node_at_offset::<ast::LetStmt>(syntax, range.start()) {
|
|
|
|
Some(stmt) if stmt.initializer().is_some() => match stmt.pat() {
|
|
|
|
Some(ast::Pat::IdentPat(it)) => it.mut_token().is_some(),
|
|
|
|
_ => false,
|
|
|
|
},
|
|
|
|
_ => false,
|
2020-01-10 13:56:58 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-15 14:28:30 -05:00
|
|
|
/// Filter out all non-literal usages for adt-defs
|
|
|
|
fn retain_adt_literal_usages(
|
|
|
|
usages: &mut UsageSearchResult,
|
|
|
|
def: Definition,
|
|
|
|
sema: &Semantics<RootDatabase>,
|
|
|
|
) {
|
|
|
|
let refs = usages.references.values_mut();
|
|
|
|
match def {
|
|
|
|
Definition::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Enum(enum_))) => {
|
|
|
|
refs.for_each(|it| {
|
|
|
|
it.retain(|reference| {
|
|
|
|
reference
|
|
|
|
.name
|
|
|
|
.as_name_ref()
|
|
|
|
.map_or(false, |name_ref| is_enum_lit_name_ref(sema, enum_, name_ref))
|
|
|
|
})
|
|
|
|
});
|
|
|
|
usages.references.retain(|_, it| !it.is_empty());
|
|
|
|
}
|
|
|
|
Definition::ModuleDef(hir::ModuleDef::Adt(_) | hir::ModuleDef::Variant(_)) => {
|
|
|
|
refs.for_each(|it| {
|
|
|
|
it.retain(|reference| reference.name.as_name_ref().map_or(false, is_lit_name_ref))
|
|
|
|
});
|
|
|
|
usages.references.retain(|_, it| !it.is_empty());
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns `Some` if the cursor is at a position for an item to search for all its constructor/literal usages
|
|
|
|
fn name_for_constructor_search(syntax: &SyntaxNode, position: FilePosition) -> Option<ast::Name> {
|
2021-02-12 14:30:55 -06:00
|
|
|
let token = syntax.token_at_offset(position.offset).right_biased()?;
|
2021-01-30 09:19:21 -06:00
|
|
|
let token_parent = token.parent()?;
|
2021-02-12 14:30:55 -06:00
|
|
|
let kind = token.kind();
|
|
|
|
if kind == T![;] {
|
2021-01-30 09:19:21 -06:00
|
|
|
ast::Struct::cast(token_parent)
|
2021-02-12 14:30:55 -06:00
|
|
|
.filter(|struct_| struct_.field_list().is_none())
|
|
|
|
.and_then(|struct_| struct_.name())
|
|
|
|
} else if kind == T!['{'] {
|
|
|
|
match_ast! {
|
2021-01-30 09:19:21 -06:00
|
|
|
match token_parent {
|
2021-02-12 14:30:55 -06:00
|
|
|
ast::RecordFieldList(rfl) => match_ast! {
|
|
|
|
match (rfl.syntax().parent()?) {
|
|
|
|
ast::Variant(it) => it.name(),
|
|
|
|
ast::Struct(it) => it.name(),
|
|
|
|
ast::Union(it) => it.name(),
|
|
|
|
_ => None,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
ast::VariantList(vl) => ast::Enum::cast(vl.syntax().parent()?)?.name(),
|
|
|
|
_ => None,
|
|
|
|
}
|
2020-01-18 06:17:34 -06:00
|
|
|
}
|
2021-02-12 14:30:55 -06:00
|
|
|
} else if kind == T!['('] {
|
2021-01-30 09:19:21 -06:00
|
|
|
let tfl = ast::TupleFieldList::cast(token_parent)?;
|
2021-02-12 14:30:55 -06:00
|
|
|
match_ast! {
|
|
|
|
match (tfl.syntax().parent()?) {
|
|
|
|
ast::Variant(it) => it.name(),
|
|
|
|
ast::Struct(it) => it.name(),
|
|
|
|
_ => None,
|
|
|
|
}
|
2020-01-18 06:17:34 -06:00
|
|
|
}
|
2021-02-12 14:30:55 -06:00
|
|
|
} else {
|
|
|
|
None
|
2020-01-18 06:17:34 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-12 14:30:55 -06:00
|
|
|
fn is_enum_lit_name_ref(
|
2020-12-14 09:39:42 -06:00
|
|
|
sema: &Semantics<RootDatabase>,
|
2021-02-12 14:30:55 -06:00
|
|
|
enum_: hir::Enum,
|
|
|
|
name_ref: &ast::NameRef,
|
|
|
|
) -> bool {
|
2021-02-13 10:57:14 -06:00
|
|
|
let path_is_variant_of_enum = |path: ast::Path| {
|
|
|
|
matches!(
|
|
|
|
sema.resolve_path(&path),
|
|
|
|
Some(PathResolution::Def(hir::ModuleDef::Variant(variant)))
|
|
|
|
if variant.parent_enum(sema.db) == enum_
|
|
|
|
)
|
|
|
|
};
|
2021-02-07 11:38:12 -06:00
|
|
|
name_ref
|
|
|
|
.syntax()
|
|
|
|
.ancestors()
|
2021-02-13 10:57:14 -06:00
|
|
|
.find_map(|ancestor| {
|
|
|
|
match_ast! {
|
|
|
|
match ancestor {
|
|
|
|
ast::PathExpr(path_expr) => path_expr.path().map(path_is_variant_of_enum),
|
|
|
|
ast::RecordExpr(record_expr) => record_expr.path().map(path_is_variant_of_enum),
|
|
|
|
_ => None,
|
|
|
|
}
|
2021-02-07 11:38:12 -06:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.unwrap_or(false)
|
|
|
|
}
|
|
|
|
|
2021-02-13 10:57:14 -06:00
|
|
|
fn path_ends_with(path: Option<ast::Path>, name_ref: &ast::NameRef) -> bool {
|
|
|
|
path.and_then(|path| path.segment())
|
|
|
|
.and_then(|segment| segment.name_ref())
|
|
|
|
.map_or(false, |segment| segment == *name_ref)
|
2021-02-07 11:38:12 -06:00
|
|
|
}
|
|
|
|
|
2021-02-13 10:57:14 -06:00
|
|
|
fn is_lit_name_ref(name_ref: &ast::NameRef) -> bool {
|
|
|
|
name_ref.syntax().ancestors().find_map(|ancestor| {
|
2021-02-12 14:30:55 -06:00
|
|
|
match_ast! {
|
|
|
|
match ancestor {
|
2021-02-13 10:57:14 -06:00
|
|
|
ast::PathExpr(path_expr) => Some(path_ends_with(path_expr.path(), name_ref)),
|
|
|
|
ast::RecordExpr(record_expr) => Some(path_ends_with(record_expr.path(), name_ref)),
|
|
|
|
_ => None,
|
2021-02-07 11:38:12 -06:00
|
|
|
}
|
2021-02-12 14:30:55 -06:00
|
|
|
}
|
2021-02-13 10:57:14 -06:00
|
|
|
}).unwrap_or(false)
|
2021-02-07 11:38:12 -06:00
|
|
|
}
|
|
|
|
|
2019-01-18 02:29:09 -06:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
2020-10-02 09:42:48 -05:00
|
|
|
use expect_test::{expect, Expect};
|
2021-10-02 05:02:06 -05:00
|
|
|
use ide_db::{base_db::FileId, search::ReferenceCategory};
|
2020-10-02 09:42:48 -05:00
|
|
|
use stdx::format_to;
|
|
|
|
|
2020-10-02 10:34:31 -05:00
|
|
|
use crate::{fixture, SearchScope};
|
2019-01-18 02:29:09 -06:00
|
|
|
|
2020-01-03 09:30:45 -06:00
|
|
|
#[test]
|
2020-01-18 06:17:34 -06:00
|
|
|
fn test_struct_literal_after_space() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
2020-06-24 04:29:43 -05:00
|
|
|
r#"
|
2021-01-06 14:15:48 -06:00
|
|
|
struct Foo $0{
|
2020-06-24 04:29:43 -05:00
|
|
|
a: i32,
|
|
|
|
}
|
|
|
|
impl Foo {
|
|
|
|
fn f() -> i32 { 42 }
|
|
|
|
}
|
|
|
|
fn main() {
|
|
|
|
let f: Foo;
|
|
|
|
f = Foo {a: Foo::f()};
|
|
|
|
}
|
|
|
|
"#,
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
Foo Struct FileId(0) 0..26 7..10
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 101..104
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-01-08 15:35:58 -06:00
|
|
|
);
|
2020-01-03 09:30:45 -06:00
|
|
|
}
|
|
|
|
|
2020-01-18 06:17:34 -06:00
|
|
|
#[test]
|
2020-06-24 04:29:43 -05:00
|
|
|
fn test_struct_literal_before_space() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
2020-06-24 04:29:43 -05:00
|
|
|
r#"
|
2021-01-06 14:15:48 -06:00
|
|
|
struct Foo$0 {}
|
2020-06-24 04:29:43 -05:00
|
|
|
fn main() {
|
|
|
|
let f: Foo;
|
|
|
|
f = Foo {};
|
|
|
|
}
|
|
|
|
"#,
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
Foo Struct FileId(0) 0..13 7..10
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 41..44
|
|
|
|
FileId(0) 54..57
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-01-18 06:17:34 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_struct_literal_with_generic_type() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
2020-06-24 04:29:43 -05:00
|
|
|
r#"
|
2021-01-06 14:15:48 -06:00
|
|
|
struct Foo<T> $0{}
|
2020-06-24 04:29:43 -05:00
|
|
|
fn main() {
|
|
|
|
let f: Foo::<i32>;
|
|
|
|
f = Foo {};
|
|
|
|
}
|
|
|
|
"#,
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
Foo Struct FileId(0) 0..16 7..10
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 64..67
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-01-18 06:17:34 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_struct_literal_for_tuple() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
2020-06-24 04:29:43 -05:00
|
|
|
r#"
|
2021-01-06 14:15:48 -06:00
|
|
|
struct Foo$0(i32);
|
2020-01-18 06:17:34 -06:00
|
|
|
|
2020-06-24 04:29:43 -05:00
|
|
|
fn main() {
|
|
|
|
let f: Foo;
|
|
|
|
f = Foo(1);
|
|
|
|
}
|
|
|
|
"#,
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
Foo Struct FileId(0) 0..16 7..10
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 54..57
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-01-18 06:17:34 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-12 14:30:55 -06:00
|
|
|
#[test]
|
|
|
|
fn test_struct_literal_for_union() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
union Foo $0{
|
|
|
|
x: u32
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let f: Foo;
|
|
|
|
f = Foo { x: 1 };
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
Foo Union FileId(0) 0..24 6..9
|
|
|
|
|
|
|
|
FileId(0) 62..65
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-12-14 09:39:42 -06:00
|
|
|
#[test]
|
|
|
|
fn test_enum_after_space() {
|
|
|
|
check(
|
|
|
|
r#"
|
2021-01-06 14:15:48 -06:00
|
|
|
enum Foo $0{
|
2020-12-14 09:39:42 -06:00
|
|
|
A,
|
2021-02-12 14:30:55 -06:00
|
|
|
B(),
|
|
|
|
C{},
|
2020-12-14 09:39:42 -06:00
|
|
|
}
|
|
|
|
fn main() {
|
|
|
|
let f: Foo;
|
|
|
|
f = Foo::A;
|
2021-02-12 14:30:55 -06:00
|
|
|
f = Foo::B();
|
|
|
|
f = Foo::C{};
|
2020-12-14 09:39:42 -06:00
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-12 14:30:55 -06:00
|
|
|
Foo Enum FileId(0) 0..37 5..8
|
2020-12-14 09:39:42 -06:00
|
|
|
|
2021-02-12 14:30:55 -06:00
|
|
|
FileId(0) 74..77
|
|
|
|
FileId(0) 90..93
|
|
|
|
FileId(0) 108..111
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_variant_record_after_space() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
enum Foo {
|
|
|
|
A $0{ n: i32 },
|
|
|
|
B,
|
|
|
|
}
|
|
|
|
fn main() {
|
|
|
|
let f: Foo;
|
|
|
|
f = Foo::B;
|
|
|
|
f = Foo::A { n: 92 };
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
A Variant FileId(0) 15..27 15..16
|
|
|
|
|
|
|
|
FileId(0) 95..96
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
#[test]
|
|
|
|
fn test_variant_tuple_before_paren() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
enum Foo {
|
|
|
|
A$0(i32),
|
|
|
|
B,
|
|
|
|
}
|
|
|
|
fn main() {
|
|
|
|
let f: Foo;
|
|
|
|
f = Foo::B;
|
|
|
|
f = Foo::A(92);
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
A Variant FileId(0) 15..21 15..16
|
2020-12-14 09:39:42 -06:00
|
|
|
|
2021-02-12 14:30:55 -06:00
|
|
|
FileId(0) 89..90
|
2020-12-14 09:39:42 -06:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_enum_before_space() {
|
|
|
|
check(
|
|
|
|
r#"
|
2021-01-06 14:15:48 -06:00
|
|
|
enum Foo$0 {
|
2020-12-14 09:39:42 -06:00
|
|
|
A,
|
|
|
|
B,
|
|
|
|
}
|
|
|
|
fn main() {
|
|
|
|
let f: Foo;
|
|
|
|
f = Foo::A;
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
Foo Enum FileId(0) 0..26 5..8
|
2020-12-14 09:39:42 -06:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 50..53
|
|
|
|
FileId(0) 63..66
|
2020-12-14 09:39:42 -06:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_enum_with_generic_type() {
|
|
|
|
check(
|
|
|
|
r#"
|
2021-01-06 14:15:48 -06:00
|
|
|
enum Foo<T> $0{
|
2020-12-14 09:39:42 -06:00
|
|
|
A(T),
|
|
|
|
B,
|
|
|
|
}
|
|
|
|
fn main() {
|
|
|
|
let f: Foo<i8>;
|
|
|
|
f = Foo::A(1);
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
Foo Enum FileId(0) 0..32 5..8
|
2020-12-14 09:39:42 -06:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 73..76
|
2020-12-14 09:39:42 -06:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_enum_for_tuple() {
|
|
|
|
check(
|
|
|
|
r#"
|
2021-01-06 14:15:48 -06:00
|
|
|
enum Foo$0{
|
2020-12-14 09:39:42 -06:00
|
|
|
A(i8),
|
|
|
|
B(i8),
|
|
|
|
}
|
|
|
|
fn main() {
|
|
|
|
let f: Foo;
|
|
|
|
f = Foo::A(1);
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
Foo Enum FileId(0) 0..33 5..8
|
2020-12-14 09:39:42 -06:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 70..73
|
2020-12-14 09:39:42 -06:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-03-25 15:03:32 -05:00
|
|
|
#[test]
|
|
|
|
fn test_find_all_refs_for_local() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
2020-06-24 04:29:43 -05:00
|
|
|
r#"
|
|
|
|
fn main() {
|
|
|
|
let mut i = 1;
|
|
|
|
let j = 1;
|
2021-01-06 14:15:48 -06:00
|
|
|
i = i$0 + j;
|
2019-03-25 15:03:32 -05:00
|
|
|
|
2020-06-24 04:29:43 -05:00
|
|
|
{
|
|
|
|
i = 0;
|
|
|
|
}
|
2019-03-25 15:03:32 -05:00
|
|
|
|
2020-06-24 04:29:43 -05:00
|
|
|
i = 5;
|
|
|
|
}"#,
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
i Local FileId(0) 20..25 24..25 Write
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 50..51 Write
|
|
|
|
FileId(0) 54..55 Read
|
|
|
|
FileId(0) 76..77 Write
|
|
|
|
FileId(0) 94..95 Write
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-01-08 15:35:58 -06:00
|
|
|
);
|
2019-03-25 15:03:32 -05:00
|
|
|
}
|
|
|
|
|
2020-02-18 11:35:10 -06:00
|
|
|
#[test]
|
|
|
|
fn search_filters_by_range() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
2020-06-24 04:29:43 -05:00
|
|
|
r#"
|
|
|
|
fn foo() {
|
2021-01-06 14:15:48 -06:00
|
|
|
let spam$0 = 92;
|
2020-06-24 04:29:43 -05:00
|
|
|
spam + spam
|
|
|
|
}
|
|
|
|
fn bar() {
|
|
|
|
let spam = 92;
|
|
|
|
spam + spam
|
|
|
|
}
|
|
|
|
"#,
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
spam Local FileId(0) 19..23 19..23
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 34..38 Read
|
|
|
|
FileId(0) 41..45 Read
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-02-18 11:35:10 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-03-25 15:03:32 -05:00
|
|
|
#[test]
|
|
|
|
fn test_find_all_refs_for_param_inside() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
2020-06-24 04:29:43 -05:00
|
|
|
r#"
|
2021-01-06 14:15:48 -06:00
|
|
|
fn foo(i : u32) -> u32 { i$0 }
|
2020-06-24 04:29:43 -05:00
|
|
|
"#,
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
i ValueParam FileId(0) 7..8 7..8
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 25..26 Read
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-06-24 04:29:43 -05:00
|
|
|
);
|
2019-03-25 15:03:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_find_all_refs_for_fn_param() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
2020-06-24 04:29:43 -05:00
|
|
|
r#"
|
2021-01-06 14:15:48 -06:00
|
|
|
fn foo(i$0 : u32) -> u32 { i }
|
2020-06-24 04:29:43 -05:00
|
|
|
"#,
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
i ValueParam FileId(0) 7..8 7..8
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 25..26 Read
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-06-24 04:29:43 -05:00
|
|
|
);
|
2019-03-25 15:03:32 -05:00
|
|
|
}
|
|
|
|
|
2019-09-14 06:38:10 -05:00
|
|
|
#[test]
|
|
|
|
fn test_find_all_refs_field_name() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
2020-06-24 04:29:43 -05:00
|
|
|
r#"
|
|
|
|
//- /lib.rs
|
|
|
|
struct Foo {
|
2021-01-06 14:15:48 -06:00
|
|
|
pub spam$0: u32,
|
2020-06-24 04:29:43 -05:00
|
|
|
}
|
2019-09-14 06:38:10 -05:00
|
|
|
|
2020-06-24 04:29:43 -05:00
|
|
|
fn main(s: Foo) {
|
|
|
|
let f = s.spam;
|
|
|
|
}
|
|
|
|
"#,
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
spam Field FileId(0) 17..30 21..25
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 67..71 Read
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-01-08 15:35:58 -06:00
|
|
|
);
|
2019-09-14 06:38:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_find_all_refs_impl_item_name() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
2020-06-24 04:29:43 -05:00
|
|
|
r#"
|
|
|
|
struct Foo;
|
|
|
|
impl Foo {
|
2021-01-06 14:15:48 -06:00
|
|
|
fn f$0(&self) { }
|
2020-06-24 04:29:43 -05:00
|
|
|
}
|
|
|
|
"#,
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
f Function FileId(0) 27..43 30..31
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-09-01 11:17:32 -05:00
|
|
|
(no references)
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-06-24 04:29:43 -05:00
|
|
|
);
|
2019-09-14 06:38:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_find_all_refs_enum_var_name() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
2020-06-24 04:29:43 -05:00
|
|
|
r#"
|
|
|
|
enum Foo {
|
|
|
|
A,
|
2021-01-06 14:15:48 -06:00
|
|
|
B$0,
|
2020-06-24 04:29:43 -05:00
|
|
|
C,
|
|
|
|
}
|
|
|
|
"#,
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
B Variant FileId(0) 22..23 22..23
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-09-01 11:17:32 -05:00
|
|
|
(no references)
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-06-24 04:29:43 -05:00
|
|
|
);
|
2019-09-14 06:38:10 -05:00
|
|
|
}
|
|
|
|
|
2020-10-08 19:57:35 -05:00
|
|
|
#[test]
|
|
|
|
fn test_find_all_refs_enum_var_field() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
enum Foo {
|
|
|
|
A,
|
2021-01-06 14:15:48 -06:00
|
|
|
B { field$0: u8 },
|
2020-10-08 19:57:35 -05:00
|
|
|
C,
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
field Field FileId(0) 26..35 26..31
|
2020-10-08 19:57:35 -05:00
|
|
|
|
2021-09-01 11:17:32 -05:00
|
|
|
(no references)
|
2020-10-08 19:57:35 -05:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-10-10 18:11:23 -05:00
|
|
|
#[test]
|
2019-10-15 14:50:28 -05:00
|
|
|
fn test_find_all_refs_two_modules() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
2020-06-24 04:29:43 -05:00
|
|
|
r#"
|
|
|
|
//- /lib.rs
|
|
|
|
pub mod foo;
|
|
|
|
pub mod bar;
|
|
|
|
|
|
|
|
fn f() {
|
|
|
|
let i = foo::Foo { n: 5 };
|
|
|
|
}
|
2019-10-10 18:11:23 -05:00
|
|
|
|
2020-06-24 04:29:43 -05:00
|
|
|
//- /foo.rs
|
|
|
|
use crate::bar;
|
2019-10-10 18:11:23 -05:00
|
|
|
|
2020-06-24 04:29:43 -05:00
|
|
|
pub struct Foo {
|
|
|
|
pub n: u32,
|
|
|
|
}
|
2019-10-10 18:11:23 -05:00
|
|
|
|
2020-06-24 04:29:43 -05:00
|
|
|
fn f() {
|
|
|
|
let i = bar::Bar { n: 5 };
|
|
|
|
}
|
2019-10-10 18:11:23 -05:00
|
|
|
|
2020-06-24 04:29:43 -05:00
|
|
|
//- /bar.rs
|
|
|
|
use crate::foo;
|
2019-10-10 18:11:23 -05:00
|
|
|
|
2020-06-24 04:29:43 -05:00
|
|
|
pub struct Bar {
|
|
|
|
pub n: u32,
|
|
|
|
}
|
2019-10-10 18:11:23 -05:00
|
|
|
|
2020-06-24 04:29:43 -05:00
|
|
|
fn f() {
|
2021-01-06 14:15:48 -06:00
|
|
|
let i = foo::Foo$0 { n: 5 };
|
2020-06-24 04:29:43 -05:00
|
|
|
}
|
|
|
|
"#,
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
Foo Struct FileId(1) 17..51 28..31
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 53..56
|
|
|
|
FileId(2) 79..82
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-01-08 15:35:58 -06:00
|
|
|
);
|
2019-10-10 18:11:23 -05:00
|
|
|
}
|
|
|
|
|
2019-10-15 14:50:28 -05:00
|
|
|
#[test]
|
|
|
|
fn test_find_all_refs_decl_module() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
2020-06-24 04:29:43 -05:00
|
|
|
r#"
|
|
|
|
//- /lib.rs
|
2021-01-06 14:15:48 -06:00
|
|
|
mod foo$0;
|
2019-10-15 14:50:28 -05:00
|
|
|
|
2020-06-24 04:29:43 -05:00
|
|
|
use foo::Foo;
|
2019-10-15 14:50:28 -05:00
|
|
|
|
2020-06-24 04:29:43 -05:00
|
|
|
fn f() {
|
|
|
|
let i = Foo { n: 5 };
|
|
|
|
}
|
2019-10-15 14:50:28 -05:00
|
|
|
|
2020-06-24 04:29:43 -05:00
|
|
|
//- /foo.rs
|
|
|
|
pub struct Foo {
|
|
|
|
pub n: u32,
|
|
|
|
}
|
|
|
|
"#,
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-06-22 12:39:59 -05:00
|
|
|
foo Module FileId(0) 0..8 4..7
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 14..17
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-06-24 04:29:43 -05:00
|
|
|
);
|
2019-10-15 14:50:28 -05:00
|
|
|
}
|
|
|
|
|
2021-06-22 12:39:59 -05:00
|
|
|
#[test]
|
|
|
|
fn test_find_all_refs_decl_module_on_self() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /lib.rs
|
|
|
|
mod foo;
|
|
|
|
|
|
|
|
//- /foo.rs
|
|
|
|
use self$0;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
foo Module FileId(0) 0..8 4..7
|
|
|
|
|
2021-06-28 09:41:35 -05:00
|
|
|
FileId(1) 4..8
|
2021-06-22 12:39:59 -05:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_find_all_refs_decl_module_on_self_crate_root() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /lib.rs
|
|
|
|
use self$0;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
Module FileId(0) 0..10
|
|
|
|
|
2021-09-01 11:17:32 -05:00
|
|
|
(no references)
|
2021-06-22 12:39:59 -05:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-10-16 08:49:35 -05:00
|
|
|
#[test]
|
|
|
|
fn test_find_all_refs_super_mod_vis() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
2020-06-24 04:29:43 -05:00
|
|
|
r#"
|
|
|
|
//- /lib.rs
|
|
|
|
mod foo;
|
2019-10-16 08:49:35 -05:00
|
|
|
|
2020-06-24 04:29:43 -05:00
|
|
|
//- /foo.rs
|
|
|
|
mod some;
|
|
|
|
use some::Foo;
|
2019-10-16 08:49:35 -05:00
|
|
|
|
2020-06-24 04:29:43 -05:00
|
|
|
fn f() {
|
|
|
|
let i = Foo { n: 5 };
|
|
|
|
}
|
2019-10-16 08:49:35 -05:00
|
|
|
|
2020-06-24 04:29:43 -05:00
|
|
|
//- /foo/some.rs
|
2021-01-06 14:15:48 -06:00
|
|
|
pub(super) struct Foo$0 {
|
2020-06-24 04:29:43 -05:00
|
|
|
pub n: u32,
|
|
|
|
}
|
|
|
|
"#,
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
Foo Struct FileId(2) 0..41 18..21
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(1) 20..23
|
|
|
|
FileId(1) 47..50
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-01-08 15:35:58 -06:00
|
|
|
);
|
2019-10-24 06:01:02 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_find_all_refs_with_scope() {
|
|
|
|
let code = r#"
|
|
|
|
//- /lib.rs
|
|
|
|
mod foo;
|
|
|
|
mod bar;
|
|
|
|
|
2021-01-06 14:15:48 -06:00
|
|
|
pub fn quux$0() {}
|
2019-10-24 06:01:02 -05:00
|
|
|
|
|
|
|
//- /foo.rs
|
|
|
|
fn f() { super::quux(); }
|
|
|
|
|
|
|
|
//- /bar.rs
|
|
|
|
fn f() { super::quux(); }
|
|
|
|
"#;
|
|
|
|
|
2020-10-02 09:42:48 -05:00
|
|
|
check_with_scope(
|
|
|
|
code,
|
|
|
|
None,
|
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
quux Function FileId(0) 19..35 26..30
|
2019-10-24 06:01:02 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(1) 16..20
|
|
|
|
FileId(2) 16..20
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-01-08 15:35:58 -06:00
|
|
|
);
|
2019-10-24 06:01:02 -05:00
|
|
|
|
2020-10-02 09:42:48 -05:00
|
|
|
check_with_scope(
|
|
|
|
code,
|
2020-10-02 09:13:48 -05:00
|
|
|
Some(SearchScope::single_file(FileId(2))),
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
quux Function FileId(0) 19..35 26..30
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(2) 16..20
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-01-08 15:35:58 -06:00
|
|
|
);
|
2019-10-16 08:49:35 -05:00
|
|
|
}
|
|
|
|
|
2019-11-15 16:13:52 -06:00
|
|
|
#[test]
|
|
|
|
fn test_find_all_refs_macro_def() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
2020-06-24 04:29:43 -05:00
|
|
|
r#"
|
|
|
|
#[macro_export]
|
2021-01-06 14:15:48 -06:00
|
|
|
macro_rules! m1$0 { () => (()) }
|
2020-06-24 04:29:43 -05:00
|
|
|
|
|
|
|
fn foo() {
|
|
|
|
m1();
|
|
|
|
m1();
|
|
|
|
}
|
|
|
|
"#,
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
m1 Macro FileId(0) 0..46 29..31
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 63..65
|
|
|
|
FileId(0) 73..75
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-01-08 15:35:58 -06:00
|
|
|
);
|
2019-11-15 16:13:52 -06:00
|
|
|
}
|
|
|
|
|
2020-01-04 16:46:01 -06:00
|
|
|
#[test]
|
2020-01-04 18:25:29 -06:00
|
|
|
fn test_basic_highlight_read_write() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
2020-06-24 04:29:43 -05:00
|
|
|
r#"
|
|
|
|
fn foo() {
|
2021-01-06 14:15:48 -06:00
|
|
|
let mut i$0 = 0;
|
2020-06-24 04:29:43 -05:00
|
|
|
i = i + 1;
|
|
|
|
}
|
|
|
|
"#,
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
i Local FileId(0) 19..24 23..24 Write
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 34..35 Write
|
|
|
|
FileId(0) 38..39 Read
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-01-09 15:01:43 -06:00
|
|
|
);
|
2020-01-04 16:46:01 -06:00
|
|
|
}
|
|
|
|
|
2020-01-04 18:25:29 -06:00
|
|
|
#[test]
|
|
|
|
fn test_basic_highlight_field_read_write() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
2020-06-24 04:29:43 -05:00
|
|
|
r#"
|
|
|
|
struct S {
|
|
|
|
f: u32,
|
|
|
|
}
|
2020-01-04 18:25:29 -06:00
|
|
|
|
2020-06-24 04:29:43 -05:00
|
|
|
fn foo() {
|
|
|
|
let mut s = S{f: 0};
|
2021-01-06 14:15:48 -06:00
|
|
|
s.f$0 = 0;
|
2020-06-24 04:29:43 -05:00
|
|
|
}
|
|
|
|
"#,
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
f Field FileId(0) 15..21 15..16
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 55..56 Read
|
|
|
|
FileId(0) 68..69 Write
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-01-09 15:01:43 -06:00
|
|
|
);
|
2020-01-04 18:25:29 -06:00
|
|
|
}
|
|
|
|
|
2020-01-10 13:56:58 -06:00
|
|
|
#[test]
|
|
|
|
fn test_basic_highlight_decl_no_write() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
2020-06-24 04:29:43 -05:00
|
|
|
r#"
|
|
|
|
fn foo() {
|
2021-01-06 14:15:48 -06:00
|
|
|
let i$0;
|
2020-06-24 04:29:43 -05:00
|
|
|
i = 1;
|
|
|
|
}
|
|
|
|
"#,
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
i Local FileId(0) 19..20 19..20
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 26..27 Write
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-06-24 04:29:43 -05:00
|
|
|
);
|
2020-01-10 13:56:58 -06:00
|
|
|
}
|
|
|
|
|
2020-05-11 04:25:18 -05:00
|
|
|
#[test]
|
|
|
|
fn test_find_struct_function_refs_outside_module() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
2020-06-24 04:29:43 -05:00
|
|
|
r#"
|
|
|
|
mod foo {
|
|
|
|
pub struct Foo;
|
2020-05-11 04:25:18 -05:00
|
|
|
|
2020-06-24 04:29:43 -05:00
|
|
|
impl Foo {
|
2021-01-06 14:15:48 -06:00
|
|
|
pub fn new$0() -> Foo { Foo }
|
2020-06-24 04:29:43 -05:00
|
|
|
}
|
|
|
|
}
|
2020-05-11 04:25:18 -05:00
|
|
|
|
2020-06-24 04:29:43 -05:00
|
|
|
fn main() {
|
|
|
|
let _f = foo::Foo::new();
|
|
|
|
}
|
|
|
|
"#,
|
2020-10-02 09:42:48 -05:00
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
new Function FileId(0) 54..81 61..64
|
2020-10-02 09:42:48 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 126..129
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-05-11 04:25:18 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-05-31 11:21:45 -05:00
|
|
|
#[test]
|
|
|
|
fn test_find_all_refs_nested_module() {
|
2020-10-02 09:42:48 -05:00
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /lib.rs
|
|
|
|
mod foo { mod bar; }
|
2020-05-31 11:21:45 -05:00
|
|
|
|
2021-01-06 14:15:48 -06:00
|
|
|
fn f$0() {}
|
2020-05-31 11:21:45 -05:00
|
|
|
|
2020-10-02 09:42:48 -05:00
|
|
|
//- /foo/bar.rs
|
|
|
|
use crate::f;
|
2020-05-31 11:21:45 -05:00
|
|
|
|
2020-10-02 09:42:48 -05:00
|
|
|
fn g() { f(); }
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
f Function FileId(0) 22..31 25..26
|
2020-05-31 11:21:45 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(1) 11..12
|
|
|
|
FileId(1) 24..25
|
2020-10-02 09:42:48 -05:00
|
|
|
"#]],
|
2020-10-09 12:55:30 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_find_all_refs_struct_pat() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
struct S {
|
2021-01-06 14:15:48 -06:00
|
|
|
field$0: u8,
|
2020-10-09 12:55:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn f(s: S) {
|
|
|
|
match s {
|
|
|
|
S { field } => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
field Field FileId(0) 15..24 15..20
|
2020-10-09 12:55:30 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 68..73 Read
|
2020-10-09 12:55:30 -05:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_find_all_refs_enum_var_pat() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
enum En {
|
|
|
|
Variant {
|
2021-01-06 14:15:48 -06:00
|
|
|
field$0: u8,
|
2020-10-09 12:55:30 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn f(e: En) {
|
|
|
|
match e {
|
|
|
|
En::Variant { field } => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
field Field FileId(0) 32..41 32..37
|
2020-10-09 12:55:30 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 102..107 Read
|
2020-10-09 12:55:30 -05:00
|
|
|
"#]],
|
2020-10-09 13:42:17 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_find_all_refs_enum_var_privacy() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
mod m {
|
|
|
|
pub enum En {
|
|
|
|
Variant {
|
2021-01-06 14:15:48 -06:00
|
|
|
field$0: u8,
|
2020-10-09 13:42:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn f() -> m::En {
|
|
|
|
m::En::Variant { field: 0 }
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
field Field FileId(0) 56..65 56..61
|
2020-10-09 13:42:17 -05:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 125..130 Read
|
2020-10-09 13:42:17 -05:00
|
|
|
"#]],
|
2020-11-28 15:55:34 -06:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_find_self_refs() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
struct Foo { bar: i32 }
|
|
|
|
|
|
|
|
impl Foo {
|
|
|
|
fn foo(self) {
|
2021-01-06 14:15:48 -06:00
|
|
|
let x = self$0.bar;
|
2020-11-28 15:55:34 -06:00
|
|
|
if true {
|
|
|
|
let _ = match () {
|
|
|
|
() => self,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
self SelfParam FileId(0) 47..51 47..51
|
2020-11-28 15:55:34 -06:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 71..75 Read
|
|
|
|
FileId(0) 152..156 Read
|
2020-11-28 15:55:34 -06:00
|
|
|
"#]],
|
2020-05-31 11:21:45 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-18 11:21:40 -06:00
|
|
|
#[test]
|
|
|
|
fn test_find_self_refs_decl() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
struct Foo { bar: i32 }
|
|
|
|
|
|
|
|
impl Foo {
|
|
|
|
fn foo(self$0) {
|
|
|
|
self;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
self SelfParam FileId(0) 47..51 47..51
|
2021-01-18 11:21:40 -06:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 63..67 Read
|
2021-01-18 11:21:40 -06:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-10-02 09:42:48 -05:00
|
|
|
fn check(ra_fixture: &str, expect: Expect) {
|
|
|
|
check_with_scope(ra_fixture, None, expect)
|
2019-03-25 15:03:32 -05:00
|
|
|
}
|
2020-01-08 15:35:58 -06:00
|
|
|
|
2020-10-02 09:13:48 -05:00
|
|
|
fn check_with_scope(ra_fixture: &str, search_scope: Option<SearchScope>, expect: Expect) {
|
2020-10-02 10:34:31 -05:00
|
|
|
let (analysis, pos) = fixture::position(ra_fixture);
|
2020-10-02 09:42:48 -05:00
|
|
|
let refs = analysis.find_all_refs(pos, search_scope).unwrap().unwrap();
|
2020-01-08 15:35:58 -06:00
|
|
|
|
2020-10-02 09:42:48 -05:00
|
|
|
let mut actual = String::new();
|
2021-09-01 11:17:32 -05:00
|
|
|
for refs in refs {
|
2020-10-02 09:42:48 -05:00
|
|
|
actual += "\n\n";
|
2020-01-09 15:27:10 -06:00
|
|
|
|
2021-09-01 11:17:32 -05:00
|
|
|
if let Some(decl) = refs.declaration {
|
|
|
|
format_to!(actual, "{}", decl.nav.debug_render());
|
2021-10-02 05:02:06 -05:00
|
|
|
if decl.is_mut {
|
|
|
|
format_to!(actual, " {:?}", ReferenceCategory::Write)
|
2021-01-11 17:05:07 -06:00
|
|
|
}
|
2021-09-01 11:17:32 -05:00
|
|
|
actual += "\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
for (file_id, references) in &refs.references {
|
|
|
|
for (range, access) in references {
|
|
|
|
format_to!(actual, "{:?} {:?}", file_id, range);
|
|
|
|
if let Some(access) = access {
|
|
|
|
format_to!(actual, " {:?}", access);
|
|
|
|
}
|
|
|
|
actual += "\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if refs.references.is_empty() {
|
|
|
|
actual += "(no references)\n";
|
2020-10-02 09:42:48 -05:00
|
|
|
}
|
2020-01-08 15:35:58 -06:00
|
|
|
}
|
2021-06-23 09:49:36 -05:00
|
|
|
expect.assert_eq(actual.trim_start())
|
2020-01-08 15:35:58 -06:00
|
|
|
}
|
2020-12-16 14:35:15 -06:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_find_lifetimes_function() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
trait Foo<'a> {}
|
|
|
|
impl<'a> Foo<'a> for &'a () {}
|
2021-01-06 14:15:48 -06:00
|
|
|
fn foo<'a, 'b: 'a>(x: &'a$0 ()) -> &'a () where &'a (): Foo<'a> {
|
2020-12-16 14:35:15 -06:00
|
|
|
fn bar<'a>(_: &'a ()) {}
|
|
|
|
x
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
'a LifetimeParam FileId(0) 55..57 55..57
|
2020-12-16 14:35:15 -06:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 63..65
|
|
|
|
FileId(0) 71..73
|
|
|
|
FileId(0) 82..84
|
|
|
|
FileId(0) 95..97
|
|
|
|
FileId(0) 106..108
|
2020-12-16 14:35:15 -06:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_find_lifetimes_type_alias() {
|
|
|
|
check(
|
|
|
|
r#"
|
2021-01-06 14:15:48 -06:00
|
|
|
type Foo<'a, T> where T: 'a$0 = &'a T;
|
2020-12-16 14:35:15 -06:00
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
'a LifetimeParam FileId(0) 9..11 9..11
|
2020-12-16 14:35:15 -06:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 25..27
|
|
|
|
FileId(0) 31..33
|
2020-12-16 14:35:15 -06:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_find_lifetimes_trait_impl() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
trait Foo<'a> {
|
|
|
|
fn foo() -> &'a ();
|
|
|
|
}
|
|
|
|
impl<'a> Foo<'a> for &'a () {
|
2021-01-06 14:15:48 -06:00
|
|
|
fn foo() -> &'a$0 () {
|
2020-12-16 14:35:15 -06:00
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
'a LifetimeParam FileId(0) 47..49 47..49
|
2020-12-16 14:35:15 -06:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 55..57
|
|
|
|
FileId(0) 64..66
|
|
|
|
FileId(0) 89..91
|
2020-12-16 14:35:15 -06:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
2020-12-21 10:18:26 -06:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_map_range_to_original() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
macro_rules! foo {($i:ident) => {$i} }
|
|
|
|
fn main() {
|
2021-01-06 14:15:48 -06:00
|
|
|
let a$0 = "test";
|
2020-12-21 10:18:26 -06:00
|
|
|
foo!(a);
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
a Local FileId(0) 59..60 59..60
|
2020-12-21 10:18:26 -06:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 80..81 Read
|
2020-12-21 10:18:26 -06:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_map_range_to_original_ref() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
macro_rules! foo {($i:ident) => {$i} }
|
|
|
|
fn main() {
|
|
|
|
let a = "test";
|
2021-01-06 14:15:48 -06:00
|
|
|
foo!(a$0);
|
2020-12-21 10:18:26 -06:00
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
a Local FileId(0) 59..60 59..60
|
2020-12-21 10:18:26 -06:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 80..81 Read
|
2020-12-21 10:18:26 -06:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
2020-12-23 10:15:01 -06:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_find_labels() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
fn foo<'a>() -> &'a () {
|
|
|
|
'a: loop {
|
|
|
|
'b: loop {
|
2021-01-06 14:15:48 -06:00
|
|
|
continue 'a$0;
|
2020-12-23 10:15:01 -06:00
|
|
|
}
|
|
|
|
break 'a;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
'a Label FileId(0) 29..32 29..31
|
2020-12-23 10:15:01 -06:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 80..82
|
|
|
|
FileId(0) 108..110
|
2020-12-23 10:15:01 -06:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
2021-01-01 03:07:01 -06:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_find_const_param() {
|
|
|
|
check(
|
|
|
|
r#"
|
2021-01-06 14:15:48 -06:00
|
|
|
fn foo<const FOO$0: usize>() -> usize {
|
2021-01-01 03:07:01 -06:00
|
|
|
FOO
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
FOO ConstParam FileId(0) 7..23 13..16
|
2021-01-01 03:07:01 -06:00
|
|
|
|
2021-02-07 11:38:12 -06:00
|
|
|
FileId(0) 42..45
|
2021-01-01 03:07:01 -06:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
2021-01-25 17:44:27 -06:00
|
|
|
|
|
|
|
#[test]
|
2021-05-08 16:30:19 -05:00
|
|
|
fn test_trait() {
|
2021-01-25 17:44:27 -06:00
|
|
|
check(
|
|
|
|
r#"
|
2021-05-08 16:30:19 -05:00
|
|
|
trait Foo$0 where Self: {}
|
|
|
|
|
|
|
|
impl Foo for () {}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
Foo Trait FileId(0) 0..24 6..9
|
|
|
|
|
|
|
|
FileId(0) 31..34
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_trait_self() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
trait Foo where Self$0 {
|
|
|
|
fn f() -> Self;
|
2021-01-25 17:44:27 -06:00
|
|
|
}
|
2021-05-08 16:30:19 -05:00
|
|
|
|
|
|
|
impl Foo for () {}
|
2021-01-25 17:44:27 -06:00
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-07 11:38:12 -06:00
|
|
|
Self TypeParam FileId(0) 6..9 6..9
|
2021-01-25 17:44:27 -06:00
|
|
|
|
2021-05-08 15:34:55 -05:00
|
|
|
FileId(0) 16..20
|
2021-05-08 16:30:19 -05:00
|
|
|
FileId(0) 37..41
|
2021-01-25 17:44:27 -06:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
2021-02-10 02:29:10 -06:00
|
|
|
|
2021-05-08 15:34:55 -05:00
|
|
|
#[test]
|
|
|
|
fn test_self_ty() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
struct $0Foo;
|
|
|
|
|
|
|
|
impl Foo where Self: {
|
|
|
|
fn f() -> Self;
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-05-08 16:30:19 -05:00
|
|
|
Foo Struct FileId(0) 0..11 7..10
|
2021-05-08 15:34:55 -05:00
|
|
|
|
2021-05-08 16:30:19 -05:00
|
|
|
FileId(0) 18..21
|
|
|
|
FileId(0) 28..32
|
|
|
|
FileId(0) 50..54
|
|
|
|
"#]],
|
2021-05-08 15:34:55 -05:00
|
|
|
);
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
struct Foo;
|
|
|
|
|
|
|
|
impl Foo where Self: {
|
|
|
|
fn f() -> Self$0;
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
impl Impl FileId(0) 13..57 18..21
|
|
|
|
|
|
|
|
FileId(0) 18..21
|
|
|
|
FileId(0) 28..32
|
|
|
|
FileId(0) 50..54
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
2021-02-10 02:29:10 -06:00
|
|
|
#[test]
|
|
|
|
fn test_self_variant_with_payload() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
enum Foo { Bar() }
|
|
|
|
|
|
|
|
impl Foo {
|
|
|
|
fn foo(self) {
|
|
|
|
match self {
|
|
|
|
Self::Bar$0() => (),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
2021-02-12 12:00:37 -06:00
|
|
|
Bar Variant FileId(0) 11..16 11..14
|
2021-02-10 02:29:10 -06:00
|
|
|
|
2021-02-12 12:00:37 -06:00
|
|
|
FileId(0) 89..92
|
2021-02-10 02:29:10 -06:00
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
2021-02-13 15:11:31 -06:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_attr_differs_from_fn_with_same_name() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
#[test]
|
|
|
|
fn test$0() {
|
|
|
|
test();
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
test Function FileId(0) 0..33 11..15
|
|
|
|
|
|
|
|
FileId(0) 24..28
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-02-23 16:31:07 -06:00
|
|
|
#[test]
|
|
|
|
fn test_const_in_pattern() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
const A$0: i32 = 42;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
match A {
|
|
|
|
A => (),
|
|
|
|
_ => (),
|
|
|
|
}
|
|
|
|
if let A = A {}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
A Const FileId(0) 0..18 6..7
|
|
|
|
|
|
|
|
FileId(0) 42..43
|
|
|
|
FileId(0) 54..55
|
|
|
|
FileId(0) 97..98
|
|
|
|
FileId(0) 101..102
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
2021-03-15 03:32:06 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_primitives() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
fn foo(_: bool) -> bo$0ol { true }
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
FileId(0) 10..14
|
|
|
|
FileId(0) 19..23
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
2021-03-15 11:43:46 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_transitive() {
|
|
|
|
check(
|
|
|
|
r#"
|
2021-07-23 12:57:16 -05:00
|
|
|
//- /level3.rs new_source_root:local crate:level3
|
2021-03-15 11:43:46 -05:00
|
|
|
pub struct Fo$0o;
|
2021-07-23 12:57:16 -05:00
|
|
|
//- /level2.rs new_source_root:local crate:level2 deps:level3
|
2021-03-15 11:43:46 -05:00
|
|
|
pub use level3::Foo;
|
2021-07-23 12:57:16 -05:00
|
|
|
//- /level1.rs new_source_root:local crate:level1 deps:level2
|
2021-03-15 11:43:46 -05:00
|
|
|
pub use level2::Foo;
|
2021-07-23 12:57:16 -05:00
|
|
|
//- /level0.rs new_source_root:local crate:level0 deps:level1
|
2021-03-15 11:43:46 -05:00
|
|
|
pub use level1::Foo;
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
Foo Struct FileId(0) 0..15 11..14
|
|
|
|
|
|
|
|
FileId(1) 16..19
|
|
|
|
FileId(2) 16..19
|
|
|
|
FileId(3) 16..19
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
2021-03-21 14:08:08 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_decl_macro_references() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- /lib.rs crate:lib
|
|
|
|
#[macro_use]
|
|
|
|
mod qux;
|
|
|
|
mod bar;
|
|
|
|
|
|
|
|
pub use self::foo;
|
|
|
|
//- /qux.rs
|
|
|
|
#[macro_export]
|
|
|
|
macro_rules! foo$0 {
|
|
|
|
() => {struct Foo;};
|
|
|
|
}
|
|
|
|
//- /bar.rs
|
|
|
|
foo!();
|
2021-07-23 12:57:16 -05:00
|
|
|
//- /other.rs crate:other deps:lib new_source_root:local
|
2021-03-21 14:08:08 -05:00
|
|
|
lib::foo!();
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
foo Macro FileId(1) 0..61 29..32
|
|
|
|
|
|
|
|
FileId(0) 46..49
|
|
|
|
FileId(2) 0..3
|
|
|
|
FileId(3) 5..8
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
2021-06-09 17:25:36 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn macro_doesnt_reference_attribute_on_call() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
macro_rules! m {
|
|
|
|
() => {};
|
|
|
|
}
|
|
|
|
|
|
|
|
#[proc_macro_test::attr_noop]
|
|
|
|
m$0!();
|
|
|
|
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
m Macro FileId(0) 0..32 13..14
|
|
|
|
|
|
|
|
FileId(0) 64..65
|
|
|
|
"#]],
|
|
|
|
);
|
|
|
|
}
|
2021-09-01 11:17:32 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn multi_def() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
macro_rules! m {
|
|
|
|
($name:ident) => {
|
|
|
|
mod module {
|
|
|
|
pub fn $name() {}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn $name() {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m!(func$0);
|
|
|
|
|
|
|
|
fn f() {
|
|
|
|
func();
|
|
|
|
module::func();
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
func Function FileId(0) 137..146 140..144
|
|
|
|
|
|
|
|
FileId(0) 161..165
|
|
|
|
|
|
|
|
|
|
|
|
func Function FileId(0) 137..146 140..144
|
|
|
|
|
|
|
|
FileId(0) 181..185
|
|
|
|
"#]],
|
|
|
|
)
|
|
|
|
}
|
2021-09-13 20:00:53 -05:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn attr_expanded() {
|
|
|
|
check(
|
|
|
|
r#"
|
|
|
|
//- proc_macros: identity
|
|
|
|
|
|
|
|
#[proc_macros::identity]
|
|
|
|
fn func$0() {
|
|
|
|
func();
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
expect![[r#"
|
|
|
|
func Function FileId(0) 26..51 29..33
|
|
|
|
|
|
|
|
FileId(0) 42..46
|
|
|
|
"#]],
|
|
|
|
)
|
|
|
|
}
|
2019-01-18 02:29:09 -06:00
|
|
|
}
|