mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 12:54:58 +00:00
Fix use crate as <name>;
imports
This commit is contained in:
parent
9d691530d5
commit
a54564378b
2 changed files with 37 additions and 16 deletions
|
@ -656,26 +656,28 @@ impl DefCollector<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match import.path.segments().last() {
|
let name = match &import.alias {
|
||||||
Some(last_segment) => {
|
Some(ImportAlias::Alias(name)) => Some(name.clone()),
|
||||||
let name = match &import.alias {
|
Some(ImportAlias::Underscore) => None,
|
||||||
Some(ImportAlias::Alias(name)) => Some(name.clone()),
|
None => match import.path.segments().last() {
|
||||||
Some(ImportAlias::Underscore) => None,
|
Some(last_segment) => Some(last_segment.clone()),
|
||||||
None => Some(last_segment.clone()),
|
None => {
|
||||||
};
|
cov_mark::hit!(bogus_paths);
|
||||||
log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def);
|
return;
|
||||||
|
|
||||||
// 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), Some(name)) = (def.take_types(), name.as_ref()) {
|
|
||||||
self.def_map.extern_prelude.insert(name.clone(), def);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
self.update(module_id, &[(name, def)], vis, ImportType::Named);
|
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), Some(name)) = (def.take_types(), name.as_ref()) {
|
||||||
|
self.def_map.extern_prelude.insert(name.clone(), def);
|
||||||
}
|
}
|
||||||
None => cov_mark::hit!(bogus_paths),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.update(module_id, &[(name, def)], vis, ImportType::Named);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -713,3 +713,22 @@ pub fn f() {}
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn use_crate_as() {
|
||||||
|
check(
|
||||||
|
r#"
|
||||||
|
use crate as foo;
|
||||||
|
|
||||||
|
use foo::bar as baz;
|
||||||
|
|
||||||
|
fn bar() {}
|
||||||
|
"#,
|
||||||
|
expect![[r#"
|
||||||
|
crate
|
||||||
|
bar: v
|
||||||
|
baz: v
|
||||||
|
foo: t
|
||||||
|
"#]],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue