diff options
Diffstat (limited to 'crates/hir_ty')
-rw-r--r-- | crates/hir_ty/src/diagnostics/decl_check.rs | 28 | ||||
-rw-r--r-- | crates/hir_ty/src/diagnostics/decl_check/case_conv.rs | 9 | ||||
-rw-r--r-- | crates/hir_ty/src/diagnostics/unsafe_check.rs | 18 | ||||
-rw-r--r-- | crates/hir_ty/src/traits.rs | 30 |
4 files changed, 75 insertions, 10 deletions
diff --git a/crates/hir_ty/src/diagnostics/decl_check.rs b/crates/hir_ty/src/diagnostics/decl_check.rs index f987636fe..f179c62b7 100644 --- a/crates/hir_ty/src/diagnostics/decl_check.rs +++ b/crates/hir_ty/src/diagnostics/decl_check.rs | |||
@@ -708,11 +708,23 @@ fn foo() { | |||
708 | } | 708 | } |
709 | 709 | ||
710 | #[test] | 710 | #[test] |
711 | fn incorrect_struct_name() { | 711 | fn incorrect_struct_names() { |
712 | check_diagnostics( | 712 | check_diagnostics( |
713 | r#" | 713 | r#" |
714 | struct non_camel_case_name {} | 714 | struct non_camel_case_name {} |
715 | // ^^^^^^^^^^^^^^^^^^^ Structure `non_camel_case_name` should have CamelCase name, e.g. `NonCamelCaseName` | 715 | // ^^^^^^^^^^^^^^^^^^^ Structure `non_camel_case_name` should have CamelCase name, e.g. `NonCamelCaseName` |
716 | |||
717 | struct SCREAMING_CASE {} | ||
718 | // ^^^^^^^^^^^^^^ Structure `SCREAMING_CASE` should have CamelCase name, e.g. `ScreamingCase` | ||
719 | "#, | ||
720 | ); | ||
721 | } | ||
722 | |||
723 | #[test] | ||
724 | fn no_diagnostic_for_camel_cased_acronyms_in_struct_name() { | ||
725 | check_diagnostics( | ||
726 | r#" | ||
727 | struct AABB {} | ||
716 | "#, | 728 | "#, |
717 | ); | 729 | ); |
718 | } | 730 | } |
@@ -728,11 +740,23 @@ struct SomeStruct { SomeField: u8 } | |||
728 | } | 740 | } |
729 | 741 | ||
730 | #[test] | 742 | #[test] |
731 | fn incorrect_enum_name() { | 743 | fn incorrect_enum_names() { |
732 | check_diagnostics( | 744 | check_diagnostics( |
733 | r#" | 745 | r#" |
734 | enum some_enum { Val(u8) } | 746 | enum some_enum { Val(u8) } |
735 | // ^^^^^^^^^ Enum `some_enum` should have CamelCase name, e.g. `SomeEnum` | 747 | // ^^^^^^^^^ Enum `some_enum` should have CamelCase name, e.g. `SomeEnum` |
748 | |||
749 | enum SOME_ENUM | ||
750 | // ^^^^^^^^^ Enum `SOME_ENUM` should have CamelCase name, e.g. `SomeEnum` | ||
751 | "#, | ||
752 | ); | ||
753 | } | ||
754 | |||
755 | #[test] | ||
756 | fn no_diagnostic_for_camel_cased_acronyms_in_enum_name() { | ||
757 | check_diagnostics( | ||
758 | r#" | ||
759 | enum AABB {} | ||
736 | "#, | 760 | "#, |
737 | ); | 761 | ); |
738 | } | 762 | } |
diff --git a/crates/hir_ty/src/diagnostics/decl_check/case_conv.rs b/crates/hir_ty/src/diagnostics/decl_check/case_conv.rs index 3800f2a6b..324d60765 100644 --- a/crates/hir_ty/src/diagnostics/decl_check/case_conv.rs +++ b/crates/hir_ty/src/diagnostics/decl_check/case_conv.rs | |||
@@ -29,7 +29,13 @@ fn detect_case(ident: &str) -> DetectedCase { | |||
29 | 29 | ||
30 | if has_uppercase { | 30 | if has_uppercase { |
31 | if !has_lowercase { | 31 | if !has_lowercase { |
32 | DetectedCase::UpperSnakeCase | 32 | if has_underscore { |
33 | DetectedCase::UpperSnakeCase | ||
34 | } else { | ||
35 | // It has uppercase only and no underscores. Ex: "AABB" | ||
36 | // This is a camel cased acronym. | ||
37 | DetectedCase::UpperCamelCase | ||
38 | } | ||
33 | } else if !has_underscore { | 39 | } else if !has_underscore { |
34 | if first_lowercase { | 40 | if first_lowercase { |
35 | DetectedCase::LowerCamelCase | 41 | DetectedCase::LowerCamelCase |
@@ -180,6 +186,7 @@ mod tests { | |||
180 | check(to_camel_case, "Weird_Case", expect![["WeirdCase"]]); | 186 | check(to_camel_case, "Weird_Case", expect![["WeirdCase"]]); |
181 | check(to_camel_case, "name", expect![["Name"]]); | 187 | check(to_camel_case, "name", expect![["Name"]]); |
182 | check(to_camel_case, "A", expect![[""]]); | 188 | check(to_camel_case, "A", expect![[""]]); |
189 | check(to_camel_case, "AABB", expect![[""]]); | ||
183 | } | 190 | } |
184 | 191 | ||
185 | #[test] | 192 | #[test] |
diff --git a/crates/hir_ty/src/diagnostics/unsafe_check.rs b/crates/hir_ty/src/diagnostics/unsafe_check.rs index 21a121aad..2da9688ca 100644 --- a/crates/hir_ty/src/diagnostics/unsafe_check.rs +++ b/crates/hir_ty/src/diagnostics/unsafe_check.rs | |||
@@ -202,4 +202,22 @@ fn main() { | |||
202 | "#, | 202 | "#, |
203 | ); | 203 | ); |
204 | } | 204 | } |
205 | |||
206 | #[test] | ||
207 | fn no_missing_unsafe_diagnostic_with_safe_intrinsic() { | ||
208 | check_diagnostics( | ||
209 | r#" | ||
210 | extern "rust-intrinsic" { | ||
211 | pub fn bitreverse(x: u32) -> u32; // Safe intrinsic | ||
212 | pub fn floorf32(x: f32) -> f32; // Unsafe intrinsic | ||
213 | } | ||
214 | |||
215 | fn main() { | ||
216 | let _ = bitreverse(12); | ||
217 | let _ = floorf32(12.0); | ||
218 | //^^^^^^^^^^^^^^ This operation is unsafe and requires an unsafe function or block | ||
219 | } | ||
220 | "#, | ||
221 | ); | ||
222 | } | ||
205 | } | 223 | } |
diff --git a/crates/hir_ty/src/traits.rs b/crates/hir_ty/src/traits.rs index 14cd3a2b4..ce1174cbe 100644 --- a/crates/hir_ty/src/traits.rs +++ b/crates/hir_ty/src/traits.rs | |||
@@ -5,6 +5,7 @@ use base_db::CrateId; | |||
5 | use chalk_ir::cast::Cast; | 5 | use chalk_ir::cast::Cast; |
6 | use chalk_solve::{logging_db::LoggingRustIrDatabase, Solver}; | 6 | use chalk_solve::{logging_db::LoggingRustIrDatabase, Solver}; |
7 | use hir_def::{lang_item::LangItemTarget, TraitId}; | 7 | use hir_def::{lang_item::LangItemTarget, TraitId}; |
8 | use stdx::panic_context; | ||
8 | 9 | ||
9 | use crate::{db::HirDatabase, DebruijnIndex, Substs}; | 10 | use crate::{db::HirDatabase, DebruijnIndex, Substs}; |
10 | 11 | ||
@@ -168,14 +169,23 @@ fn solve( | |||
168 | }; | 169 | }; |
169 | 170 | ||
170 | let mut solve = || { | 171 | let mut solve = || { |
171 | if is_chalk_print() { | 172 | let _ctx = if is_chalk_debug() || is_chalk_print() { |
172 | let logging_db = LoggingRustIrDatabase::new(context); | 173 | Some(panic_context::enter(format!("solving {:?}", goal))) |
173 | let solution = solver.solve_limited(&logging_db, goal, &should_continue); | 174 | } else { |
174 | log::debug!("chalk program:\n{}", logging_db); | 175 | None |
176 | }; | ||
177 | let solution = if is_chalk_print() { | ||
178 | let logging_db = | ||
179 | LoggingRustIrDatabaseLoggingOnDrop(LoggingRustIrDatabase::new(context)); | ||
180 | let solution = solver.solve_limited(&logging_db.0, goal, &should_continue); | ||
175 | solution | 181 | solution |
176 | } else { | 182 | } else { |
177 | solver.solve_limited(&context, goal, &should_continue) | 183 | solver.solve_limited(&context, goal, &should_continue) |
178 | } | 184 | }; |
185 | |||
186 | log::debug!("solve({:?}) => {:?}", goal, solution); | ||
187 | |||
188 | solution | ||
179 | }; | 189 | }; |
180 | 190 | ||
181 | // don't set the TLS for Chalk unless Chalk debugging is active, to make | 191 | // don't set the TLS for Chalk unless Chalk debugging is active, to make |
@@ -183,11 +193,17 @@ fn solve( | |||
183 | let solution = | 193 | let solution = |
184 | if is_chalk_debug() { chalk::tls::set_current_program(db, solve) } else { solve() }; | 194 | if is_chalk_debug() { chalk::tls::set_current_program(db, solve) } else { solve() }; |
185 | 195 | ||
186 | log::debug!("solve({:?}) => {:?}", goal, solution); | ||
187 | |||
188 | solution | 196 | solution |
189 | } | 197 | } |
190 | 198 | ||
199 | struct LoggingRustIrDatabaseLoggingOnDrop<'a>(LoggingRustIrDatabase<Interner, ChalkContext<'a>>); | ||
200 | |||
201 | impl<'a> Drop for LoggingRustIrDatabaseLoggingOnDrop<'a> { | ||
202 | fn drop(&mut self) { | ||
203 | eprintln!("chalk program:\n{}", self.0); | ||
204 | } | ||
205 | } | ||
206 | |||
191 | fn is_chalk_debug() -> bool { | 207 | fn is_chalk_debug() -> bool { |
192 | std::env::var("CHALK_DEBUG").is_ok() | 208 | std::env::var("CHALK_DEBUG").is_ok() |
193 | } | 209 | } |