diff options
| author | xizheyin <xizheyin@smail.nju.edu.cn> | 2025-05-16 16:55:46 +0800 |
|---|---|---|
| committer | xizheyin <xizheyin@smail.nju.edu.cn> | 2025-05-17 01:01:54 +0800 |
| commit | 742c27bc524b806d04c34f22810f88cbf5fa4483 (patch) | |
| tree | 29ed2052c9dd8fe3d94ddb72e5144ee7027e7ad5 | |
| parent | 43ff8855ac55da567a5e2966e0942700d120e067 (diff) | |
| download | rust-742c27bc524b806d04c34f22810f88cbf5fa4483.tar.gz rust-742c27bc524b806d04c34f22810f88cbf5fa4483.zip | |
Do not emit help when shorthand from macro when suggest `?` or `expect`
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
| -rw-r--r-- | compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs | 1 | ||||
| -rw-r--r-- | tests/ui/typeck/macro-shorthand-issue-140659.rs | 1 | ||||
| -rw-r--r-- | tests/ui/typeck/macro-shorthand-issue-140659.stderr | 4 |
3 files changed, 1 insertions, 5 deletions
diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 91eb1989864..d3618a6ae69 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -2034,6 +2034,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; let sugg = match self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) { + Some(_) if expr.span.from_expansion() => return false, Some(ident) => format!(": {ident}{sugg}"), None => sugg.to_string(), }; diff --git a/tests/ui/typeck/macro-shorthand-issue-140659.rs b/tests/ui/typeck/macro-shorthand-issue-140659.rs index dba06b43d39..d71a7ff1d3d 100644 --- a/tests/ui/typeck/macro-shorthand-issue-140659.rs +++ b/tests/ui/typeck/macro-shorthand-issue-140659.rs @@ -45,7 +45,6 @@ fn process<T: Reencode>(op: &Operator, reencoder: &mut T) -> Instruction { }; } - // This should give the specific error message with the wrong help suggestion for_each_operator!(translate) } diff --git a/tests/ui/typeck/macro-shorthand-issue-140659.stderr b/tests/ui/typeck/macro-shorthand-issue-140659.stderr index 419db947571..12537754d80 100644 --- a/tests/ui/typeck/macro-shorthand-issue-140659.stderr +++ b/tests/ui/typeck/macro-shorthand-issue-140659.stderr @@ -10,10 +10,6 @@ LL | for_each_operator!(translate) = note: expected type `u32` found enum `Result<u32, <T as Reencode>::Error>` = 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) -help: consider using `Result::expect` to unwrap the `Result<u32, <T as Reencode>::Error>` value, panicking if the value is a `Result::Err` - | -LL | }: tag_index.expect("REASON") - | ++++++++++++++++++++++++++++ error: aborting due to 1 previous error |
