Skip to content

Commit eb9bba8

Browse files
Walk into nested bodies when suggesting unit for unit fallback
1 parent cac63ff commit eb9bba8

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

compiler/rustc_hir_typeck/src/fallback.rs

+6
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,12 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> {
684684
}
685685

686686
fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Self::Result {
687+
if let hir::ExprKind::Closure(&hir::Closure { body, .. })
688+
| hir::ExprKind::ConstBlock(hir::ConstBlock { body, .. }) = expr.kind
689+
{
690+
self.visit_body(self.fcx.tcx.hir().body(body))?;
691+
}
692+
687693
// Try to suggest adding an explicit qself `()` to a trait method path.
688694
// i.e. changing `Default::default()` to `<() as Default>::default()`.
689695
if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind

tests/ui/never_type/dont-suggest-turbofish-from-expansion.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ note: the lint level is defined here
1717
|
1818
LL | #![deny(dependency_on_unit_never_type_fallback)]
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
20+
help: use `()` annotations to avoid fallback changes
21+
|
22+
LL | let created: () = create_ok_default()?;
23+
| ++++
2024

2125
error: aborting due to 1 previous error
2226

0 commit comments

Comments
 (0)