W1013
W1013 — Anascast to the type the value already has, such asx as i32whenxis ani32.
What the compiler reports
Warning[W1013] at {{.*}}warning_for_a_cast_to_the_same_type.vx:22:16: this value is already i32, so the cast does nothing
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
//
//
// `x as i32` when `x` is already an `i32` does nothing (W1013). A widening cast, a cast of a
// literal, and `v as T` in a generic function used with `T = i32` get no warning.
fn convert<T>(v : i32) -> T {
return v as T;
}
fn main() -> i32 {
let x : i32 = 1;
let same = x as i32;
let wide = x as i64;
let one = 1 as i32;
let minus_one = -1 as i32;
let y : i32 = convert(x);
print(wide);
return same + one + minus_one + y;
}
From tests/frontend/pass/warning_for_a_cast_to_the_same_type.vx, which asserts this diagnostic on every commit.
Related
A tour of VxThe chapter covering the rule this code enforces.
All diagnosticsEvery code the compiler can emit, grouped by stage.
W1010An
unsafe block with nothing inside it that needs unsafe.
W1014An as cast of a number known while compiling that does not fit the target type, such as 100000 as i8, which gives -96. For a cast to usize, such as (-1i64) as usize, the program stops at that cast.