From 34c87072e967d82ec1d2c02aa979f1c00422a681 Mon Sep 17 00:00:00 2001 From: LusterSourav <282348889+LusterSourav@users.noreply.github.com> Date: Sun, 22 Nov 2026 20:39:15 +0530 Subject: [PATCH 01/10] Mark expected lint diagnostics so they skip long type files --- compiler/rustc_errors/src/diagnostic.rs | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 6d60b031dd7c6..f829b97bfbd26 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -18,9 +18,9 @@ use tracing::debug; use crate::dedup_hash::DedupHashEncoder; use crate::{ - CodeSuggestion, DiagCtxtHandle, DiagMessage, ErrCode, ErrorGuaranteed, ExplicitBug, Level, - MultiSpan, StashKey, Style, Sublevel, Substitution, SubstitutionPart, SuggestionStyle, - Suggestions, + CodeSuggestion, DiagCtxtHandle, DiagMessage, EmissionOverride, ErrCode, ErrorGuaranteed, + ExplicitBug, Level, MultiSpan, StashKey, Style, Sublevel, Substitution, SubstitutionPart, + SuggestionStyle, Suggestions, }; /// Trait implemented by error types. This is rarely implemented manually. Instead, use @@ -203,6 +203,15 @@ pub struct DiagInner { pub emitted_at: DiagLocation, } +/// Marker stored in `long_ty_path` for diagnostics that are never shown. Real paths are never empty. +pub fn suppressed_long_ty_path() -> PathBuf { + PathBuf::new() +} + +pub fn is_long_ty_path_suppressed(path: &Option) -> bool { + path.as_ref().is_some_and(|p| p.as_os_str().is_empty()) +} + impl DiagInner { #[track_caller] pub fn new>(level: Level, message: M) -> Self { @@ -220,7 +229,9 @@ impl DiagInner { suggestions: Suggestions::Enabled(vec![]), args: Default::default(), is_lint: None, - long_ty_path: None, + // Expected lints are never shown, so they must not write long type files. + long_ty_path: matches!(level, Level::Warning(Some(EmissionOverride::Expected { .. }))) + .then(suppressed_long_ty_path), emitted_at: DiagLocation::caller(), } } @@ -1139,7 +1150,9 @@ impl<'a> Diag<'a> { /// `cancel`, etc. Afterwards, `drop` is the only code that will be run on /// `self`. fn take_diag(&mut self) -> DiagInner { - if let Some(path) = &self.long_ty_path { + if let Some(path) = &self.long_ty_path + && !is_long_ty_path_suppressed(&self.long_ty_path) + { self.note(format!( "the full name for the type has been written to '{}'", path.display() From e639c86dbffed842c57dba133e940247d04b55e4 Mon Sep 17 00:00:00 2001 From: LusterSourav <282348889+LusterSourav@users.noreply.github.com> Date: Sun, 22 Nov 2026 20:39:21 +0530 Subject: [PATCH 02/10] Export long type path marker helpers --- compiler/rustc_errors/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index fb6e1d43a4375..ab2caeb8e4dd4 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -33,7 +33,7 @@ pub use codes::*; pub use decorate_diag::{BufferedEarlyLint, DecorateDiagCompat, LintBuffer}; pub use diagnostic::{ Diag, DiagDecorator, DiagInner, DiagLocation, DiagStyledString, Diagnostic, StringPart, - Subdiag, Subdiagnostic, + Subdiag, Subdiagnostic, is_long_ty_path_suppressed, suppressed_long_ty_path, }; pub use diagnostic_impls::{ DiagSymbolList, ElidedLifetimeInPathSubdiag, ExpectedLifetimeParameter, From f620a00e7434037f6599c2761d4d21bcfc30f9f6 Mon Sep 17 00:00:00 2001 From: LusterSourav <282348889+LusterSourav@users.noreply.github.com> Date: Sun, 22 Nov 2026 20:39:24 +0530 Subject: [PATCH 03/10] Skip long type file write for expected lints --- compiler/rustc_middle/src/ty/error.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/ty/error.rs b/compiler/rustc_middle/src/ty/error.rs index 989ed3aa2ad88..a44798d596e15 100644 --- a/compiler/rustc_middle/src/ty/error.rs +++ b/compiler/rustc_middle/src/ty/error.rs @@ -4,7 +4,7 @@ use std::hash::{DefaultHasher, Hash, Hasher}; use std::io::{Read, Write}; use std::path::PathBuf; -use rustc_errors::pluralize; +use rustc_errors::{is_long_ty_path_suppressed, pluralize}; use rustc_hir as hir; use rustc_hir::def::{CtorOf, DefKind}; use rustc_macros::extension; @@ -302,6 +302,9 @@ impl<'tcx> TyCtxt<'tcx> { if regular == short { return regular; } + if is_long_ty_path_suppressed(path) { + return short; + } // Ensure we create an unique file for the type passed in when we create a file. let mut s = DefaultHasher::new(); t.hash(&mut s); From 0947103f73a64d73a3039bbd82b23145f4ad7e43 Mon Sep 17 00:00:00 2001 From: LusterSourav <282348889+LusterSourav@users.noreply.github.com> Date: Sun, 22 Nov 2026 20:39:28 +0530 Subject: [PATCH 04/10] Add test input with expected lint --- tests/run-make/expect-lint-no-long-type-file/lint.rs | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tests/run-make/expect-lint-no-long-type-file/lint.rs diff --git a/tests/run-make/expect-lint-no-long-type-file/lint.rs b/tests/run-make/expect-lint-no-long-type-file/lint.rs new file mode 100644 index 0000000000000..395662948b511 --- /dev/null +++ b/tests/run-make/expect-lint-no-long-type-file/lint.rs @@ -0,0 +1,5 @@ +#![expect(improper_ctypes_definitions, dead_code)] + +extern "C" fn foo(_: Option>>>>>>>) {} + +fn main() {} From a81ef9df705a8a3c0538751d7c58b6f05262b214 Mon Sep 17 00:00:00 2001 From: LusterSourav <282348889+LusterSourav@users.noreply.github.com> Date: Sun, 22 Nov 2026 20:39:31 +0530 Subject: [PATCH 05/10] Add test input with shown lint --- tests/run-make/expect-lint-no-long-type-file/allowed.rs | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tests/run-make/expect-lint-no-long-type-file/allowed.rs diff --git a/tests/run-make/expect-lint-no-long-type-file/allowed.rs b/tests/run-make/expect-lint-no-long-type-file/allowed.rs new file mode 100644 index 0000000000000..5b620901d8732 --- /dev/null +++ b/tests/run-make/expect-lint-no-long-type-file/allowed.rs @@ -0,0 +1,5 @@ +#![warn(improper_ctypes_definitions)] + +extern "C" fn foo(_: Option>>>>>>>) {} + +fn main() {} From 55d08769475d2f1080985fb64591682826c3f096 Mon Sep 17 00:00:00 2001 From: LusterSourav <282348889+LusterSourav@users.noreply.github.com> Date: Sun, 22 Nov 2026 20:39:35 +0530 Subject: [PATCH 06/10] Add run make test for expect long type files --- .../expect-lint-no-long-type-file/rmake.rs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/run-make/expect-lint-no-long-type-file/rmake.rs diff --git a/tests/run-make/expect-lint-no-long-type-file/rmake.rs b/tests/run-make/expect-lint-no-long-type-file/rmake.rs new file mode 100644 index 0000000000000..48877e2cb9179 --- /dev/null +++ b/tests/run-make/expect-lint-no-long-type-file/rmake.rs @@ -0,0 +1,30 @@ +// Regression test for https://github.com/rust-lang/rust/issues/166293. +// An expected lint is never shown, so it must not write a long type file to disk. +// A lint that is shown still must write one, which guards against a vacuous pass. + +use run_make_support::{rfs, rustc}; + +fn long_type_files() -> usize { + rfs::read_dir(".") + .filter_map(|entry| entry.ok()) + .filter(|entry| entry.file_name().to_string_lossy().contains("long-type")) + .count() +} + +fn main() { + rustc() + .input("lint.rs") + .edition("2024") + .arg("-Zwrite-long-types-to-disk=yes") + .arg("--diagnostic-width=60") + .run(); + assert_eq!(long_type_files(), 0, "expected lint created a long type file"); + + rustc() + .input("allowed.rs") + .edition("2024") + .arg("-Zwrite-long-types-to-disk=yes") + .arg("--diagnostic-width=60") + .run(); + assert_eq!(long_type_files(), 1, "shown lint should create a long type file"); +} From c45c7a3b310e92c670a226fd4da110d0666d2c42 Mon Sep 17 00:00:00 2001 From: LusterSourav <282348889+LusterSourav@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:04:24 +0530 Subject: [PATCH 07/10] Fix: suppress long-type file for expected lints --- compiler/rustc_errors/src/diagnostic.rs | 6 ++---- compiler/rustc_errors/src/lib.rs | 4 ++-- .../expect-lint-no-long-type-file/{lint.rs => expected.rs} | 0 .../expect-lint-no-long-type-file/{allowed.rs => shown.rs} | 0 4 files changed, 4 insertions(+), 6 deletions(-) rename tests/run-make/expect-lint-no-long-type-file/{lint.rs => expected.rs} (100%) rename tests/run-make/expect-lint-no-long-type-file/{allowed.rs => shown.rs} (100%) diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index f829b97bfbd26..84a82fdbae153 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -204,9 +204,7 @@ pub struct DiagInner { } /// Marker stored in `long_ty_path` for diagnostics that are never shown. Real paths are never empty. -pub fn suppressed_long_ty_path() -> PathBuf { - PathBuf::new() -} +pub const SUPPRESSED_LONG_TY_PATH: PathBuf = PathBuf::new(); pub fn is_long_ty_path_suppressed(path: &Option) -> bool { path.as_ref().is_some_and(|p| p.as_os_str().is_empty()) @@ -231,7 +229,7 @@ impl DiagInner { is_lint: None, // Expected lints are never shown, so they must not write long type files. long_ty_path: matches!(level, Level::Warning(Some(EmissionOverride::Expected { .. }))) - .then(suppressed_long_ty_path), + .then_some(SUPPRESSED_LONG_TY_PATH), emitted_at: DiagLocation::caller(), } } diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index ab2caeb8e4dd4..a04380bbb820f 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -32,8 +32,8 @@ pub use anstyle::{ pub use codes::*; pub use decorate_diag::{BufferedEarlyLint, DecorateDiagCompat, LintBuffer}; pub use diagnostic::{ - Diag, DiagDecorator, DiagInner, DiagLocation, DiagStyledString, Diagnostic, StringPart, - Subdiag, Subdiagnostic, is_long_ty_path_suppressed, suppressed_long_ty_path, + Diag, DiagDecorator, DiagInner, DiagLocation, DiagStyledString, Diagnostic, + SUPPRESSED_LONG_TY_PATH, StringPart, Subdiag, Subdiagnostic, is_long_ty_path_suppressed, }; pub use diagnostic_impls::{ DiagSymbolList, ElidedLifetimeInPathSubdiag, ExpectedLifetimeParameter, diff --git a/tests/run-make/expect-lint-no-long-type-file/lint.rs b/tests/run-make/expect-lint-no-long-type-file/expected.rs similarity index 100% rename from tests/run-make/expect-lint-no-long-type-file/lint.rs rename to tests/run-make/expect-lint-no-long-type-file/expected.rs diff --git a/tests/run-make/expect-lint-no-long-type-file/allowed.rs b/tests/run-make/expect-lint-no-long-type-file/shown.rs similarity index 100% rename from tests/run-make/expect-lint-no-long-type-file/allowed.rs rename to tests/run-make/expect-lint-no-long-type-file/shown.rs From aeaf42de4ae3d85b988b1c2a468cd94509a73041 Mon Sep 17 00:00:00 2001 From: LusterSourav <282348889+LusterSourav@users.noreply.github.com> Date: Tue, 24 Nov 2026 18:04:55 +0530 Subject: [PATCH 08/10] Test: add test for expected/allowed lints not writing long-type files --- .../expect-lint-no-long-type-file/rmake.rs | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/tests/run-make/expect-lint-no-long-type-file/rmake.rs b/tests/run-make/expect-lint-no-long-type-file/rmake.rs index 48877e2cb9179..c5c05356f87b2 100644 --- a/tests/run-make/expect-lint-no-long-type-file/rmake.rs +++ b/tests/run-make/expect-lint-no-long-type-file/rmake.rs @@ -1,30 +1,43 @@ // Regression test for https://github.com/rust-lang/rust/issues/166293. -// An expected lint is never shown, so it must not write a long type file to disk. +// Expected and allowed lints are never shown, so they must not write a long type file to disk. // A lint that is shown still must write one, which guards against a vacuous pass. use run_make_support::{rfs, rustc}; -fn long_type_files() -> usize { - rfs::read_dir(".") - .filter_map(|entry| entry.ok()) - .filter(|entry| entry.file_name().to_string_lossy().contains("long-type")) - .count() -} - -fn main() { +/// Compiles `input` and returns the long type files it created, removing them afterwards so +/// that every case is counted independently. +fn compile_and_count_long_type_files(input: &str) -> usize { rustc() - .input("lint.rs") + .input(input) .edition("2024") .arg("-Zwrite-long-types-to-disk=yes") .arg("--diagnostic-width=60") .run(); - assert_eq!(long_type_files(), 0, "expected lint created a long type file"); - rustc() - .input("allowed.rs") - .edition("2024") - .arg("-Zwrite-long-types-to-disk=yes") - .arg("--diagnostic-width=60") - .run(); - assert_eq!(long_type_files(), 1, "shown lint should create a long type file"); + let files: Vec<_> = rfs::read_dir(".") + .filter_map(|entry| entry.ok()) + .filter(|entry| entry.file_name().to_string_lossy().contains("long-type")) + .collect(); + for file in &files { + rfs::remove_file(file.path()); + } + files.len() +} + +fn main() { + assert_eq!( + compile_and_count_long_type_files("expected.rs"), + 0, + "expected lint created a long type file" + ); + assert_eq!( + compile_and_count_long_type_files("allowed.rs"), + 0, + "allowed lint created a long type file" + ); + assert_eq!( + compile_and_count_long_type_files("shown.rs"), + 1, + "shown lint should create a long type file" + ); } From b95e366956310b79277d98bd23e91aac23ef59bd Mon Sep 17 00:00:00 2001 From: LusterSourav <282348889+LusterSourav@users.noreply.github.com> Date: Tue, 24 Nov 2026 20:46:17 +0530 Subject: [PATCH 09/10] Restore allowed.rs test file --- tests/run-make/expect-lint-no-long-type-file/allowed.rs | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 tests/run-make/expect-lint-no-long-type-file/allowed.rs diff --git a/tests/run-make/expect-lint-no-long-type-file/allowed.rs b/tests/run-make/expect-lint-no-long-type-file/allowed.rs new file mode 100644 index 0000000000000..1e66b9b51a355 --- /dev/null +++ b/tests/run-make/expect-lint-no-long-type-file/allowed.rs @@ -0,0 +1,5 @@ +#![allow(improper_ctypes_definitions)] + +extern "C" fn foo(_: Option>>>>>>>) {} + +fn main() {} \ No newline at end of file From d0d48c094e62f4098c3e81115368c5e8701de87b Mon Sep 17 00:00:00 2001 From: LusterSourav <282348889+LusterSourav@users.noreply.github.com> Date: Tue, 24 Nov 2026 22:40:15 +0530 Subject: [PATCH 10/10] Fix trailing newline in allowed.rs --- tests/run-make/expect-lint-no-long-type-file/allowed.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/run-make/expect-lint-no-long-type-file/allowed.rs b/tests/run-make/expect-lint-no-long-type-file/allowed.rs index 1e66b9b51a355..e781a2c5c6817 100644 --- a/tests/run-make/expect-lint-no-long-type-file/allowed.rs +++ b/tests/run-make/expect-lint-no-long-type-file/allowed.rs @@ -2,4 +2,4 @@ extern "C" fn foo(_: Option>>>>>>>) {} -fn main() {} \ No newline at end of file +fn main() {}