Skip to content

Commit 502ac07

Browse files
authored
Rollup merge of rust-lang#82090 - notriddle:consider-using-a-semicolon-here, r=estebank
Do not consider using a semicolon inside of a different-crate macro Fixes rust-lang#81943
2 parents f30f76b + ba6c648 commit 502ac07

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

compiler/rustc_typeck/src/check/coercion.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use rustc_hir as hir;
4242
use rustc_hir::def_id::DefId;
4343
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
4444
use rustc_infer::infer::{Coercion, InferOk, InferResult};
45+
use rustc_middle::lint::in_external_macro;
4546
use rustc_middle::ty::adjustment::{
4647
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCast,
4748
};
@@ -1448,7 +1449,12 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
14481449
expected.is_unit(),
14491450
pointing_at_return_type,
14501451
) {
1451-
if cond_expr.span.desugaring_kind().is_none() {
1452+
// If the block is from an external macro, then do not suggest
1453+
// adding a semicolon, because there's nowhere to put it.
1454+
// See issue #81943.
1455+
if cond_expr.span.desugaring_kind().is_none()
1456+
&& !in_external_macro(fcx.tcx.sess, cond_expr.span)
1457+
{
14521458
err.span_label(cond_expr.span, "expected this to be `()`");
14531459
if expr.can_have_side_effects() {
14541460
fcx.suggest_semicolon_at_end(cond_expr.span, &mut err);

src/test/ui/typeck/issue-81943.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn f<F: Fn(i32)>(f: F) { f(0); }
2+
fn main() {
3+
f(|x| dbg!(x)); //~ERROR
4+
f(|x| match x { tmp => { tmp } }); //~ERROR
5+
macro_rules! d {
6+
($e:expr) => { match $e { x => { x } } } //~ERROR
7+
}
8+
f(|x| d!(x));
9+
}

src/test/ui/typeck/issue-81943.stderr

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/issue-81943.rs:3:9
3+
|
4+
LL | f(|x| dbg!(x));
5+
| ^^^^^^^ expected `()`, found `i32`
6+
|
7+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
8+
9+
error[E0308]: mismatched types
10+
--> $DIR/issue-81943.rs:4:28
11+
|
12+
LL | f(|x| match x { tmp => { tmp } });
13+
| -------------------^^^----- help: consider using a semicolon here
14+
| | |
15+
| | expected `()`, found `i32`
16+
| expected this to be `()`
17+
18+
error[E0308]: mismatched types
19+
--> $DIR/issue-81943.rs:6:38
20+
|
21+
LL | ($e:expr) => { match $e { x => { x } } }
22+
| ------------------^----- help: consider using a semicolon here
23+
| | |
24+
| | expected `()`, found `i32`
25+
| expected this to be `()`
26+
LL | }
27+
LL | f(|x| d!(x));
28+
| ----- in this macro invocation
29+
|
30+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
31+
32+
error: aborting due to 3 previous errors
33+
34+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)