Skip to content

Commit

Permalink
Rollup merge of rust-lang#82090 - notriddle:consider-using-a-semicolo…
Browse files Browse the repository at this point in the history
…n-here, r=estebank

Do not consider using a semicolon inside of a different-crate macro

Fixes rust-lang#81943
  • Loading branch information
Dylan-DPC authored Feb 23, 2021
2 parents f30f76b + ba6c648 commit 502ac07
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
8 changes: 7 additions & 1 deletion compiler/rustc_typeck/src/check/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_infer::infer::{Coercion, InferOk, InferResult};
use rustc_middle::lint::in_external_macro;
use rustc_middle::ty::adjustment::{
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCast,
};
Expand Down Expand Up @@ -1448,7 +1449,12 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
expected.is_unit(),
pointing_at_return_type,
) {
if cond_expr.span.desugaring_kind().is_none() {
// If the block is from an external macro, then do not suggest
// adding a semicolon, because there's nowhere to put it.
// See issue #81943.
if cond_expr.span.desugaring_kind().is_none()
&& !in_external_macro(fcx.tcx.sess, cond_expr.span)
{
err.span_label(cond_expr.span, "expected this to be `()`");
if expr.can_have_side_effects() {
fcx.suggest_semicolon_at_end(cond_expr.span, &mut err);
Expand Down
9 changes: 9 additions & 0 deletions src/test/ui/typeck/issue-81943.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn f<F: Fn(i32)>(f: F) { f(0); }
fn main() {
f(|x| dbg!(x)); //~ERROR
f(|x| match x { tmp => { tmp } }); //~ERROR
macro_rules! d {
($e:expr) => { match $e { x => { x } } } //~ERROR
}
f(|x| d!(x));
}
34 changes: 34 additions & 0 deletions src/test/ui/typeck/issue-81943.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
error[E0308]: mismatched types
--> $DIR/issue-81943.rs:3:9
|
LL | f(|x| dbg!(x));
| ^^^^^^^ expected `()`, found `i32`
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0308]: mismatched types
--> $DIR/issue-81943.rs:4:28
|
LL | f(|x| match x { tmp => { tmp } });
| -------------------^^^----- help: consider using a semicolon here
| | |
| | expected `()`, found `i32`
| expected this to be `()`

error[E0308]: mismatched types
--> $DIR/issue-81943.rs:6:38
|
LL | ($e:expr) => { match $e { x => { x } } }
| ------------------^----- help: consider using a semicolon here
| | |
| | expected `()`, found `i32`
| expected this to be `()`
LL | }
LL | f(|x| d!(x));
| ----- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 3 previous errors

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

0 comments on commit 502ac07

Please sign in to comment.