Skip to content

Commit 204e81c

Browse files
authoredNov 19, 2021
Rollup merge of rust-lang#89580 - estebank:trait-bounds-are-tricky, r=nagisa
Point at source of trait bound obligations in more places Be more thorough in using `ItemObligation` and `BindingObligation` when evaluating obligations so that we can point at trait bounds that introduced unfulfilled obligations. We no longer incorrectly point at unrelated trait bounds (`substs-ppaux.verbose.stderr`). In particular, we now point at trait bounds on method calls. We no longer point at "obvious" obligation sources (we no longer have a note pointing at `Trait` saying "required by a bound in `Trait`", like in `associated-types-no-suitable-supertrait*`). We no longer point at associated items (`ImplObligation`), as they didn't add any user actionable information, they just added noise. Address part of rust-lang#89418.
2 parents 6320b99 + a8dcc87 commit 204e81c

File tree

220 files changed

+2046
-2739
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

220 files changed

+2046
-2739
lines changed
 

‎compiler/rustc_errors/src/emitter.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -1266,22 +1266,37 @@ impl EmitterWriter {
12661266
}
12671267
self.msg_to_buffer(&mut buffer, msg, max_line_num_len, "note", None);
12681268
} else {
1269+
let mut label_width = 0;
12691270
// The failure note level itself does not provide any useful diagnostic information
12701271
if *level != Level::FailureNote {
12711272
buffer.append(0, level.to_str(), Style::Level(*level));
1273+
label_width += level.to_str().len();
12721274
}
12731275
// only render error codes, not lint codes
12741276
if let Some(DiagnosticId::Error(ref code)) = *code {
12751277
buffer.append(0, "[", Style::Level(*level));
12761278
buffer.append(0, &code, Style::Level(*level));
12771279
buffer.append(0, "]", Style::Level(*level));
1280+
label_width += 2 + code.len();
12781281
}
12791282
let header_style = if is_secondary { Style::HeaderMsg } else { Style::MainHeaderMsg };
12801283
if *level != Level::FailureNote {
12811284
buffer.append(0, ": ", header_style);
1285+
label_width += 2;
12821286
}
12831287
for &(ref text, _) in msg.iter() {
1284-
buffer.append(0, &replace_tabs(text), header_style);
1288+
// Account for newlines to align output to its label.
1289+
for (line, text) in replace_tabs(text).lines().enumerate() {
1290+
buffer.append(
1291+
0 + line,
1292+
&format!(
1293+
"{}{}",
1294+
if line == 0 { String::new() } else { " ".repeat(label_width) },
1295+
text
1296+
),
1297+
header_style,
1298+
);
1299+
}
12851300
}
12861301
}
12871302

‎compiler/rustc_infer/src/infer/error_reporting/mod.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -2113,10 +2113,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
21132113
None
21142114
},
21152115
self.tcx.generics_of(owner.to_def_id()),
2116+
hir.span(hir_id),
21162117
)
21172118
});
2119+
2120+
let span = match generics {
2121+
// This is to get around the trait identity obligation, that has a `DUMMY_SP` as signal
2122+
// for other diagnostics, so we need to recover it here.
2123+
Some((_, _, node)) if span.is_dummy() => node,
2124+
_ => span,
2125+
};
2126+
21182127
let type_param_span = match (generics, bound_kind) {
2119-
(Some((_, ref generics)), GenericKind::Param(ref param)) => {
2128+
(Some((_, ref generics, _)), GenericKind::Param(ref param)) => {
21202129
// Account for the case where `param` corresponds to `Self`,
21212130
// which doesn't have the expected type argument.
21222131
if !(generics.has_self && param.index == 0) {
@@ -2153,7 +2162,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
21532162
};
21542163
let new_lt = generics
21552164
.as_ref()
2156-
.and_then(|(parent_g, g)| {
2165+
.and_then(|(parent_g, g, _)| {
21572166
let mut possible = (b'a'..=b'z').map(|c| format!("'{}", c as char));
21582167
let mut lts_names = g
21592168
.params
@@ -2175,7 +2184,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
21752184
.unwrap_or("'lt".to_string());
21762185
let add_lt_sugg = generics
21772186
.as_ref()
2178-
.and_then(|(_, g)| g.params.first())
2187+
.and_then(|(_, g, _)| g.params.first())
21792188
.and_then(|param| param.def_id.as_local())
21802189
.map(|def_id| {
21812190
(

0 commit comments

Comments
 (0)