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

Remaining unsoundness in the termination check #1232

Open
arnaudgolfouse opened this issue Nov 12, 2024 · 0 comments
Open

Remaining unsoundness in the termination check #1232

arnaudgolfouse opened this issue Nov 12, 2024 · 0 comments
Assignees
Labels
bug Something isn't working soundness Enhance soundness

Comments

@arnaudgolfouse
Copy link
Collaborator

After #1220, the termination check must be reworked (again), as it allows the following two incorrect examples:

Recursive instantiation

trait Tr1 {
    fn f();
}

trait Tr2 {
    fn g();
}

impl<T> Tr1 for T where T : Tr2 {
    fn f() {
        T::g()
    }
}

impl Tr2 for u32 {
    fn g() {
        h()
    }
}

fn call_f<T: Tr1>() {
    T::f()
}

fn h() {
    call_f::<u32>()
}

When calling call_f, the bound T: Tr2 does not appear, but it is used. To visit trait bounds correctly, see in rustc_traits/src/codegen.rs, the implementation of function codegen_select_candidate.

Default function uses trait instance

trait Tr {
    fn f();
}

default impl<T> Tr for T {
    fn f() { g::<Self>(); }
}

fn g<T: Tr>() {
    <T as Tr>::f();
}

This is never flagged by the current check, even if we do something like

impl Tr for i32 {}

fn h() {
    <i32 as Tr>::f();
}

We should forbid f from using the trait instance it is defining.

@jhjourdan jhjourdan added bug Something isn't working soundness Enhance soundness labels Nov 13, 2024
@jhjourdan jhjourdan self-assigned this Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working soundness Enhance soundness
Projects
None yet
Development

No branches or pull requests

2 participants