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 ++++++++----- 3 files changed, 17 insertions(+), 5 deletions(-) (limited to 'crates/hir_def') 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) => { -- cgit v1.2.3