Skip to content
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

Deeply deny fn and raw ptrs in const generics #99651

Merged

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Jul 23, 2022

I think this is right -- just because we wrap a fn ptr in a wrapper type does not mean we should allow it in a const parameter.

We now reject both of these in the same way:

#![feature(adt_const_params)]

#[derive(Eq, PartialEq)]
struct Wrapper();

fn foo<const W: Wrapper>() {}

fn foo2<const F: fn()>() {}

This does regress one test (src/test/ui/consts/refs_check_const_eq-issue-88384.stderr), but I'm not sure it should've passed in the first place.

cc: @b-naber who introduced that test^
fixes #99641

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 23, 2022
@rust-highfive
Copy link
Collaborator

r? @petrochenkov

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 23, 2022
@compiler-errors
Copy link
Member Author

r? @oli-obk who reviewed last PR which was similar (#98907)

@oli-obk
Copy link
Contributor

oli-obk commented Jul 24, 2022

That bool argument did not get more readable by inverting its meaning 😆

That's preexisting, but maybe make the function private and expose two wrappers with explanatory names instead?

@compiler-errors
Copy link
Member Author

I only inverted it because I didn't want to come up with a better name for the boolean, but yeah I can split it into several functions.

@compiler-errors compiler-errors force-pushed the fn-and-raw-ptr-in-const-generics branch from 636c870 to 10b69ab Compare July 25, 2022 03:39
@oli-obk
Copy link
Contributor

oli-obk commented Jul 25, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Jul 25, 2022

📌 Commit 10b69ab has been approved by oli-obk

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 25, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 26, 2022
…onst-generics, r=oli-obk

Deeply deny fn and raw ptrs in const generics

I think this is right -- just because we wrap a fn ptr in a wrapper type does not mean we should allow it in a const parameter.

We now reject both of these in the same way:

```
#![feature(adt_const_params)]

#[derive(Eq, PartialEq)]
struct Wrapper();

fn foo<const W: Wrapper>() {}

fn foo2<const F: fn()>() {}
```

This does regress one test (`src/test/ui/consts/refs_check_const_eq-issue-88384.stderr`), but I'm not sure it should've passed in the first place.

cc: `@b-naber` who introduced that test^
fixes rust-lang#99641
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 27, 2022
…laumeGomez

Rollup of 7 pull requests

Successful merges:

 - rust-lang#94247 (Fix slice::ChunksMut aliasing)
 - rust-lang#99358 (Allow `ValTree::try_to_raw_bytes` on `u8` array)
 - rust-lang#99651 (Deeply deny fn and raw ptrs in const generics)
 - rust-lang#99710 (lint: add bad opt access internal lint)
 - rust-lang#99717 (Add some comments to the docs issue template to clarify)
 - rust-lang#99728 (Clean up HIR-based lifetime resolution)
 - rust-lang#99812 (Fix headings colors)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 9e7b7d5 into rust-lang:master Jul 27, 2022
@rustbot rustbot added this to the 1.64.0 milestone Jul 27, 2022
@compiler-errors compiler-errors deleted the fn-and-raw-ptr-in-const-generics branch August 11, 2023 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

expected ConstKind::Value ICE when putting (fn(),) in a const generic parameter (requires adt_const_params)
6 participants