W1003

W1003 — Unreachable code after return, break, or continue

What the compiler reports

Warning[W1003] at {{.*}}code_after_return_is_checked.vx:[[# @LINE + 2]]:3: Unreachable code
Error[E2001] at {{.*}}code_after_return_is_checked.vx:[[# @LINE + 1]]:17: Undefined variable 'undefined_name'
Error[E4001] at {{.*}}code_after_return_is_checked.vx:[[# @LINE + 1]]:21: Use of moved or consumed linear variable: v
2 error(s) emitted

The fragments the test suite holds the compiler to. An ellipsis marks text the test does not constrain; the emitted message also carries a source location.

A program that triggers it

//
// Part of the Vx Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// Code after `return`, `break` or `continue` never runs, but it is still checked.

import std::vec;

fn take(v : Vec<i32>) -> void {}

fn unknown_name() -> i32 {
  return 0;
  let y : i32 = undefined_name;
  return y;
}

fn moved_twice() -> i32 {
  let v = Vec<i32>::new();
  loop {
    break;
    take(v);
    let f = || take(v);
    f();
  }
  return 0;
}

fn main() -> i32 {
  return unknown_name() + moved_twice();
}

From tests/frontend/fail/code_after_return_is_checked.vx, which asserts this diagnostic on every commit.

Related