mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 04:44:57 +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,13 +656,18 @@ impl DefCollector<'_> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match import.path.segments().last() {
|
|
||||||
Some(last_segment) => {
|
|
||||||
let name = match &import.alias {
|
let name = match &import.alias {
|
||||||
Some(ImportAlias::Alias(name)) => Some(name.clone()),
|
Some(ImportAlias::Alias(name)) => Some(name.clone()),
|
||||||
Some(ImportAlias::Underscore) => None,
|
Some(ImportAlias::Underscore) => None,
|
||||||
None => Some(last_segment.clone()),
|
None => match import.path.segments().last() {
|
||||||
|
Some(last_segment) => Some(last_segment.clone()),
|
||||||
|
None => {
|
||||||
|
cov_mark::hit!(bogus_paths);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
log::debug!("resolved import {:?} ({:?}) to {:?}", name, import, def);
|
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
|
||||||
|
@ -674,9 +679,6 @@ impl DefCollector<'_> {
|
||||||
|
|
||||||
self.update(module_id, &[(name, def)], vis, ImportType::Named);
|
self.update(module_id, &[(name, def)], vis, ImportType::Named);
|
||||||
}
|
}
|
||||||
None => cov_mark::hit!(bogus_paths),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(
|
fn update(
|
||||||
|
|
|
@ -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