Repository navigation
Skip long type files for expected lints #166357
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
base: main
Are you sure you want to change the base?
Changes from all commits
34c8707
e639c86
f620a00
0947103
a81ef9d
55d0876
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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<PathBuf>) -> bool { | ||
| path.as_ref().is_some_and(|p| p.as_os_str().is_empty()) | ||
| } | ||
|
|
||
| impl DiagInner { | ||
| #[track_caller] | ||
| pub fn new<M: Into<DiagMessage>>(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 { .. }))) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit confused about why this works. From what I'm seeing,
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wowow didn't thought about it !!!!!
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a later step overwrites the field unconditionally, the marker is lost and the fix does nothing
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well on the other hand the test seems to pass, so apparently it does something
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually could we make this a custom enum rather than an option? I think that's clearer
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I agree a enum with none, suppresed and some(PathBuf) states the intent directl & its removes the empty path trick and makes it hard to forget the suppresed case here cost is that every place that uses the field need updting hmhmhm
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. but the q is i have to changes it one many file like 40+ The trait IntoDiagArg has a method that takes &mut option PathBuf ,it is declared in rustc_error_messages.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this enum get me more edits... ???????
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could u please suggest me what to doooo plsss |
||
| .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() | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the file called
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the name is misleding , the file tests expected lints, so it should be renamed to something like expected.rs If it is meant for allowed lints, the lint lvl in it should be allllow...... |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #![warn(improper_ctypes_definitions)] | ||
|
|
||
| extern "C" fn foo(_: Option<Option<Option<Option<Option<Option<Option<Option<i32>>>>>>>>) {} | ||
|
|
||
| fn main() {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #![expect(improper_ctypes_definitions, dead_code)] | ||
|
|
||
| extern "C" fn foo(_: Option<Option<Option<Option<Option<Option<Option<Option<i32>>>>>>>>) {} | ||
|
|
||
| fn main() {} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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"); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we also test what the behaviour for allowed lints is?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be a
constrather than a functionView changes since the review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes,PathBuf::new() is const so a const can replace the func compare with the existing code before changing it,a const PathBuf can't be used directly in a match but it can still be cloned = or compared!!