Rollup merge of #88450 - notriddle:notriddle/maybe_whole_expr, r=cjgillot
fix(rustc_parse): correct span in `maybe_whole_expr!` Fixes #87812
This commit is contained in:
commit
7696aca55f
5 changed files with 64 additions and 2 deletions
|
@ -41,7 +41,7 @@ macro_rules! maybe_whole_expr {
|
||||||
let path = path.clone();
|
let path = path.clone();
|
||||||
$p.bump();
|
$p.bump();
|
||||||
return Ok($p.mk_expr(
|
return Ok($p.mk_expr(
|
||||||
$p.token.span,
|
$p.prev_token.span,
|
||||||
ExprKind::Path(None, path),
|
ExprKind::Path(None, path),
|
||||||
AttrVec::new(),
|
AttrVec::new(),
|
||||||
));
|
));
|
||||||
|
@ -50,7 +50,7 @@ macro_rules! maybe_whole_expr {
|
||||||
let block = block.clone();
|
let block = block.clone();
|
||||||
$p.bump();
|
$p.bump();
|
||||||
return Ok($p.mk_expr(
|
return Ok($p.mk_expr(
|
||||||
$p.token.span,
|
$p.prev_token.span,
|
||||||
ExprKind::Block(block, None),
|
ExprKind::Block(block, None),
|
||||||
AttrVec::new(),
|
AttrVec::new(),
|
||||||
));
|
));
|
||||||
|
|
11
src/test/ui/parser/issue-87812-path.rs
Normal file
11
src/test/ui/parser/issue-87812-path.rs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
macro_rules! foo {
|
||||||
|
( $f:path ) => {{
|
||||||
|
let _: usize = $f; //~ERROR
|
||||||
|
}};
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Baz;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
foo!(Baz);
|
||||||
|
}
|
16
src/test/ui/parser/issue-87812-path.stderr
Normal file
16
src/test/ui/parser/issue-87812-path.stderr
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
error[E0308]: mismatched types
|
||||||
|
--> $DIR/issue-87812-path.rs:3:24
|
||||||
|
|
|
||||||
|
LL | let _: usize = $f;
|
||||||
|
| ----- ^^ expected `usize`, found struct `Baz`
|
||||||
|
| |
|
||||||
|
| expected due to this
|
||||||
|
...
|
||||||
|
LL | foo!(Baz);
|
||||||
|
| ---------- in this macro invocation
|
||||||
|
|
|
||||||
|
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0308`.
|
13
src/test/ui/parser/issue-87812.rs
Normal file
13
src/test/ui/parser/issue-87812.rs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
#![deny(break_with_label_and_loop)]
|
||||||
|
|
||||||
|
macro_rules! foo {
|
||||||
|
( $f:block ) => {
|
||||||
|
'_l: loop {
|
||||||
|
break '_l $f; //~ERROR
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let x = foo!({ 3 });
|
||||||
|
}
|
22
src/test/ui/parser/issue-87812.stderr
Normal file
22
src/test/ui/parser/issue-87812.stderr
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
error: this labeled break expression is easy to confuse with an unlabeled break with a labeled value expression
|
||||||
|
--> $DIR/issue-87812.rs:6:13
|
||||||
|
|
|
||||||
|
LL | break '_l $f;
|
||||||
|
| ^^^^^^^^^^^^
|
||||||
|
...
|
||||||
|
LL | let x = foo!({ 3 });
|
||||||
|
| ----------- in this macro invocation
|
||||||
|
|
|
||||||
|
note: the lint level is defined here
|
||||||
|
--> $DIR/issue-87812.rs:1:9
|
||||||
|
|
|
||||||
|
LL | #![deny(break_with_label_and_loop)]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
= note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
help: wrap this expression in parentheses
|
||||||
|
|
|
||||||
|
LL | break '_l ($f);
|
||||||
|
| + +
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue