]> git.lizzy.rs Git - rust.git/blob - crates/ide/src/diagnostics.rs
Merge #7038
[rust.git] / crates / ide / src / diagnostics.rs
1 //! Collects diagnostics & fixits  for a single file.
2 //!
3 //! The tricky bit here is that diagnostics are produced by hir 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.
6
7 mod fixes;
8 mod field_shorthand;
9
10 use std::cell::RefCell;
11
12 use hir::{
13     diagnostics::{Diagnostic as _, DiagnosticCode, DiagnosticSinkBuilder},
14     Semantics,
15 };
16 use ide_db::base_db::SourceDatabase;
17 use ide_db::RootDatabase;
18 use itertools::Itertools;
19 use rustc_hash::FxHashSet;
20 use syntax::{
21     ast::{self, AstNode},
22     SyntaxNode, TextRange, T,
23 };
24 use text_edit::TextEdit;
25
26 use crate::{FileId, Label, SourceChange, SourceFileEdit};
27
28 use self::fixes::DiagnosticWithFix;
29
30 #[derive(Debug)]
31 pub struct Diagnostic {
32     // pub name: Option<String>,
33     pub message: String,
34     pub range: TextRange,
35     pub severity: Severity,
36     pub fix: Option<Fix>,
37     pub unused: bool,
38     pub code: Option<DiagnosticCode>,
39 }
40
41 impl Diagnostic {
42     fn error(range: TextRange, message: String) -> Self {
43         Self { message, range, severity: Severity::Error, fix: None, unused: false, code: None }
44     }
45
46     fn hint(range: TextRange, message: String) -> Self {
47         Self {
48             message,
49             range,
50             severity: Severity::WeakWarning,
51             fix: None,
52             unused: false,
53             code: None,
54         }
55     }
56
57     fn with_fix(self, fix: Option<Fix>) -> Self {
58         Self { fix, ..self }
59     }
60
61     fn with_unused(self, unused: bool) -> Self {
62         Self { unused, ..self }
63     }
64
65     fn with_code(self, code: Option<DiagnosticCode>) -> Self {
66         Self { code, ..self }
67     }
68 }
69
70 #[derive(Debug)]
71 pub struct Fix {
72     pub label: Label,
73     pub source_change: SourceChange,
74     /// Allows to trigger the fix only when the caret is in the range given
75     pub fix_trigger_range: TextRange,
76 }
77
78 impl Fix {
79     fn new(label: &str, source_change: SourceChange, fix_trigger_range: TextRange) -> Self {
80         let label = Label::new(label);
81         Self { label, source_change, fix_trigger_range }
82     }
83 }
84
85 #[derive(Debug, Copy, Clone)]
86 pub enum Severity {
87     Error,
88     WeakWarning,
89 }
90
91 #[derive(Default, Debug, Clone)]
92 pub struct DiagnosticsConfig {
93     pub disable_experimental: bool,
94     pub disabled: FxHashSet<String>,
95 }
96
97 pub(crate) fn diagnostics(
98     db: &RootDatabase,
99     config: &DiagnosticsConfig,
100     file_id: FileId,
101 ) -> Vec<Diagnostic> {
102     let _p = profile::span("diagnostics");
103     let sema = Semantics::new(db);
104     let parse = db.parse(file_id);
105     let mut res = Vec::new();
106
107     // [#34344] Only take first 128 errors to prevent slowing down editor/ide, the number 128 is chosen arbitrarily.
108     res.extend(
109         parse
110             .errors()
111             .iter()
112             .take(128)
113             .map(|err| Diagnostic::error(err.range(), format!("Syntax Error: {}", err))),
114     );
115
116     for node in parse.tree().syntax().descendants() {
117         check_unnecessary_braces_in_use_statement(&mut res, file_id, &node);
118         field_shorthand::check(&mut res, file_id, &node);
119     }
120     let res = RefCell::new(res);
121     let sink_builder = DiagnosticSinkBuilder::new()
122         .on::<hir::diagnostics::UnresolvedModule, _>(|d| {
123             res.borrow_mut().push(diagnostic_with_fix(d, &sema));
124         })
125         .on::<hir::diagnostics::MissingFields, _>(|d| {
126             res.borrow_mut().push(diagnostic_with_fix(d, &sema));
127         })
128         .on::<hir::diagnostics::MissingOkInTailExpr, _>(|d| {
129             res.borrow_mut().push(diagnostic_with_fix(d, &sema));
130         })
131         .on::<hir::diagnostics::NoSuchField, _>(|d| {
132             res.borrow_mut().push(diagnostic_with_fix(d, &sema));
133         })
134         .on::<hir::diagnostics::RemoveThisSemicolon, _>(|d| {
135             res.borrow_mut().push(diagnostic_with_fix(d, &sema));
136         })
137         .on::<hir::diagnostics::IncorrectCase, _>(|d| {
138             res.borrow_mut().push(warning_with_fix(d, &sema));
139         })
140         .on::<hir::diagnostics::InactiveCode, _>(|d| {
141             // If there's inactive code somewhere in a macro, don't propagate to the call-site.
142             if d.display_source().file_id.expansion_info(db).is_some() {
143                 return;
144             }
145
146             // Override severity and mark as unused.
147             res.borrow_mut().push(
148                 Diagnostic::hint(sema.diagnostics_display_range(d).range, d.message())
149                     .with_unused(true)
150                     .with_code(Some(d.code())),
151             );
152         })
153         .on::<hir::diagnostics::UnresolvedProcMacro, _>(|d| {
154             // Use more accurate position if available.
155             let display_range =
156                 d.precise_location.unwrap_or_else(|| sema.diagnostics_display_range(d).range);
157
158             // FIXME: it would be nice to tell the user whether proc macros are currently disabled
159             res.borrow_mut()
160                 .push(Diagnostic::hint(display_range, d.message()).with_code(Some(d.code())));
161         })
162         // Only collect experimental diagnostics when they're enabled.
163         .filter(|diag| !(diag.is_experimental() && config.disable_experimental))
164         .filter(|diag| !config.disabled.contains(diag.code().as_str()));
165
166     // Finalize the `DiagnosticSink` building process.
167     let mut sink = sink_builder
168         // Diagnostics not handled above get no fix and default treatment.
169         .build(|d| {
170             res.borrow_mut().push(
171                 Diagnostic::error(sema.diagnostics_display_range(d).range, d.message())
172                     .with_code(Some(d.code())),
173             );
174         });
175
176     if let Some(m) = sema.to_module_def(file_id) {
177         m.diagnostics(db, &mut sink);
178     };
179     drop(sink);
180     res.into_inner()
181 }
182
183 fn diagnostic_with_fix<D: DiagnosticWithFix>(d: &D, sema: &Semantics<RootDatabase>) -> Diagnostic {
184     Diagnostic::error(sema.diagnostics_display_range(d).range, d.message())
185         .with_fix(d.fix(&sema))
186         .with_code(Some(d.code()))
187 }
188
189 fn warning_with_fix<D: DiagnosticWithFix>(d: &D, sema: &Semantics<RootDatabase>) -> Diagnostic {
190     Diagnostic::hint(sema.diagnostics_display_range(d).range, d.message())
191         .with_fix(d.fix(&sema))
192         .with_code(Some(d.code()))
193 }
194
195 fn check_unnecessary_braces_in_use_statement(
196     acc: &mut Vec<Diagnostic>,
197     file_id: FileId,
198     node: &SyntaxNode,
199 ) -> Option<()> {
200     let use_tree_list = ast::UseTreeList::cast(node.clone())?;
201     if let Some((single_use_tree,)) = use_tree_list.use_trees().collect_tuple() {
202         let use_range = use_tree_list.syntax().text_range();
203         let edit =
204             text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(&single_use_tree)
205                 .unwrap_or_else(|| {
206                     let to_replace = single_use_tree.syntax().text().to_string();
207                     let mut edit_builder = TextEdit::builder();
208                     edit_builder.delete(use_range);
209                     edit_builder.insert(use_range.start(), to_replace);
210                     edit_builder.finish()
211                 });
212
213         acc.push(
214             Diagnostic::hint(use_range, "Unnecessary braces in use statement".to_string())
215                 .with_fix(Some(Fix::new(
216                     "Remove unnecessary braces",
217                     SourceFileEdit { file_id, edit }.into(),
218                     use_range,
219                 ))),
220         );
221     }
222
223     Some(())
224 }
225
226 fn text_edit_for_remove_unnecessary_braces_with_self_in_use_statement(
227     single_use_tree: &ast::UseTree,
228 ) -> Option<TextEdit> {
229     let use_tree_list_node = single_use_tree.syntax().parent()?;
230     if single_use_tree.path()?.segment()?.syntax().first_child_or_token()?.kind() == T![self] {
231         let start = use_tree_list_node.prev_sibling_or_token()?.text_range().start();
232         let end = use_tree_list_node.text_range().end();
233         return Some(TextEdit::delete(TextRange::new(start, end)));
234     }
235     None
236 }
237
238 #[cfg(test)]
239 mod tests {
240     use expect_test::{expect, Expect};
241     use stdx::trim_indent;
242     use test_utils::assert_eq_text;
243
244     use crate::{fixture, DiagnosticsConfig};
245
246     /// Takes a multi-file input fixture with annotated cursor positions,
247     /// and checks that:
248     ///  * a diagnostic is produced
249     ///  * this diagnostic fix trigger range touches the input cursor position
250     ///  * that the contents of the file containing the cursor match `after` after the diagnostic fix is applied
251     pub(crate) fn check_fix(ra_fixture_before: &str, ra_fixture_after: &str) {
252         let after = trim_indent(ra_fixture_after);
253
254         let (analysis, file_position) = fixture::position(ra_fixture_before);
255         let diagnostic = analysis
256             .diagnostics(&DiagnosticsConfig::default(), file_position.file_id)
257             .unwrap()
258             .pop()
259             .unwrap();
260         let fix = diagnostic.fix.unwrap();
261         let actual = {
262             let file_id = fix.source_change.source_file_edits.first().unwrap().file_id;
263             let mut actual = analysis.file_text(file_id).unwrap().to_string();
264
265             // Go from the last one to the first one, so that ranges won't be affected by previous edits.
266             // FIXME: https://github.com/rust-analyzer/rust-analyzer/issues/4901#issuecomment-644675309
267             for edit in fix.source_change.source_file_edits.iter().rev() {
268                 edit.edit.apply(&mut actual);
269             }
270             actual
271         };
272
273         assert_eq_text!(&after, &actual);
274         assert!(
275             fix.fix_trigger_range.contains_inclusive(file_position.offset),
276             "diagnostic fix range {:?} does not touch cursor position {:?}",
277             fix.fix_trigger_range,
278             file_position.offset
279         );
280     }
281
282     /// Takes a multi-file input fixture with annotated cursor position and checks that no diagnostics
283     /// apply to the file containing the cursor.
284     pub(crate) fn check_no_diagnostics(ra_fixture: &str) {
285         let (analysis, files) = fixture::files(ra_fixture);
286         let diagnostics = files
287             .into_iter()
288             .flat_map(|file_id| {
289                 analysis.diagnostics(&DiagnosticsConfig::default(), file_id).unwrap()
290             })
291             .collect::<Vec<_>>();
292         assert_eq!(diagnostics.len(), 0, "unexpected diagnostics:\n{:#?}", diagnostics);
293     }
294
295     fn check_expect(ra_fixture: &str, expect: Expect) {
296         let (analysis, file_id) = fixture::file(ra_fixture);
297         let diagnostics = analysis.diagnostics(&DiagnosticsConfig::default(), file_id).unwrap();
298         expect.assert_debug_eq(&diagnostics)
299     }
300
301     #[test]
302     fn test_wrap_return_type() {
303         check_fix(
304             r#"
305 //- /main.rs crate:main deps:core
306 use core::result::Result::{self, Ok, Err};
307
308 fn div(x: i32, y: i32) -> Result<i32, ()> {
309     if y == 0 {
310         return Err(());
311     }
312     x / y<|>
313 }
314 //- /core/lib.rs crate:core
315 pub mod result {
316     pub enum Result<T, E> { Ok(T), Err(E) }
317 }
318 "#,
319             r#"
320 use core::result::Result::{self, Ok, Err};
321
322 fn div(x: i32, y: i32) -> Result<i32, ()> {
323     if y == 0 {
324         return Err(());
325     }
326     Ok(x / y)
327 }
328 "#,
329         );
330     }
331
332     #[test]
333     fn test_wrap_return_type_handles_generic_functions() {
334         check_fix(
335             r#"
336 //- /main.rs crate:main deps:core
337 use core::result::Result::{self, Ok, Err};
338
339 fn div<T>(x: T) -> Result<T, i32> {
340     if x == 0 {
341         return Err(7);
342     }
343     <|>x
344 }
345 //- /core/lib.rs crate:core
346 pub mod result {
347     pub enum Result<T, E> { Ok(T), Err(E) }
348 }
349 "#,
350             r#"
351 use core::result::Result::{self, Ok, Err};
352
353 fn div<T>(x: T) -> Result<T, i32> {
354     if x == 0 {
355         return Err(7);
356     }
357     Ok(x)
358 }
359 "#,
360         );
361     }
362
363     #[test]
364     fn test_wrap_return_type_handles_type_aliases() {
365         check_fix(
366             r#"
367 //- /main.rs crate:main deps:core
368 use core::result::Result::{self, Ok, Err};
369
370 type MyResult<T> = Result<T, ()>;
371
372 fn div(x: i32, y: i32) -> MyResult<i32> {
373     if y == 0 {
374         return Err(());
375     }
376     x <|>/ y
377 }
378 //- /core/lib.rs crate:core
379 pub mod result {
380     pub enum Result<T, E> { Ok(T), Err(E) }
381 }
382 "#,
383             r#"
384 use core::result::Result::{self, Ok, Err};
385
386 type MyResult<T> = Result<T, ()>;
387
388 fn div(x: i32, y: i32) -> MyResult<i32> {
389     if y == 0 {
390         return Err(());
391     }
392     Ok(x / y)
393 }
394 "#,
395         );
396     }
397
398     #[test]
399     fn test_wrap_return_type_not_applicable_when_expr_type_does_not_match_ok_type() {
400         check_no_diagnostics(
401             r#"
402 //- /main.rs crate:main deps:core
403 use core::result::Result::{self, Ok, Err};
404
405 fn foo() -> Result<(), i32> { 0 }
406
407 //- /core/lib.rs crate:core
408 pub mod result {
409     pub enum Result<T, E> { Ok(T), Err(E) }
410 }
411 "#,
412         );
413     }
414
415     #[test]
416     fn test_wrap_return_type_not_applicable_when_return_type_is_not_result() {
417         check_no_diagnostics(
418             r#"
419 //- /main.rs crate:main deps:core
420 use core::result::Result::{self, Ok, Err};
421
422 enum SomeOtherEnum { Ok(i32), Err(String) }
423
424 fn foo() -> SomeOtherEnum { 0 }
425
426 //- /core/lib.rs crate:core
427 pub mod result {
428     pub enum Result<T, E> { Ok(T), Err(E) }
429 }
430 "#,
431         );
432     }
433
434     #[test]
435     fn test_fill_struct_fields_empty() {
436         check_fix(
437             r#"
438 struct TestStruct { one: i32, two: i64 }
439
440 fn test_fn() {
441     let s = TestStruct {<|>};
442 }
443 "#,
444             r#"
445 struct TestStruct { one: i32, two: i64 }
446
447 fn test_fn() {
448     let s = TestStruct { one: (), two: ()};
449 }
450 "#,
451         );
452     }
453
454     #[test]
455     fn test_fill_struct_fields_self() {
456         check_fix(
457             r#"
458 struct TestStruct { one: i32 }
459
460 impl TestStruct {
461     fn test_fn() { let s = Self {<|>}; }
462 }
463 "#,
464             r#"
465 struct TestStruct { one: i32 }
466
467 impl TestStruct {
468     fn test_fn() { let s = Self { one: ()}; }
469 }
470 "#,
471         );
472     }
473
474     #[test]
475     fn test_fill_struct_fields_enum() {
476         check_fix(
477             r#"
478 enum Expr {
479     Bin { lhs: Box<Expr>, rhs: Box<Expr> }
480 }
481
482 impl Expr {
483     fn new_bin(lhs: Box<Expr>, rhs: Box<Expr>) -> Expr {
484         Expr::Bin {<|> }
485     }
486 }
487 "#,
488             r#"
489 enum Expr {
490     Bin { lhs: Box<Expr>, rhs: Box<Expr> }
491 }
492
493 impl Expr {
494     fn new_bin(lhs: Box<Expr>, rhs: Box<Expr>) -> Expr {
495         Expr::Bin { lhs: (), rhs: () }
496     }
497 }
498 "#,
499         );
500     }
501
502     #[test]
503     fn test_fill_struct_fields_partial() {
504         check_fix(
505             r#"
506 struct TestStruct { one: i32, two: i64 }
507
508 fn test_fn() {
509     let s = TestStruct{ two: 2<|> };
510 }
511 "#,
512             r"
513 struct TestStruct { one: i32, two: i64 }
514
515 fn test_fn() {
516     let s = TestStruct{ two: 2, one: () };
517 }
518 ",
519         );
520     }
521
522     #[test]
523     fn test_fill_struct_fields_no_diagnostic() {
524         check_no_diagnostics(
525             r"
526             struct TestStruct { one: i32, two: i64 }
527
528             fn test_fn() {
529                 let one = 1;
530                 let s = TestStruct{ one, two: 2 };
531             }
532         ",
533         );
534     }
535
536     #[test]
537     fn test_fill_struct_fields_no_diagnostic_on_spread() {
538         check_no_diagnostics(
539             r"
540             struct TestStruct { one: i32, two: i64 }
541
542             fn test_fn() {
543                 let one = 1;
544                 let s = TestStruct{ ..a };
545             }
546         ",
547         );
548     }
549
550     #[test]
551     fn test_unresolved_module_diagnostic() {
552         check_expect(
553             r#"mod foo;"#,
554             expect![[r#"
555                 [
556                     Diagnostic {
557                         message: "unresolved module",
558                         range: 0..8,
559                         severity: Error,
560                         fix: Some(
561                             Fix {
562                                 label: "Create module",
563                                 source_change: SourceChange {
564                                     source_file_edits: [],
565                                     file_system_edits: [
566                                         CreateFile {
567                                             dst: AnchoredPathBuf {
568                                                 anchor: FileId(
569                                                     0,
570                                                 ),
571                                                 path: "foo.rs",
572                                             },
573                                             initial_contents: "",
574                                         },
575                                     ],
576                                     is_snippet: false,
577                                 },
578                                 fix_trigger_range: 0..8,
579                             },
580                         ),
581                         unused: false,
582                         code: Some(
583                             DiagnosticCode(
584                                 "unresolved-module",
585                             ),
586                         ),
587                     },
588                 ]
589             "#]],
590         );
591     }
592
593     #[test]
594     fn range_mapping_out_of_macros() {
595         // FIXME: this is very wrong, but somewhat tricky to fix.
596         check_fix(
597             r#"
598 fn some() {}
599 fn items() {}
600 fn here() {}
601
602 macro_rules! id { ($($tt:tt)*) => { $($tt)*}; }
603
604 fn main() {
605     let _x = id![Foo { a: <|>42 }];
606 }
607
608 pub struct Foo { pub a: i32, pub b: i32 }
609 "#,
610             r#"
611 fn some(, b: ()) {}
612 fn items() {}
613 fn here() {}
614
615 macro_rules! id { ($($tt:tt)*) => { $($tt)*}; }
616
617 fn main() {
618     let _x = id![Foo { a: 42 }];
619 }
620
621 pub struct Foo { pub a: i32, pub b: i32 }
622 "#,
623         );
624     }
625
626     #[test]
627     fn test_check_unnecessary_braces_in_use_statement() {
628         check_no_diagnostics(
629             r#"
630 use a;
631 use a::{c, d::e};
632
633 mod a {
634     mod c {}
635     mod d {
636         mod e {}
637     }
638 }
639 "#,
640         );
641         check_fix(
642             r"
643             mod b {}
644             use {<|>b};
645             ",
646             r"
647             mod b {}
648             use b;
649             ",
650         );
651         check_fix(
652             r"
653             mod b {}
654             use {b<|>};
655             ",
656             r"
657             mod b {}
658             use b;
659             ",
660         );
661         check_fix(
662             r"
663             mod a { mod c {} }
664             use a::{c<|>};
665             ",
666             r"
667             mod a { mod c {} }
668             use a::c;
669             ",
670         );
671         check_fix(
672             r"
673             mod a {}
674             use a::{self<|>};
675             ",
676             r"
677             mod a {}
678             use a;
679             ",
680         );
681         check_fix(
682             r"
683             mod a { mod c {} mod d { mod e {} } }
684             use a::{c, d::{e<|>}};
685             ",
686             r"
687             mod a { mod c {} mod d { mod e {} } }
688             use a::{c, d::e};
689             ",
690         );
691     }
692
693     #[test]
694     fn test_add_field_from_usage() {
695         check_fix(
696             r"
697 fn main() {
698     Foo { bar: 3, baz<|>: false};
699 }
700 struct Foo {
701     bar: i32
702 }
703 ",
704             r"
705 fn main() {
706     Foo { bar: 3, baz: false};
707 }
708 struct Foo {
709     bar: i32,
710     baz: bool
711 }
712 ",
713         )
714     }
715
716     #[test]
717     fn test_add_field_in_other_file_from_usage() {
718         check_fix(
719             r#"
720 //- /main.rs
721 mod foo;
722
723 fn main() {
724     foo::Foo { bar: 3, <|>baz: false};
725 }
726 //- /foo.rs
727 struct Foo {
728     bar: i32
729 }
730 "#,
731             r#"
732 struct Foo {
733     bar: i32,
734     pub(crate) baz: bool
735 }
736 "#,
737         )
738     }
739
740     #[test]
741     fn test_disabled_diagnostics() {
742         let mut config = DiagnosticsConfig::default();
743         config.disabled.insert("unresolved-module".into());
744
745         let (analysis, file_id) = fixture::file(r#"mod foo;"#);
746
747         let diagnostics = analysis.diagnostics(&config, file_id).unwrap();
748         assert!(diagnostics.is_empty());
749
750         let diagnostics = analysis.diagnostics(&DiagnosticsConfig::default(), file_id).unwrap();
751         assert!(!diagnostics.is_empty());
752     }
753
754     #[test]
755     fn test_rename_incorrect_case() {
756         check_fix(
757             r#"
758 pub struct test_struct<|> { one: i32 }
759
760 pub fn some_fn(val: test_struct) -> test_struct {
761     test_struct { one: val.one + 1 }
762 }
763 "#,
764             r#"
765 pub struct TestStruct { one: i32 }
766
767 pub fn some_fn(val: TestStruct) -> TestStruct {
768     TestStruct { one: val.one + 1 }
769 }
770 "#,
771         );
772
773         check_fix(
774             r#"
775 pub fn some_fn(NonSnakeCase<|>: u8) -> u8 {
776     NonSnakeCase
777 }
778 "#,
779             r#"
780 pub fn some_fn(non_snake_case: u8) -> u8 {
781     non_snake_case
782 }
783 "#,
784         );
785
786         check_fix(
787             r#"
788 pub fn SomeFn<|>(val: u8) -> u8 {
789     if val != 0 { SomeFn(val - 1) } else { val }
790 }
791 "#,
792             r#"
793 pub fn some_fn(val: u8) -> u8 {
794     if val != 0 { some_fn(val - 1) } else { val }
795 }
796 "#,
797         );
798
799         check_fix(
800             r#"
801 fn some_fn() {
802     let whatAWeird_Formatting<|> = 10;
803     another_func(whatAWeird_Formatting);
804 }
805 "#,
806             r#"
807 fn some_fn() {
808     let what_a_weird_formatting = 10;
809     another_func(what_a_weird_formatting);
810 }
811 "#,
812         );
813     }
814
815     #[test]
816     fn test_uppercase_const_no_diagnostics() {
817         check_no_diagnostics(
818             r#"
819 fn foo() {
820     const ANOTHER_ITEM<|>: &str = "some_item";
821 }
822 "#,
823         );
824     }
825
826     #[test]
827     fn test_rename_incorrect_case_struct_method() {
828         check_fix(
829             r#"
830 pub struct TestStruct;
831
832 impl TestStruct {
833     pub fn SomeFn<|>() -> TestStruct {
834         TestStruct
835     }
836 }
837 "#,
838             r#"
839 pub struct TestStruct;
840
841 impl TestStruct {
842     pub fn some_fn() -> TestStruct {
843         TestStruct
844     }
845 }
846 "#,
847         );
848     }
849
850     #[test]
851     fn test_single_incorrect_case_diagnostic_in_function_name_issue_6970() {
852         let input = r#"fn FOO<|>() {}"#;
853         let expected = r#"fn foo() {}"#;
854
855         let (analysis, file_position) = fixture::position(input);
856         let diagnostics =
857             analysis.diagnostics(&DiagnosticsConfig::default(), file_position.file_id).unwrap();
858         assert_eq!(diagnostics.len(), 1);
859
860         check_fix(input, expected);
861     }
862 }