mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
fix error on wrong path
This commit is contained in:
parent
0d6b8baa89
commit
c51a6a7bdd
4 changed files with 42 additions and 11 deletions
|
@ -1,4 +1,5 @@
|
|||
test_utils::marks!(
|
||||
bogus_paths
|
||||
name_res_works_for_broken_modules
|
||||
can_import_enum_variant
|
||||
type_var_cycles_resolve_completely
|
||||
|
|
|
@ -213,7 +213,8 @@ where
|
|||
}
|
||||
}
|
||||
} else {
|
||||
let last_segment = import.path.segments.last().unwrap();
|
||||
match import.path.segments.last() {
|
||||
Some(last_segment) => {
|
||||
let name = import.alias.clone().unwrap_or_else(|| last_segment.name.clone());
|
||||
log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def);
|
||||
|
||||
|
@ -226,6 +227,9 @@ where
|
|||
let resolution = Resolution { def, import: Some(import_id) };
|
||||
self.update(module_id, Some(import_id), &[(name, resolution)]);
|
||||
}
|
||||
None => tested_by!(bogus_paths),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn update(
|
||||
|
|
|
@ -96,6 +96,32 @@ E: t
|
|||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bogus_paths() {
|
||||
covers!(bogus_paths);
|
||||
let map = def_map(
|
||||
"
|
||||
//- /lib.rs
|
||||
mod foo;
|
||||
struct S;
|
||||
use self;
|
||||
|
||||
//- /foo/mod.rs
|
||||
use super;
|
||||
use crate;
|
||||
|
||||
",
|
||||
);
|
||||
assert_snapshot_matches!(map, @r###"
|
||||
crate
|
||||
foo: t
|
||||
S: t v
|
||||
|
||||
crate::foo
|
||||
"###
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn use_as() {
|
||||
let map = def_map(
|
||||
|
|
|
@ -30,13 +30,13 @@ use std::sync::atomic::{AtomicUsize, Ordering};
|
|||
|
||||
#[macro_export]
|
||||
macro_rules! tested_by {
|
||||
($ident:ident) => {
|
||||
($ident:ident) => {{
|
||||
#[cfg(test)]
|
||||
{
|
||||
// sic! use call-site crate
|
||||
crate::marks::$ident.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
||||
}
|
||||
};
|
||||
}};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
|
|
Loading…
Reference in a new issue