-
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
Improve errors about #[deprecated] attribute #78626
Improve errors about #[deprecated] attribute #78626
Conversation
e87c60d
to
c2da4fc
Compare
This comment has been minimized.
This comment has been minimized.
They have no effect there, but were silently accepted.
c2da4fc
to
9fc991a
Compare
compiler/rustc_attr/src/builtin.rs
Outdated
struct_span_err!(diagnostic, attr.span, E0550, "multiple deprecated attributes") | ||
.span_note(*span, "first deprecation attribute here") |
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.
Can this happen multiple times (if you have three deprecation attributes)? If so, reword the label to not make it technically incorrect.
Also, use prefer to use span_label
when possible.
struct_span_err!(diagnostic, attr.span, E0550, "multiple deprecated attributes") | |
.span_note(*span, "first deprecation attribute here") | |
struct_span_err!(diagnostic, attr.span, E0550, "multiple deprecated attributes") | |
.span_label(attr.span, "repeated deprecated attribute") | |
.span_label(*span, "prior deprecation attribute") |
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.
It stops right after the first duplicate, so having three deprecation attributes wouldn't output any more diagnostics than two.
Is there documentation somewhere about all the different options for diagnostics, like span_label
, span_suggestion_short
, etc.?
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.
https://github.com/rust-lang/rust/blob/master/compiler/rustc_errors/src/diagnostic.rs has all the methods that can be used and they have good docstrings for the most part.
(From the PR feedback.) Co-authored-by: Esteban Küber <[email protected]>
Thanks! Updated. |
@bors r+ |
📌 Commit 9c647d1 has been approved by |
…-trait-impl, r=estebank Improve errors about #[deprecated] attribute This change: 1. Turns `#[deprecated]` on a trait impl block into an error, which fixes rust-lang#78625; 2. Changes these and other errors about `#[deprecated]` to use the span of the attribute instead of the item; and 3. Turns this error into a lint, to make sure it can be capped with `--cap-lints` and doesn't break any existing dependencies. Can be reviewed per commit. --- Example: ```rust struct X; #[deprecated = "a"] impl Default for X { #[deprecated = "b"] fn default() -> Self { X } } ``` Before: ``` error: This deprecation annotation is useless --> src/main.rs:6:5 | 6 | / fn default() -> Self { 7 | | X 8 | | } | |_____^ ``` After: ``` error: this `#[deprecated]' annotation has no effect --> src/main.rs:3:1 | 3 | #[deprecated = "a"] | ^^^^^^^^^^^^^^^^^^^ help: try removing the deprecation attribute | = note: `#[deny(useless_deprecated)]` on by default error: this `#[deprecated]' annotation has no effect --> src/main.rs:5:5 | 5 | #[deprecated = "b"] | ^^^^^^^^^^^^^^^^^^^ help: try removing the deprecation attribute ```
Rollup of 7 pull requests Successful merges: - rust-lang#77950 (Add support for SHA256 source file hashing) - rust-lang#78624 (Sync rustc_codegen_cranelift) - rust-lang#78626 (Improve errors about #[deprecated] attribute) - rust-lang#78659 (Corrected suggestion for generic parameters in `function_item_references` lint) - rust-lang#78687 (Suggest library/std when running all stage 0 tests) - rust-lang#78699 (Show more error information in lldb_batchmode) - rust-lang#78709 (Fix panic in bootstrap for non-workspace path dependencies.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
443: Remove useless deprecation annotation r=kpcyrd a=kpcyrd This should fix our broken CI. The change in rustc was caused by rust-lang/rust#78626, further discussion in rust-lang/rust#79304. Co-authored-by: kpcyrd <[email protected]>
443: Remove useless deprecation annotation r=kpp a=kpcyrd This should fix our broken CI. The change in rustc was caused by rust-lang/rust#78626, further discussion in rust-lang/rust#79304. Co-authored-by: kpcyrd <[email protected]>
This change:
#[deprecated]
on a trait impl block into an error, which fixes Deprecation attribute on trait impl block is accepted but has no effect #78625;#[deprecated]
to use the span of the attribute instead of the item; and--cap-lints
and doesn't break any existing dependencies.Can be reviewed per commit.
Example:
Before:
After: