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_ty/src/diagnostics/decl_check.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'crates/hir_ty/src') 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 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(+) (limited to 'crates/hir_ty/src') 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