mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 01:17:27 +00:00
add support for cfg feature attributes on expression #4063
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
This commit is contained in:
parent
05981823ba
commit
b87b335e68
2 changed files with 36 additions and 0 deletions
|
@ -141,6 +141,10 @@ impl ExprCollector<'_> {
|
|||
|
||||
fn collect_expr(&mut self, expr: ast::Expr) -> ExprId {
|
||||
let syntax_ptr = AstPtr::new(&expr);
|
||||
let attrs = self.expander.parse_attrs(&expr);
|
||||
if !self.expander.is_cfg_enabled(&attrs) {
|
||||
return self.missing_expr();
|
||||
}
|
||||
match expr {
|
||||
ast::Expr::IfExpr(e) => {
|
||||
let then_branch = self.collect_block_opt(e.then_branch());
|
||||
|
|
|
@ -390,6 +390,38 @@ fn no_such_field_with_feature_flag_diagnostics_on_struct_lit() {
|
|||
assert_snapshot!(diagnostics, @r###""###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_such_field_with_feature_flag_diagnostics_on_block_expr() {
|
||||
let diagnostics = TestDB::with_files(
|
||||
r#"
|
||||
//- /lib.rs crate:foo cfg:feature=foo
|
||||
struct S {
|
||||
#[cfg(feature = "foo")]
|
||||
foo: u32,
|
||||
#[cfg(not(feature = "foo"))]
|
||||
bar: u32,
|
||||
}
|
||||
|
||||
impl S {
|
||||
fn new(bar: u32) -> Self {
|
||||
#[cfg(feature = "foo")]
|
||||
{
|
||||
Self { foo: bar }
|
||||
}
|
||||
#[cfg(not(feature = "foo"))]
|
||||
{
|
||||
Self { bar }
|
||||
}
|
||||
}
|
||||
}
|
||||
"#,
|
||||
)
|
||||
.diagnostics()
|
||||
.0;
|
||||
|
||||
assert_snapshot!(diagnostics, @r###""###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_such_field_with_feature_flag_diagnostics_on_struct_fields() {
|
||||
let diagnostics = TestDB::with_files(
|
||||
|
|
Loading…
Reference in a new issue