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

coherence doesn't permit negative impls to take advantage of implied bounds #93875

Closed
nikomatsakis opened this issue Feb 10, 2022 · 0 comments · Fixed by #100888
Closed

coherence doesn't permit negative impls to take advantage of implied bounds #93875

nikomatsakis opened this issue Feb 10, 2022 · 0 comments · Fixed by #100888
Assignees
Labels
C-bug Category: This is a bug. F-negative_impls #![feature(negative_impls)]

Comments

@nikomatsakis
Copy link
Contributor

#93652 implemented the "negative coherence" rules, but it left one part undone. When we try to prove T: !Trait for some trait, we ought to include in the environment the "wf" bounds for the input types on the impl; the current logic does not. As a result, tests like src/test/ui/coherence/coherence-negative-outlives-lifetimes.rs do not compile:

trait MyPredicate<'a> {}
impl<'a, T> !MyPredicate<'a> for &T where T: 'a {}
trait MyTrait<'a> {}
impl<'a, T: MyPredicate<'a>> MyTrait<'a> for T {}
impl<'a, T> MyTrait<'a> for &'a T {}

Here, for MyTrait to be legal, we would have to be able to prove that T: !MyPredicate<'a>. There is a negative impl, but it requires that T: 'a, which we are not able to prove. However, we ought to be able to, because the impl in question is for &'a T, and that includes a WF bound that T: 'a.

cc @spastorino

@nikomatsakis nikomatsakis added C-bug Category: This is a bug. F-negative_impls #![feature(negative_impls)] labels Feb 10, 2022
@spastorino spastorino self-assigned this Jul 6, 2022
@bors bors closed this as completed in 0fcabec Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-negative_impls #![feature(negative_impls)]
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants