Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
faa7966
fix #[expect(dead_code)] liveness propagation
mu001999 Mar 25, 2026
821d9b2
tests: add whitespace tests for vertical tab behavior
Brace1000 Apr 9, 2026
1609baf
tests: add ignore-tidy-tab directive to whitespace tests
Brace1000 Apr 9, 2026
7c00dc2
tests: expand vertical tab lexer test to cover all Pattern_White_Spac…
Brace1000 Apr 11, 2026
1546b1d
tests: add whitespace/ README entry explaining lexer vs stdlib mismatch
Brace1000 Apr 11, 2026
5b487fc
Update ascii_whitespace_excludes_vertical_tab.rs
Brace1000 Apr 9, 2026
91fd464
Update ascii_whitespace_excludes_vertical_tab.rs
Brace1000 Apr 9, 2026
874a618
Update ascii_whitespace_excludes_vertical_tab.rs
Brace1000 Apr 9, 2026
b727680
fix tidy: add whitespace README entry
Brace1000 Apr 9, 2026
52f1d1e
Update README.md with missing full stop
Brace1000 Apr 9, 2026
c5aea24
Update ascii_whitespace_excludes_vertical_tab.rs
Brace1000 Apr 9, 2026
f219e91
fix tidy: use full path format for whitespace README entry
Brace1000 Apr 11, 2026
87fcb28
fix tidy: README order, trailing newlines in whitespace tests
Brace1000 Apr 11, 2026
47fb045
fix: add run-pass directive and restore embedded whitespace bytes
Brace1000 Apr 11, 2026
f06914b
fix tidy: remove duplicate whitespace README entry
Brace1000 Apr 11, 2026
7027a64
Brace1000 Apr 14, 2026
4d8a428
git add tests/ui/whitespace/invalid_whitespace.rs
Brace1000 Apr 14, 2026
93b13d3
Fix tidy: add trailing newline
Brace1000 Apr 14, 2026
7e47ea6
Update invalid_whitespace.rs
Brace1000 Apr 14, 2026
00a37bb
Update invalid_whitespace.rs
Brace1000 Apr 14, 2026
a2e128a
Clean up whitespace in invalid_whitespace.rs
Brace1000 Apr 14, 2026
233f744
Update invalid_whitespace.rs
Brace1000 Apr 14, 2026
b32995b
Clarify ZERO WIDTH SPACE usage in test
Brace1000 Apr 14, 2026
ead2b71
Improve error messages for invalid whitespace
Brace1000 Apr 14, 2026
d0bc9e4
Modify invalid_whitespace test for clarity
Brace1000 Apr 14, 2026
2f981ce
Resolve unknown token error in invalid_whitespace.rs
Brace1000 Apr 14, 2026
3d1ad29
Remove invisible character from variable assignment
Brace1000 Apr 14, 2026
2506ce4
Improve error message for invalid whitespace
Brace1000 Apr 14, 2026
f1eb5e7
Improve error handling for invisible characters
Brace1000 Apr 14, 2026
16b2655
Document error for unknown token due to whitespace
Brace1000 Apr 14, 2026
701bc97
Update error message for invalid whitespace handling
Brace1000 Apr 14, 2026
ece7316
Modify invalid_whitespace.rs for whitespace checks
Brace1000 Apr 14, 2026
a1eb231
Correct whitespace in variable declaration
Brace1000 Apr 14, 2026
6e459b9
Update error message for invalid whitespace
Brace1000 Apr 14, 2026
dc0d44a
Update invalid_whitespace.stderr
Brace1000 Apr 14, 2026
5661524
Refine error handling for invalid whitespace test
Brace1000 Apr 14, 2026
523f70a
Update invalid_whitespace.rs
Brace1000 Apr 14, 2026
1db9763
Fix whitespace issues in invalid_whitespace.rs
Brace1000 Apr 14, 2026
52225e6
Update invalid_whitespace.stderr file
Brace1000 Apr 15, 2026
185a582
Clean up whitespace in invalid_whitespace.rs
Brace1000 Apr 15, 2026
43f045c
Update invalid_whitespace.stderr
Brace1000 Apr 15, 2026
ae05a49
Fix wrong suggestion for returning async closure
chenyukang Jan 13, 2026
21cd762
Rewrite `FlatMapInPlace`.
nnethercote Apr 21, 2026
b1c7595
Ensure we don't feed owners from ast lowering if we ever make that qu…
oli-obk Apr 20, 2026
39f517f
Move diagnostic::on_const target check
mejrs Apr 20, 2026
5ba06cc
Always refer to non-const trait impls
mejrs Apr 20, 2026
26d2c30
Move diagnostic::on_move target check
mejrs Apr 20, 2026
59503ec
Move diagnostic::on_unimplemented target check
mejrs Apr 20, 2026
c62be6e
Move diagnostic::on_unknown target check
mejrs Apr 20, 2026
80fb0aa
Move diagnostic::do_not_recommend target checking
mejrs Apr 20, 2026
3990dda
say "implementation(s) in "not on trait impl" lints
mejrs Apr 20, 2026
a4c79fc
Rollup merge of #155028 - Brace1000:whitespace-tests, r=chenyukang
jhpratt Apr 21, 2026
4348c16
Rollup merge of #155582 - nnethercote:overhaul-flat_map_in_place, r=c…
jhpratt Apr 21, 2026
6e9a1c5
Rollup merge of #151194 - chenyukang:yukang-fix-150701-async-closure,…
jhpratt Apr 21, 2026
a46164f
Rollup merge of #154377 - mu001999-contrib:fix/dead-code, r=TaKO8Ki
jhpratt Apr 21, 2026
b6d4b38
Rollup merge of #155572 - mejrs:move_target_checks, r=JonathanBrouwer…
jhpratt Apr 21, 2026
d8aff48
Rollup merge of #155586 - oli-obk:assert-ignored-feed, r=petrochenkov
jhpratt Apr 21, 2026
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
Move diagnostic::on_unknown target check
  • Loading branch information
mejrs committed Apr 21, 2026
commit c62be6e99294b61d55a3dee1a879b72d1f2603f5
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use rustc_errors::Diagnostic;
use rustc_hir::attrs::diagnostic::Directive;
use rustc_session::lint::builtin::MISPLACED_DIAGNOSTIC_ATTRIBUTES;

use crate::ShouldEmit;
use crate::attributes::diagnostic::*;
use crate::attributes::prelude::*;
use crate::errors::DiagnosticOnUnknownOnlyForImports;

#[derive(Default)]
pub(crate) struct OnUnknownParser {
Expand All @@ -25,6 +29,22 @@ impl OnUnknownParser {
let span = cx.attr_span;
self.span = Some(span);

// At early parsing we get passed `Target::Crate` regardless of the item we're on.
// Only do target checking if we're late.
let early = matches!(cx.stage.should_emit(), ShouldEmit::Nothing);

if !early && !matches!(cx.target, Target::Use) {
let target_span = cx.target_span;
cx.emit_dyn_lint(
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
move |dcx, level| {
DiagnosticOnUnknownOnlyForImports { target_span }.into_diag(dcx, level)
},
span,
);
return;
}

let Some(items) = parse_list(cx, args, mode) else { return };

if let Some(directive) = parse_directive_items(cx, mode, items.mixed(), true) {
Expand All @@ -41,7 +61,7 @@ impl<S: Stage> AttributeParser<S> for OnUnknownParser {
this.parse(cx, args, Mode::DiagnosticOnUnknown);
},
)];
//FIXME attribute is not parsed for non-use statements but diagnostics are issued in `check_attr.rs`
// "Allowed" for all targets, but noop for all but use statements.
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);

fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_attr_parsing/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,10 @@ pub(crate) struct DiagnosticOnMoveOnlyForAdt;
#[derive(Diagnostic)]
#[diag("`#[diagnostic::on_unimplemented]` can only be applied to trait definitions")]
pub(crate) struct DiagnosticOnUnimplementedOnlyForTraits;

#[derive(Diagnostic)]
#[diag("`#[diagnostic::on_unknown]` can only be applied to `use` statements")]
pub(crate) struct DiagnosticOnUnknownOnlyForImports {
#[label("not an import")]
pub target_span: Span,
}
22 changes: 1 addition & 21 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,6 @@ struct DiagnosticOnConstOnlyForNonConstTraitImpls {
item_span: Span,
}

#[derive(Diagnostic)]
#[diag("`#[diagnostic::on_unknown]` can only be applied to `use` statements")]
struct DiagnosticOnUnknownOnlyForImports {
#[label("not an import")]
item_span: Span,
}

fn target_from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem<'_>) -> Target {
match impl_item.kind {
hir::ImplItemKind::Const(..) => Target::AssocConst,
Expand Down Expand Up @@ -208,7 +201,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
},
Attribute::Parsed(AttributeKind::DoNotRecommend{attr_span}) => {self.check_do_not_recommend(*attr_span, hir_id, target, item)},
Attribute::Parsed(AttributeKind::OnUnimplemented{directive,..}) => {self.check_diagnostic_on_unimplemented(hir_id, directive.as_deref())},
Attribute::Parsed(AttributeKind::OnUnknown { span, .. }) => { self.check_diagnostic_on_unknown(*span, hir_id, target) },
Attribute::Parsed(AttributeKind::OnConst{span, ..}) => {self.check_diagnostic_on_const(*span, hir_id, target, item)}
Attribute::Parsed(AttributeKind::OnMove { directive , .. }) => {
self.check_diagnostic_on_move(hir_id, directive.as_deref())
Expand Down Expand Up @@ -260,6 +252,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| AttributeKind::NoMain
| AttributeKind::NoMangle(..)
| AttributeKind::NoStd { .. }
| AttributeKind::OnUnknown { .. }
| AttributeKind::Optimize(..)
| AttributeKind::PanicRuntime
| AttributeKind::PatchableFunctionEntry { .. }
Expand Down Expand Up @@ -625,19 +618,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
}

/// Checks if `#[diagnostic::on_unknown]` is applied to a trait impl
fn check_diagnostic_on_unknown(&self, attr_span: Span, hir_id: HirId, target: Target) {
if !matches!(target, Target::Use) {
let item_span = self.tcx.hir_span(hir_id);
self.tcx.emit_node_span_lint(
MISPLACED_DIAGNOSTIC_ATTRIBUTES,
hir_id,
attr_span,
DiagnosticOnUnknownOnlyForImports { item_span },
);
}
}

/// Checks if an `#[inline]` is applied to a function or a closure.
fn check_inline(&self, hir_id: HirId, attr_span: Span, kind: &InlineAttr, target: Target) {
match target {
Expand Down
20 changes: 10 additions & 10 deletions tests/ui/diagnostic_namespace/on_unknown/incorrect-locations.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | #[diagnostic::on_unknown(message = "foo")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | extern crate std as other_std;
| ----------------------------- not an import
| ------------------------------ not an import
|
= note: `#[warn(misplaced_diagnostic_attributes)]` (part of `#[warn(unknown_or_malformed_diagnostic_attributes)]`) on by default

Expand All @@ -16,7 +16,7 @@ LL | #[diagnostic::on_unknown(message = "foo")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | const CONST: () = ();
| --------------- not an import
| --------------------- not an import

warning: `#[diagnostic::on_unknown]` can only be applied to `use` statements
--> $DIR/incorrect-locations.rs:13:1
Expand All @@ -25,7 +25,7 @@ LL | #[diagnostic::on_unknown(message = "foo")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | static STATIC: () = ();
| ----------------- not an import
| ----------------------- not an import

warning: `#[diagnostic::on_unknown]` can only be applied to `use` statements
--> $DIR/incorrect-locations.rs:17:1
Expand All @@ -34,7 +34,7 @@ LL | #[diagnostic::on_unknown(message = "foo")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | type Type = ();
| --------- not an import
| --------------- not an import

warning: `#[diagnostic::on_unknown]` can only be applied to `use` statements
--> $DIR/incorrect-locations.rs:21:1
Expand All @@ -43,7 +43,7 @@ LL | #[diagnostic::on_unknown(message = "foo")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | enum Enum {}
| --------- not an import
| ------------ not an import

warning: `#[diagnostic::on_unknown]` can only be applied to `use` statements
--> $DIR/incorrect-locations.rs:25:1
Expand All @@ -52,7 +52,7 @@ LL | #[diagnostic::on_unknown(message = "foo")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | impl Enum {}
| --------- not an import
| ------------ not an import

warning: `#[diagnostic::on_unknown]` can only be applied to `use` statements
--> $DIR/incorrect-locations.rs:29:1
Expand All @@ -70,7 +70,7 @@ LL | #[diagnostic::on_unknown(message = "foo")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | fn fun() {}
| -------- not an import
| ----------- not an import

warning: `#[diagnostic::on_unknown]` can only be applied to `use` statements
--> $DIR/incorrect-locations.rs:37:1
Expand All @@ -79,7 +79,7 @@ LL | #[diagnostic::on_unknown(message = "foo")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | struct Struct {}
| ------------- not an import
| ---------------- not an import

warning: `#[diagnostic::on_unknown]` can only be applied to `use` statements
--> $DIR/incorrect-locations.rs:41:1
Expand All @@ -88,7 +88,7 @@ LL | #[diagnostic::on_unknown(message = "foo")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | trait Trait {}
| ----------- not an import
| -------------- not an import

warning: `#[diagnostic::on_unknown]` can only be applied to `use` statements
--> $DIR/incorrect-locations.rs:45:1
Expand All @@ -97,7 +97,7 @@ LL | #[diagnostic::on_unknown(message = "foo")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | impl Trait for i32 {}
| ------------------ not an import
| --------------------- not an import

warning: 11 warnings emitted