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

Initial implementation of unsafe binder types #130514

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Sep 18, 2024

I've written up some motivation about unsafe binders here: https://hackmd.io/@compiler-errors/HkXwoBPaR

Specifically, I'd like to provide a coherent way to represent lifetimes in structs which are unnameable and can't be plugged by 'static. This has been toyed around with in the past, such as 'unsafe lifetimes1, but the document above calls out some questions in that design and proposes a different solution via "unsafe binder types". Making these their own distinct type solves a lot of those problems, and while users still need to be careful with these types by using unsafe {} when interconverting them, they're far more self-contained.

r? @ghost

I'll be opening a lang team experiment for this before I put this up for actual review. I'm mostly putting this here so we can reference it.

Tracking:

Footnotes

  1. https://internals.rust-lang.org/t/rfc-basic-unsafe-lifetime/16873

@rustbot rustbot added PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Sep 18, 2024
@compiler-errors compiler-errors changed the title Initial implementation of unsafe binders Initial implementation of unsafe binder types Sep 18, 2024
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the A-rustdoc-json Area: Rustdoc JSON backend label Sep 18, 2024
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Sep 23, 2024

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

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#16 2.893 Building wheels for collected packages: reuse
#16 2.894   Building wheel for reuse (pyproject.toml): started
#16 3.138   Building wheel for reuse (pyproject.toml): finished with status 'done'
#16 3.139   Created wheel for reuse: filename=reuse-4.0.3-cp310-cp310-manylinux_2_35_x86_64.whl size=132715 sha256=dfa09868353292d98f811d3efdb0d54d07389e808efc71d68e3b93c514bf8bec
#16 3.140   Stored in directory: /tmp/pip-ephem-wheel-cache-jvcljmyz/wheels/3d/8d/0a/e0fc6aba4494b28a967ab5eaf951c121d9c677958714e34532
#16 3.142 Installing collected packages: boolean-py, binaryornot, tomlkit, reuse, python-debian, markupsafe, license-expression, jinja2, chardet, attrs
#16 3.530 Successfully installed attrs-23.2.0 binaryornot-0.4.4 boolean-py-4.0 chardet-5.2.0 jinja2-3.1.4 license-expression-30.3.0 markupsafe-2.1.5 python-debian-0.1.49 reuse-4.0.3 tomlkit-0.13.0
#16 3.530 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#16 DONE 3.6s
---
    Checking toml_edit v0.19.15
    Checking semver v1.0.23
    Checking cargo_metadata v0.18.1
    Checking toml v0.7.8
error[E0277]: the `?` operator can only be used on `Result`s, not `Option`s, in a method that returns `Result`
     |
     |
792  |     fn rewrite_result(&self, context: &RewriteContext<'_>, shape: Shape) -> RewriteResult {
     |     ------------------------------------------------------------------------------------- this function returns a `Result`
...
1022 |                     shape.offset_left(result.len())?
     |                                                    ^ use `.ok_or(...)?` to provide an error compatible with `std::result::Result<std::string::String, RewriteError>`
     |
     = help: the trait `FromResidual<std::option::Option<Infallible>>` is not implemented for `std::result::Result<std::string::String, RewriteError>`
     = help: the trait `FromResidual<std::result::Result<Infallible, E>>` is implemented for `std::result::Result<T, F>`

error[E0277]: the `?` operator can only be used on `Result`s, not `Option`s, in a method that returns `Result`
     |
     |
792  |     fn rewrite_result(&self, context: &RewriteContext<'_>, shape: Shape) -> RewriteResult {
     |     ------------------------------------------------------------------------------------- this function returns a `Result`
...
1024 |                     shape.visual_indent(result.len()).sub_width(result.len())?
     |                                                                              ^ use `.ok_or(...)?` to provide an error compatible with `std::result::Result<std::string::String, RewriteError>`
     |
     = help: the trait `FromResidual<std::option::Option<Infallible>>` is not implemented for `std::result::Result<std::string::String, RewriteError>`
     = help: the trait `FromResidual<std::result::Result<Infallible, E>>` is implemented for `std::result::Result<T, F>`

error[E0277]: the `?` operator can only be used on `Result`s, not `Option`s, in a method that returns `Result`
     |
     |
792  |     fn rewrite_result(&self, context: &RewriteContext<'_>, shape: Shape) -> RewriteResult {
     |     ------------------------------------------------------------------------------------- this function returns a `Result`
...
1027 |                 let rewrite = binder.inner_ty.rewrite(context, inner_ty_shape)?;
     |                                                                               ^ use `.ok_or(...)?` to provide an error compatible with `std::result::Result<std::string::String, RewriteError>`
     |
     = help: the trait `FromResidual<std::option::Option<Infallible>>` is not implemented for `std::result::Result<std::string::String, RewriteError>`
     = help: the trait `FromResidual<std::result::Result<Infallible, E>>` is implemented for `std::result::Result<T, F>`
error[E0308]: mismatched types
    --> src/tools/rustfmt/src/types.rs:1029:17
     |
     |
792  |     fn rewrite_result(&self, context: &RewriteContext<'_>, shape: Shape) -> RewriteResult {
     |                                                                             ------------- expected `std::result::Result<std::string::String, RewriteError>` because of return type
1029 |                 Some(result)
1029 |                 Some(result)
     |                 ^^^^^^^^^^^^ expected `Result<String, RewriteError>`, found `Option<String>`
     = note: expected enum `std::result::Result<std::string::String, RewriteError>`
                found enum `std::option::Option<std::string::String>`

Some errors have detailed explanations: E0277, E0308.

@bors
Copy link
Contributor

bors commented Sep 24, 2024

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

@Dylan-DPC Dylan-DPC added S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-json Area: Rustdoc JSON backend PG-exploit-mitigations Project group: Exploit mitigations S-experimental Status: Ongoing experiment that does not require reviewing and won't be merged in its current state. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants