W1006

W1006 — &&x, a borrow of a borrow, where &x was 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