Auto merge of #100510 - compiler-errors:as-a-treat, r=jackh726
make `TypeError` impl `Copy` r? `@ghost`
This commit is contained in:
commit
76c427d6e2
8 changed files with 37 additions and 38 deletions
|
@ -484,9 +484,7 @@ fn try_extract_error_from_region_constraints<'tcx>(
|
||||||
};
|
};
|
||||||
nice_error.try_report_from_nll().or_else(|| {
|
nice_error.try_report_from_nll().or_else(|| {
|
||||||
if let SubregionOrigin::Subtype(trace) = cause {
|
if let SubregionOrigin::Subtype(trace) = cause {
|
||||||
Some(
|
Some(infcx.report_and_explain_type_error(*trace, TypeError::RegionsPlaceholderMismatch))
|
||||||
infcx.report_and_explain_type_error(*trace, &TypeError::RegionsPlaceholderMismatch),
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
|
@ -457,7 +457,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Adds a note if the types come from similarly named crates
|
/// Adds a note if the types come from similarly named crates
|
||||||
fn check_and_note_conflicting_crates(&self, err: &mut Diagnostic, terr: &TypeError<'tcx>) {
|
fn check_and_note_conflicting_crates(&self, err: &mut Diagnostic, terr: TypeError<'tcx>) {
|
||||||
use hir::def_id::CrateNum;
|
use hir::def_id::CrateNum;
|
||||||
use rustc_hir::definitions::DisambiguatedDefPathData;
|
use rustc_hir::definitions::DisambiguatedDefPathData;
|
||||||
use ty::print::Printer;
|
use ty::print::Printer;
|
||||||
|
@ -561,7 +561,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
match *terr {
|
match terr {
|
||||||
TypeError::Sorts(ref exp_found) => {
|
TypeError::Sorts(ref exp_found) => {
|
||||||
// if they are both "path types", there's a chance of ambiguity
|
// if they are both "path types", there's a chance of ambiguity
|
||||||
// due to different versions of the same crate
|
// due to different versions of the same crate
|
||||||
|
@ -583,7 +583,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
err: &mut Diagnostic,
|
err: &mut Diagnostic,
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
exp_found: Option<ty::error::ExpectedFound<Ty<'tcx>>>,
|
exp_found: Option<ty::error::ExpectedFound<Ty<'tcx>>>,
|
||||||
terr: &TypeError<'tcx>,
|
terr: TypeError<'tcx>,
|
||||||
) {
|
) {
|
||||||
match *cause.code() {
|
match *cause.code() {
|
||||||
ObligationCauseCode::Pattern { origin_expr: true, span: Some(span), root_ty } => {
|
ObligationCauseCode::Pattern { origin_expr: true, span: Some(span), root_ty } => {
|
||||||
|
@ -1432,7 +1432,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
secondary_span: Option<(Span, String)>,
|
secondary_span: Option<(Span, String)>,
|
||||||
mut values: Option<ValuePairs<'tcx>>,
|
mut values: Option<ValuePairs<'tcx>>,
|
||||||
terr: &TypeError<'tcx>,
|
terr: TypeError<'tcx>,
|
||||||
swap_secondary_and_primary: bool,
|
swap_secondary_and_primary: bool,
|
||||||
prefer_label: bool,
|
prefer_label: bool,
|
||||||
) {
|
) {
|
||||||
|
@ -1713,7 +1713,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
ty::error::TypeError::Sorts(terr)
|
ty::error::TypeError::Sorts(terr)
|
||||||
if exp_found.map_or(false, |ef| terr.found == ef.found) =>
|
if exp_found.map_or(false, |ef| terr.found == ef.found) =>
|
||||||
{
|
{
|
||||||
Some(*terr)
|
Some(terr)
|
||||||
}
|
}
|
||||||
_ => exp_found,
|
_ => exp_found,
|
||||||
};
|
};
|
||||||
|
@ -2091,7 +2091,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
pub fn report_and_explain_type_error(
|
pub fn report_and_explain_type_error(
|
||||||
&self,
|
&self,
|
||||||
trace: TypeTrace<'tcx>,
|
trace: TypeTrace<'tcx>,
|
||||||
terr: &TypeError<'tcx>,
|
terr: TypeError<'tcx>,
|
||||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||||
use crate::traits::ObligationCauseCode::MatchExpressionArm;
|
use crate::traits::ObligationCauseCode::MatchExpressionArm;
|
||||||
|
|
||||||
|
@ -2781,12 +2781,12 @@ pub enum FailureCode {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ObligationCauseExt<'tcx> {
|
pub trait ObligationCauseExt<'tcx> {
|
||||||
fn as_failure_code(&self, terr: &TypeError<'tcx>) -> FailureCode;
|
fn as_failure_code(&self, terr: TypeError<'tcx>) -> FailureCode;
|
||||||
fn as_requirement_str(&self) -> &'static str;
|
fn as_requirement_str(&self) -> &'static str;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
|
impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
|
||||||
fn as_failure_code(&self, terr: &TypeError<'tcx>) -> FailureCode {
|
fn as_failure_code(&self, terr: TypeError<'tcx>) -> FailureCode {
|
||||||
use self::FailureCode::*;
|
use self::FailureCode::*;
|
||||||
use crate::traits::ObligationCauseCode::*;
|
use crate::traits::ObligationCauseCode::*;
|
||||||
match self.code() {
|
match self.code() {
|
||||||
|
@ -2823,7 +2823,7 @@ impl<'tcx> ObligationCauseExt<'tcx> for ObligationCause<'tcx> {
|
||||||
TypeError::IntrinsicCast => {
|
TypeError::IntrinsicCast => {
|
||||||
Error0308("cannot coerce intrinsics to function pointers")
|
Error0308("cannot coerce intrinsics to function pointers")
|
||||||
}
|
}
|
||||||
TypeError::ObjectUnsafeCoercion(did) => Error0038(*did),
|
TypeError::ObjectUnsafeCoercion(did) => Error0038(did),
|
||||||
_ => Error0308("mismatched types"),
|
_ => Error0308("mismatched types"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
match origin {
|
match origin {
|
||||||
infer::Subtype(box trace) => {
|
infer::Subtype(box trace) => {
|
||||||
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
|
let terr = TypeError::RegionsDoesNotOutlive(sup, sub);
|
||||||
let mut err = self.report_and_explain_type_error(trace, &terr);
|
let mut err = self.report_and_explain_type_error(trace, terr);
|
||||||
match (*sub, *sup) {
|
match (*sub, *sup) {
|
||||||
(ty::RePlaceholder(_), ty::RePlaceholder(_)) => {}
|
(ty::RePlaceholder(_), ty::RePlaceholder(_)) => {}
|
||||||
(ty::RePlaceholder(_), _) => {
|
(ty::RePlaceholder(_), _) => {
|
||||||
|
@ -406,7 +406,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
infer::Subtype(box trace) => {
|
infer::Subtype(box trace) => {
|
||||||
let terr = TypeError::RegionsPlaceholderMismatch;
|
let terr = TypeError::RegionsPlaceholderMismatch;
|
||||||
return self.report_and_explain_type_error(trace, &terr);
|
return self.report_and_explain_type_error(trace, terr);
|
||||||
}
|
}
|
||||||
_ => return self.report_concrete_failure(placeholder_origin, sub, sup),
|
_ => return self.report_concrete_failure(placeholder_origin, sub, sup),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1527,8 +1527,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
actual: Ty<'tcx>,
|
actual: Ty<'tcx>,
|
||||||
err: TypeError<'tcx>,
|
err: TypeError<'tcx>,
|
||||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||||
let trace = TypeTrace::types(cause, true, expected, actual);
|
self.report_and_explain_type_error(TypeTrace::types(cause, true, expected, actual), err)
|
||||||
self.report_and_explain_type_error(trace, &err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn report_mismatched_consts(
|
pub fn report_mismatched_consts(
|
||||||
|
@ -1538,8 +1537,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
actual: ty::Const<'tcx>,
|
actual: ty::Const<'tcx>,
|
||||||
err: TypeError<'tcx>,
|
err: TypeError<'tcx>,
|
||||||
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
|
||||||
let trace = TypeTrace::consts(cause, true, expected, actual);
|
self.report_and_explain_type_error(TypeTrace::consts(cause, true, expected, actual), err)
|
||||||
self.report_and_explain_type_error(trace, &err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn replace_bound_vars_with_fresh_vars<T>(
|
pub fn replace_bound_vars_with_fresh_vars<T>(
|
||||||
|
|
|
@ -30,7 +30,8 @@ impl<T> ExpectedFound<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Data structures used in type unification
|
// Data structures used in type unification
|
||||||
#[derive(Clone, Debug, TypeFoldable, TypeVisitable)]
|
#[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable)]
|
||||||
|
#[rustc_pass_by_value]
|
||||||
pub enum TypeError<'tcx> {
|
pub enum TypeError<'tcx> {
|
||||||
Mismatch,
|
Mismatch,
|
||||||
ConstnessMismatch(ExpectedFound<ty::BoundConstness>),
|
ConstnessMismatch(ExpectedFound<ty::BoundConstness>),
|
||||||
|
@ -211,7 +212,7 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> TypeError<'tcx> {
|
impl<'tcx> TypeError<'tcx> {
|
||||||
pub fn must_include_note(&self) -> bool {
|
pub fn must_include_note(self) -> bool {
|
||||||
use self::TypeError::*;
|
use self::TypeError::*;
|
||||||
match self {
|
match self {
|
||||||
CyclicTy(_) | CyclicConst(_) | UnsafetyMismatch(_) | ConstnessMismatch(_)
|
CyclicTy(_) | CyclicConst(_) | UnsafetyMismatch(_) | ConstnessMismatch(_)
|
||||||
|
@ -347,7 +348,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
pub fn note_and_explain_type_err(
|
pub fn note_and_explain_type_err(
|
||||||
self,
|
self,
|
||||||
diag: &mut Diagnostic,
|
diag: &mut Diagnostic,
|
||||||
err: &TypeError<'tcx>,
|
err: TypeError<'tcx>,
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
body_owner_def_id: DefId,
|
body_owner_def_id: DefId,
|
||||||
|
@ -568,7 +569,7 @@ impl<T> Trait<T> for X {
|
||||||
}
|
}
|
||||||
TargetFeatureCast(def_id) => {
|
TargetFeatureCast(def_id) => {
|
||||||
let target_spans =
|
let target_spans =
|
||||||
self.get_attrs(*def_id, sym::target_feature).map(|attr| attr.span);
|
self.get_attrs(def_id, sym::target_feature).map(|attr| attr.span);
|
||||||
diag.note(
|
diag.note(
|
||||||
"functions with `#[target_feature]` can only be coerced to `unsafe` function pointers"
|
"functions with `#[target_feature]` can only be coerced to `unsafe` function pointers"
|
||||||
);
|
);
|
||||||
|
@ -640,7 +641,7 @@ impl<T> Trait<T> for X {
|
||||||
self,
|
self,
|
||||||
diag: &mut Diagnostic,
|
diag: &mut Diagnostic,
|
||||||
proj_ty: &ty::ProjectionTy<'tcx>,
|
proj_ty: &ty::ProjectionTy<'tcx>,
|
||||||
values: &ExpectedFound<Ty<'tcx>>,
|
values: ExpectedFound<Ty<'tcx>>,
|
||||||
body_owner_def_id: DefId,
|
body_owner_def_id: DefId,
|
||||||
cause_code: &ObligationCauseCode<'_>,
|
cause_code: &ObligationCauseCode<'_>,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -1507,8 +1507,7 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
self.probe(|_| {
|
self.probe(|_| {
|
||||||
let err_buf;
|
let mut err = error.err;
|
||||||
let mut err = &error.err;
|
|
||||||
let mut values = None;
|
let mut values = None;
|
||||||
|
|
||||||
// try to find the mismatched types to report the error with.
|
// try to find the mismatched types to report the error with.
|
||||||
|
@ -1544,14 +1543,13 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
| ObligationCauseCode::ObjectCastObligation(..)
|
| ObligationCauseCode::ObjectCastObligation(..)
|
||||||
| ObligationCauseCode::OpaqueType
|
| ObligationCauseCode::OpaqueType
|
||||||
);
|
);
|
||||||
if let Err(error) = self.at(&obligation.cause, obligation.param_env).eq_exp(
|
if let Err(new_err) = self.at(&obligation.cause, obligation.param_env).eq_exp(
|
||||||
is_normalized_ty_expected,
|
is_normalized_ty_expected,
|
||||||
normalized_ty,
|
normalized_ty,
|
||||||
data.term,
|
data.term,
|
||||||
) {
|
) {
|
||||||
values = Some((data, is_normalized_ty_expected, normalized_ty, data.term));
|
values = Some((data, is_normalized_ty_expected, normalized_ty, data.term));
|
||||||
err_buf = error;
|
err = new_err;
|
||||||
err = &err_buf;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -291,7 +291,7 @@ fn compare_predicate_entailment<'tcx>(
|
||||||
debug!("sub_types failed: impl ty {:?}, trait ty {:?}", impl_fty, trait_fty);
|
debug!("sub_types failed: impl ty {:?}, trait ty {:?}", impl_fty, trait_fty);
|
||||||
|
|
||||||
let (impl_err_span, trait_err_span) =
|
let (impl_err_span, trait_err_span) =
|
||||||
extract_spans_for_error_reporting(&infcx, &terr, &cause, impl_m, trait_m);
|
extract_spans_for_error_reporting(&infcx, terr, &cause, impl_m, trait_m);
|
||||||
|
|
||||||
cause.span = impl_err_span;
|
cause.span = impl_err_span;
|
||||||
|
|
||||||
|
@ -381,7 +381,7 @@ fn compare_predicate_entailment<'tcx>(
|
||||||
expected: trait_fty.into(),
|
expected: trait_fty.into(),
|
||||||
found: impl_fty.into(),
|
found: impl_fty.into(),
|
||||||
})),
|
})),
|
||||||
&terr,
|
terr,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
@ -468,7 +468,7 @@ fn check_region_bounds_on_impl_item<'tcx>(
|
||||||
#[instrument(level = "debug", skip(infcx))]
|
#[instrument(level = "debug", skip(infcx))]
|
||||||
fn extract_spans_for_error_reporting<'a, 'tcx>(
|
fn extract_spans_for_error_reporting<'a, 'tcx>(
|
||||||
infcx: &infer::InferCtxt<'a, 'tcx>,
|
infcx: &infer::InferCtxt<'a, 'tcx>,
|
||||||
terr: &TypeError<'_>,
|
terr: TypeError<'_>,
|
||||||
cause: &ObligationCause<'tcx>,
|
cause: &ObligationCause<'tcx>,
|
||||||
impl_m: &ty::AssocItem,
|
impl_m: &ty::AssocItem,
|
||||||
trait_m: &ty::AssocItem,
|
trait_m: &ty::AssocItem,
|
||||||
|
@ -488,7 +488,7 @@ fn extract_spans_for_error_reporting<'a, 'tcx>(
|
||||||
_ => bug!("{:?} is not a TraitItemKind::Fn", trait_m),
|
_ => bug!("{:?} is not a TraitItemKind::Fn", trait_m),
|
||||||
});
|
});
|
||||||
|
|
||||||
match *terr {
|
match terr {
|
||||||
TypeError::ArgumentMutability(i) => {
|
TypeError::ArgumentMutability(i) => {
|
||||||
(impl_args.nth(i).unwrap(), trait_args.and_then(|mut args| args.nth(i)))
|
(impl_args.nth(i).unwrap(), trait_args.and_then(|mut args| args.nth(i)))
|
||||||
}
|
}
|
||||||
|
@ -1143,7 +1143,7 @@ pub(crate) fn compare_const_impl<'tcx>(
|
||||||
expected: trait_ty.into(),
|
expected: trait_ty.into(),
|
||||||
found: impl_ty.into(),
|
found: impl_ty.into(),
|
||||||
})),
|
})),
|
||||||
&terr,
|
terr,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
);
|
);
|
||||||
|
|
|
@ -578,7 +578,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
// First, check if we just need to wrap some arguments in a tuple.
|
// First, check if we just need to wrap some arguments in a tuple.
|
||||||
if let Some((mismatch_idx, terr)) =
|
if let Some((mismatch_idx, terr)) =
|
||||||
compatibility_diagonal.iter().enumerate().find_map(|(i, c)| {
|
compatibility_diagonal.iter().enumerate().find_map(|(i, c)| {
|
||||||
if let Compatibility::Incompatible(Some(terr)) = c { Some((i, terr)) } else { None }
|
if let Compatibility::Incompatible(Some(terr)) = c {
|
||||||
|
Some((i, *terr))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
})
|
})
|
||||||
{
|
{
|
||||||
// Is the first bad expected argument a tuple?
|
// Is the first bad expected argument a tuple?
|
||||||
|
@ -707,8 +711,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let (expected_ty, _) = formal_and_expected_inputs[*expected_idx];
|
let (expected_ty, _) = formal_and_expected_inputs[*expected_idx];
|
||||||
let cause = &self.misc(provided_span);
|
let cause = &self.misc(provided_span);
|
||||||
let trace = TypeTrace::types(cause, true, expected_ty, provided_ty);
|
let trace = TypeTrace::types(cause, true, expected_ty, provided_ty);
|
||||||
if !matches!(trace.cause.as_failure_code(e), FailureCode::Error0308(_)) {
|
if !matches!(trace.cause.as_failure_code(*e), FailureCode::Error0308(_)) {
|
||||||
self.report_and_explain_type_error(trace, e).emit();
|
self.report_and_explain_type_error(trace, *e).emit();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
|
@ -732,7 +736,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
let (provided_ty, provided_arg_span) = provided_arg_tys[*provided_idx];
|
let (provided_ty, provided_arg_span) = provided_arg_tys[*provided_idx];
|
||||||
let cause = &self.misc(provided_arg_span);
|
let cause = &self.misc(provided_arg_span);
|
||||||
let trace = TypeTrace::types(cause, true, expected_ty, provided_ty);
|
let trace = TypeTrace::types(cause, true, expected_ty, provided_ty);
|
||||||
let mut err = self.report_and_explain_type_error(trace, err);
|
let mut err = self.report_and_explain_type_error(trace, *err);
|
||||||
self.emit_coerce_suggestions(
|
self.emit_coerce_suggestions(
|
||||||
&mut err,
|
&mut err,
|
||||||
&provided_args[*provided_idx],
|
&provided_args[*provided_idx],
|
||||||
|
@ -802,7 +806,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||||
Error::Invalid(provided_idx, expected_idx, compatibility) => {
|
Error::Invalid(provided_idx, expected_idx, compatibility) => {
|
||||||
let (formal_ty, expected_ty) = formal_and_expected_inputs[expected_idx];
|
let (formal_ty, expected_ty) = formal_and_expected_inputs[expected_idx];
|
||||||
let (provided_ty, provided_span) = provided_arg_tys[provided_idx];
|
let (provided_ty, provided_span) = provided_arg_tys[provided_idx];
|
||||||
if let Compatibility::Incompatible(error) = &compatibility {
|
if let Compatibility::Incompatible(error) = compatibility {
|
||||||
let cause = &self.misc(provided_span);
|
let cause = &self.misc(provided_span);
|
||||||
let trace = TypeTrace::types(cause, true, expected_ty, provided_ty);
|
let trace = TypeTrace::types(cause, true, expected_ty, provided_ty);
|
||||||
if let Some(e) = error {
|
if let Some(e) = error {
|
||||||
|
|
Loading…
Add table
Reference in a new issue