-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disentangle ForwardGenericParamBan
and ConstParamTy
ribs
#138259
Conversation
ah right 🤔 I guess at the time I thought that params would include all params in scope but that doesnt make any sense xd |
#![feature(adt_const_params)]
trait Trait<const N: usize> {
fn foo<const M: [u8; N]>() {}
} Can you add a test that we forbid this? Apparently we don't have such a test already ^^' |
7cf39de
to
ea88485
Compare
This comment has been minimized.
This comment has been minimized.
ea88485
to
a79f97b
Compare
This PR changes a file inside |
@bors r+ this is much nicer now thx |
…r=BoxyUwU Disentangle `ForwardGenericParamBan` and `ConstParamTy` ribs In rust-lang#137617, the `ConstParamTy` rib was adjusted to act kinda like the `ForwardGenericParamBan`. However, this means that it no longer served its purpose banning generics from *parent items*. Although we still are checking for param type validity using the `ConstParamTy_` trait, which means that we weren't accepting code we shouldn't, I think it's a bit strange for us not to be rejecting code like this during *resolution* and instead letting these malformed const generics leak into the type system: ```rust trait Foo<T> { fn bar<const N: T>() {} } ``` This PR does a few things: 1. Introduce a `ForwardGenericParamBanReason` enum, and start using the `ForwardGenericParamBan` rib to ban forward-declared params in const tys when `generic_const_parameter_types` is enabled. 2. Start using the `ConstParamTy` rib to ban *all* generics when `generic_const_parameter_types` is disabled. 3. Improve the diagnostics for both of the cases above, and for forward-declared params in parameter defaults too :3 r? `@BoxyUwU` or reassign
I think this failed in rollup: #138382 (comment)
@bors r- |
gamer |
This comment has been minimized.
This comment has been minimized.
a79f97b
to
42773bf
Compare
@bors r=BoxyUwU |
…earth Rollup of 12 pull requests Successful merges: - rust-lang#134076 (Stabilize `std::io::ErrorKind::InvalidFilename`) - rust-lang#137504 (Move methods from Map to TyCtxt, part 4.) - rust-lang#138175 (Support rmeta inputs for --crate-type=bin --emit=obj) - rust-lang#138259 (Disentangle `ForwardGenericParamBan` and `ConstParamTy` ribs) - rust-lang#138280 (fix ICE in pretty-printing `global_asm!`) - rust-lang#138318 (Rustdoc: remove a bunch of `@ts-expect-error` from main.js) - rust-lang#138331 (Use `RUSTC_LINT_FLAGS` more) - rust-lang#138357 (merge `TypeChecker` and `TypeVerifier`) - rust-lang#138394 (remove unnecessary variant) - rust-lang#138403 (Delegation: one more ICE fix for `MethodCall` generation) - rust-lang#138407 (Delegation: reject C-variadics) - rust-lang#138409 (Use sa_sigaction instead of sa_union.__su_sigaction for AIX) r? `@ghost` `@rustbot` modify labels: rollup
@bors rollup |
…earth Rollup of 12 pull requests Successful merges: - rust-lang#134076 (Stabilize `std::io::ErrorKind::InvalidFilename`) - rust-lang#137504 (Move methods from Map to TyCtxt, part 4.) - rust-lang#138175 (Support rmeta inputs for --crate-type=bin --emit=obj) - rust-lang#138259 (Disentangle `ForwardGenericParamBan` and `ConstParamTy` ribs) - rust-lang#138280 (fix ICE in pretty-printing `global_asm!`) - rust-lang#138318 (Rustdoc: remove a bunch of `@ts-expect-error` from main.js) - rust-lang#138331 (Use `RUSTC_LINT_FLAGS` more) - rust-lang#138357 (merge `TypeChecker` and `TypeVerifier`) - rust-lang#138394 (remove unnecessary variant) - rust-lang#138403 (Delegation: one more ICE fix for `MethodCall` generation) - rust-lang#138407 (Delegation: reject C-variadics) - rust-lang#138409 (Use sa_sigaction instead of sa_union.__su_sigaction for AIX) r? `@ghost` `@rustbot` modify labels: rollup
In #137617, the
ConstParamTy
rib was adjusted to act kinda like theForwardGenericParamBan
. However, this means that it no longer served its purpose banning generics from parent items. Although we still are checking for param type validity using theConstParamTy_
trait, which means that we weren't accepting code we shouldn't, I think it's a bit strange for us not to be rejecting code like this during resolution and instead letting these malformed const generics leak into the type system:This PR does a few things:
ForwardGenericParamBanReason
enum, and start using theForwardGenericParamBan
rib to ban forward-declared params in const tys whengeneric_const_parameter_types
is enabled.ConstParamTy
rib to ban all generics whengeneric_const_parameter_types
is disabled.r? @BoxyUwU or reassign