aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/diagnostics.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide/src/diagnostics.rs')
-rw-r--r--crates/ide/src/diagnostics.rs146
1 files changed, 11 insertions, 135 deletions
diff --git a/crates/ide/src/diagnostics.rs b/crates/ide/src/diagnostics.rs
index 3fbd21c30..caaa89e0a 100644
--- a/crates/ide/src/diagnostics.rs
+++ b/crates/ide/src/diagnostics.rs
@@ -4,15 +4,16 @@
4//! macro-expanded files, but we need to present them to the users in terms of 4//! macro-expanded files, but we need to present them to the users in terms of
5//! original files. So we need to map the ranges. 5//! original files. So we need to map the ranges.
6 6
7mod unresolved_module; 7mod inactive_code;
8mod macro_error;
9mod missing_fields;
10mod no_such_field;
11mod unimplemented_builtin_macro;
8mod unresolved_extern_crate; 12mod unresolved_extern_crate;
9mod unresolved_import; 13mod unresolved_import;
10mod unresolved_macro_call; 14mod unresolved_macro_call;
15mod unresolved_module;
11mod unresolved_proc_macro; 16mod unresolved_proc_macro;
12mod unimplemented_builtin_macro;
13mod macro_error;
14mod inactive_code;
15mod missing_fields;
16 17
17mod fixes; 18mod fixes;
18mod field_shorthand; 19mod field_shorthand;
@@ -161,9 +162,6 @@ pub(crate) fn diagnostics(
161 .on::<hir::diagnostics::MissingOkOrSomeInTailExpr, _>(|d| { 162 .on::<hir::diagnostics::MissingOkOrSomeInTailExpr, _>(|d| {
162 res.borrow_mut().push(diagnostic_with_fix(d, &sema, resolve)); 163 res.borrow_mut().push(diagnostic_with_fix(d, &sema, resolve));
163 }) 164 })
164 .on::<hir::diagnostics::NoSuchField, _>(|d| {
165 res.borrow_mut().push(diagnostic_with_fix(d, &sema, resolve));
166 })
167 .on::<hir::diagnostics::RemoveThisSemicolon, _>(|d| { 165 .on::<hir::diagnostics::RemoveThisSemicolon, _>(|d| {
168 res.borrow_mut().push(diagnostic_with_fix(d, &sema, resolve)); 166 res.borrow_mut().push(diagnostic_with_fix(d, &sema, resolve));
169 }) 167 })
@@ -220,14 +218,15 @@ pub(crate) fn diagnostics(
220 for diag in diags { 218 for diag in diags {
221 #[rustfmt::skip] 219 #[rustfmt::skip]
222 let d = match diag { 220 let d = match diag {
223 AnyDiagnostic::UnresolvedModule(d) => unresolved_module::unresolved_module(&ctx, &d), 221 AnyDiagnostic::MacroError(d) => macro_error::macro_error(&ctx, &d),
222 AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d),
223 AnyDiagnostic::NoSuchField(d) => no_such_field::no_such_field(&ctx, &d),
224 AnyDiagnostic::UnimplementedBuiltinMacro(d) => unimplemented_builtin_macro::unimplemented_builtin_macro(&ctx, &d),
224 AnyDiagnostic::UnresolvedExternCrate(d) => unresolved_extern_crate::unresolved_extern_crate(&ctx, &d), 225 AnyDiagnostic::UnresolvedExternCrate(d) => unresolved_extern_crate::unresolved_extern_crate(&ctx, &d),
225 AnyDiagnostic::UnresolvedImport(d) => unresolved_import::unresolved_import(&ctx, &d), 226 AnyDiagnostic::UnresolvedImport(d) => unresolved_import::unresolved_import(&ctx, &d),
226 AnyDiagnostic::UnresolvedMacroCall(d) => unresolved_macro_call::unresolved_macro_call(&ctx, &d), 227 AnyDiagnostic::UnresolvedMacroCall(d) => unresolved_macro_call::unresolved_macro_call(&ctx, &d),
228 AnyDiagnostic::UnresolvedModule(d) => unresolved_module::unresolved_module(&ctx, &d),
227 AnyDiagnostic::UnresolvedProcMacro(d) => unresolved_proc_macro::unresolved_proc_macro(&ctx, &d), 229 AnyDiagnostic::UnresolvedProcMacro(d) => unresolved_proc_macro::unresolved_proc_macro(&ctx, &d),
228 AnyDiagnostic::UnimplementedBuiltinMacro(d) => unimplemented_builtin_macro::unimplemented_builtin_macro(&ctx, &d),
229 AnyDiagnostic::MissingFields(d) => missing_fields::missing_fields(&ctx, &d),
230 AnyDiagnostic::MacroError(d) => macro_error::macro_error(&ctx, &d),
231 230
232 AnyDiagnostic::InactiveCode(d) => match inactive_code::inactive_code(&ctx, &d) { 231 AnyDiagnostic::InactiveCode(d) => match inactive_code::inactive_code(&ctx, &d) {
233 Some(it) => it, 232 Some(it) => it,
@@ -723,129 +722,6 @@ fn foo() { break; }
723 } 722 }
724 723
725 #[test] 724 #[test]
726 fn no_such_field_diagnostics() {
727 check_diagnostics(
728 r#"
729struct S { foo: i32, bar: () }
730impl S {
731 fn new() -> S {
732 S {
733 //^ Missing structure fields:
734 //| - bar
735 foo: 92,
736 baz: 62,
737 //^^^^^^^ no such field
738 }
739 }
740}
741"#,
742 );
743 }
744 #[test]
745 fn no_such_field_with_feature_flag_diagnostics() {
746 check_diagnostics(
747 r#"
748//- /lib.rs crate:foo cfg:feature=foo
749struct MyStruct {
750 my_val: usize,
751 #[cfg(feature = "foo")]
752 bar: bool,
753}
754
755impl MyStruct {
756 #[cfg(feature = "foo")]
757 pub(crate) fn new(my_val: usize, bar: bool) -> Self {
758 Self { my_val, bar }
759 }
760 #[cfg(not(feature = "foo"))]
761 pub(crate) fn new(my_val: usize, _bar: bool) -> Self {
762 Self { my_val }
763 }
764}
765"#,
766 );
767 }
768
769 #[test]
770 fn no_such_field_enum_with_feature_flag_diagnostics() {
771 check_diagnostics(
772 r#"
773//- /lib.rs crate:foo cfg:feature=foo
774enum Foo {
775 #[cfg(not(feature = "foo"))]
776 Buz,
777 #[cfg(feature = "foo")]
778 Bar,
779 Baz
780}
781
782fn test_fn(f: Foo) {
783 match f {
784 Foo::Bar => {},
785 Foo::Baz => {},
786 }
787}
788"#,
789 );
790 }
791
792 #[test]
793 fn no_such_field_with_feature_flag_diagnostics_on_struct_lit() {
794 check_diagnostics(
795 r#"
796//- /lib.rs crate:foo cfg:feature=foo
797struct S {
798 #[cfg(feature = "foo")]
799 foo: u32,
800 #[cfg(not(feature = "foo"))]
801 bar: u32,
802}
803
804impl S {
805 #[cfg(feature = "foo")]
806 fn new(foo: u32) -> Self {
807 Self { foo }
808 }
809 #[cfg(not(feature = "foo"))]
810 fn new(bar: u32) -> Self {
811 Self { bar }
812 }
813 fn new2(bar: u32) -> Self {
814 #[cfg(feature = "foo")]
815 { Self { foo: bar } }
816 #[cfg(not(feature = "foo"))]
817 { Self { bar } }
818 }
819 fn new2(val: u32) -> Self {
820 Self {
821 #[cfg(feature = "foo")]
822 foo: val,
823 #[cfg(not(feature = "foo"))]
824 bar: val,
825 }
826 }
827}
828"#,
829 );
830 }
831
832 #[test]
833 fn no_such_field_with_type_macro() {
834 check_diagnostics(
835 r#"
836macro_rules! Type { () => { u32 }; }
837struct Foo { bar: Type![] }
838
839impl Foo {
840 fn new() -> Self {
841 Foo { bar: 0 }
842 }
843}
844"#,
845 );
846 }
847
848 #[test]
849 fn missing_unsafe_diagnostic_with_raw_ptr() { 725 fn missing_unsafe_diagnostic_with_raw_ptr() {
850 check_diagnostics( 726 check_diagnostics(
851 r#" 727 r#"