W1020

W1020 — *&x, a borrow that is dereferenced at once. It is the same as x.

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