Skip to content

implement Move trait prototype - #156018

Closed
nia-e wants to merge 4 commits into
rust-lang:mainfrom
nia-e:move-trait
Closed

implement Move trait prototype#156018
nia-e wants to merge 4 commits into
rust-lang:mainfrom
nia-e:move-trait

Conversation

@nia-e

@nia-e nia-e commented Apr 30, 2026

Copy link
Copy Markdown
Member

View all comments

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

r? lcnr

@rustbot rustbot added 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 Apr 30, 2026
@nia-e

nia-e commented Apr 30, 2026

Copy link
Copy Markdown
Member Author

@bors try @rust-timer queue

@rust-timer

This comment was marked as off-topic.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 30, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Apr 30, 2026
implement `Move` trait prototype
@nia-e

nia-e commented Apr 30, 2026

Copy link
Copy Markdown
Member Author

(tests are broken, mostly due to diagnostics changing)

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment was marked as outdated.

@rust-log-analyzer

This comment has been minimized.

@lcnr

lcnr commented May 1, 2026

Copy link
Copy Markdown
Contributor

the zerovec changes rely on a need candidate preference change 🤔 :3

what i've done in https://github.com/rust-lang/rust/pull/146201/changes#diff-34d5893dd95fe09f9a0fd3341efacd1c21853bb34ba29d9d79bb9af26bb8a0a0

let key = self.infcx.param_env.and(type_op::prove_predicate::ProvePredicate { predicate });
let op = CustomTypeOp::new(
|ocx| {
let res = type_op::QueryTypeOp::perform_locally_with_next_solver(ocx, key, span);

@lcnr lcnr May 1, 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.

if you look at what perform_locally_with_next_solver, it should just be the thing you do in the error path anyways 🤔 🤷

actually, we could make scrape_region_constraints generic over the expected errors, and have a FallibleCustomTypeOp which uses it while expecting potential errors. Instead instead of always emitting a delayed bug if there are errors, scrape_region_constraints would just report the failures as proper type errors 🤔 that seems nicer to me

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

right, ok - wasn't sure if that level of overhaul was on the table. it was kind of difficult to recreate the predicate in scrape_region_constraints (thus me doing it this way) but if i can mess with it that makes my life easier :D

Comment thread compiler/rustc_borrowck/src/type_check/mod.rs Outdated
Comment thread compiler/rustc_hir_analysis/src/check/wfcheck.rs Outdated
Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs Outdated
let relaxed_bounds = collect_relaxed_bounds(hir_bounds, context);
self.reject_duplicate_relaxed_bounds(relaxed_bounds);

let Some(move_did) = tcx.lang_items().move_trait() else {

@lcnr lcnr May 1, 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.

I'd just always require_lang_item :3 requiring core to provide the trait definition for Move seems innocent enough

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

that's what I tried initially, but it means we need to add Move in a quadrillion tests that don't depend on core 🫠

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.

we should have some mini_core somewhere that most such tests should use 😅

are there still proper #[no_core] tests that don't use an existing mini_core?

Comment thread compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs Outdated
}

// Don't use `add_implicit_bounds` directly to skip adding `Sized`.
self.add_implicit_move_bound(

@lcnr lcnr May 1, 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.

hmm, I'd prefer add_implicit_bound here, because otherwise we have to do that when adding Forget later on

View changes since the review

Comment thread compiler/rustc_middle/src/ty/context.rs Outdated
}

pub fn is_implicit_trait(self, def_id: DefId) -> bool {
self.is_default_trait(def_id) || matches!(self.as_lang_item(def_id), Some(LangItem::Move))

@lcnr lcnr May 1, 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.

why are we not treating Sized as an implicit trait?

View changes since the review

@nia-e nia-e May 1, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sized is weird enough (sometimes the bound is Sized, sometimes MetaSized etc) that i thought it made more sense to treat it separately. like, arguably MetaSized should also be an implicit trait but that would change behaviour at most callsites i think.

though i realise this is kinda confusing naming given that I also wrote add_implicit_trait_bounds that does add sized...

}

// Backward compatibility for default auto traits.
// Backward compatibility for default auto traits & `Move`.

@lcnr lcnr May 1, 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.

this is somewhat meh, Move is a default auto trait 😅 ✨ , just not add default_auto_trait

View changes since the review

@fmease fmease May 1, 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.

In general, this PR doesn't seem to use the "infrastructure" provided by internal feature more_maybe_bounds unlike earlier experiments.

I lack the context, so I don't know why that's done this way. However, if the "proper" Move and Forget default auto traits won't use all the preexisting MMB lowering routines, then I'd rather remove that internal feature entirely since it's evidently being supplanted (and also won't be needed anymore anyway as its purpose was to experiment with new default bounds).

Maintaining two incredibly similar but still somehow distinct features (default vs. "implicit") is somewhat meh I dare say. We probably want to notify Vadim then who is the owner of MMB IIRC.

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.

yeah, I agree. Ripping out that feature in favor of actually having individual traits seems good to me. Reusing these features doesn't simplify adding new traits. Having one non-sized trait is nice to properly handle things though

@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@nia-e

nia-e commented May 4, 2026

Copy link
Copy Markdown
Member Author

curious what the perf hit is without doing any special handling. should actually work this time :D

@bors try @rust-timer queue

@rust-timer

This comment was marked as duplicate.

@rust-bors

This comment has been minimized.

@lcnr

lcnr commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 24, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jul 24, 2026
implement `Move` trait prototype
@rust-bors

rust-bors Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

💔 Test for b373540 failed: CI. Failed job:

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the A-attributes Area: Attributes (`#[…]`, `#![…]`) label Aug 21, 2026
@lcnr

lcnr commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 21, 2026
implement `Move` trait prototype
@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' (19749) panicked at library/coretests/tests/mem/type_info.rs:369:9:
assertion `left == right` failed: unexpected ids.
actual: [TypeId(0xeff143cada5c252eeb97a379bd3afff1), TypeId(0xb0ecf8e2d74c22b56d21dade0483b5c3)]
expected: [TypeId(0x58664381986b010a958eaa22c03eab81)]
  left: {TypeId(0xeff143cada5c252eeb97a379bd3afff1), TypeId(0xb0ecf8e2d74c22b56d21dade0483b5c3)}
 right: {TypeId(0x58664381986b010a958eaa22c03eab81)}
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.

@rust-bors

rust-bors Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: a238f16 (a238f167ac6e36167ceb7d6094bd56262913350c)
Base parent: 16a623a (16a623ad672a92409b5c04beb303583c6cf72a7e)

@rust-timer

This comment has been minimized.

@zannabianca1997 zannabianca1997 mentioned this pull request Aug 21, 2026
5 tasks
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (a238f16): comparison URL.

Overall result: ❌✅ regressions and improvements - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never rustc-perf
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
1.5% [0.2%, 12.0%] 151
Regressions ❌
(secondary)
1.1% [0.0%, 4.5%] 195
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.3% [-0.4%, -0.2%] 3
All ❌✅ (primary) 1.5% [0.2%, 12.0%] 151

Max RSS (memory usage)

Results (primary 1.7%, secondary 3.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.9% [0.4%, 5.9%] 23
Regressions ❌
(secondary)
3.3% [0.6%, 7.1%] 8
Improvements ✅
(primary)
-3.4% [-3.4%, -3.4%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.7% [-3.4%, 5.9%] 24

Cycles

Results (primary 3.4%, secondary 2.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.4% [2.1%, 9.0%] 28
Regressions ❌
(secondary)
2.5% [1.4%, 4.4%] 30
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.4% [2.1%, 9.0%] 28

Binary size

Results (primary 0.2%, secondary 0.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.2% [0.0%, 1.1%] 124
Regressions ❌
(secondary)
0.2% [0.0%, 2.1%] 157
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.2% [0.0%, 1.1%] 124

Bootstrap: 457.604s -> 457.673s (0.02%)
Artifact size: 398.89 MiB -> 398.95 MiB (0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 21, 2026
@lcnr

lcnr commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

closing in favor of #161457

@lcnr lcnr closed this Aug 21, 2026
@rustbot rustbot removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. perf-regression Performance regression. 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. T-rust-analyzer Relevant to the rust-analyzer 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