File: unsatisfied-const-trait-bound.rs

package info (click to toggle)
rustc-web 1.78.0%2Bdfsg1-2~deb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,245,420 kB
  • sloc: xml: 147,985; javascript: 18,022; sh: 11,083; python: 10,265; ansic: 6,172; cpp: 5,023; asm: 4,390; makefile: 4,269
file content (33 lines) | stat: -rw-r--r-- 933 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Ensure that we print unsatisfied always-const trait bounds as `const Trait` in diagnostics.

#![feature(const_trait_impl, effects, generic_const_exprs)]
#![allow(incomplete_features)]

fn require<T: const Trait>() {}

#[const_trait]
trait Trait {
    fn make() -> u32;
}

struct Ty;

impl Trait for Ty {
    fn make() -> u32 { 0 }
}

fn main() {
    require::<Ty>(); //~ ERROR the trait bound `Ty: const Trait` is not satisfied
}

struct Container<const N: u32>;

// FIXME(effects): Somehow emit `the trait bound `T: const Trait` is not satisfied` here instead
//                 and suggest changing `Trait` to `const Trait`.
fn accept0<T: Trait>(_: Container<{ T::make() }>) {}
//~^ ERROR mismatched types

// FIXME(effects): Instead of suggesting `+ const Trait`, suggest
//                 changing `~const Trait` to `const Trait`.
const fn accept1<T: ~const Trait>(_: Container<{ T::make() }>) {}
//~^ ERROR mismatched types