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

impl const wrongly accepts impl with non-const provided methods #79450

Closed
jonas-schievink opened this issue Nov 26, 2020 · 3 comments · Fixed by #86571 or #105237
Closed

impl const wrongly accepts impl with non-const provided methods #79450

jonas-schievink opened this issue Nov 26, 2020 · 3 comments · Fixed by #86571 or #105237
Assignees
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-const_trait_impl `#![feature(const_trait_impl)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jonas-schievink
Copy link
Contributor

This prints no error, but prov is not const-safe, so the impl const Tr should not be accepted:

#![feature(const_trait_impl)]

trait Tr {
    fn req(&self);
    
    fn prov(&self) {
        println!("lul");
        self.req();
    }
}

struct S;

impl const Tr for S {
    fn req(&self) {}
}
@jonas-schievink jonas-schievink added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. F-const_trait_impl `#![feature(const_trait_impl)]` labels Nov 26, 2020
@camelid camelid added A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. A-const-eval Area: Constant evaluation (MIR interpretation) labels Nov 26, 2020
@oli-obk
Copy link
Contributor

oli-obk commented Nov 27, 2020

I guess for impl const blocks we need to enforce that no defaulted fallbacks are used at all. This is discussed a bit in the RFC, but for now we should just disallow this entirely

@kadiwa4
Copy link
Contributor

kadiwa4 commented Jul 25, 2022

This issue applies again, it seems that the part of the test that checked this was removed in #96964.

Or is this intentionally accepted without an error now?

@oli-obk oli-obk reopened this Jul 25, 2022
@oli-obk oli-obk self-assigned this Jul 25, 2022
@kadiwa4
Copy link
Contributor

kadiwa4 commented Dec 2, 2022

@oli-obk oli-obk added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Dec 2, 2022
JohnTitor added a commit to JohnTitor/rust that referenced this issue Dec 4, 2022
Signed-off-by: Yuki Okushi <jtitor@2k36.org>
bors added a commit to rust-lang-ci/rust that referenced this issue Dec 4, 2022
…iaskrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#104856 (Don't suggest associated function call for associated const.)
 - rust-lang#105123 (Fix passing MACOSX_DEPLOYMENT_TARGET to the linker)
 - rust-lang#105142 (Make inline const block `ExprWithBlock`)
 - rust-lang#105237 (Add regression test for rust-lang#79450)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors closed this as completed in da9585b Dec 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation (MIR interpretation) A-const-fn Area: const fn foo(..) {..}. Pure functions which can be applied at compile time. C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-const_trait_impl `#![feature(const_trait_impl)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
4 participants