mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +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,18 +213,22 @@ where
|
|||
}
|
||||
}
|
||||
} else {
|
||||
let last_segment = import.path.segments.last().unwrap();
|
||||
let name = import.alias.clone().unwrap_or_else(|| last_segment.name.clone());
|
||||
log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def);
|
||||
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);
|
||||
|
||||
// extern crates in the crate root are special-cased to insert entries into the extern prelude: rust-lang/rust#54658
|
||||
if import.is_extern_crate && module_id == self.def_map.root {
|
||||
if let Some(def) = def.take_types() {
|
||||
self.def_map.extern_prelude.insert(name.clone(), def);
|
||||
// extern crates in the crate root are special-cased to insert entries into the extern prelude: rust-lang/rust#54658
|
||||
if import.is_extern_crate && module_id == self.def_map.root {
|
||||
if let Some(def) = def.take_types() {
|
||||
self.def_map.extern_prelude.insert(name.clone(), def);
|
||||
}
|
||||
}
|
||||
let resolution = Resolution { def, import: Some(import_id) };
|
||||
self.update(module_id, Some(import_id), &[(name, resolution)]);
|
||||
}
|
||||
None => tested_by!(bogus_paths),
|
||||
}
|
||||
let resolution = Resolution { def, import: Some(import_id) };
|
||||
self.update(module_id, Some(import_id), &[(name, resolution)]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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