From d82292e1ce8112cfa5e42d0221a563649d067747 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 10 Dec 2020 15:45:01 +0100 Subject: Ignore extern items in incorrect-case check --- crates/hir_def/src/data.rs | 4 ++++ crates/hir_def/src/item_tree.rs | 5 +++++ crates/hir_def/src/item_tree/lower.rs | 13 ++++++++----- crates/hir_ty/src/diagnostics/decl_check.rs | 19 +++++++++++++++++++ 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/crates/hir_def/src/data.rs b/crates/hir_def/src/data.rs index 146045938..dd3a906af 100644 --- a/crates/hir_def/src/data.rs +++ b/crates/hir_def/src/data.rs @@ -28,6 +28,7 @@ pub struct FunctionData { pub has_body: bool, pub is_unsafe: bool, pub is_varargs: bool, + pub is_extern: bool, pub visibility: RawVisibility, } @@ -46,6 +47,7 @@ impl FunctionData { has_body: func.has_body, is_unsafe: func.is_unsafe, is_varargs: func.is_varargs, + is_extern: func.is_extern, visibility: item_tree[func.visibility].clone(), }) } @@ -191,6 +193,7 @@ pub struct StaticData { pub type_ref: TypeRef, pub visibility: RawVisibility, pub mutable: bool, + pub is_extern: bool, } impl StaticData { @@ -204,6 +207,7 @@ impl StaticData { type_ref: statik.type_ref.clone(), visibility: item_tree[statik.visibility].clone(), mutable: statik.mutable, + is_extern: statik.is_extern, }) } } diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index 7eb388bae..b3ec252fd 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs @@ -507,6 +507,9 @@ pub struct Function { pub has_self_param: bool, pub has_body: bool, pub is_unsafe: bool, + /// Whether the function is located in an `extern` block (*not* whether it is an + /// `extern "abi" fn`). + pub is_extern: bool, pub params: Box<[TypeRef]>, pub is_varargs: bool, pub ret_type: TypeRef, @@ -565,6 +568,8 @@ pub struct Static { pub name: Name, pub visibility: RawVisibilityId, pub mutable: bool, + /// Whether the static is in an `extern` block. + pub is_extern: bool, pub type_ref: TypeRef, pub ast_id: FileAstId, } diff --git a/crates/hir_def/src/item_tree/lower.rs b/crates/hir_def/src/item_tree/lower.rs index ca7fb4a43..63b2826f8 100644 --- a/crates/hir_def/src/item_tree/lower.rs +++ b/crates/hir_def/src/item_tree/lower.rs @@ -340,6 +340,7 @@ impl Ctx { has_self_param, has_body, is_unsafe: func.unsafe_token().is_some(), + is_extern: false, params: params.into_boxed_slice(), is_varargs, ret_type, @@ -378,7 +379,7 @@ impl Ctx { let visibility = self.lower_visibility(static_); let mutable = static_.mut_token().is_some(); let ast_id = self.source_ast_id_map.ast_id(static_); - let res = Static { name, visibility, mutable, type_ref, ast_id }; + let res = Static { name, visibility, mutable, type_ref, ast_id, is_extern: false }; Some(id(self.data().statics.alloc(res))) } @@ -554,13 +555,15 @@ impl Ctx { let attrs = Attrs::new(&item, &self.hygiene); let id: ModItem = match item { ast::ExternItem::Fn(ast) => { - let func = self.lower_function(&ast)?; - self.data().functions[func.index].is_unsafe = - is_intrinsic_fn_unsafe(&self.data().functions[func.index].name); - func.into() + let func_id = self.lower_function(&ast)?; + let func = &mut self.data().functions[func_id.index]; + func.is_unsafe = is_intrinsic_fn_unsafe(&func.name); + func.is_extern = true; + func_id.into() } ast::ExternItem::Static(ast) => { let statik = self.lower_static(&ast)?; + self.data().statics[statik.index].is_extern = true; statik.into() } ast::ExternItem::TypeAlias(ty) => { diff --git a/crates/hir_ty/src/diagnostics/decl_check.rs b/crates/hir_ty/src/diagnostics/decl_check.rs index 4b3e2fa8f..724bad867 100644 --- a/crates/hir_ty/src/diagnostics/decl_check.rs +++ b/crates/hir_ty/src/diagnostics/decl_check.rs @@ -87,6 +87,10 @@ impl<'a, 'b> DeclValidator<'a, 'b> { fn validate_func(&mut self, db: &dyn HirDatabase, func: FunctionId) { let data = db.function_data(func); + if data.is_extern { + return; + } + let body = db.body(func.into()); // Recursively validate inner scope items, such as static variables and constants. @@ -648,6 +652,9 @@ impl<'a, 'b> DeclValidator<'a, 'b> { fn validate_static(&mut self, db: &dyn HirDatabase, static_id: StaticId) { let data = db.static_data(static_id); + if data.is_extern { + return; + } if self.allowed(db, static_id.into(), allow::NON_UPPER_CASE_GLOBAL) { return; @@ -920,4 +927,16 @@ fn main() { "#, ); } + + #[test] + fn ignores_extern_items() { + check_diagnostics( + r#" +extern { + fn NonSnakeCaseName(SOME_VAR: u8) -> u8; + pub static SomeStatic: u8 = 10; +} + "#, + ); + } } -- cgit v1.2.3 From d338513e95d8180702c59c4b1c95540331191a68 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 10 Dec 2020 15:53:48 +0100 Subject: Remove item tree tests They were useful during initial development of the item tree, but now just cause churn --- crates/hir_def/src/item_tree.rs | 2 - crates/hir_def/src/item_tree/tests.rs | 439 ---------------------------------- 2 files changed, 441 deletions(-) delete mode 100644 crates/hir_def/src/item_tree/tests.rs diff --git a/crates/hir_def/src/item_tree.rs b/crates/hir_def/src/item_tree.rs index b3ec252fd..c017b352d 100644 --- a/crates/hir_def/src/item_tree.rs +++ b/crates/hir_def/src/item_tree.rs @@ -1,8 +1,6 @@ //! A simplified AST that only contains items. mod lower; -#[cfg(test)] -mod tests; use std::{ any::type_name, diff --git a/crates/hir_def/src/item_tree/tests.rs b/crates/hir_def/src/item_tree/tests.rs deleted file mode 100644 index 4b354c4c1..000000000 --- a/crates/hir_def/src/item_tree/tests.rs +++ /dev/null @@ -1,439 +0,0 @@ -use base_db::fixture::WithFixture; -use expect_test::{expect, Expect}; -use hir_expand::{db::AstDatabase, HirFileId, InFile}; -use rustc_hash::FxHashSet; -use std::sync::Arc; -use stdx::format_to; -use syntax::{ast, AstNode}; - -use crate::{db::DefDatabase, test_db::TestDB}; - -use super::{ItemTree, ModItem, ModKind}; - -fn test_inner_items(ra_fixture: &str) { - let (db, file_id) = TestDB::with_single_file(ra_fixture); - let file_id = HirFileId::from(file_id); - let tree = db.item_tree(file_id); - let root = db.parse_or_expand(file_id).unwrap(); - let ast_id_map = db.ast_id_map(file_id); - - // Traverse the item tree and collect all module/impl/trait-level items as AST nodes. - let mut outer_items = FxHashSet::default(); - let mut worklist = tree.top_level_items().to_vec(); - while let Some(item) = worklist.pop() { - let node: ast::Item = match item { - ModItem::Import(it) => tree.source(&db, InFile::new(file_id, it)).into(), - ModItem::ExternCrate(it) => tree.source(&db, InFile::new(file_id, it)).into(), - ModItem::Function(it) => tree.source(&db, InFile::new(file_id, it)).into(), - ModItem::Struct(it) => tree.source(&db, InFile::new(file_id, it)).into(), - ModItem::Union(it) => tree.source(&db, InFile::new(file_id, it)).into(), - ModItem::Enum(it) => tree.source(&db, InFile::new(file_id, it)).into(), - ModItem::Const(it) => tree.source(&db, InFile::new(file_id, it)).into(), - ModItem::Static(it) => tree.source(&db, InFile::new(file_id, it)).into(), - ModItem::TypeAlias(it) => tree.source(&db, InFile::new(file_id, it)).into(), - ModItem::Mod(it) => { - if let ModKind::Inline { items } = &tree[it].kind { - worklist.extend(&**items); - } - tree.source(&db, InFile::new(file_id, it)).into() - } - ModItem::Trait(it) => { - worklist.extend(tree[it].items.iter().map(|item| ModItem::from(*item))); - tree.source(&db, InFile::new(file_id, it)).into() - } - ModItem::Impl(it) => { - worklist.extend(tree[it].items.iter().map(|item| ModItem::from(*item))); - tree.source(&db, InFile::new(file_id, it)).into() - } - ModItem::MacroCall(_) => continue, - }; - - outer_items.insert(node); - } - - // Now descend the root node and check that all `ast::ModuleItem`s are either recorded above, or - // registered as inner items. - for item in root.descendants().skip(1).filter_map(ast::Item::cast) { - if outer_items.contains(&item) { - continue; - } - - let ast_id = ast_id_map.ast_id(&item); - assert!(!tree.inner_items(ast_id).is_empty()); - } -} - -fn item_tree(ra_fixture: &str) -> Arc { - let (db, file_id) = TestDB::with_single_file(ra_fixture); - db.item_tree(file_id.into()) -} - -fn print_item_tree(ra_fixture: &str) -> String { - let tree = item_tree(ra_fixture); - let mut out = String::new(); - - format_to!(out, "inner attrs: {:?}\n\n", tree.top_level_attrs()); - format_to!(out, "top-level items:\n"); - for item in tree.top_level_items() { - fmt_mod_item(&mut out, &tree, *item); - format_to!(out, "\n"); - } - - if !tree.inner_items.is_empty() { - format_to!(out, "\ninner items:\n\n"); - for (ast_id, items) in &tree.inner_items { - format_to!(out, "for AST {:?}:\n", ast_id); - for inner in items { - fmt_mod_item(&mut out, &tree, *inner); - format_to!(out, "\n\n"); - } - } - } - - out -} - -fn fmt_mod_item(out: &mut String, tree: &ItemTree, item: ModItem) { - let attrs = tree.attrs(item.into()); - if !attrs.is_empty() { - format_to!(out, "#[{:?}]\n", attrs); - } - - let mut children = String::new(); - match item { - ModItem::ExternCrate(it) => { - format_to!(out, "{:?}", tree[it]); - } - ModItem::Import(it) => { - format_to!(out, "{:?}", tree[it]); - } - ModItem::Function(it) => { - format_to!(out, "{:?}", tree[it]); - } - ModItem::Struct(it) => { - format_to!(out, "{:?}", tree[it]); - } - ModItem::Union(it) => { - format_to!(out, "{:?}", tree[it]); - } - ModItem::Enum(it) => { - format_to!(out, "{:?}", tree[it]); - } - ModItem::Const(it) => { - format_to!(out, "{:?}", tree[it]); - } - ModItem::Static(it) => { - format_to!(out, "{:?}", tree[it]); - } - ModItem::Trait(it) => { - format_to!(out, "{:?}", tree[it]); - for item in &*tree[it].items { - fmt_mod_item(&mut children, tree, ModItem::from(*item)); - format_to!(children, "\n"); - } - } - ModItem::Impl(it) => { - format_to!(out, "{:?}", tree[it]); - for item in &*tree[it].items { - fmt_mod_item(&mut children, tree, ModItem::from(*item)); - format_to!(children, "\n"); - } - } - ModItem::TypeAlias(it) => { - format_to!(out, "{:?}", tree[it]); - } - ModItem::Mod(it) => { - format_to!(out, "{:?}", tree[it]); - match &tree[it].kind { - ModKind::Inline { items } => { - for item in &**items { - fmt_mod_item(&mut children, tree, *item); - format_to!(children, "\n"); - } - } - ModKind::Outline {} => {} - } - } - ModItem::MacroCall(it) => { - format_to!(out, "{:?}", tree[it]); - } - } - - for line in children.lines() { - format_to!(out, "\n> {}", line); - } -} - -fn check(ra_fixture: &str, expect: Expect) { - let actual = print_item_tree(ra_fixture); - expect.assert_eq(&actual); -} - -#[test] -fn smoke() { - check( - r" - #![attr] - - #[attr_on_use] - use {a, b::*}; - - #[ext_crate] - extern crate krate; - - #[on_trait] - trait Tr { - #[assoc_ty] - type AssocTy: Tr<()>; - - #[assoc_const] - const CONST: u8; - - #[assoc_method] - fn method(&self); - - #[assoc_dfl_method] - fn dfl_method(&mut self) {} - } - - #[struct0] - struct Struct0; - - #[struct1] - struct Struct1(#[struct1fld] u8); - - #[struct2] - struct Struct2 { - #[struct2fld] - fld: (T, ), - } - - #[en] - enum En { - #[enum_variant] - Variant { - #[enum_field] - field: u8, - }, - } - - #[un] - union Un { - #[union_fld] - fld: u16, - } - ", - expect![[r##" - inner attrs: Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr"))] }, input: None }]) } - - top-level items: - #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }] - Import { path: ModPath { kind: Plain, segments: [Name(Text("a"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: false, is_prelude: false, ast_id: FileAstId::(0), index: 0 } - #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_on_use"))] }, input: None }]) }] - Import { path: ModPath { kind: Plain, segments: [Name(Text("b"))] }, alias: None, visibility: RawVisibilityId("pub(self)"), is_glob: true, is_prelude: false, ast_id: FileAstId::(0), index: 1 } - #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("ext_crate"))] }, input: None }]) }] - ExternCrate { name: Name(Text("krate")), alias: None, visibility: RawVisibilityId("pub(self)"), is_macro_use: false, ast_id: FileAstId::(1) } - #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_trait"))] }, input: None }]) }] - Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [TypeAlias(Idx::(0)), Const(Idx::(0)), Function(Idx::(0)), Function(Idx::(1))], ast_id: FileAstId::(2) } - > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_ty"))] }, input: None }]) }] - > TypeAlias { name: Name(Text("AssocTy")), visibility: RawVisibilityId("pub(self)"), bounds: [Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Tr"))] }, generic_args: [Some(GenericArgs { args: [Type(Tuple([]))], has_self_type: false, bindings: [] })] })], generic_params: GenericParamsId(4294967295), type_ref: None, is_extern: false, ast_id: FileAstId::(8) } - > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_const"))] }, input: None }]) }] - > Const { name: Some(Name(Text("CONST"))), visibility: RawVisibilityId("pub(self)"), type_ref: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("u8"))] }, generic_args: [None] }), ast_id: FileAstId::(9) } - > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_method"))] }, input: None }]) }] - > Function { name: Name(Text("method")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: true, has_body: false, is_unsafe: false, params: [Reference(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Self"))] }, generic_args: [None] }), Shared)], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::(10) } - > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("assoc_dfl_method"))] }, input: None }]) }] - > Function { name: Name(Text("dfl_method")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: true, has_body: true, is_unsafe: false, params: [Reference(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Self"))] }, generic_args: [None] }), Mut)], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::(11) } - #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("struct0"))] }, input: None }]) }] - Struct { name: Name(Text("Struct0")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(1), fields: Unit, ast_id: FileAstId::(3), kind: Unit } - #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("struct1"))] }, input: None }]) }] - Struct { name: Name(Text("Struct1")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(2), fields: Tuple(IdRange::(0..1)), ast_id: FileAstId::(4), kind: Tuple } - #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("struct2"))] }, input: None }]) }] - Struct { name: Name(Text("Struct2")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(3), fields: Record(IdRange::(1..2)), ast_id: FileAstId::(5), kind: Record } - #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("en"))] }, input: None }]) }] - Enum { name: Name(Text("En")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), variants: IdRange::(0..1), ast_id: FileAstId::(6) } - #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("un"))] }, input: None }]) }] - Union { name: Name(Text("Un")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), fields: Record(IdRange::(3..4)), ast_id: FileAstId::(7) } - "##]], - ); -} - -#[test] -fn simple_inner_items() { - check( - r" - impl D for Response { - fn foo() { - end(); - fn end() { - let _x: T = loop {}; - } - } - } - ", - expect![[r#" - inner attrs: Attrs { entries: None } - - top-level items: - Impl { generic_params: GenericParamsId(0), target_trait: Some(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("D"))] }, generic_args: [None] })), target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Response"))] }, generic_args: [Some(GenericArgs { args: [Type(Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("T"))] }, generic_args: [None] }))], has_self_type: false, bindings: [] })] }), is_negative: false, items: [Function(Idx::(1))], ast_id: FileAstId::(0) } - > Function { name: Name(Text("foo")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, has_body: true, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::(1) } - - inner items: - - for AST FileAstId::(2): - Function { name: Name(Text("end")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(1), has_self_param: false, has_body: true, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::(2) } - - "#]], - ); -} - -#[test] -fn extern_attrs() { - check( - r#" - #[block_attr] - extern "C" { - #[attr_a] - fn a() {} - #[attr_b] - fn b() {} - } - "#, - expect![[r##" - inner attrs: Attrs { entries: None } - - top-level items: - #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }, Attr { path: ModPath { kind: Plain, segments: [Name(Text("block_attr"))] }, input: None }]) }] - Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, has_body: true, is_unsafe: true, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::(1) } - #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }, Attr { path: ModPath { kind: Plain, segments: [Name(Text("block_attr"))] }, input: None }]) }] - Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, has_body: true, is_unsafe: true, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::(2) } - "##]], - ); -} - -#[test] -fn trait_attrs() { - check( - r#" - #[trait_attr] - trait Tr { - #[attr_a] - fn a() {} - #[attr_b] - fn b() {} - } - "#, - expect![[r##" - inner attrs: Attrs { entries: None } - - top-level items: - #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("trait_attr"))] }, input: None }]) }] - Trait { name: Name(Text("Tr")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(0), auto: false, items: [Function(Idx::(0)), Function(Idx::(1))], ast_id: FileAstId::(0) } - > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }]) }] - > Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, has_body: true, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::(1) } - > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }]) }] - > Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, has_body: true, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::(2) } - "##]], - ); -} - -#[test] -fn impl_attrs() { - check( - r#" - #[impl_attr] - impl Ty { - #[attr_a] - fn a() {} - #[attr_b] - fn b() {} - } - "#, - expect![[r##" - inner attrs: Attrs { entries: None } - - top-level items: - #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("impl_attr"))] }, input: None }]) }] - Impl { generic_params: GenericParamsId(4294967295), target_trait: None, target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("Ty"))] }, generic_args: [None] }), is_negative: false, items: [Function(Idx::(0)), Function(Idx::(1))], ast_id: FileAstId::(0) } - > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_a"))] }, input: None }]) }] - > Function { name: Name(Text("a")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, has_body: true, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::(1) } - > #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("attr_b"))] }, input: None }]) }] - > Function { name: Name(Text("b")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, has_body: true, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::(2) } - "##]], - ); -} - -#[test] -fn cursed_inner_items() { - test_inner_items( - r" - struct S(T); - - enum En { - Var1 { - t: [(); { trait Inner {} 0 }], - }, - - Var2([u16; { enum Inner {} 0 }]), - } - - type Ty = [En; { struct Inner; 0 }]; - - impl En { - fn assoc() { - trait InnerTrait {} - struct InnerStruct {} - impl InnerTrait for InnerStruct {} - } - } - - trait Tr { - type AssocTy = [u8; { fn f() {} }]; - - const AssocConst: [u8; { fn f() {} }]; - } - ", - ); -} - -#[test] -fn inner_item_attrs() { - check( - r" - fn foo() { - #[on_inner] - fn inner() {} - } - ", - expect![[r##" - inner attrs: Attrs { entries: None } - - top-level items: - Function { name: Name(Text("foo")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, has_body: true, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::(0) } - - inner items: - - for AST FileAstId::(1): - #[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_inner"))] }, input: None }]) }] - Function { name: Name(Text("inner")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, has_body: true, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::(1) } - - "##]], - ); -} - -#[test] -fn assoc_item_macros() { - check( - r" - impl S { - items!(); - } - ", - expect![[r#" - inner attrs: Attrs { entries: None } - - top-level items: - Impl { generic_params: GenericParamsId(4294967295), target_trait: None, target_type: Path(Path { type_anchor: None, mod_path: ModPath { kind: Plain, segments: [Name(Text("S"))] }, generic_args: [None] }), is_negative: false, items: [MacroCall(Idx::(0))], ast_id: FileAstId::(0) } - > MacroCall { name: None, path: ModPath { kind: Plain, segments: [Name(Text("items"))] }, is_export: false, is_local_inner: false, is_builtin: false, ast_id: FileAstId::(1) } - "#]], - ); -} -- cgit v1.2.3 From 05d4a5a1507673281cc2d9caad7cb9474379c3d9 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Thu, 10 Dec 2020 15:56:04 +0100 Subject: Use mark/hit --- crates/hir_ty/src/diagnostics/decl_check.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/hir_ty/src/diagnostics/decl_check.rs b/crates/hir_ty/src/diagnostics/decl_check.rs index 724bad867..25587e116 100644 --- a/crates/hir_ty/src/diagnostics/decl_check.rs +++ b/crates/hir_ty/src/diagnostics/decl_check.rs @@ -26,6 +26,7 @@ use syntax::{ ast::{self, NameOwner}, AstNode, AstPtr, }; +use test_utils::mark; use crate::{ db::HirDatabase, @@ -88,6 +89,7 @@ impl<'a, 'b> DeclValidator<'a, 'b> { fn validate_func(&mut self, db: &dyn HirDatabase, func: FunctionId) { let data = db.function_data(func); if data.is_extern { + mark::hit!(extern_func_incorrect_case_ignored); return; } @@ -653,6 +655,7 @@ impl<'a, 'b> DeclValidator<'a, 'b> { fn validate_static(&mut self, db: &dyn HirDatabase, static_id: StaticId) { let data = db.static_data(static_id); if data.is_extern { + mark::hit!(extern_static_incorrect_case_ignored); return; } @@ -716,6 +719,8 @@ fn pat_equals_to_name(pat: Option, name: &Name) -> bool { #[cfg(test)] mod tests { + use test_utils::mark; + use crate::diagnostics::tests::check_diagnostics; #[test] @@ -930,6 +935,8 @@ fn main() { #[test] fn ignores_extern_items() { + mark::check!(extern_func_incorrect_case_ignored); + mark::check!(extern_static_incorrect_case_ignored); check_diagnostics( r#" extern { -- cgit v1.2.3