-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Rework "long type names" printing logic #136328
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ use std::hash::{Hash, Hasher}; | |
use std::marker::PhantomData; | ||
use std::ops::{Deref, DerefMut}; | ||
use std::panic; | ||
use std::path::PathBuf; | ||
use std::thread::panicking; | ||
|
||
use rustc_data_structures::fx::FxIndexMap; | ||
|
@@ -301,6 +302,7 @@ pub struct DiagInner { | |
|
||
pub is_lint: Option<IsLint>, | ||
|
||
pub long_ty_path: Option<PathBuf>, | ||
/// With `-Ztrack_diagnostics` enabled, | ||
/// we print where in rustc this error was emitted. | ||
pub(crate) emitted_at: DiagLocation, | ||
|
@@ -324,6 +326,7 @@ impl DiagInner { | |
args: Default::default(), | ||
sort_span: DUMMY_SP, | ||
is_lint: None, | ||
long_ty_path: None, | ||
emitted_at: DiagLocation::caller(), | ||
} | ||
} | ||
|
@@ -1293,9 +1296,20 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { | |
/// `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 { | ||
self.note(format!( | ||
"the full name for the type has been written to '{}'", | ||
path.display() | ||
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. Question: not necessarily for this PR, but this doesn't handle path-remapping ( |
||
)); | ||
self.note("consider using `--verbose` to print the full type name to the console"); | ||
} | ||
Box::into_inner(self.diag.take().unwrap()) | ||
} | ||
Comment on lines
1298
to
1307
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. Now there's no chance of forgetting to print this path (although we need to remember to use 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. Suggestion: could you add that remark as a doc comment for |
||
|
||
pub fn long_ty_path(&mut self) -> &mut Option<PathBuf> { | ||
&mut self.long_ty_path | ||
} | ||
|
||
/// Most `emit_producing_guarantee` functions use this as a starting point. | ||
fn emit_producing_nothing(mut self) { | ||
let diag = self.take_diag(); | ||
|
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 is an example of the intended way of using this. This is the safest way of creating a short string because there's no way of forgetting to print the "full name written to
path
" message.