File: artificial-block.rs

package info (click to toggle)
rustc 1.87.0%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 925,564 kB
  • sloc: xml: 158,127; python: 36,039; javascript: 19,761; sh: 19,737; cpp: 18,981; ansic: 13,133; asm: 4,376; makefile: 710; perl: 29; lisp: 28; ruby: 19; sql: 11
file content (30 lines) | stat: -rw-r--r-- 1,249 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//! Check that we don't get compile errors on unreachable code after the `{ return 3; }` artificial
//! block below. This test is run-pass to also exercise the codegen, but it might be possible to
//! reduce to build-pass or even check-pass.
//!
//! This test was introduced as part of commit `a833f152baa17460e8414355e832d30d5161f8e8` which
//! removes an "artificial block". See also commit `3d738e9e0634a4cd6239d1317bd7dad53be68dc8` for
//! more elaboration, reproduced below (this is outdated for *today*'s rustc as of 2024-12-10, but
//! is helpful to understand the original intention):
//!
//! > Return a fresh, unreachable context after ret, break, and cont
//! >
//! > This ensures we don't get compile errors on unreachable code (see
//! > test/run-pass/artificial-block.rs for an example of sane code that wasn't compiling). In the
//! > future, we might want to warn about non-trivial code appearing in an unreachable context,
//! > and/or avoid generating unreachable code altogether (though I'm sure LLVM will weed it out as
//! > well).
//!
//! Since then, `ret` became `return`, `int` became `isize` and `assert` became a macro.

//@ run-pass

fn f() -> isize {
    {
        return 3;
    }
}

fn main() {
    assert_eq!(f(), 3);
}