-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Fixed #17823 #30937
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
Fixed #17823 #30937
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 |
---|---|---|
|
@@ -479,20 +479,38 @@ impl<'a, 'tcx> ErrorReporting<'tcx> for InferCtxt<'a, 'tcx> { | |
trace: TypeTrace<'tcx>, | ||
terr: &TypeError<'tcx>) | ||
-> DiagnosticBuilder<'tcx> { | ||
fn is_simple_type<'tcx>(ty: Ty<'tcx>) -> bool { | ||
use middle::ty::TypeVariants::*; | ||
match ty.sty { | ||
TyBool | TyChar | TyInt(_) | TyUint(_) | TyFloat(_) => true, | ||
_ => false, | ||
} | ||
} | ||
|
||
let expected_found_str = match self.values_str(&trace.values) { | ||
Some(v) => v, | ||
None => { | ||
return self.tcx.sess.diagnostic().struct_dummy(); /* derived error */ | ||
} | ||
}; | ||
|
||
let is_simple_error = if let &TypeError::Sorts(ref values) = terr { | ||
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 only make simple errors for TypeError::Sorts? Do other kinds of error never give the repetitive pattern? 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 don't understand what TypeError::Sorts for. Maybe other kinds also give the repetitive pattern, I will see. 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. How can I check for TypeError::IntMismatch? 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. Only TypeError::Sorts has repetitive error. |
||
is_simple_type(values.expected) && is_simple_type(values.found) | ||
} else { | ||
false | ||
}; | ||
let err = if is_simple_error { | ||
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. rename err to expected_found_str |
||
expected_found_str | ||
} else { | ||
format!("{} ({})", expected_found_str, terr) | ||
}; | ||
|
||
let mut err = struct_span_err!(self.tcx.sess, | ||
trace.origin.span(), | ||
E0308, | ||
"{}: {} ({})", | ||
"{}: {}", | ||
trace.origin, | ||
expected_found_str, | ||
terr); | ||
err); | ||
|
||
self.check_and_note_conflicting_crates(&mut err, terr, trace.origin.span()); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,4 @@ fn main() { | |
//~^ ERROR mismatched types | ||
//~| expected `char` | ||
//~| found `u8` | ||
//~| expected char | ||
//~| found u8 | ||
} |
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 should be a method on
TyS
rather than a function here -is_primitive
maybe