diff options
| author | Michael Goulet <michael@errs.io> | 2025-02-05 19:01:26 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-02-05 19:01:55 +0000 |
| commit | eb9bba879a33995ae6769cbb906d45370f0af018 (patch) | |
| tree | 6ceb8baabfa7aef29d03920b8741c4e484383a71 | |
| parent | cac63ffc0fe4d963f902311d5938e03a0a8437aa (diff) | |
| download | rust-eb9bba879a33995ae6769cbb906d45370f0af018.tar.gz rust-eb9bba879a33995ae6769cbb906d45370f0af018.zip | |
Walk into nested bodies when suggesting unit for unit fallback
| -rw-r--r-- | compiler/rustc_hir_typeck/src/fallback.rs | 6 | ||||
| -rw-r--r-- | tests/ui/never_type/dont-suggest-turbofish-from-expansion.stderr | 4 |
2 files changed, 10 insertions, 0 deletions
diff --git a/compiler/rustc_hir_typeck/src/fallback.rs b/compiler/rustc_hir_typeck/src/fallback.rs index b09649f006d..4618c5d3849 100644 --- a/compiler/rustc_hir_typeck/src/fallback.rs +++ b/compiler/rustc_hir_typeck/src/fallback.rs @@ -684,6 +684,12 @@ impl<'tcx> Visitor<'tcx> for AnnotateUnitFallbackVisitor<'_, 'tcx> { } fn visit_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Self::Result { + if let hir::ExprKind::Closure(&hir::Closure { body, .. }) + | hir::ExprKind::ConstBlock(hir::ConstBlock { body, .. }) = expr.kind + { + self.visit_body(self.fcx.tcx.hir().body(body))?; + } + // Try to suggest adding an explicit qself `()` to a trait method path. // i.e. changing `Default::default()` to `<() as Default>::default()`. if let hir::ExprKind::Path(hir::QPath::Resolved(None, path)) = expr.kind diff --git a/tests/ui/never_type/dont-suggest-turbofish-from-expansion.stderr b/tests/ui/never_type/dont-suggest-turbofish-from-expansion.stderr index b72324129e5..3fe642a8401 100644 --- a/tests/ui/never_type/dont-suggest-turbofish-from-expansion.stderr +++ b/tests/ui/never_type/dont-suggest-turbofish-from-expansion.stderr @@ -17,6 +17,10 @@ note: the lint level is defined here | LL | #![deny(dependency_on_unit_never_type_fallback)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +help: use `()` annotations to avoid fallback changes + | +LL | let created: () = create_ok_default()?; + | ++++ error: aborting due to 1 previous error |
