mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 05:38:46 +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!(
|
test_utils::marks!(
|
||||||
|
bogus_paths
|
||||||
name_res_works_for_broken_modules
|
name_res_works_for_broken_modules
|
||||||
can_import_enum_variant
|
can_import_enum_variant
|
||||||
type_var_cycles_resolve_completely
|
type_var_cycles_resolve_completely
|
||||||
|
|
|
@ -213,18 +213,22 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let last_segment = import.path.segments.last().unwrap();
|
match import.path.segments.last() {
|
||||||
let name = import.alias.clone().unwrap_or_else(|| last_segment.name.clone());
|
Some(last_segment) => {
|
||||||
log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def);
|
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
|
// 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 import.is_extern_crate && module_id == self.def_map.root {
|
||||||
if let Some(def) = def.take_types() {
|
if let Some(def) = def.take_types() {
|
||||||
self.def_map.extern_prelude.insert(name.clone(), def);
|
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]
|
#[test]
|
||||||
fn use_as() {
|
fn use_as() {
|
||||||
let map = def_map(
|
let map = def_map(
|
||||||
|
|
|
@ -30,13 +30,13 @@ use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! tested_by {
|
macro_rules! tested_by {
|
||||||
($ident:ident) => {
|
($ident:ident) => {{
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
{
|
{
|
||||||
// sic! use call-site crate
|
// sic! use call-site crate
|
||||||
crate::marks::$ident.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
crate::marks::$ident.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
||||||
}
|
}
|
||||||
};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
|
|
Loading…
Reference in a new issue