Skip to content

Commit bae1e03

Browse files
committed
fixed error reporting for mismatched traits
mismatched traits were previously referred to as types
1 parent 39a295f commit bae1e03

File tree

1 file changed

+24
-5
lines changed
  • src/librustc_infer/infer/error_reporting

1 file changed

+24
-5
lines changed

src/librustc_infer/infer/error_reporting/mod.rs

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,8 +1402,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14021402
}
14031403

14041404
debug!("note_type_err(diag={:?})", diag);
1405+
enum Mismatch<'a> {
1406+
Variable(ty::error::ExpectedFound<Ty<'a>>),
1407+
Fixed(&'static str),
1408+
}
14051409
let (expected_found, exp_found, is_simple_error) = match values {
1406-
None => (None, None, false),
1410+
None => (None, Mismatch::Fixed("type"), false),
14071411
Some(values) => {
14081412
let (is_simple_error, exp_found) = match values {
14091413
ValuePairs::Types(exp_found) => {
@@ -1417,9 +1421,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14171421
)
14181422
.report(diag);
14191423

1420-
(is_simple_err, Some(exp_found))
1424+
(is_simple_err, Mismatch::Variable(exp_found))
14211425
}
1422-
_ => (false, None),
1426+
ValuePairs::TraitRefs(_) => (false, Mismatch::Fixed("trait")),
1427+
_ => (false, Mismatch::Fixed("type")),
14231428
};
14241429
let vals = match self.values_str(&values) {
14251430
Some((expected, found)) => Some((expected, found)),
@@ -1445,8 +1450,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14451450
}
14461451
};
14471452
if let Some((expected, found)) = expected_found {
1448-
let expected_label = exp_found.map_or("type".into(), |ef| ef.expected.prefix_string());
1449-
let found_label = exp_found.map_or("type".into(), |ef| ef.found.prefix_string());
1453+
let expected_label = match exp_found {
1454+
Mismatch::Variable(ef) => ef.expected.prefix_string(),
1455+
Mismatch::Fixed(s) => s.into(),
1456+
};
1457+
let found_label = match exp_found {
1458+
Mismatch::Variable(ef) => ef.found.prefix_string(),
1459+
Mismatch::Fixed(s) => s.into(),
1460+
};
1461+
let exp_found = match exp_found {
1462+
Mismatch::Variable(exp_found) => Some(exp_found),
1463+
Mismatch::Fixed(_) => None,
1464+
};
14501465
match (&terr, expected == found) {
14511466
(TypeError::Sorts(values), extra) => {
14521467
let sort_string = |ty: Ty<'tcx>| match (extra, &ty.kind) {
@@ -1499,6 +1514,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14991514
}
15001515
}
15011516
}
1517+
let exp_found = match exp_found {
1518+
Mismatch::Variable(exp_found) => Some(exp_found),
1519+
Mismatch::Fixed(_) => None,
1520+
};
15021521
if let Some(exp_found) = exp_found {
15031522
self.suggest_as_ref_where_appropriate(span, &exp_found, diag);
15041523
}

0 commit comments

Comments
 (0)