-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
#[diagnostic::on_unimplemented]
without filters
#114452
#[diagnostic::on_unimplemented]
without filters
#114452
Conversation
r? @TaKO8Ki (rustbot has picked a reviewer for you, use r? to override) |
tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.rs
Outdated
Show resolved
Hide resolved
tests/ui/diagnostic_namespace/on_unimplemented/feature-gate-diagnostic_on_unimplemented.rs
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
8a50b1a
to
8ffd5f6
Compare
/// be available on newer compiler versions | ||
pub MALFORMED_DIAGNOSTIC_ATTRIBUTES, | ||
Warn, | ||
"unrecognized diagnostic attribute options" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are too many new lints for this feature, IMO.
Is it ever necessary to e.g. allow malformed diagnostic attributes, but warn on unknown?
I don't think so, this lints generally exists to warn on diagnostic attributes that are both known and well-formed, just on some other version of Rust compiler, so the distinction is not significant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also the previous lint was introduced as stable, but it should probably use a feature gate @feature_gate = sym::feature_gate_name;
for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Will change that to use the other lint. We might consider renaming the lint then.
For the @feature_gate
change: Is it ok to put that into this PR as well or should that be opened as a separate PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed 9f51111 to address these concerns.
c59ef01
to
9f51111
Compare
☔ The latest upstream changes (presumably #114023) made this pull request unmergeable. Please resolve the merge conflicts. |
9f51111
to
adcaef1
Compare
r? compiler |
☔ The latest upstream changes (presumably #115094) made this pull request unmergeable. Please resolve the merge conflicts. |
adcaef1
to
fe719f9
Compare
compiler/rustc_ast/src/attr/mod.rs
Outdated
.segments | ||
.iter() | ||
.zip(name) | ||
.all(|(s, n)| s.ident == Ident::with_dummy_span(*n)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This equality is weird, and relies on the fact that idents are equal only if their symbols are equal and their span contexts are identical:
https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_span/symbol.rs.html#1795-1800
If you're just trying to compare the symbols against name
, then try
.all(|(s, n)| s.ident == Ident::with_dummy_span(*n)) | |
.all(|(s, n)| s.ident.name == *n) |
let def_kind = tcx.def_kind(id.owner_id); | ||
if !matches!(def_kind, DefKind::Trait) { | ||
let item_def_id = id.owner_id.to_def_id(); | ||
if let Some(attr) = tcx | ||
.get_attrs_by_path(item_def_id, Box::new([sym::diagnostic, sym::on_unimplemented])) | ||
.next() | ||
{ | ||
tcx.emit_spanned_lint( | ||
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, | ||
tcx.hir().local_def_id_to_hir_id(item_def_id.expect_local()), | ||
vec![attr.span], | ||
DiagnosticOnUnimplementedOnlyForTraits, | ||
); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this check should live here. Attr validation better lives in compiler/rustc_passes/src/check_attr.rs
or something like that.
compiler/rustc_middle/src/ty/mod.rs
Outdated
pub fn get_attrs_by_path( | ||
self, | ||
did: impl Into<DefId>, | ||
attr: Box<[Symbol]>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this take a Box
? 😅
Please use lifetimes here and make it &'a [Symbol]
-- the allocation here is really unnecessary.
compiler/rustc_middle/src/ty/mod.rs
Outdated
@@ -2410,6 +2410,23 @@ impl<'tcx> TyCtxt<'tcx> { | |||
} | |||
} | |||
|
|||
pub fn get_attrs_by_path( | |||
self, | |||
did: impl Into<DefId>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this take an Into<DefId>
? It's really general -- please just take a DefId
, and make the caller call into_def_id()
if needed.
tcx.emit_spanned_lint( | ||
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, | ||
tcx.hir().local_def_id_to_hir_id(item_def_id.expect_local()), | ||
vec![attr.span], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Span
is Into<MultiSpan>
vec![attr.span], | |
attr.span, |
@@ -401,15 +410,30 @@ impl<'tcx> OnUnimplementedDirective { | |||
&& message.is_none() | |||
&& label.is_none() | |||
&& note.is_none() | |||
&& !is_diagnostic_namespace_variant | |||
// disallow filters for now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// disallow filters for now | |
// FIXME(diagnostic_namespace): disallow filters for now |
is_diagnostic_namespace_variant, | ||
) { | ||
Ok(Some(subcommand)) => subcommands.push(subcommand), | ||
Ok(None) => unreachable!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok(None) => unreachable!( | |
Ok(None) => bug!( |
@rustbot author |
@compiler-errors Thanks for the review. These comments are really helpful. ❤️ @rustbot reviewer |
tcx.emit_spanned_lint( | ||
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, | ||
tcx.hir().local_def_id_to_hir_id(item_def_id.expect_local()), | ||
vec![attr.span], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix this here too.
tcx.emit_spanned_lint( | ||
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, | ||
tcx.hir().local_def_id_to_hir_id(item_def_id.expect_local()), | ||
vec![attr.span], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
This comment has been minimized.
This comment has been minimized.
Also please squash all of these "apply suggestions", "address suggestion", "update" commits. It's not super needed to retain them in git history, and I don't really review them individually. Thanks! |
attr_span: Span, | ||
hir_id: HirId, | ||
target: Target, | ||
) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also mentioned making this function not return bool.
@@ -284,6 +292,23 @@ impl CheckAttrVisitor<'_> { | |||
} | |||
} | |||
|
|||
/// Checks if `#[diagnostic::on_unimplemented[` is applied to a trait definition |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Checks if `#[diagnostic::on_unimplemented[` is applied to a trait definition | |
/// Checks if `#[diagnostic::on_unimplemented]` is applied to a trait definition |
compiler/rustc_ast/src/attr/mod.rs
Outdated
@@ -99,6 +99,22 @@ impl Attribute { | |||
} | |||
} | |||
|
|||
pub fn is_path(&self, name: &[Symbol]) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name here is a bit weird, since it's inconsistent with is_word
, which only allows #[word]
and not #[word()]
. Maybe let's name this path_matches
or something?
e0d4bc0
to
3538130
Compare
This comment has been minimized.
This comment has been minimized.
This commit adds support for a `#[diagnostic::on_unimplemented]` attribute with the following options: * `message` to customize the primary error message * `note` to add a customized note message to an error message * `label` to customize the label part of the error message Co-authored-by: León Orell Valerian Liehr <[email protected]> Co-authored-by: Michael Goulet <[email protected]>
3538130
to
5b8a7a0
Compare
@compiler-errors This PR is still marked as |
@weiznich: please be patient, it's been less than 24 hours since you last updated it, as far as I can tell. I haven't had the time to review the changes, and probably will not for a few days. |
I'm mainly asking because you did not remove the |
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (327e6cf): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 636.485s -> 634.734s (-0.28%) |
This commit adds support for a
#[diagnostic::on_unimplemented]
attribute with the following options:message
to customize the primary error messagenote
to add a customized note message to an error messagelabel
to customize the label part of the error messageThe relevant behavior is specified in RFC-3368