Skip to content

Add check before suggest removing parens #114779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/suggestions/issue-114701.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
enum Enum<T> { , SVariant { v: T }, UVariant } //~ ERROR expected identifier, found `,`

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 () else { false }, //~ ERROR this `if` expression
);
);
}

fn main() {
is_variant!(UVariant, Enum::<()>::UVariant); //~ ERROR expected function
}
48 changes: 48 additions & 0 deletions tests/ui/suggestions/issue-114701.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
error: expected identifier, found `,`
--> $DIR/issue-114701.rs:1:16
|
LL | enum Enum<T> { , SVariant { v: T }, UVariant }
| ^
| |
| expected identifier
| help: remove this comma

error: this `if` expression is missing a block after the condition
--> $DIR/issue-114701.rs:8:17
|
LL | assert!(if let Enum::$variant::<()> $matcher = $expr () else { false },
| ^^
...
LL | is_variant!(UVariant, Enum::<()>::UVariant);
| ------------------------------------------- in this macro invocation
|
help: add a block here
--> $DIR/issue-114701.rs:8:64
|
LL | assert!(if let Enum::$variant::<()> $matcher = $expr () else { false },
| ^
...
LL | is_variant!(UVariant, Enum::<()>::UVariant);
| ------------------------------------------- in this macro invocation
= note: this error originates in the macro `is_variant` (in Nightly builds, run with -Z macro-backtrace for more info)
help: remove the `if` if you meant to write a `let...else` statement
|
LL - assert!(if let Enum::$variant::<()> $matcher = $expr () else { false },
LL + assert!(let Enum::$variant::<()> $matcher = $expr () else { false },
|

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 () else { false },
| -------- call expression requires function
...
LL | is_variant!(UVariant, Enum::<()>::UVariant);
| ^^^^^^^^^^^^^^^^^^^^

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0618`.