diff options
Diffstat (limited to 'crates/hir_ty')
-rw-r--r-- | crates/hir_ty/src/diagnostics/decl_check.rs | 26 | ||||
-rw-r--r-- | crates/hir_ty/src/display.rs | 43 | ||||
-rw-r--r-- | crates/hir_ty/src/test_db.rs | 8 |
3 files changed, 54 insertions, 23 deletions
diff --git a/crates/hir_ty/src/diagnostics/decl_check.rs b/crates/hir_ty/src/diagnostics/decl_check.rs index 4b3e2fa8f..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::{ | |||
26 | ast::{self, NameOwner}, | 26 | ast::{self, NameOwner}, |
27 | AstNode, AstPtr, | 27 | AstNode, AstPtr, |
28 | }; | 28 | }; |
29 | use test_utils::mark; | ||
29 | 30 | ||
30 | use crate::{ | 31 | use crate::{ |
31 | db::HirDatabase, | 32 | db::HirDatabase, |
@@ -87,6 +88,11 @@ impl<'a, 'b> DeclValidator<'a, 'b> { | |||
87 | 88 | ||
88 | fn validate_func(&mut self, db: &dyn HirDatabase, func: FunctionId) { | 89 | fn validate_func(&mut self, db: &dyn HirDatabase, func: FunctionId) { |
89 | let data = db.function_data(func); | 90 | let data = db.function_data(func); |
91 | if data.is_extern { | ||
92 | mark::hit!(extern_func_incorrect_case_ignored); | ||
93 | return; | ||
94 | } | ||
95 | |||
90 | let body = db.body(func.into()); | 96 | let body = db.body(func.into()); |
91 | 97 | ||
92 | // Recursively validate inner scope items, such as static variables and constants. | 98 | // Recursively validate inner scope items, such as static variables and constants. |
@@ -648,6 +654,10 @@ impl<'a, 'b> DeclValidator<'a, 'b> { | |||
648 | 654 | ||
649 | fn validate_static(&mut self, db: &dyn HirDatabase, static_id: StaticId) { | 655 | fn validate_static(&mut self, db: &dyn HirDatabase, static_id: StaticId) { |
650 | let data = db.static_data(static_id); | 656 | let data = db.static_data(static_id); |
657 | if data.is_extern { | ||
658 | mark::hit!(extern_static_incorrect_case_ignored); | ||
659 | return; | ||
660 | } | ||
651 | 661 | ||
652 | if self.allowed(db, static_id.into(), allow::NON_UPPER_CASE_GLOBAL) { | 662 | if self.allowed(db, static_id.into(), allow::NON_UPPER_CASE_GLOBAL) { |
653 | return; | 663 | return; |
@@ -709,6 +719,8 @@ fn pat_equals_to_name(pat: Option<ast::Pat>, name: &Name) -> bool { | |||
709 | 719 | ||
710 | #[cfg(test)] | 720 | #[cfg(test)] |
711 | mod tests { | 721 | mod tests { |
722 | use test_utils::mark; | ||
723 | |||
712 | use crate::diagnostics::tests::check_diagnostics; | 724 | use crate::diagnostics::tests::check_diagnostics; |
713 | 725 | ||
714 | #[test] | 726 | #[test] |
@@ -920,4 +932,18 @@ fn main() { | |||
920 | "#, | 932 | "#, |
921 | ); | 933 | ); |
922 | } | 934 | } |
935 | |||
936 | #[test] | ||
937 | fn ignores_extern_items() { | ||
938 | mark::check!(extern_func_incorrect_case_ignored); | ||
939 | mark::check!(extern_static_incorrect_case_ignored); | ||
940 | check_diagnostics( | ||
941 | r#" | ||
942 | extern { | ||
943 | fn NonSnakeCaseName(SOME_VAR: u8) -> u8; | ||
944 | pub static SomeStatic: u8 = 10; | ||
945 | } | ||
946 | "#, | ||
947 | ); | ||
948 | } | ||
923 | } | 949 | } |
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 14e8c0633..e77481906 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs | |||
@@ -297,26 +297,7 @@ impl HirDisplay for ApplicationTy { | |||
297 | } | 297 | } |
298 | TypeCtor::FnPtr { is_varargs, .. } => { | 298 | TypeCtor::FnPtr { is_varargs, .. } => { |
299 | let sig = FnSig::from_fn_ptr_substs(&self.parameters, is_varargs); | 299 | let sig = FnSig::from_fn_ptr_substs(&self.parameters, is_varargs); |
300 | write!(f, "fn(")?; | 300 | sig.hir_fmt(f)?; |
301 | f.write_joined(sig.params(), ", ")?; | ||
302 | if is_varargs { | ||
303 | if sig.params().is_empty() { | ||
304 | write!(f, "...")?; | ||
305 | } else { | ||
306 | write!(f, ", ...")?; | ||
307 | } | ||
308 | } | ||
309 | write!(f, ")")?; | ||
310 | let ret = sig.ret(); | ||
311 | if *ret != Ty::unit() { | ||
312 | let ret_display = ret.into_displayable( | ||
313 | f.db, | ||
314 | f.max_size, | ||
315 | f.omit_verbose_types, | ||
316 | f.display_target, | ||
317 | ); | ||
318 | write!(f, " -> {}", ret_display)?; | ||
319 | } | ||
320 | } | 301 | } |
321 | TypeCtor::FnDef(def) => { | 302 | TypeCtor::FnDef(def) => { |
322 | let sig = f.db.callable_item_signature(def).subst(&self.parameters); | 303 | let sig = f.db.callable_item_signature(def).subst(&self.parameters); |
@@ -584,6 +565,28 @@ impl HirDisplay for Ty { | |||
584 | } | 565 | } |
585 | } | 566 | } |
586 | 567 | ||
568 | impl HirDisplay for FnSig { | ||
569 | fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { | ||
570 | write!(f, "fn(")?; | ||
571 | f.write_joined(self.params(), ", ")?; | ||
572 | if self.is_varargs { | ||
573 | if self.params().is_empty() { | ||
574 | write!(f, "...")?; | ||
575 | } else { | ||
576 | write!(f, ", ...")?; | ||
577 | } | ||
578 | } | ||
579 | write!(f, ")")?; | ||
580 | let ret = self.ret(); | ||
581 | if *ret != Ty::unit() { | ||
582 | let ret_display = | ||
583 | ret.into_displayable(f.db, f.max_size, f.omit_verbose_types, f.display_target); | ||
584 | write!(f, " -> {}", ret_display)?; | ||
585 | } | ||
586 | Ok(()) | ||
587 | } | ||
588 | } | ||
589 | |||
587 | fn write_bounds_like_dyn_trait( | 590 | fn write_bounds_like_dyn_trait( |
588 | predicates: &[GenericPredicate], | 591 | predicates: &[GenericPredicate], |
589 | f: &mut HirFormatter, | 592 | f: &mut HirFormatter, |
diff --git a/crates/hir_ty/src/test_db.rs b/crates/hir_ty/src/test_db.rs index 22254b765..646e16bbe 100644 --- a/crates/hir_ty/src/test_db.rs +++ b/crates/hir_ty/src/test_db.rs | |||
@@ -5,7 +5,9 @@ use std::{ | |||
5 | sync::{Arc, Mutex}, | 5 | sync::{Arc, Mutex}, |
6 | }; | 6 | }; |
7 | 7 | ||
8 | use base_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast}; | 8 | use base_db::{ |
9 | salsa, AnchoredPath, CrateId, FileId, FileLoader, FileLoaderDelegate, SourceDatabase, Upcast, | ||
10 | }; | ||
9 | use hir_def::{db::DefDatabase, ModuleId}; | 11 | use hir_def::{db::DefDatabase, ModuleId}; |
10 | use hir_expand::db::AstDatabase; | 12 | use hir_expand::db::AstDatabase; |
11 | use rustc_hash::{FxHashMap, FxHashSet}; | 13 | use rustc_hash::{FxHashMap, FxHashSet}; |
@@ -67,8 +69,8 @@ impl FileLoader for TestDB { | |||
67 | fn file_text(&self, file_id: FileId) -> Arc<String> { | 69 | fn file_text(&self, file_id: FileId) -> Arc<String> { |
68 | FileLoaderDelegate(self).file_text(file_id) | 70 | FileLoaderDelegate(self).file_text(file_id) |
69 | } | 71 | } |
70 | fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> { | 72 | fn resolve_path(&self, path: AnchoredPath) -> Option<FileId> { |
71 | FileLoaderDelegate(self).resolve_path(anchor, path) | 73 | FileLoaderDelegate(self).resolve_path(path) |
72 | } | 74 | } |
73 | fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> { | 75 | fn relevant_crates(&self, file_id: FileId) -> Arc<FxHashSet<CrateId>> { |
74 | FileLoaderDelegate(self).relevant_crates(file_id) | 76 | FileLoaderDelegate(self).relevant_crates(file_id) |