Skip to content

Conversation

@Pasta-coder
Copy link
Contributor

The lint attributes (allow, deny, warn, forbid) require arguments specifying which lints to affect. Using them without arguments (e.g. #[allow]) is invalid. This patch adds validation to reject empty lint attributes.

Fixes #4225

gcc/rust/ChangeLog:

* util/rust-attributes.cc: Check for empty lint attributes.

gcc/testsuite/ChangeLog:

* rust/compile/allow-malformed.rs: New test.

@Pasta-coder Pasta-coder force-pushed the fix/allow-malformed-4225 branch from e2442c7 to a047314 Compare January 5, 2026 08:04
@Pasta-coder Pasta-coder marked this pull request as draft January 6, 2026 13:26
@Pasta-coder
Copy link
Contributor Author

drafted to resolve merge conflicts

Pasta-coder added a commit to Pasta-coder/gccrs that referenced this pull request Jan 16, 2026
Emit a diagnostic when lint attributes (allow, deny, warn, forbid) are
used without arguments. Previously, these attributes were accepted silently
if malformed, which could lead to confusion or ignored lints. This ensures
users are informed of the expected form: #[allow(lint_name)].

Fixes Rust-GCC#4358

gcc/rust/ChangeLog:

	* util/rust-attributes.cc (check_lint_attribute): New helper.
	(AttributeChecker::visit): Call helper for lint attributes on functions.

gcc/testsuite/ChangeLog:

	* rust/compile/allow-malformed.rs: New test.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix/allow-malformed-4225 branch from a047314 to f262c54 Compare January 16, 2026 16:58
@Pasta-coder Pasta-coder marked this pull request as ready for review January 16, 2026 16:58
Pasta-coder added a commit to Pasta-coder/gccrs that referenced this pull request Jan 16, 2026
Emit a diagnostic when lint attributes (allow, deny, warn, forbid) are
used without arguments. Previously, these attributes were accepted silently
if malformed, which could lead to confusion or ignored lints. This ensures
users are informed of the expected form: #[allow(lint_name)].

Fixes Rust-GCC#4358

gcc/rust/ChangeLog:

	* util/rust-attributes.cc (check_lint_attribute): New helper.
	(AttributeChecker::visit): Call helper for lint attributes on functions.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-4225.rs: New test.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix/allow-malformed-4225 branch from f262c54 to c84343e Compare January 16, 2026 17:06
Emit a diagnostic when lint attributes (allow, deny, warn, forbid) are
used without arguments. Previously, these attributes were accepted silently
if malformed, which could lead to confusion or ignored lints. This ensures
users are informed of the expected form: #[allow(lint_name)].

Fixes Rust-GCC#4358

gcc/rust/ChangeLog:

	* util/rust-attributes.cc (check_lint_attribute): New helper.
	(AttributeChecker::visit): Call helper for lint attributes on functions.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-4225.rs: New test.

Signed-off-by: Jayant Chauhan <[email protected]>
@Pasta-coder Pasta-coder force-pushed the fix/allow-malformed-4225 branch from c84343e to 4278810 Compare January 16, 2026 17:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

malformed allow attribute should give error

1 participant