Skip to content

Commit 5cceb19

Browse files
committed
Document artificial-block.rs
1 parent d20803d commit 5cceb19

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

tests/ui/artificial-block.rs

+27-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
1+
//! Check that we don't get compile errors on unreachable code after the `{ ret 3; }` artificial
2+
//! block below. This test is run-pass to also exercise the codegen, but it might be possible to
3+
//! reduce to build-pass or even check-pass.
4+
//!
5+
//! This test was introduced as part of commit `a833f152baa17460e8414355e832d30d5161f8e8` which
6+
//! removes an "artificial block". See also commit `8d381823e2aa1524eabeb3219d7dc1d5007e6096` for
7+
//! more elaboration, produced below (this is outdated for *today*'s rustc as of Dec 05, 2024, but
8+
//! is helpful to understand the original intention):
9+
//!
10+
//! > Return a fresh, unreachable context after ret, break, and cont
11+
//! >
12+
//! > This ensures we don't get compile errors on unreachable code (see
13+
//! > test/run-pass/artificial-block.rs for an example of sane code that wasn't compiling). In the
14+
//! > future, we might want to warn about non-trivial code appearing in an unreachable context,
15+
//! > and/or avoid generating unreachable code altogether (though I'm sure LLVM will weed it out as
16+
//! > well).
17+
//!
18+
//! Since then, `ret` -> `return`, `int` -> `isize`, `assert` became a macro.
19+
120
//@ run-pass
221

3-
fn f() -> isize { { return 3; } }
22+
fn f() -> isize {
23+
{
24+
return 3;
25+
}
26+
}
427

5-
pub fn main() { assert_eq!(f(), 3); }
28+
fn main() {
29+
assert_eq!(f(), 3);
30+
}

0 commit comments

Comments
 (0)