W1006
W1006 —&&x, a borrow of a borrow, where&xwas probably meant.
What the compiler reports
Warning[W1006] at {{.*}}warning_for_a_borrow_of_a_borrow.vx:20:12: this borrows a borrow
Warning[W1006] at {{.*}}warning_for_a_borrow_of_a_borrow.vx:21:16: this borrows a borrow
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` and `& &x` borrow a borrow: a reference to a reference, where `&x` was probably meant
// (W1006). A plain `&x` gets no warning, nor does `&r` of a reference kept in a variable, nor
// `&&x` where the declared type asks for a reference to a reference.
fn main() -> i32 {
let x : i32 = 1;
let rr = &&x;
let spaced = & &x;
let r = &x;
let also = &r;
let asked : &&i32 = &&x;
return **rr + **spaced + *r + **also + **asked;
}
From tests/frontend/pass/warning_for_a_borrow_of_a_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.
W1005A
let that reuses a name already declared in the same block, so the first value can no longer be named.
W1007An as cast that widens, such as x as i64 when x is an i32. It cannot lose a value, and i64::from(x) says so.