Skip to content
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

Rollup of 10 pull requests #134391

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
665d7ad
Improve testing coverage for `#[diagnostic::do_not_recommend]`
weiznich Oct 22, 2024
68cd044
Check `#[diagnostic::do_not_recommend]` for arguments
weiznich Oct 23, 2024
70ab7a7
Stabilize `#[diagnostic::do_not_recommend]`
weiznich Oct 23, 2024
fad597f
Also warn against `#[diagnostic::do_not_recommend]` on plain impls
weiznich Oct 25, 2024
577b5f3
CI: use free runners for x86_64-gnu-llvm jobs
marcoieni Dec 10, 2024
e67e9b4
fix
marcoieni Dec 10, 2024
4f0e781
split better
marcoieni Dec 11, 2024
bb88d7a
fix
marcoieni Dec 11, 2024
84ba41d
remove unnecessary change
marcoieni Dec 11, 2024
abd8352
restore command
marcoieni Dec 11, 2024
a8bc3cf
fix
marcoieni Dec 11, 2024
d74de1f
debug
marcoieni Dec 11, 2024
754fb24
debug
marcoieni Dec 11, 2024
9ed728d
debug
marcoieni Dec 11, 2024
eec9bcf
more debug
marcoieni Dec 11, 2024
fee220a
fix
marcoieni Dec 11, 2024
1f38572
fix
marcoieni Dec 11, 2024
7ce2944
test stage 1 in separate job
marcoieni Dec 12, 2024
aa0fd46
copy script
marcoieni Dec 12, 2024
a1abbaa
remove echo logs
marcoieni Dec 12, 2024
2bf1cec
refactor
marcoieni Dec 12, 2024
c2f4550
remove echo
marcoieni Dec 12, 2024
a67a71d
add files
marcoieni Dec 12, 2024
4fa9078
fix path
marcoieni Dec 12, 2024
ac078a4
fix path
marcoieni Dec 12, 2024
de16ed3
Correctly handle comments in attributes in doctests source code
GuillaumeGomez Dec 13, 2024
165f37e
rustc_mir_build: Clarify that 'mirrored' does not mean 'flipped' or '…
Enselic Dec 12, 2024
f068d8b
rustdoc-search: show `impl Trait` inline when unhighlighted
notriddle Dec 13, 2024
246835e
rustdoc-search: let From and Into be unboxed
notriddle Dec 13, 2024
0be3ed0
rustdoc-search: update documentation with notes about unboxing
notriddle Dec 13, 2024
0f82cff
Keep track of patterns that could have introduced a binding, but didn't
estebank Dec 13, 2024
8c8e8d3
Use `ErrorGuaranteed` more
estebank Dec 15, 2024
733fd03
Use `span_label` as it looks better when we show pattern missing bind…
estebank Dec 15, 2024
9c4a61f
Add ui regression test for #134221
GuillaumeGomez Dec 13, 2024
2383985
Also handle cases where attributes are unclosed
GuillaumeGomez Dec 16, 2024
bdb88c9
Avoid creating a fn sig type just to unwrap it again to get at its si…
oli-obk Dec 16, 2024
f387b9d
Properly name a def id variable
oli-obk Dec 16, 2024
4032b9d
Avoid wrapping a trivially defaultable type in `Option`
oli-obk Dec 16, 2024
1c7d54e
Deduplicate some pretty printing logic
oli-obk Dec 16, 2024
1d834c2
Avoid wrapping fn sig in a fn pointer when we want to just print the sig
oli-obk Dec 16, 2024
86e0eab
tests/ui/asm: Remove uses of rustc_attrs, lang_items, and decl_macro …
taiki-e Dec 16, 2024
c367cc3
Remove unneeded handling of backlines in doctest attributes
GuillaumeGomez Dec 16, 2024
418ce11
Rollup merge of #132056 - weiznich:diagnostic_do_not_recommend_final_…
GuillaumeGomez Dec 16, 2024
9bc21a9
Rollup merge of #134124 - MarcoIeni:split-llvm-jobs, r=Kobzol
GuillaumeGomez Dec 16, 2024
b77879f
Rollup merge of #134197 - Enselic:mirror, r=lcnr
GuillaumeGomez Dec 16, 2024
77ba33d
Rollup merge of #134260 - GuillaumeGomez:doctest-attrs, r=notriddle
GuillaumeGomez Dec 16, 2024
cfe295a
Rollup merge of #134277 - notriddle:notriddle/inline-into, r=Guillaum…
GuillaumeGomez Dec 16, 2024
c15f2e0
Rollup merge of #134284 - estebank:issue-74863, r=lcnr
GuillaumeGomez Dec 16, 2024
70b1524
Rollup merge of #134385 - taiki-e:ui-asm-minicore, r=compiler-errors
GuillaumeGomez Dec 16, 2024
b349110
Rollup merge of #134386 - oli-obk:some-trait-impl-diff-diagnostic-cle…
GuillaumeGomez Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Check #[diagnostic::do_not_recommend] for arguments
This commit adds a check that verifies that no arguments are passed to
`#[diagnostic::do_not_recommend]`. If we detect arguments we emit a warning.
  • Loading branch information
weiznich committed Dec 4, 2024
commit 68cd04447304f7f9d56b5373d86b0c0e449e42f8
3 changes: 3 additions & 0 deletions compiler/rustc_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ passes_ignored_derived_impls =
passes_implied_feature_not_exist =
feature `{$implied_by}` implying `{$feature}` does not exist
passes_incorrect_do_not_recommend_args =
`#[diagnostic::do_not_recommend]` does not expect any arguments
passes_incorrect_do_not_recommend_location =
`#[diagnostic::do_not_recommend]` can only be placed on trait implementations
Expand Down
18 changes: 16 additions & 2 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
for attr in attrs {
match attr.path().as_slice() {
[sym::diagnostic, sym::do_not_recommend, ..] => {
self.check_do_not_recommend(attr.span, hir_id, target)
self.check_do_not_recommend(attr.span, hir_id, target, attr)
}
[sym::diagnostic, sym::on_unimplemented, ..] => {
self.check_diagnostic_on_unimplemented(attr.span, hir_id, target)
Expand Down Expand Up @@ -351,7 +351,13 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}

/// Checks if `#[diagnostic::do_not_recommend]` is applied on a trait impl.
fn check_do_not_recommend(&self, attr_span: Span, hir_id: HirId, target: Target) {
fn check_do_not_recommend(
&self,
attr_span: Span,
hir_id: HirId,
target: Target,
attr: &Attribute,
) {
if !matches!(target, Target::Impl) {
self.tcx.emit_node_span_lint(
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
Expand All @@ -360,6 +366,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
errors::IncorrectDoNotRecommendLocation,
);
}
if !matches!(attr.meta_kind(), Some(MetaItemKind::Word)) {
self.tcx.emit_node_span_lint(
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
hir_id,
attr_span,
errors::DoNotRecommendDoesNotExpectArgs,
);
}
}

/// Checks if `#[diagnostic::on_unimplemented]` is applied to a trait definition
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ use crate::lang_items::Duplicate;
#[diag(passes_incorrect_do_not_recommend_location)]
pub(crate) struct IncorrectDoNotRecommendLocation;

#[derive(LintDiagnostic)]
#[diag(passes_incorrect_do_not_recommend_args)]
pub(crate) struct DoNotRecommendDoesNotExpectArgs;

#[derive(Diagnostic)]
#[diag(passes_autodiff_attr)]
pub(crate) struct AutoDiffAttr {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
warning: `#[diagnostic::do_not_recommend]` does not expect any arguments
--> $DIR/does_not_acccept_args.rs:12:1
|
LL | #[diagnostic::do_not_recommend(not_accepted)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default

warning: `#[diagnostic::do_not_recommend]` does not expect any arguments
--> $DIR/does_not_acccept_args.rs:16:1
|
LL | #[diagnostic::do_not_recommend(not_accepted = "foo")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: `#[diagnostic::do_not_recommend]` does not expect any arguments
--> $DIR/does_not_acccept_args.rs:20:1
|
LL | #[diagnostic::do_not_recommend(not_accepted(42))]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: 3 warnings emitted

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
warning: `#[diagnostic::do_not_recommend]` does not expect any arguments
--> $DIR/does_not_acccept_args.rs:12:1
|
LL | #[diagnostic::do_not_recommend(not_accepted)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default

warning: `#[diagnostic::do_not_recommend]` does not expect any arguments
--> $DIR/does_not_acccept_args.rs:16:1
|
LL | #[diagnostic::do_not_recommend(not_accepted = "foo")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: `#[diagnostic::do_not_recommend]` does not expect any arguments
--> $DIR/does_not_acccept_args.rs:20:1
|
LL | #[diagnostic::do_not_recommend(not_accepted(42))]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: 3 warnings emitted

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//@ check-pass
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver

#![feature(do_not_recommend)]

trait Foo {}
trait Bar {}
trait Baz {}

#[diagnostic::do_not_recommend(not_accepted)]
//~^ WARNING `#[diagnostic::do_not_recommend]` does not expect any arguments
impl<T> Foo for T where T: Send {}

#[diagnostic::do_not_recommend(not_accepted = "foo")]
//~^ WARNING `#[diagnostic::do_not_recommend]` does not expect any arguments
impl<T> Bar for T where T: Send {}

#[diagnostic::do_not_recommend(not_accepted(42))]
//~^ WARNING `#[diagnostic::do_not_recommend]` does not expect any arguments
impl<T> Baz for T where T: Send {}

fn main() {}