Introduce #[diagnostic::on_move(message)]#150935
Introduce #[diagnostic::on_move(message)]#150935rperier wants to merge 1 commit intorust-lang:mainfrom
Conversation
|
These commits modify the If this was unintentional then you should revert the changes before this PR is merged. Some changes occurred in compiler/rustc_passes/src/check_attr.rs |
|
rustbot has assigned @JonathanBrouwer. Use |
|
r? @estebank |
|
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 |
|
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. |
9a0162d to
8071a7d
Compare
|
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 |
This comment has been minimized.
This comment has been minimized.
|
I have reworked my code and moved everything to
|
8071a7d to
09506a4
Compare
This comment has been minimized.
This comment has been minimized.
09506a4 to
829651a
Compare
This comment has been minimized.
This comment has been minimized.
|
Rebased onto main, I have also fixed the size of |
| #[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` | ||
| )] |
There was a problem hiding this comment.
This can't be an error; this must be a lint. But you will need #151516 to do so.
There was a problem hiding this comment.
Hi. Since this morning, these "cases" are no longer handled at all. The parser does not report anything and I get an empty MetaItemListParser (there are no sub_parsers) in onMoveParser::convert , see #t-compiler/help > #diagnostic::on_move(message) (PR #150935) @ 💬 for the full description. Is it expected ? I mean I cannot emit the lint myself, I have an empty ArgParser context, and the parser reports nothing.
There was a problem hiding this comment.
I think, I got it. This is due to https://github.com/rust-lang/rust/blob/main/compiler/rustc_attr_parsing/src/parser.rs#L132 . I can of course emit a lint myself when the MetaItemListParser is empty, it's a shame to no longer have the context of the error, we had a more fine grained context with a span before. The span now will be the full diagnostic attribute.
There was a problem hiding this comment.
It is possible to replace the entire span https://github.com/rust-lang/rust/blob/main/compiler/rustc_attr_parsing/src/parser.rs#L135 by e.span (or build a span from e) ? so we would have a span on the attr in this case instead of the whole diagnostic attribute.
| #[derive(Clone, Debug, Encodable, Decodable, HashStable_Generic, PrintAttribute)] | ||
| pub struct OnMoveAttrArg { | ||
| pub symbol: Symbol, | ||
| pub format_ranges: ThinVec<(usize, usize)>, | ||
| } |
There was a problem hiding this comment.
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 :)
829651a to
b12aa8b
Compare
This comment has been minimized.
This comment has been minimized.
|
Rebased onto main. I have covered changes related to #151516 .
If I can help for this (by proposing a patch for a generic lint, for example), feel free to ask. |
This comment has been minimized.
This comment has been minimized.
b12aa8b to
1efb939
Compare
This comment has been minimized.
This comment has been minimized.
7d94896 to
472c486
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
#151558 has merged :) |
|
@rustbot -S-blocked |
Yes, This is what I am currently doing :) . I am also realigning on stuffs like format attr handling, like it is done on |
472c486 to
ccfb4fa
Compare
This comment has been minimized.
This comment has been minimized.
|
Rebased onto main:
Remaining tasks:
EDIT: I have to use |
This comment has been minimized.
This comment has been minimized.
ccfb4fa to
4aaa5b9
Compare
This comment has been minimized.
This comment has been minimized.
c815bc7 to
ca385ba
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
I assume this is still work in progress right? Make sure to mark it as waiting-on-review when it's ready, then I'll take a look |
|
Hi, yes, it is still work in progress. I think it should be ready this weekend. |
|
No hurry :) just wanted to verify |
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.
ca385ba to
5d6b5bf
Compare
|
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. |
|
I think that's it for now, two remaining tasks:
@rustbot ready |
There was a problem hiding this comment.
Thanks, I think this looks good generally. One important thing missing though is a feature gate; the consensus on Zulip was that this should be unstable for now.
Do I add "notes=" to diagnostic::on_move(...) as it is parsed and part of the Directive ?
Sure, why not? I'd prefer if this attribute was consistent with the others.
Please also add more tests:
- for when the item is in another crate as the error message generally is different (there's no recommendation to implement Clone, for example).
- for when we hit an explicit
Copybound, likefn take_copy<T: Copy>(t: T){}; then this attribute should do nothing. (or should it?)
| this: "This".to_string(), | ||
| trait_sugared: "Sugared".to_string(), | ||
| item_context: "Context", |
There was a problem hiding this comment.
You can set these to "" or anything else, they only do something for rustc_on_unimplemented anyway. (note to self: maybe this could be nicer)
There was a problem hiding this comment.
Yeah, perhaps a "default" constructor or something, might help in such a case... no ?
| impl<S: Stage> SingleAttributeParser<S> for OnMoveParser { | ||
| const PATH: &[Symbol] = &[sym::diagnostic, sym::on_move]; | ||
| const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost; | ||
| const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn; |
There was a problem hiding this comment.
The other diagnostic attributes allow multiple uses of the attribute and merge it, for consistency this one should too.
| if let Some(directive) = directive { | ||
| directive.visit_params(&mut |argument_name, span| { | ||
| self.tcx.emit_node_span_lint( | ||
| MALFORMED_DIAGNOSTIC_FORMAT_LITERALS, | ||
| hir_id, | ||
| span, | ||
| errors::OnMoveMalformedFormatLiterals { name: argument_name }, | ||
| ) | ||
| }); | ||
| } |
There was a problem hiding this comment.
IMO something like this should be allowed
#[diagnostic::on_move(message = "please do not the {X}")]
pub struct MyStruct<X>{
_x: X,
}| && let Some(directive) = find_attr!(self.infcx.tcx, item_def.did(), OnMove { directive, .. } => directive) | ||
| && let Some(directive) = directive |
There was a problem hiding this comment.
| && let Some(directive) = find_attr!(self.infcx.tcx, item_def.did(), OnMove { directive, .. } => directive) | |
| && let Some(directive) = directive | |
| && let Some(Some(directive)) = find_attr!(self.infcx.tcx, item_def.did(), OnMove { directive, .. } => directive) |
Or
| && let Some(directive) = find_attr!(self.infcx.tcx, item_def.did(), OnMove { directive, .. } => directive) | |
| && let Some(directive) = directive | |
| && let Some(directive) = find_attr!(self.infcx.tcx, item_def.did(), OnMove { directive, .. } => directive).flatten() |
|
|
||
| fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> { | ||
| let Some(list) = args.list() else { | ||
| cx.expected_list(cx.attr_span, args); |
| return None; | ||
| }; | ||
|
|
||
| Some(AttributeKind::OnMove { span: cx.attr_span, directive: Some(Box::new(directive)) }) |
There was a problem hiding this comment.
All these return None should really return OnMove {span, None}
View all comments
cc #149862
This is a first proposal. I have deliberately kept it simpler than
diagnostic::on_unimplemented.Few questions/remarks:
rustc_astfrom the borrowck ?Suggestions are welcomed !