Skip to content

Move trait prototype - #161457

Draft
zannabianca1997 wants to merge 31 commits into
rust-lang:mainfrom
zannabianca1997:move-trait
Draft

Move trait prototype#161457
zannabianca1997 wants to merge 31 commits into
rust-lang:mainfrom
zannabianca1997:move-trait

Conversation

@zannabianca1997

@zannabianca1997 zannabianca1997 commented Aug 21, 2026

Copy link
Copy Markdown

View all comments

Finishing the work started by @nia-e in #156018 :

Add a barebones implementation for Move (#149607), pending some diagnostics changes & tests.

TODO

  • next solver currently errors when not enabling feature(move_trait)
  • change printing of trait objects to not show Move
  • change printing of opaque types to not show Move
  • fix mangling of Move bounds
  • how to handle empty trait object that now are dyn Move
  • relationship between PhantomData<T>: Move and T: Move
  • also make sure rustdoc handles move correctly
  • valuable to look into why diesel regresses

r? lcnr

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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 Aug 21, 2026
@rustbot

rustbot commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @lcnr (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions for more information.

@rust-log-analyzer

This comment has been minimized.

@lcnr lcnr mentioned this pull request Aug 21, 2026
3 tasks
@lcnr lcnr changed the title Move trait prototype Move trait prototype Aug 21, 2026
@zannabianca1997

Copy link
Copy Markdown
Author

A quick ./x.py test tests/ui locally to have a baseline

test result: FAILED. 9 passed; 206 failed; 21862 ignored; 0 measured; 0 filtered out; finished in 1.14s

Oh wow that got done with A LOT of tests
@zannabianca1997

Copy link
Copy Markdown
Author
test result: FAILED. 21801 passed; 32 failed; 244 ignored; 0 measured; 0 filtered out; finished in 168.70s

wow that were a lot of them. looks like the next batch is a bunch of fn that now has fn() + Move

@rust-log-analyzer

This comment has been minimized.

@zannabianca1997

Copy link
Copy Markdown
Author

looking at the errors, there is also a bunch of (dyn + 'static) printing.

Those are all checks going around the trait_alias feature, that created before empty trait object and now creates what are effectively dyn Move, that are being misprinted.

That sure raises a question - can we handle them now? ummm - putting this aside in favour of lower hanging fruits

This is one of the two options, the other being break ABI. I suspect we
can do it, Rust not having a stable one (?)
@zannabianca1997

Copy link
Copy Markdown
Author

@lcnr this last one (520bc2f)

it's better to break the ABI and accept all aymbol mangling containing Move or we have to decide a way to mangle ?Move? I know rust has no stable abi but to put it in all symbols seems a bit too much

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

mostly to avoid adding to every single dynamic symbol the `+ Move`
the output uses the debug print and parses it with regex

fixed the regex to fetch the first trait, instead of Move
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@zannabianca1997
zannabianca1997 force-pushed the move-trait branch 2 times, most recently from 0acfa71 to c51c5c0 Compare September 2, 2026 18:04
@rust-log-analyzer

This comment has been minimized.

handled Move as an additional bound instead of removing it from the
gathered explicit clauses

addressed an old FIXME that gave me the direction

reverted the changes of a couple of tests that now see the Move
@rust-log-analyzer

This comment has been minimized.

{T: PointeeSized + ?Move} *mut T,
{T: PointeeSized + ?Move} &T,
{T: PointeeSized + ?Move} &mut T,
{T: PointeeSized + ?Move} PhantomData<T>,

@cramertj cramertj Sep 2, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Apologies for the drive-by, but it's surprising to me that PhantomData would unconditionally implement Move, rather than implementing it only when T: Move. Other marker trait impls for PhantomData are conditional on T: https://doc.rust-lang.org/std/marker/struct.PhantomData.html#synthetic-implementations

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

ummm...

I often saw phantomdata as a way to maintain pointer type info, so having &'a T be somewhat equivalent to (*const (), PhantomData<&'a T>). Wouldn't not implementing Move for it make this kind of pointers immovable? The moveability of the pointer should not be related to the one of the pointee

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

generally I see in the future a proliferation of Phantom* types (like #135806) to represent different aspects you want to inherit from the type

result.clauses = tcx.arena.alloc_from_iter(result.clauses.iter().copied().filter(|p| {
!p.0.as_trait_clause().is_some_and(|p| {
p.polarity() == ClausePolarity::Positive
&& matches!(tcx.as_lang_item(p.def_id()), Some(LangItem::Move))

@lcnr lcnr Sep 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

for perf reasons, it might actually be faster to do

if !tcx.features().move_trait() {
    let move_trait = tcx.get_lang_item(LangItem::Move);
    // filter_by_comparing to that :>
}

might be worth another perf run with that change 😁

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Oh that's a get for each clause - totally missed that. I guess that T: Move clause would be common enough to make caching that at least equal in performance

You should call the perf run right? Also need to check diesel as I am hopefully almost done with fixing the tests

Comment thread compiler/rustc_hir_analysis/src/collect/item_bounds.rs Outdated
@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Again, not very sure of this. I don't really know the itanium c++ stuff, but looks like Send and Sync are there so it should contains it?
And removing it in favour of `?Move` makes a ton of other tests fail. So I guess i'll let it like this and let it breaks later if it does
@rustbot rustbot added the PG-exploit-mitigations Project group: Exploit mitigations label Sep 6, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job x86_64-gnu-gcc-core-tests failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
---- mem::type_info::test_dynamic_traits stdout ----
---- mem::type_info::test_dynamic_traits stderr ----

thread 'main' (19197) panicked at library/coretests/tests/mem/type_info.rs:364:9:
assertion `left == right` failed: unexpected ids.
actual: [TypeId(0x9b192d704cbe10d507bc1e5256cef3a9), TypeId(0x19e931f02a5065b2fd07215b8865ce8c)]
expected: [TypeId(0xa73276c55ec593447079ff75a7990bc5)]
  left: {TypeId(0x19e931f02a5065b2fd07215b8865ce8c), TypeId(0x9b192d704cbe10d507bc1e5256cef3a9)}
 right: {TypeId(0xa73276c55ec593447079ff75a7990bc5)}
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
---- mem::type_info::test_dynamic_traits stdout end ----

failures:
    mem::type_info::test_dynamic_traits

Important

For more information how to resolve CI failures of this job, visit this link.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) PG-exploit-mitigations Project group: Exploit mitigations S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

7 participants