-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Tweak E0277 highlighting and "long type" path printing #132086
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
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 |
---|---|---|
|
@@ -1835,23 +1835,32 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | |
if impl_trait_ref.references_error() { | ||
return false; | ||
} | ||
let self_ty = impl_trait_ref.self_ty().to_string(); | ||
err.highlighted_help(vec![ | ||
StringPart::normal(format!( | ||
"the trait `{}` ", | ||
impl_trait_ref.print_trait_sugared() | ||
)), | ||
StringPart::highlighted("is"), | ||
StringPart::normal(" implemented for `"), | ||
StringPart::highlighted(impl_trait_ref.self_ty().to_string()), | ||
if let [TypeError::Sorts(_)] = &terrs[..] { | ||
StringPart::normal(self_ty) | ||
} else { | ||
StringPart::highlighted(self_ty) | ||
}, | ||
StringPart::normal("`"), | ||
]); | ||
|
||
if let [TypeError::Sorts(exp_found)] = &terrs[..] { | ||
let exp_found = self.resolve_vars_if_possible(*exp_found); | ||
err.help(format!( | ||
"for that trait implementation, expected `{}`, found `{}`", | ||
exp_found.expected, exp_found.found | ||
)); | ||
err.highlighted_help(vec![ | ||
StringPart::normal("for that trait implementation, "), | ||
StringPart::normal("expected `"), | ||
StringPart::highlighted(exp_found.expected.to_string()), | ||
StringPart::normal("`, found `"), | ||
StringPart::highlighted(exp_found.found.to_string()), | ||
StringPart::normal("`"), | ||
]); | ||
} | ||
|
||
true | ||
|
@@ -2160,6 +2169,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | |
// First, attempt to add note to this error with an async-await-specific | ||
// message, and fall back to regular note otherwise. | ||
if !self.maybe_note_obligation_cause_for_async_await(err, obligation) { | ||
let mut long_ty_file = None; | ||
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 [PATH-PREFIX 1/2]: does it make sense to pull 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. @jieyouxu it would. We need to pull 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. Ah, I see I've ran into this exact problem before in #121739 (comment) EDIT: posted this on the wrong review comment chain. |
||
self.note_obligation_cause_code( | ||
obligation.cause.body_id, | ||
err, | ||
|
@@ -2168,7 +2178,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | |
obligation.cause.code(), | ||
&mut vec![], | ||
&mut Default::default(), | ||
&mut long_ty_file, | ||
); | ||
if let Some(file) = long_ty_file { | ||
err.note(format!( | ||
"the full name for the type has been written to '{}'", | ||
file.display(), | ||
)); | ||
err.note("consider using `--verbose` to print the full type name to the console"); | ||
} | ||
self.suggest_unsized_bound_if_applicable(err, obligation); | ||
if let Some(span) = err.span.primary_span() | ||
&& let Some(mut diag) = | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -305,6 +305,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | |
if let ObligationCauseCode::WhereClause(..) | ||
| ObligationCauseCode::WhereClauseInExpr(..) = code | ||
{ | ||
let mut long_ty_file = None; | ||
self.note_obligation_cause_code( | ||
error.obligation.cause.body_id, | ||
&mut diag, | ||
|
@@ -313,7 +314,17 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { | |
code, | ||
&mut vec![], | ||
&mut Default::default(), | ||
&mut long_ty_file, | ||
); | ||
if let Some(file) = long_ty_file { | ||
diag.note(format!( | ||
"the full name for the type has been written to '{}'", | ||
file.display(), | ||
Comment on lines
+321
to
+322
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. Discussion [PATH-PREFIX 2/2]: I believe this is one of the places where we will leak the path prefix even with To be clear, I'm not saying this should be done in this PR, just as a remark that this can be a potential issue. 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. That's a good point. We should have a single method for printing the long type paths |
||
)); | ||
diag.note( | ||
"consider using `--verbose` to print the full type name to the console", | ||
); | ||
} | ||
} | ||
diag.emit() | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//@ only-linux | ||
//@ compile-flags: --error-format=human --color=always | ||
//@ error-pattern: the trait bound | ||
|
||
trait Foo<T>: Bar<T> {} | ||
|
||
trait Bar<T> {} | ||
|
||
struct Struct; | ||
|
||
impl<T, K> Foo<K> for T where T: Bar<K> | ||
{} | ||
|
||
impl<'a> Bar<()> for Struct {} | ||
|
||
fn foo() -> impl Foo<i32> { | ||
Struct | ||
} | ||
|
||
fn main() {} |
Uh oh!
There was an error while loading. Please reload this page.