diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-08-16 08:43:51 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-16 08:43:51 +0200 |
| commit | 8f1c8116f660eefcd926659b1dec71c46709e114 (patch) | |
| tree | ea3e9f51158e868cd041cd5a575ae11af50479ec | |
| parent | e21e039a78420576412500521bf2e9990bbde523 (diff) | |
| parent | 860fc246088c349bd95ce2da3e8637bb0c590105 (diff) | |
| download | rust-8f1c8116f660eefcd926659b1dec71c46709e114.tar.gz rust-8f1c8116f660eefcd926659b1dec71c46709e114.zip | |
Rollup merge of #114779 - MU001999:fix/114701, r=petrochenkov
Add check before suggest removing parens Fixes #114701
| -rw-r--r-- | compiler/rustc_hir_typeck/src/callee.rs | 1 | ||||
| -rw-r--r-- | tests/ui/suggestions/issue-114701.rs | 15 | ||||
| -rw-r--r-- | tests/ui/suggestions/issue-114701.stderr | 15 |
3 files changed, 31 insertions, 0 deletions
diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index dd79d1afc62..02371f85ac3 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -599,6 +599,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { = self.typeck_results.borrow().qpath_res(qpath, callee_expr.hir_id) // Only suggest removing parens if there are no arguments && arg_exprs.is_empty() + && call_expr.span.contains(callee_expr.span) { let descr = match kind { def::CtorOf::Struct => "struct", diff --git a/tests/ui/suggestions/issue-114701.rs b/tests/ui/suggestions/issue-114701.rs new file mode 100644 index 00000000000..81d7803ec8c --- /dev/null +++ b/tests/ui/suggestions/issue-114701.rs @@ -0,0 +1,15 @@ +enum Enum<T> { SVariant { v: T }, UVariant } + +macro_rules! is_variant { + (TSVariant, ) => (!); + (SVariant, ) => (!); + (UVariant, $expr:expr) => (is_variant!(@check UVariant, {}, $expr)); + (@check $variant:ident, $matcher:tt, $expr:expr) => ( + assert!(if let Enum::$variant::<()> $matcher = $expr () { true } else { false }, + ); + ); +} + +fn main() { + is_variant!(UVariant, Enum::<()>::UVariant); //~ ERROR expected function +} diff --git a/tests/ui/suggestions/issue-114701.stderr b/tests/ui/suggestions/issue-114701.stderr new file mode 100644 index 00000000000..67462a09c78 --- /dev/null +++ b/tests/ui/suggestions/issue-114701.stderr @@ -0,0 +1,15 @@ +error[E0618]: expected function, found `Enum<()>` + --> $DIR/issue-114701.rs:14:27 + | +LL | enum Enum<T> { SVariant { v: T }, UVariant } + | -------- `Enum::UVariant` defined here +... +LL | assert!(if let Enum::$variant::<()> $matcher = $expr () { true } else { false }, + | -------- call expression requires function +... +LL | is_variant!(UVariant, Enum::<()>::UVariant); + | ^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0618`. |
