- .on::<hir::diagnostics::UnresolvedModule, _>(|d| {
- res.borrow_mut().push(diagnostic_with_fix(d, &sema, resolve));
- })
- .on::<hir::diagnostics::MissingFields, _>(|d| {
- res.borrow_mut().push(diagnostic_with_fix(d, &sema, resolve));
- })
- .on::<hir::diagnostics::MissingOkOrSomeInTailExpr, _>(|d| {
- res.borrow_mut().push(diagnostic_with_fix(d, &sema, resolve));
- })
- .on::<hir::diagnostics::NoSuchField, _>(|d| {
- res.borrow_mut().push(diagnostic_with_fix(d, &sema, resolve));
- })
- .on::<hir::diagnostics::RemoveThisSemicolon, _>(|d| {
- res.borrow_mut().push(diagnostic_with_fix(d, &sema, resolve));
- })
- .on::<hir::diagnostics::IncorrectCase, _>(|d| {
- res.borrow_mut().push(warning_with_fix(d, &sema, resolve));
- })
- .on::<hir::diagnostics::ReplaceFilterMapNextWithFindMap, _>(|d| {
- res.borrow_mut().push(warning_with_fix(d, &sema, resolve));
- })
- .on::<hir::diagnostics::InactiveCode, _>(|d| {
- // If there's inactive code somewhere in a macro, don't propagate to the call-site.
- if d.display_source().file_id.expansion_info(db).is_some() {
- return;
- }
-
- // Override severity and mark as unused.
- res.borrow_mut().push(
- Diagnostic::hint(
- sema.diagnostics_display_range(d.display_source()).range,
- d.message(),
- )
- .with_unused(true)
- .with_code(Some(d.code())),
- );
- })
- .on::<UnlinkedFile, _>(|d| {
- // Limit diagnostic to the first few characters in the file. This matches how VS Code
- // renders it with the full span, but on other editors, and is less invasive.
- let range = sema.diagnostics_display_range(d.display_source()).range;
- let range = range.intersect(TextRange::up_to(TextSize::of("..."))).unwrap_or(range);
-
- // Override severity and mark as unused.
- res.borrow_mut().push(
- Diagnostic::hint(range, d.message())
- .with_fixes(d.fixes(&sema, resolve))
- .with_code(Some(d.code())),
- );
- })
- .on::<hir::diagnostics::UnresolvedProcMacro, _>(|d| {
- // Use more accurate position if available.
- let display_range = d
- .precise_location
- .unwrap_or_else(|| sema.diagnostics_display_range(d.display_source()).range);
-
- // FIXME: it would be nice to tell the user whether proc macros are currently disabled
- res.borrow_mut()
- .push(Diagnostic::hint(display_range, d.message()).with_code(Some(d.code())));
- })
- .on::<hir::diagnostics::UnresolvedMacroCall, _>(|d| {
- let last_path_segment = sema.db.parse_or_expand(d.file).and_then(|root| {
- d.node
- .to_node(&root)
- .path()
- .and_then(|it| it.segment())
- .and_then(|it| it.name_ref())
- .map(|it| InFile::new(d.file, SyntaxNodePtr::new(it.syntax())))
- });
- let diagnostics = last_path_segment.unwrap_or_else(|| d.display_source());
- let display_range = sema.diagnostics_display_range(diagnostics).range;
- res.borrow_mut()
- .push(Diagnostic::error(display_range, d.message()).with_code(Some(d.code())));
- })
- .on::<hir::diagnostics::UnimplementedBuiltinMacro, _>(|d| {
- let display_range = sema.diagnostics_display_range(d.display_source()).range;
- res.borrow_mut()
- .push(Diagnostic::hint(display_range, d.message()).with_code(Some(d.code())));
- })