Revert "Rollup merge of #122661 - estebank:assert-macro-span, r=petro… · rust-lang/rust@b38a86f (original) (raw)
`@@ -1618,18 +1618,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
`
1618
1618
`{
`
1619
1619
`let e = self.tcx.erase_and_anonymize_regions(e);
`
1620
1620
`let f = self.tcx.erase_and_anonymize_regions(f);
`
1621
``
`-
let mut expected = with_forced_trimmed_paths!(e.sort_string(self.tcx));
`
1622
``
`-
let mut found = with_forced_trimmed_paths!(f.sort_string(self.tcx));
`
1623
``
`-
if let ObligationCauseCode::Pattern { span, .. } = cause.code()
`
1624
``
`-
&& let Some(span) = span
`
1625
``
`-
&& !span.from_expansion()
`
1626
``
`-
&& cause.span.from_expansion()
`
1627
``
`-
{
`
1628
``
`` -
// When the type error comes from a macro like assert!(), and we are pointing at
``
1629
``
`-
// code the user wrote the cause and effect are reversed as the expected value is
`
1630
``
`-
// what the macro expanded to.
`
1631
``
`-
(found, expected) = (expected, found);
`
1632
``
`-
}
`
``
1621
`+
let expected = with_forced_trimmed_paths!(e.sort_string(self.tcx));
`
``
1622
`+
let found = with_forced_trimmed_paths!(f.sort_string(self.tcx));
`
1633
1623
`if expected == found {
`
1634
1624
`label_or_note(span, terr.to_string(self.tcx));
`
1635
1625
`} else {
`
`@@ -2152,9 +2142,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
`
2152
2142
`) -> Option<(DiagStyledString, DiagStyledString)> {
`
2153
2143
`match values {
`
2154
2144
`ValuePairs::Regions(exp_found) => self.expected_found_str(exp_found),
`
2155
``
`-
ValuePairs::Terms(exp_found) => {
`
2156
``
`-
self.expected_found_str_term(cause, exp_found, long_ty_path)
`
2157
``
`-
}
`
``
2145
`+
ValuePairs::Terms(exp_found) => self.expected_found_str_term(exp_found, long_ty_path),
`
2158
2146
`ValuePairs::Aliases(exp_found) => self.expected_found_str(exp_found),
`
2159
2147
`ValuePairs::ExistentialTraitRef(exp_found) => self.expected_found_str(exp_found),
`
2160
2148
`ValuePairs::ExistentialProjection(exp_found) => self.expected_found_str(exp_found),
`
`@@ -2193,35 +2181,15 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
`
2193
2181
``
2194
2182
`fn expected_found_str_term(
`
2195
2183
`&self,
`
2196
``
`-
cause: &ObligationCause<'tcx>,
`
2197
2184
`exp_found: ty::error::ExpectedFound<ty::Term<'tcx>>,
`
2198
2185
`long_ty_path: &mut Option,
`
2199
2186
`) -> Option<(DiagStyledString, DiagStyledString)> {
`
2200
2187
`let exp_found = self.resolve_vars_if_possible(exp_found);
`
2201
2188
`if exp_found.references_error() {
`
2202
2189
`return None;
`
2203
2190
`}
`
2204
``
`-
let (mut expected, mut found) = (exp_found.expected, exp_found.found);
`
2205
``
-
2206
``
`-
if let ObligationCauseCode::Pattern { span, .. } = cause.code()
`
2207
``
`-
&& let Some(span) = span
`
2208
``
`-
&& !span.from_expansion()
`
2209
``
`-
&& cause.span.from_expansion()
`
2210
``
`-
{
`
2211
``
`` -
// When the type error comes from a macro like assert!(), and we are pointing at
``
2212
``
`-
// code the user wrote, the cause and effect are reversed as the expected value is
`
2213
``
`` -
// what the macro expanded to. So if the user provided a Type when the macro is
``
2214
``
`` -
// written in such a way that a bool was expected, we want to print:
``
2215
``
`` -
// = note: expected bool
``
2216
``
`` -
// found Type"
``
2217
``
`` -
// but as far as the compiler is concerned, after expansion what was expected was Type
``
2218
``
`` -
// = note: expected Type
``
2219
``
`` -
// found bool"
``
2220
``
`-
// so we reverse them here to match user expectation.
`
2221
``
`-
(expected, found) = (found, expected);
`
2222
``
`-
}
`
2223
2191
``
2224
``
`-
Some(match (expected.kind(), found.kind()) {
`
``
2192
`+
Some(match (exp_found.expected.kind(), exp_found.found.kind()) {
`
2225
2193
`(ty::TermKind::Ty(expected), ty::TermKind::Ty(found)) => {
`
2226
2194
`let (mut exp, mut fnd) = self.cmp(expected, found);
`
2227
2195
`// Use the terminal width as the basis to determine when to compress the printed
`