mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-16 13:30:56 +00:00
Merge 9358354c5a
into f8fdf544e4
This commit is contained in:
commit
ada177d8d7
2 changed files with 17 additions and 13 deletions
|
@ -81,7 +81,7 @@ impl ImportScope {
|
||||||
) -> Option<Self> {
|
) -> Option<Self> {
|
||||||
// The closest block expression ancestor
|
// The closest block expression ancestor
|
||||||
let mut block = None;
|
let mut block = None;
|
||||||
let mut required_cfgs = Vec::new();
|
let mut required_cfgs: Vec<ast::Attr> = Vec::new();
|
||||||
// Walk up the ancestor tree searching for a suitable node to do insertions on
|
// Walk up the ancestor tree searching for a suitable node to do insertions on
|
||||||
// with special handling on cfg-gated items, in which case we want to insert imports locally
|
// with special handling on cfg-gated items, in which case we want to insert imports locally
|
||||||
// or FIXME: annotate inserted imports with the same cfg
|
// or FIXME: annotate inserted imports with the same cfg
|
||||||
|
@ -113,9 +113,14 @@ impl ImportScope {
|
||||||
required_cfgs,
|
required_cfgs,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
required_cfgs.extend(has_attrs.attrs().filter(|attr| {
|
let mut attrs: Vec<ast::Attr> = has_attrs
|
||||||
|
.attrs()
|
||||||
|
.filter(|attr| {
|
||||||
attr.as_simple_call().is_some_and(|(ident, _)| ident == "cfg")
|
attr.as_simple_call().is_some_and(|(ident, _)| ident == "cfg")
|
||||||
}));
|
})
|
||||||
|
.collect();
|
||||||
|
attrs.append(&mut required_cfgs);
|
||||||
|
required_cfgs = attrs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -194,12 +199,8 @@ fn insert_use_with_alias_option(
|
||||||
use_tree = use_tree.clone_for_update();
|
use_tree = use_tree.clone_for_update();
|
||||||
use_tree.wrap_in_tree_list();
|
use_tree.wrap_in_tree_list();
|
||||||
}
|
}
|
||||||
let use_item = make::use_(None, None, use_tree).clone_for_update();
|
|
||||||
for attr in
|
let use_item = make::use_(scope.required_cfgs.clone(), None, use_tree).clone_for_update();
|
||||||
scope.required_cfgs.iter().map(|attr| attr.syntax().clone_subtree().clone_for_update())
|
|
||||||
{
|
|
||||||
ted::insert(ted::Position::first_child_of(use_item.syntax()), attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
// merge into existing imports if possible
|
// merge into existing imports if possible
|
||||||
if let Some(mb) = mb {
|
if let Some(mb) = mb {
|
||||||
|
|
|
@ -101,20 +101,23 @@ fn respects_cfg_attr_multiple_layers() {
|
||||||
check(
|
check(
|
||||||
r"bar::Bar",
|
r"bar::Bar",
|
||||||
r#"
|
r#"
|
||||||
#[cfg(test)]
|
#[cfg(test1)]
|
||||||
impl () {
|
impl () {
|
||||||
#[cfg(test2)]
|
#[cfg(test2)]
|
||||||
|
#[cfg(test3)]
|
||||||
fn f($0) {}
|
fn f($0) {}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
r#"
|
r#"
|
||||||
#[cfg(test)]
|
#[cfg(test1)]
|
||||||
#[cfg(test2)]
|
#[cfg(test2)]
|
||||||
|
#[cfg(test3)]
|
||||||
use bar::Bar;
|
use bar::Bar;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test1)]
|
||||||
impl () {
|
impl () {
|
||||||
#[cfg(test2)]
|
#[cfg(test2)]
|
||||||
|
#[cfg(test3)]
|
||||||
fn f() {}
|
fn f() {}
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue