E3042

E3042 — A bound on a type parameter, T : Name, where no trait called Name is declared or imported. Usually a misspelling or a missing import.

What the compiler reports

Error[E3042]: the bound `T : NoSuchB` on `enum Pick` names no trait
Error[E3042]: the bound `T : NoSuchD` on `fn mixed` names no trait
Error[E3042]: the bound `T : NoSuchC` on `fn never_called` names no trait
Error[E3042]: the bound `T : NoSuchF` on `impl Size for Twice<T>` names no trait
Error[E3042]: the bound `T : NoSuchE` on `method Shape::area` names no trait
Error[E3042]: the bound `U : NoSuchG` on `method Twice<T>::scaled` names no trait
Error[E3042]: the bound `T : NoSuchA` on `struct Holder` names no trait
7 error(s) emitted

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

//
// A bound that names a trait nobody declared is refused wherever it is written, even on a
// function nobody calls. Each `NoSuch` name below is reported once; `Size` exists and is not.

trait Size {
  fn size(self : &Self) -> i32;
}

struct Holder<T : NoSuchA> {
  v : T,
}

enum Pick<T : NoSuchB> {
  One(T),
}

fn never_called<T : NoSuchC>(v : T) -> i32 {
  return 1;
}

fn mixed<T : Size + NoSuchD>(v : T) -> i32 {
  return 1;
}

// A default body is copied into each impl of the trait, and reported only here.
trait Shape {
  fn area<T : NoSuchE>(self : &Self, t : T) -> i32 {
    return 0;
  }
}

struct Twice<T> {
  inner : T,
}

impl<T : NoSuchF> Size for Twice<T> {
  fn size(self : &Twice<T>) -> i32 {
    return 2;
  }
}

impl<T> Shape for Twice<T> {}

// `Topology` is a keyword that marks a topology parameter, not a trait.
fn on_any<D : Topology>(x : i32) -> i32 {
  return x;
}

impl<T> Twice<T> {
  fn scaled<U : NoSuchG>(self : &Twice<T>, u : U) -> i32 {
    return 3;
  }
}

fn main() -> i32 {
  return 0;
}

From tests/frontend/fail/bound_names_no_trait.vx, which asserts this diagnostic on every commit.

Related