Skip to content

Conversation

@rperier
Copy link
Contributor

@rperier rperier commented Jan 10, 2026

cc #149862

This is a first proposal. I have deliberately kept it simpler than diagnostic::on_unimplemented.

Few questions/remarks:

  • Do I need to move the OnMoveDirective logic into a dedicated module perhaps ? let's say into compiler/rustc_borrowck/src/diagnostics/on_move.rs
  • No problems to depend on crates like rustc_ast from the borrowck ?
  • Notes are not supported yet. While message and label are very static , in the sense that they are emitted in the same way from the same place in the borrowck, it is not the case for the notes. It would make the code more complex. But, I can add support for notes if it does make sense.

Suggestions are welcomed !

@rustbot
Copy link
Collaborator

rustbot commented Jan 10, 2026

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 10, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 10, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 10, 2026

r? @JonathanBrouwer

rustbot has assigned @JonathanBrouwer.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rperier
Copy link
Contributor Author

rperier commented Jan 10, 2026

r? @estebank

@rustbot rustbot assigned estebank and unassigned JonathanBrouwer Jan 10, 2026
@mejrs
Copy link
Contributor

mejrs commented Jan 13, 2026

I'm currently working on migrating the existing diagnostic attribute infrastructure, can you do this PR after that? It's going to be quite a mess to resolve that conflict.

Is this meant to be only used by the standard library or also by users? If only by std, I think you should forego the attribute and instead check whether T implements UseCloned and recommend a clone (or .use if on nightly).

@rperier
Copy link
Contributor Author

rperier commented Jan 14, 2026

Yeah I can completly wait until you finished your work and do my PR after that, It was my intention to be honest . Resolving conflicts or rebasing is not an issue for me.

@rperier rperier force-pushed the provide_diagnostic_on_move_for_smart_pointers branch from 9a0162d to 8071a7d Compare January 21, 2026 19:15
@rustbot
Copy link
Collaborator

rustbot commented Jan 21, 2026

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

Changes to the size of AST and/or HIR nodes.

cc @nnethercote

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann, @JonathanBrouwer

@rustbot

This comment has been minimized.

@rperier
Copy link
Contributor Author

rperier commented Jan 21, 2026

I have reworked my code and moved everything to rustc_attr_parsing and rustc_hir/src/attrs/data_structures.rs. Few questions/remarks remain:

  • Perhaps, It would make sense to allow this diagnostic attribute to be used only for nightly, for now, what do you think ?
  • I can wait until some refactoring for attributes are merged upstream, and wait for my PR being merged after that, if it helps, no problems for me

@rperier rperier force-pushed the provide_diagnostic_on_move_for_smart_pointers branch from 8071a7d to 09506a4 Compare January 21, 2026 19:26
@rust-bors

This comment has been minimized.

This might be helpful for smart pointers to explains why they aren't Copy
and what to do instead or just to let the user know that .clone() is very
cheap and can be called without a performance penalty.
@rperier rperier force-pushed the provide_diagnostic_on_move_for_smart_pointers branch from 09506a4 to 829651a Compare January 22, 2026 19:23
@rustbot
Copy link
Collaborator

rustbot commented Jan 22, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rperier
Copy link
Contributor Author

rperier commented Jan 22, 2026

Rebased onto main, I have also fixed the size of AttributeKind::OnMove

Comment on lines +1 to +10
#[diagnostic::on_move(
message = Foo,
//~^ERROR expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found expression
label = "Bar",
)]
#[diagnostic::on_move(
message = "Foo"
label = "Bar",
//~^ERROR expected `,`, found `label`
)]
Copy link
Contributor

Choose a reason for hiding this comment

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

This can't be an error; this must be a lint. But you will need #151516 to do so.

Comment on lines +572 to +576
#[derive(Clone, Debug, Encodable, Decodable, HashStable_Generic, PrintAttribute)]
pub struct OnMoveAttrArg {
pub symbol: Symbol,
pub format_ranges: ThinVec<(usize, usize)>,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I plan on moving a fair bit of the format and string stuff that on_unimplemented uses into rustc_hir; you should be able to reuse some of that in this PR :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I will do

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

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants