reviews
This commit is contained in:
parent
611db1d3f3
commit
25ed5d5db2
@ -1044,7 +1044,6 @@ fn check_impl_items_against_trait<'tcx>(
|
|||||||
let impl_item_full = tcx.hir().impl_item(impl_item.id);
|
let impl_item_full = tcx.hir().impl_item(impl_item.id);
|
||||||
match impl_item_full.kind {
|
match impl_item_full.kind {
|
||||||
hir::ImplItemKind::Const(..) => {
|
hir::ImplItemKind::Const(..) => {
|
||||||
// Find associated const definition.
|
|
||||||
let _ = tcx.compare_assoc_const_impl_item_with_trait_item((
|
let _ = tcx.compare_assoc_const_impl_item_with_trait_item((
|
||||||
impl_item.id.def_id.def_id,
|
impl_item.id.def_id.def_id,
|
||||||
ty_impl_item.trait_item_def_id.unwrap(),
|
ty_impl_item.trait_item_def_id.unwrap(),
|
||||||
|
@ -1349,53 +1349,54 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
|
|||||||
|
|
||||||
debug!("compare_const_impl: trait_ty={:?}", trait_ty);
|
debug!("compare_const_impl: trait_ty={:?}", trait_ty);
|
||||||
|
|
||||||
let maybe_error_reported = infcx
|
let err = infcx
|
||||||
.at(&cause, param_env)
|
.at(&cause, param_env)
|
||||||
.sup(trait_ty, impl_ty)
|
.sup(trait_ty, impl_ty)
|
||||||
.map(|ok| ocx.register_infer_ok_obligations(ok))
|
.map(|ok| ocx.register_infer_ok_obligations(ok));
|
||||||
.map_err(|terr| {
|
|
||||||
debug!(
|
|
||||||
"checking associated const for compatibility: impl ty {:?}, trait ty {:?}",
|
|
||||||
impl_ty, trait_ty
|
|
||||||
);
|
|
||||||
|
|
||||||
// Locate the Span containing just the type of the offending impl
|
if let Err(terr) = err {
|
||||||
match tcx.hir().expect_impl_item(impl_const_item_def).kind {
|
debug!(
|
||||||
ImplItemKind::Const(ref ty, _) => cause.span = ty.span,
|
"checking associated const for compatibility: impl ty {:?}, trait ty {:?}",
|
||||||
_ => bug!("{:?} is not a impl const", impl_const_item),
|
impl_ty, trait_ty
|
||||||
|
);
|
||||||
|
|
||||||
|
// Locate the Span containing just the type of the offending impl
|
||||||
|
match tcx.hir().expect_impl_item(impl_const_item_def).kind {
|
||||||
|
ImplItemKind::Const(ref ty, _) => cause.span = ty.span,
|
||||||
|
_ => bug!("{:?} is not a impl const", impl_const_item),
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut diag = struct_span_err!(
|
||||||
|
tcx.sess,
|
||||||
|
cause.span,
|
||||||
|
E0326,
|
||||||
|
"implemented const `{}` has an incompatible type for trait",
|
||||||
|
trait_const_item.name
|
||||||
|
);
|
||||||
|
|
||||||
|
let trait_c_span = trait_const_item_def.as_local().map(|trait_c_def_id| {
|
||||||
|
// Add a label to the Span containing just the type of the const
|
||||||
|
match tcx.hir().expect_trait_item(trait_c_def_id).kind {
|
||||||
|
TraitItemKind::Const(ref ty, _) => ty.span,
|
||||||
|
_ => bug!("{:?} is not a trait const", trait_const_item),
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut diag = struct_span_err!(
|
|
||||||
tcx.sess,
|
|
||||||
cause.span,
|
|
||||||
E0326,
|
|
||||||
"implemented const `{}` has an incompatible type for trait",
|
|
||||||
trait_const_item.name
|
|
||||||
);
|
|
||||||
|
|
||||||
let trait_c_span = trait_const_item_def.as_local().map(|trait_c_def_id| {
|
|
||||||
// Add a label to the Span containing just the type of the const
|
|
||||||
match tcx.hir().expect_trait_item(trait_c_def_id).kind {
|
|
||||||
TraitItemKind::Const(ref ty, _) => ty.span,
|
|
||||||
_ => bug!("{:?} is not a trait const", trait_const_item),
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
infcx.note_type_err(
|
|
||||||
&mut diag,
|
|
||||||
&cause,
|
|
||||||
trait_c_span.map(|span| (span, "type in trait".to_owned())),
|
|
||||||
Some(infer::ValuePairs::Terms(ExpectedFound {
|
|
||||||
expected: trait_ty.into(),
|
|
||||||
found: impl_ty.into(),
|
|
||||||
})),
|
|
||||||
terr,
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
diag.emit()
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
infcx.note_type_err(
|
||||||
|
&mut diag,
|
||||||
|
&cause,
|
||||||
|
trait_c_span.map(|span| (span, "type in trait".to_owned())),
|
||||||
|
Some(infer::ValuePairs::Terms(ExpectedFound {
|
||||||
|
expected: trait_ty.into(),
|
||||||
|
found: impl_ty.into(),
|
||||||
|
})),
|
||||||
|
terr,
|
||||||
|
false,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
return Err(diag.emit());
|
||||||
|
};
|
||||||
|
|
||||||
// Check that all obligations are satisfied by the implementation's
|
// Check that all obligations are satisfied by the implementation's
|
||||||
// version.
|
// version.
|
||||||
let errors = ocx.select_all_or_error();
|
let errors = ocx.select_all_or_error();
|
||||||
@ -1407,7 +1408,7 @@ pub(crate) fn raw_compare_const_impl<'tcx>(
|
|||||||
let outlives_environment = OutlivesEnvironment::new(param_env);
|
let outlives_environment = OutlivesEnvironment::new(param_env);
|
||||||
infcx
|
infcx
|
||||||
.check_region_obligations_and_report_errors(impl_const_item_def, &outlives_environment);
|
.check_region_obligations_and_report_errors(impl_const_item_def, &outlives_environment);
|
||||||
maybe_error_reported
|
Ok(())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user