Skip to content

Commit 41b9ec6

Browse files
committed
Do not emit help when shorthand from macro when suggest ? or expect
Signed-off-by: xizheyin <[email protected]>
1 parent 43ff885 commit 41b9ec6

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2034,8 +2034,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20342034
};
20352035

20362036
let sugg = match self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
2037+
Some(_) if expr.span.from_expansion() => return false,
20372038
Some(ident) => format!(": {ident}{sugg}"),
2038-
None => sugg.to_string(),
2039+
_ => sugg.to_string(),
20392040
};
20402041

20412042
let span = expr.span.find_oldest_ancestor_in_same_ctxt();

tests/ui/typeck/macro-shorthand-issue-140659.stderr

-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@ LL | for_each_operator!(translate)
1010
= note: expected type `u32`
1111
found enum `Result<u32, <T as Reencode>::Error>`
1212
= note: this error originates in the macro `translate` which comes from the expansion of the macro `for_each_operator` (in Nightly builds, run with -Z macro-backtrace for more info)
13-
help: consider using `Result::expect` to unwrap the `Result<u32, <T as Reencode>::Error>` value, panicking if the value is a `Result::Err`
14-
|
15-
LL | }: tag_index.expect("REASON")
16-
| ++++++++++++++++++++++++++++
1713

1814
error: aborting due to 1 previous error
1915

0 commit comments

Comments
 (0)