Skip to content

Commit 34b5b77

Browse files
committed
Do not suggest compatible variants inside macro
Signed-off-by: xizheyin <[email protected]>
1 parent 7e17ecf commit 34b5b77

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,10 +2422,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24222422
{
24232423
expr = expr_
24242424
}
2425+
let expr_span = expr.span.find_oldest_ancestor_in_same_ctxt();
24252426

24262427
vec![
2427-
(expr.span.shrink_to_lo(), format!("{prefix}{variant}{open}")),
2428-
(expr.span.shrink_to_hi(), close.to_owned()),
2428+
(expr_span.shrink_to_lo(), format!("{prefix}{variant}{open}")),
2429+
(expr_span.shrink_to_hi(), close.to_owned()),
24292430
]
24302431
};
24312432

tests/ui/typeck/suggestions/suggest-compatible-variants-macro-issue-142359.stderr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ LL | | };
1313
= note: expected enum `ControlFlow<i32, _>`
1414
found unit type `()`
1515
= note: this error originates in the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
16+
help: try wrapping the expression in `std::ops::ControlFlow::Continue`
17+
|
18+
LL | Ok(r) => { std::ops::ControlFlow::Continue(println!("A"))}
19+
| ++++++++++++++++++++++++++++++++ +
1620

1721
error: aborting due to 1 previous error
1822

0 commit comments

Comments
 (0)