Rollup merge of #106131 - compiler-errors:not-ptrs, r=davidtwco
Mention "signature" rather than "fn pointer" when impl/trait methods are incompatible Fixes #80929 Fixes #67296
This commit is contained in:
commit
6afd16171d
39 changed files with 169 additions and 142 deletions
|
@ -427,3 +427,15 @@ impl<'tcx> ToTrace<'tcx> for ty::AliasTy<'tcx> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> ToTrace<'tcx> for ty::FnSig<'tcx> {
|
||||
fn to_trace(
|
||||
_: TyCtxt<'tcx>,
|
||||
cause: &ObligationCause<'tcx>,
|
||||
a_is_expected: bool,
|
||||
a: Self,
|
||||
b: Self,
|
||||
) -> TypeTrace<'tcx> {
|
||||
TypeTrace { cause: cause.clone(), values: Sigs(ExpectedFound::new(a_is_expected, a, b)) }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1428,8 +1428,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
impl<'tcx> OpaqueTypesVisitor<'tcx> {
|
||||
fn visit_expected_found(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
expected: Ty<'tcx>,
|
||||
found: Ty<'tcx>,
|
||||
expected: impl TypeVisitable<'tcx>,
|
||||
found: impl TypeVisitable<'tcx>,
|
||||
ignore_span: Span,
|
||||
) -> Self {
|
||||
let mut types_visitor = OpaqueTypesVisitor {
|
||||
|
@ -1569,6 +1569,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
_ => (false, Mismatch::Fixed("type")),
|
||||
}
|
||||
}
|
||||
ValuePairs::Sigs(infer::ExpectedFound { expected, found }) => {
|
||||
OpaqueTypesVisitor::visit_expected_found(self.tcx, expected, found, span)
|
||||
.report(diag);
|
||||
(false, Mismatch::Fixed("signature"))
|
||||
}
|
||||
ValuePairs::TraitRefs(_) | ValuePairs::PolyTraitRefs(_) => {
|
||||
(false, Mismatch::Fixed("trait"))
|
||||
}
|
||||
|
@ -2040,6 +2045,17 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
ret => ret,
|
||||
}
|
||||
}
|
||||
infer::Sigs(exp_found) => {
|
||||
let exp_found = self.resolve_vars_if_possible(exp_found);
|
||||
if exp_found.references_error() {
|
||||
return None;
|
||||
}
|
||||
let (exp, fnd) = self.cmp_fn_sig(
|
||||
&ty::Binder::dummy(exp_found.expected),
|
||||
&ty::Binder::dummy(exp_found.found),
|
||||
);
|
||||
Some((exp, fnd, None, None))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
use crate::errors::{ConsiderBorrowingParamHelp, RelationshipHelp, TraitImplDiff};
|
||||
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
|
||||
use crate::infer::lexical_region_resolve::RegionResolutionError;
|
||||
use crate::infer::Subtype;
|
||||
use crate::infer::{Subtype, ValuePairs};
|
||||
use crate::traits::ObligationCauseCode::CompareImplItemObligation;
|
||||
use rustc_errors::ErrorGuaranteed;
|
||||
use rustc_hir as hir;
|
||||
|
@ -11,6 +11,7 @@ use rustc_hir::def::Res;
|
|||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::intravisit::Visitor;
|
||||
use rustc_middle::hir::nested_filter;
|
||||
use rustc_middle::ty::error::ExpectedFound;
|
||||
use rustc_middle::ty::print::RegionHighlightMode;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor};
|
||||
use rustc_span::Span;
|
||||
|
@ -23,22 +24,27 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||
let error = self.error.as_ref()?;
|
||||
debug!("try_report_impl_not_conforming_to_trait {:?}", error);
|
||||
if let RegionResolutionError::SubSupConflict(
|
||||
_,
|
||||
var_origin,
|
||||
sub_origin,
|
||||
_sub,
|
||||
sup_origin,
|
||||
_sup,
|
||||
_,
|
||||
) = error.clone()
|
||||
_,
|
||||
var_origin,
|
||||
sub_origin,
|
||||
_sub,
|
||||
sup_origin,
|
||||
_sup,
|
||||
_,
|
||||
) = error.clone()
|
||||
&& let (Subtype(sup_trace), Subtype(sub_trace)) = (&sup_origin, &sub_origin)
|
||||
&& let sub_expected_found @ Some((sub_expected, sub_found)) = sub_trace.values.ty()
|
||||
&& let sup_expected_found @ Some(_) = sup_trace.values.ty()
|
||||
&& let CompareImplItemObligation { trait_item_def_id, .. } = sub_trace.cause.code()
|
||||
&& sup_expected_found == sub_expected_found
|
||||
&& sub_trace.values == sup_trace.values
|
||||
&& let ValuePairs::Sigs(ExpectedFound { expected, found }) = sub_trace.values
|
||||
{
|
||||
let guar =
|
||||
self.emit_err(var_origin.span(), sub_expected, sub_found, *trait_item_def_id);
|
||||
// FIXME(compiler-errors): Don't like that this needs `Ty`s, but
|
||||
// all of the region highlighting machinery only deals with those.
|
||||
let guar = self.emit_err(
|
||||
var_origin.span(),
|
||||
self.cx.tcx.mk_fn_ptr(ty::Binder::dummy(expected)),
|
||||
self.cx.tcx.mk_fn_ptr(ty::Binder::dummy(found)),
|
||||
*trait_item_def_id,
|
||||
);
|
||||
return Some(guar);
|
||||
}
|
||||
None
|
||||
|
|
|
@ -361,6 +361,7 @@ pub enum ValuePairs<'tcx> {
|
|||
Terms(ExpectedFound<ty::Term<'tcx>>),
|
||||
TraitRefs(ExpectedFound<ty::TraitRef<'tcx>>),
|
||||
PolyTraitRefs(ExpectedFound<ty::PolyTraitRef<'tcx>>),
|
||||
Sigs(ExpectedFound<ty::FnSig<'tcx>>),
|
||||
}
|
||||
|
||||
impl<'tcx> ValuePairs<'tcx> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue