Skip to content

Conversation

@ShigrafS
Copy link

Closes: #9

Description

This PR introduces a new lint pr_missing_newline that detects pr_* logging macro calls without a trailing "\n". Proper newline termination in kernel-style logging is essential to prevent concatenated or malformed log output.

Key goals achieved:

  • Added an early lint that checks pr_* macros (excluding pr_cont) for missing trailing newlines.
  • Integrated the lint into klint so it runs alongside existing lints.
  • Included UI tests covering valid and invalid cases, including formatted pr_* calls.
  • Fixed build/test issues encountered while adding the lint (duplicate crate attributes and rustc-internal warnings).

Acceptance Criteria Fulfillment

  • Implemented PrMissingNewline lint and registered it as an early lint in klint.
  • Lint triggers warnings for all pr_* calls without trailing "\n", except pr_cont.
  • Added a UI test in tests/ui/pr_missing_newline.rs validating proper detection.
  • Verified that the build succeeds and all other tests pass after lint integration.

Changes Summary

  • New Lint: pr_missing_newline implemented in src/hir_lints/pr_missing_newline.rs.

  • Lint Registration: Registered in src/main.rs under early lints.

  • Tests: Added tests/ui/pr_missing_newline.rs covering:

    • Calls with missing newline → triggers warning
    • Calls with trailing newline → no warning
    • pr_cont calls → exempt
  • Build/Test Fixes:

    • Removed duplicate crate attributes in validation tests
    • Suppressed compiler warnings in src/main.rs and other modules
  • Minor Dependency Updates: Updated Cargo.toml/Cargo.lock as needed for build/test stability.


Limitations (Experimental Phase)

  • Only checks the first string literal of the macro; complex dynamic formatting might not be fully validated.
  • Assumes typical pr_* usage patterns; unusual token streams could bypass detection.
  • Excludes pr_cont as per kernel logging conventions.

How to Test

  1. Run all tests to ensure nothing breaks:

    cargo test
  2. Check the UI test specifically:

    cargo test --test compile-test
  3. Add a pr_* macro without a trailing newline in any Rust file, and confirm that klint warns appropriately.


Remove manual 'register_tool(klint)' attributes as they are already injected by the test harness, preventing 'already registered' errors during test execution.
- Allow 
ustc::implicit_sysroot_crate_import in src/main.rs to support 	racing, itertools, and 	hiserror from sysroot.
- Allow 
ustc::potential_query_instability in src/infallible_allocation.rs and src/monomorphize_collector.rs for deterministic iteration order issues.
@ShigrafS ShigrafS marked this pull request as ready for review January 31, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Warn on pr_* calls without trailing "\n"

1 participant