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

Allow opaque types in trait impl headers and rely on coherence to reject unsound cases #103488

Merged
merged 10 commits into from
Nov 23, 2022

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Oct 24, 2022

r? @lcnr

fixes #99840

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 24, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 24, 2022
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is still unsound when equating two opaque types with the same DefId during coherence, similar to #102048. With the current setup that might be difficult to fix, though I might be wrong.

We can land this PR and then I can try to write an example and open an issue.

compiler/rustc_middle/src/ty/fast_reject.rs Outdated Show resolved Hide resolved
fn eq(&self, _other: &(Foo, i32)) -> bool {
true
}
}

fn foo() -> Foo {
//~^ ERROR can't compare `Bar` with `(Bar, i32)`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected, still weird 😁

@oli-obk oli-obk force-pushed the impl_trait_for_tait branch from 87bc33e to a41f93a Compare October 27, 2022 12:00
Comment on lines 10 to 17
error[E0119]: conflicting implementations of trait `Bop` for type `Bar<()>`
--> $DIR/impl_trait_for_same_tait.rs:27:1
|
LL | impl Bop for Bar<()> {}
| -------------------- first implementation here
...
LL | impl Bop for Barr {
| ^^^^^^^^^^^^^^^^^ conflicting implementation for `Bar<()>`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure yet how to improve this diagnostic beyond looking at the entries in take_opaque_types() and doing some guessing for common cases.

@oli-obk oli-obk force-pushed the impl_trait_for_tait branch from a41f93a to 86dc770 Compare October 27, 2022 15:18
@bors
Copy link
Contributor

bors commented Oct 29, 2022

☔ The latest upstream changes (presumably #103727) made this pull request unmergeable. Please resolve the merge conflicts.

@oli-obk oli-obk force-pushed the impl_trait_for_tait branch from 86dc770 to 4d7c724 Compare November 2, 2022 15:20
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the impl_trait_for_tait branch from 4d7c724 to b8a45f6 Compare November 3, 2022 07:55
@rustbot
Copy link
Collaborator

rustbot commented Nov 3, 2022

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@bors
Copy link
Contributor

bors commented Nov 4, 2022

☔ The latest upstream changes (presumably #101834) made this pull request unmergeable. Please resolve the merge conflicts.

@oli-obk oli-obk force-pushed the impl_trait_for_tait branch from b8a45f6 to c67ec50 Compare November 7, 2022 15:21
compiler/rustc_infer/src/infer/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_infer/src/infer/combine.rs Show resolved Hide resolved
@@ -809,6 +831,10 @@ impl<'tcx> TypeRelation<'tcx> for ConstInferUnifier<'_, 'tcx> {
true
}

fn mark_ambiguous(&mut self) {
bug!()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that should be reachable when using generic const exprs when relating a const inference var (from a const param) with an unevaluated constant during coherence

@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the impl_trait_for_tait branch from 5b9d06f to 1e768de Compare November 15, 2022 16:40
compiler/rustc_infer/src/infer/error_reporting/mod.rs Outdated Show resolved Hide resolved
compiler/rustc_infer/src/infer/glb.rs Outdated Show resolved Hide resolved
compiler/rustc_infer/src/infer/glb.rs Outdated Show resolved Hide resolved
compiler/rustc_infer/src/infer/lub.rs Outdated Show resolved Hide resolved
compiler/rustc_infer/src/infer/lub.rs Outdated Show resolved Hide resolved
@oli-obk oli-obk force-pushed the impl_trait_for_tait branch from 200226d to 8774fa8 Compare November 17, 2022 10:08
@bors
Copy link
Contributor

bors commented Nov 21, 2022

☔ The latest upstream changes (presumably #103491) made this pull request unmergeable. Please resolve the merge conflicts.

@oli-obk oli-obk force-pushed the impl_trait_for_tait branch from 8774fa8 to 603a83b Compare November 21, 2022 16:44
@oli-obk oli-obk force-pushed the impl_trait_for_tait branch from 603a83b to c16a90f Compare November 21, 2022 16:47
Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me


// Ok because `i32` does not implement `Dummy`,
// so it can't possibly be the hidden type of `F`.
impl Test for i32 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does that work? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when coherence is checking whether F conflicts with i32 we register i32 as the hidden type of F and that fails because i32: !Dummy but F = impl Dummy.

@oli-obk
Copy link
Contributor Author

oli-obk commented Nov 22, 2022

@bors r=lcnr

@bors
Copy link
Contributor

bors commented Nov 22, 2022

📌 Commit c16a90f has been approved by lcnr

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 Nov 22, 2022
Manishearth added a commit to Manishearth/rust that referenced this pull request Nov 22, 2022
Allow opaque types in trait impl headers and rely on coherence to reject unsound cases

r? `@lcnr`

fixes rust-lang#99840
Manishearth added a commit to Manishearth/rust that referenced this pull request Nov 22, 2022
Allow opaque types in trait impl headers and rely on coherence to reject unsound cases

r? ``@lcnr``

fixes rust-lang#99840
Manishearth added a commit to Manishearth/rust that referenced this pull request Nov 23, 2022
Allow opaque types in trait impl headers and rely on coherence to reject unsound cases

r? ```@lcnr```

fixes rust-lang#99840
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 23, 2022
…earth

Rollup of 6 pull requests

Successful merges:

 - rust-lang#103488 (Allow opaque types in trait impl headers and rely on coherence to reject unsound cases)
 - rust-lang#104359 (Refactor must_use lint into two parts)
 - rust-lang#104612 (Lower return type outside async block creation)
 - rust-lang#104621 (Fix --extern library finding errors)
 - rust-lang#104647 (enable fuzzy_provenance_casts lint in liballoc and libstd)
 - rust-lang#104750 (Bump `fd-lock` in `bootstrap` again)

Failed merges:

 - rust-lang#104732 (Refactor `ty::ClosureKind` related stuff)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 53eab24 into rust-lang:master Nov 23, 2022
@rustbot rustbot added this to the 1.67.0 milestone Nov 23, 2022
@oli-obk oli-obk deleted the impl_trait_for_tait branch November 23, 2022 10:25
@Mark-Simulacrum Mark-Simulacrum added the perf-regression Performance regression. label Nov 29, 2022
@Mark-Simulacrum
Copy link
Member

This PR was a perf regression (see the report here #104758 (comment)). It's relatively small and mostly limited to secondary workloads so I'm marking as triaged.

@Mark-Simulacrum Mark-Simulacrum added the perf-regression-triaged The performance regression has been triaged. label Nov 29, 2022
flip1995 pushed a commit to flip1995/rust that referenced this pull request Dec 1, 2022
Allow opaque types in trait impl headers and rely on coherence to reject unsound cases

r? ````@lcnr````

fixes rust-lang#99840
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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.

TAIT: it's possible to impl a trait for a tait by using projections
7 participants