Rust Types Team
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # the most `dyn` of traits {%preview https://github.com/rust-lang/rust/issues/57893 %} https://github.com/rust-lang/rust/issues/57893#issuecomment-2860064425 core constraints - need to choose builtin candidate for methods, support `dyn Any` - need to choose assoc types from impl, due to `<T as Trait>::Assoc` norm doesn't matter what we do, need to detect overlap. this must not care about trait object args: - can't handle higher rankeds - also, auto traits? ## what to do if there's overlap - completely disable builtin impl if there's overlap and the trait has an assoc type/const - ???? whatever, ## how to detct overlap `fn overlap_with_builtin(dyn_trait_def_id, goal_trait_def_id, [auto_traits?]) -> bool` - must be consistent between crates, all crates in the crate graph must agree whether the builtin impl is disabled - it's otherwise always allowed to return "does overlap" - if `dyn Trait` does not impl super trait via a builtin impl, it must also not impl `Trait` via builtin - https://github.com/rust-lang/rust/pull/132289#issuecomment-2564492153 doing it outside the trait solver feels horrible :> ### how would we impl it via coherence #### naive way take `dyn Trait` with infer args check for overlap with user written impls - what if there are quiery cycles when checking `overlap_with_builtin` - does not handle cases where there is only overlap for `dyn for<'a> Trait<&'a ()>`. we need to detect overlap for that #### ```rust // check for overlap of `dyn Trait` via this dummy impl impl<T: !Sized> Trait for T {} // this may overlap with the following :< but must not // be considered to do so as there is no blanket impl impl<T: NotImplemented + ?Sized> Trait for T {} ``` #### via typing mode ```rust // check for overlap of `dyn Trait` via this dummy impl impl<T: !Sized> Trait for dyn Trait<idk> {} // this may overlap with the following :< but must not // be considered to do so as there is no blanket impl impl<T: NotImplemented + ?Sized> Trait for T {} ``` when assembling builtin candidates for a trait object, always bail with ambiguity issue: explicit impls for trait objects can also be higher ranked. when looking at candidates which references a dyn?, always say MAYBE ALWAYS DISABLE LEAK CHECK WITH THIS TYPING MODE, instead of using `trait_has_impl_which_may_shadow_dyn`, fail with ambiguity - different auto traits - arity of projections :> alternative: change type relations + matches on `ty::Dyn` to not look at args iwth that typing mode - keep leak check :> ### outside of coherence {%preview https://github.com/rust-lang/rust/pull/132289 %} `fn trait_has_impl_which_may_shadow_dyn` when proving where-bounds of the blanket impl, we need to copy the is_knowable coherence check https://github.com/rust-lang/rust/pull/132289#issuecomment-2564587796 pretty much: if any where-bound of blanket impls has an unconstrained (or inside fundamental) arg, err Alternative: just always error impls with object types as self-type as foreign #### 3rd repro: https://github.com/rust-lang/rust/pull/132289#issuecomment-2564599221 Adding a downstream impl with a normalizeable alias as the self type, must not disable the upstream builtin impl ### rarw uwu design proposal > alternative: change type relations + matches on `ty::Dyn` to not look at args iwth that typing mode > - keep leak check :> do we always want to disable all impls, or maybe allow super trait but disable sub trait. IMPORTANT: force encode cross crate. Coherence may return "may overlap" in downstream but not root. ## SO FUCKING UWU actually, prefering methods over user impls is certainly unsound https://github.com/rust-lang/rust/issues/57893#issuecomment-2860064425 So, we've got a good reason to just entirely forbid this ### how to continue supporting `dyn Any` add intrinsic ```rust fn vtable_ref<T, R>(this: &T, f: F, fallback: impl FnOnce(&T) -> R) -> R; fn vtable_mut<T, R>(this: &mut T, f: F, fallback: impl FnOnce(&mut T) -> R) -> R; ``` ```rust trait Any: 'static {} impl<T: ?Sized + 'static> Any for T { fn type_id(&self) -> TypeId { vtable_ref(self, <dyn Any as Any>::type_id, |_| { TypeId::of::<T>() }) } } ``` ```rust trait Trait<T> {} // downstream struct Local; impl Trait<Local> for dyn Trait<Local> {} ``` ### how to deal with breakage - future compat lint traits with blanket impls which overlap. We can lint on the overlapping impl --- - silently preferring user impl seems very ass for `Any`. Very surprising and hard to lint at usage site. - can we hard error on overlap? probably not, affects too many impls, e.g. `ToString`, `TryFuture`, and much more Given an attribute to crate authors to explicitly opt out of emitting a builtin impl. The attribute replaces the check Without the attribute: - edition curr, future compat warn deps - edition next, hard error on trait definition

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully