Closed
Description
#![feature(generic_const_exprs)]
trait Trait {
const N: usize;
}
struct Struct<const N: usize>;
type Alias<T: Trait> = Struct<{<T as Trait>::N}>;
Compiling this code (Playground) produces the following diagnostics:
warning: bounds on generic parameters are not enforced in type aliases
--> src/lib.rs:9:19
|
9 | pub type Alias<T: Trait> = Struct<{<T as Trait>::N}>;
| ^^^^^
|
= note: `#[warn(type_alias_bounds)]` on by default
help: the bound will not be checked when the type alias is used, and should be removed
|
9 - pub type Alias<T: Trait> = Struct<{<T as Trait>::N}>;
9 + pub type Alias<T> = Struct<{<T as Trait>::N}>;
|
I expected to see this happen: The compiler should not have suggested removing : Trait
from the type alias.
Instead, this happened: Removing : Trait
as per the compiler's suggestion breaks the code.
error[E0277]: the trait bound `T: Trait` is not satisfied
--> src/lib.rs:9:29
|
9 | pub type Alias<T> = Struct<{<T as Trait>::N}>;
| ^^^^^^^^^^^^^^^ the trait `Trait` is not implemented for `T`
|
help: consider restricting type parameter `T`
|
9 | pub type Alias<T: Trait> = Struct<{<T as Trait>::N}>;
| +++++++
Meta
rustc --version --verbose
:
rustc 1.61.0-nightly (532d3cda9 2022-02-23)
binary: rustc
commit-hash: 532d3cda90b8a729cd982548649d32803d265052
commit-date: 2022-02-23
host: aarch64-apple-darwin
release: 1.61.0-nightly
LLVM version: 14.0.0
Activity
ChayimFriedman2 commentedon Feb 27, 2022
Should the compiler not warn or not err when the bound is missing?
fmease commentedon Jun 5, 2024
This should relatively easy to fix. I've assigned myself to this issue as well as all(?) other L-type_alias_boundsLint: type_alias_bounds
issues because I consider it part of my work on
lazy_type_alias
.type_alias_bounds
actually signifies #126575Rollup merge of rust-lang#126575 - fmease:update-lint-type_alias_boun…
Unrolled build for rust-lang#126575