From b4ca582b8986c36d23726dc292c41b06fe7f9c6b Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Sun, 25 Feb 2024 18:51:22 +0100 Subject: rename 'try' intrinsic to 'catch_unwind' --- tests/assembly/wasm_exceptions.rs | 2 +- tests/codegen/wasm_exceptions.rs | 2 +- tests/run-make/wasm-exceptions-nostd/src/lib.rs | 2 +- tests/ui/interior-mutability/interior-mutability.stderr | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/assembly/wasm_exceptions.rs b/tests/assembly/wasm_exceptions.rs index 2ca62a78688..45df444dca4 100644 --- a/tests/assembly/wasm_exceptions.rs +++ b/tests/assembly/wasm_exceptions.rs @@ -41,7 +41,7 @@ pub fn test_cleanup() { #[no_mangle] pub fn test_rtry() { unsafe { - core::intrinsics::r#try(|_| { + core::intrinsics::catch_unwind(|_| { may_panic(); }, core::ptr::null_mut(), |data, exception| { log_number(data as usize); diff --git a/tests/codegen/wasm_exceptions.rs b/tests/codegen/wasm_exceptions.rs index 48a7357bfd8..66d2bbed709 100644 --- a/tests/codegen/wasm_exceptions.rs +++ b/tests/codegen/wasm_exceptions.rs @@ -35,7 +35,7 @@ pub fn test_cleanup() { #[no_mangle] pub fn test_rtry() { unsafe { - core::intrinsics::r#try(|_| { + core::intrinsics::catch_unwind(|_| { may_panic(); }, core::ptr::null_mut(), |data, exception| { log_number(data as usize); diff --git a/tests/run-make/wasm-exceptions-nostd/src/lib.rs b/tests/run-make/wasm-exceptions-nostd/src/lib.rs index 7049d2fd9e0..9d336510469 100644 --- a/tests/run-make/wasm-exceptions-nostd/src/lib.rs +++ b/tests/run-make/wasm-exceptions-nostd/src/lib.rs @@ -39,7 +39,7 @@ pub extern "C" fn start() -> usize { let data = 0x1234usize as *mut u8; // Something to recognize unsafe { - core::intrinsics::r#try(|data: *mut u8| { + core::intrinsics::catch_unwind(|data: *mut u8| { let _log_on_drop = LogOnDrop; logging::log_str(&alloc::format!("`r#try` called with ptr {:?}", data)); diff --git a/tests/ui/interior-mutability/interior-mutability.stderr b/tests/ui/interior-mutability/interior-mutability.stderr index 7b08a645405..29b250c1b07 100644 --- a/tests/ui/interior-mutability/interior-mutability.stderr +++ b/tests/ui/interior-mutability/interior-mutability.stderr @@ -15,7 +15,7 @@ note: required because it's used within this closure | LL | catch_unwind(|| { x.set(23); }); | ^^ -note: required by a bound in `catch_unwind` +note: required by a bound in `std::panic::catch_unwind` --> $SRC_DIR/std/src/panic.rs:LL:COL error: aborting due to 1 previous error -- cgit 1.4.1-3-g733a5 From 1658ca082a1d510480a7c228b0b6bfb83863d0e9 Mon Sep 17 00:00:00 2001 From: Lieselotte <52315535+she3py@users.noreply.github.com> Date: Mon, 26 Feb 2024 21:47:10 +0100 Subject: Properly emit `expected ;` on `#[attr] expr` --- compiler/rustc_parse/src/parser/diagnostics.rs | 6 ++--- ...over-from-trailing-outer-attribute-in-body-1.rs | 9 ++++++++ ...-from-trailing-outer-attribute-in-body-1.stderr | 27 ++++++++++++++++++++++ ...over-from-trailing-outer-attribute-in-body-2.rs | 15 ++++++++++++ ...-from-trailing-outer-attribute-in-body-2.stderr | 26 +++++++++++++++++++++ ...ecover-from-trailing-outer-attribute-in-body.rs | 9 -------- ...er-from-trailing-outer-attribute-in-body.stderr | 27 ---------------------- 7 files changed, 79 insertions(+), 40 deletions(-) create mode 100644 tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-1.rs create mode 100644 tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-1.stderr create mode 100644 tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-2.rs create mode 100644 tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-2.stderr delete mode 100644 tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body.rs delete mode 100644 tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body.stderr (limited to 'tests') diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index cc1f7c8ac7d..995e140b329 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -800,9 +800,8 @@ impl<'a> Parser<'a> { { Ok(next_attr) => next_attr, Err(inner_err) => { - err.cancel(); inner_err.cancel(); - return self.dcx().span_delayed_bug(expr.span, "not a tail expression"); + return err.emit(); } } && let ast::AttrKind::Normal(next_attr_kind) = next_attr.kind @@ -813,9 +812,8 @@ impl<'a> Parser<'a> { let next_expr = match snapshot.parse_expr() { Ok(next_expr) => next_expr, Err(inner_err) => { - err.cancel(); inner_err.cancel(); - return self.dcx().span_delayed_bug(expr.span, "not a tail expression"); + return err.emit(); } }; // We have for sure diff --git a/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-1.rs b/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-1.rs new file mode 100644 index 00000000000..a7412f51782 --- /dev/null +++ b/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-1.rs @@ -0,0 +1,9 @@ +// Issue #118164: recovery path leaving unemitted error behind +fn bar() -> String { + #[cfg(feature = )] + [1, 2, 3].iter().map().collect::() //~ ERROR expected `;`, found `#` + #[attr] //~ ERROR expected statement after outer attribute +} +fn main() { + let _ = bar(); +} diff --git a/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-1.stderr b/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-1.stderr new file mode 100644 index 00000000000..dcc2e92c47a --- /dev/null +++ b/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-1.stderr @@ -0,0 +1,27 @@ +error: expected `;`, found `#` + --> $DIR/properly-recover-from-trailing-outer-attribute-in-body-1.rs:4:47 + | +LL | #[cfg(feature = )] + | ------------------ only `;` terminated statements or tail expressions are allowed after this attribute +LL | [1, 2, 3].iter().map().collect::() + | ^ expected `;` here +LL | #[attr] + | - unexpected token + | +help: add `;` here + | +LL | [1, 2, 3].iter().map().collect::(); + | + +help: alternatively, consider surrounding the expression with a block + | +LL | { [1, 2, 3].iter().map().collect::() } + | + + + +error: expected statement after outer attribute + --> $DIR/properly-recover-from-trailing-outer-attribute-in-body-1.rs:5:5 + | +LL | #[attr] + | ^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-2.rs b/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-2.rs new file mode 100644 index 00000000000..ad9e7ad707b --- /dev/null +++ b/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-2.rs @@ -0,0 +1,15 @@ +// Issue #121647: recovery path leaving unemitted error behind + +macro_rules! the_macro { + ( $foo:stmt ; $bar:stmt ; ) => { + #[cfg()] + $foo //~ ERROR expected `;`, found `#` + + #[cfg(bar)] + $bar + }; +} + +fn main() { + the_macro!( (); (); ); +} diff --git a/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-2.stderr b/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-2.stderr new file mode 100644 index 00000000000..7b9b8319674 --- /dev/null +++ b/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-2.stderr @@ -0,0 +1,26 @@ +error: expected `;`, found `#` + --> $DIR/properly-recover-from-trailing-outer-attribute-in-body-2.rs:6:13 + | +LL | #[cfg()] + | -------- only `;` terminated statements or tail expressions are allowed after this attribute +LL | $foo + | ^ expected `;` here +LL | +LL | #[cfg(bar)] + | - unexpected token +... +LL | the_macro!( (); (); ); + | --------------------- in this macro invocation + | + = note: this error originates in the macro `the_macro` (in Nightly builds, run with -Z macro-backtrace for more info) +help: add `;` here + | +LL | $foo; + | + +help: alternatively, consider surrounding the expression with a block + | +LL | the_macro!( { () }; (); ); + | + + + +error: aborting due to 1 previous error + diff --git a/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body.rs b/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body.rs deleted file mode 100644 index a7412f51782..00000000000 --- a/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body.rs +++ /dev/null @@ -1,9 +0,0 @@ -// Issue #118164: recovery path leaving unemitted error behind -fn bar() -> String { - #[cfg(feature = )] - [1, 2, 3].iter().map().collect::() //~ ERROR expected `;`, found `#` - #[attr] //~ ERROR expected statement after outer attribute -} -fn main() { - let _ = bar(); -} diff --git a/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body.stderr b/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body.stderr deleted file mode 100644 index dd0081cc2df..00000000000 --- a/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body.stderr +++ /dev/null @@ -1,27 +0,0 @@ -error: expected `;`, found `#` - --> $DIR/properly-recover-from-trailing-outer-attribute-in-body.rs:4:47 - | -LL | #[cfg(feature = )] - | ------------------ only `;` terminated statements or tail expressions are allowed after this attribute -LL | [1, 2, 3].iter().map().collect::() - | ^ expected `;` here -LL | #[attr] - | - unexpected token - | -help: add `;` here - | -LL | [1, 2, 3].iter().map().collect::(); - | + -help: alternatively, consider surrounding the expression with a block - | -LL | { [1, 2, 3].iter().map().collect::() } - | + + - -error: expected statement after outer attribute - --> $DIR/properly-recover-from-trailing-outer-attribute-in-body.rs:5:5 - | -LL | #[attr] - | ^^^^^^^ - -error: aborting due to 2 previous errors - -- cgit 1.4.1-3-g733a5