From a54dbbfd0e66b10601883fecdb16c2eaed0c32ca Mon Sep 17 00:00:00 2001 From: Boxy Date: Sun, 14 Jul 2024 07:57:53 +0100 Subject: [PATCH] add_effects_test --- .../effects/mismatched_generic_args.rs | 24 +++++++ .../effects/mismatched_generic_args.stderr | 64 +++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 tests/ui/rfcs/rfc-2632-const-trait-impl/effects/mismatched_generic_args.rs create mode 100644 tests/ui/rfcs/rfc-2632-const-trait-impl/effects/mismatched_generic_args.stderr diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/mismatched_generic_args.rs b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/mismatched_generic_args.rs new file mode 100644 index 0000000000000..21e91c731b363 --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/mismatched_generic_args.rs @@ -0,0 +1,24 @@ +#![feature(generic_const_exprs)] +//~^ WARN: the feature `generic_const_exprs` is incomplete + +// Regression test for #125770 which would ICE under the old effects desugaring that +// created a const generic parameter for constness on `Add`. + +use std::ops::Add; + +pub struct Dimension; + +pub struct Quantity(S); +//~^ ERROR: `Dimension` is forbidden as the type of a const generic parameter + +impl Add for Quantity {} +//~^ ERROR: trait takes at most 1 generic argument +//~| ERROR: `Dimension` is forbidden as the type of a const generic parameter + +pub fn add(x: Quantity) -> Quantity { + //~^ ERROR: `Dimension` is forbidden as the type of a const generic parameter + x + y + //~^ ERROR: cannot find value `y` in this scope +} + +fn main() {} diff --git a/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/mismatched_generic_args.stderr b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/mismatched_generic_args.stderr new file mode 100644 index 0000000000000..8c814295de465 --- /dev/null +++ b/tests/ui/rfcs/rfc-2632-const-trait-impl/effects/mismatched_generic_args.stderr @@ -0,0 +1,64 @@ +error[E0425]: cannot find value `y` in this scope + --> $DIR/mismatched_generic_args.rs:20:9 + | +LL | pub fn add(x: Quantity) -> Quantity { + | - similarly named const parameter `U` defined here +LL | +LL | x + y + | ^ help: a const parameter with a similar name exists: `U` + +warning: the feature `generic_const_exprs` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/mismatched_generic_args.rs:1:12 + | +LL | #![feature(generic_const_exprs)] + | ^^^^^^^^^^^^^^^^^^^ + | + = note: see issue #76560 for more information + = note: `#[warn(incomplete_features)]` on by default + +error: `Dimension` is forbidden as the type of a const generic parameter + --> $DIR/mismatched_generic_args.rs:11:33 + | +LL | pub struct Quantity(S); + | ^^^^^^^^^ + | + = note: the only supported types are integers, `bool` and `char` +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | + +error[E0107]: trait takes at most 1 generic argument but 2 generic arguments were supplied + --> $DIR/mismatched_generic_args.rs:14:36 + | +LL | impl Add for Quantity {} + | ^^^ expected at most 1 generic argument + +error: `Dimension` is forbidden as the type of a const generic parameter + --> $DIR/mismatched_generic_args.rs:14:15 + | +LL | impl Add for Quantity {} + | ^^^^^^^^^ + | + = note: the only supported types are integers, `bool` and `char` +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | + +error: `Dimension` is forbidden as the type of a const generic parameter + --> $DIR/mismatched_generic_args.rs:18:21 + | +LL | pub fn add(x: Quantity) -> Quantity { + | ^^^^^^^^^ + | + = note: the only supported types are integers, `bool` and `char` +help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types + | +LL + #![feature(adt_const_params)] + | + +error: aborting due to 5 previous errors; 1 warning emitted + +Some errors have detailed explanations: E0107, E0425. +For more information about an error, try `rustc --explain E0107`.