Closed
Description
I tried this code (https://github.com/rust-lang/rust/blob/0da6d42f297642a60f2640ec313b879b376b9ad8/compiler/rustc_mir/src/interpret/validity.rs#L78-L96):
macro_rules! try_validation {
($e:expr, $where:expr,
$( $( $p:pat )|+ => { $( $what_fmt:expr ),+ } $( expected { $( $expected_fmt:expr ),+ } )? ),+ $(,)?
) => {{
match $e {
Ok(x) => x,
// We catch the error and turn it into a validation failure. We are okay with
// allocation here as this can only slow down builds that fail anyway.
$( $( Err(InterpErrorInfo { kind: $p, .. }) )|+ =>
throw_validation_failure!(
$where,
{ $( $what_fmt ),+ } $( expected { $( $expected_fmt ),+ } )?
),
)+
#[allow(unreachable_patterns)]
Err(e) => Err::<!, _>(e)?,
}
}};
}
I expected to see this happen: The Err(e)?
is replaced with return Err(e)
.
Instead, this happened: It's replaced with return Err(e);
, causing a syntax error since this is an expression context.
error: expected one of `)`, `,`, `.`, `?`, or an operator, found `;`
--> compiler/rustc_mir/src/interpret/validity.rs:97:18
|
78 | / macro_rules! try_validation {
79 | | ($e:expr, $where:expr,
80 | | $( $( $p:pat )|+ => { $( $what_fmt:expr ),+ } $( expected { $( $expected_fmt:expr ),+ } )? ),+ $(,)?
81 | | ) => {{
... |
93 | | Err(e) => return Err(try_validation!(
| |__________________________________-
94 | || self.ecx.memory.read_bytes(mplace.ptr, Size::from_bytes(len)),
95 | || self.path,
96 | || err_ub!(InvalidUninitBytes(..)) => { "uninitialized data in `str`" },
97 | || );),
| || -^ expected one of `)`, `,`, `.`, `?`, or an operator
| ||_________________|
| | in this macro invocation (#2)
98 | | }
99 | | }};
100 | | }
| | -
| | |
| |_in this expansion of `try_validation!` (#1)
| in this expansion of `try_validation!` (#2)
...
341 | / try_validation!(
342 | | self.ecx.read_size_and_align_from_vtable(vtable),
343 | | self.path,
344 | | err_unsup!(ReadPointerAsBytes) => { "invalid size or align in vtable" },
345 | | );
| |___________________- in this macro invocation (#1)
warning: returning an `Err(_)` with the `?` operator
--> compiler/rustc_mir/src/interpret/validity.rs:93:23
|
78 | / macro_rules! try_validation {
79 | | ($e:expr, $where:expr,
80 | | $( $( $p:pat )|+ => { $( $what_fmt:expr ),+ } $( expected { $( $expected_fmt:expr ),+ } )? ),+ $(,)?
81 | | ) => {{
... |
93 | | Err(e) => Err::<!, _>(e)?,
| | ^^^^^^^^^^^^^^^
94 | | }
95 | | }};
96 | | }
| |_- in this expansion of `try_validation!`
...
310 | / try_validation!(
311 | | self.ecx.memory.check_ptr_access_align(
312 | | vtable,
313 | | 3 * self.ecx.tcx.data_layout.pointer_size, // drop, size, align
... |
325 | | { "too small vtable" },
326 | | );
| |__________________- in this macro invocation
|
= note: `#[warn(clippy::try_err)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#try_err
help: try this
|
93 | Err(e) => return Err(try_validation!(
94 | self.ecx.memory.check_ptr_access_align(
95 | vtable,
96 | 3 * self.ecx.tcx.data_layout.pointer_size, // drop, size, align
97 | Some(self.ecx.tcx.data_layout.pointer_align.abi),
98 | CheckInAllocMsg::InboundsTest,
...
Meta
cargo clippy -V
: clippy 0.0.212 (ffa2e7a 2020-10-24)