Skip to content

Commit 8f1c811

Browse files
authored
Rollup merge of #114779 - MU001999:fix/114701, r=petrochenkov
Add check before suggest removing parens Fixes #114701
2 parents e21e039 + 860fc24 commit 8f1c811

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

compiler/rustc_hir_typeck/src/callee.rs

+1
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
599599
= self.typeck_results.borrow().qpath_res(qpath, callee_expr.hir_id)
600600
// Only suggest removing parens if there are no arguments
601601
&& arg_exprs.is_empty()
602+
&& call_expr.span.contains(callee_expr.span)
602603
{
603604
let descr = match kind {
604605
def::CtorOf::Struct => "struct",

tests/ui/suggestions/issue-114701.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
enum Enum<T> { SVariant { v: T }, UVariant }
2+
3+
macro_rules! is_variant {
4+
(TSVariant, ) => (!);
5+
(SVariant, ) => (!);
6+
(UVariant, $expr:expr) => (is_variant!(@check UVariant, {}, $expr));
7+
(@check $variant:ident, $matcher:tt, $expr:expr) => (
8+
assert!(if let Enum::$variant::<()> $matcher = $expr () { true } else { false },
9+
);
10+
);
11+
}
12+
13+
fn main() {
14+
is_variant!(UVariant, Enum::<()>::UVariant); //~ ERROR expected function
15+
}
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0618]: expected function, found `Enum<()>`
2+
--> $DIR/issue-114701.rs:14:27
3+
|
4+
LL | enum Enum<T> { SVariant { v: T }, UVariant }
5+
| -------- `Enum::UVariant` defined here
6+
...
7+
LL | assert!(if let Enum::$variant::<()> $matcher = $expr () { true } else { false },
8+
| -------- call expression requires function
9+
...
10+
LL | is_variant!(UVariant, Enum::<()>::UVariant);
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0618`.

0 commit comments

Comments
 (0)