W1020
W1020 —*&x, a borrow that is dereferenced at once. It is the same asx.
What the compiler reports
Warning[W1020] at {{.*}}warning_for_deref_of_a_fresh_borrow.vx:18:11: this dereferences a borrow made in the same place
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` borrows `x` and dereferences the borrow at once, which is just `x` (W1020).
// Dereferencing a reference kept in a variable, `*r`, is ordinary and gets no warning.
fn main() -> i32 {
let x : i32 = 1;
let y = *&x;
let r = &x;
let z = *r;
return y + z;
}
From tests/frontend/pass/warning_for_deref_of_a_fresh_borrow.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.
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.
W1022A transfer into the memory the value is already in. It only makes a copy.