mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Rm ValuePairs::Ty/Const
Remove old value pairs which is a strict subset of Terms.
This commit is contained in:
parent
fdd6f4e56c
commit
be236d7fc2
@ -258,7 +258,10 @@ impl<'tcx> ToTrace<'tcx> for Ty<'tcx> {
|
|||||||
a: Self,
|
a: Self,
|
||||||
b: Self,
|
b: Self,
|
||||||
) -> TypeTrace<'tcx> {
|
) -> TypeTrace<'tcx> {
|
||||||
TypeTrace { cause: cause.clone(), values: Types(ExpectedFound::new(a_is_expected, a, b)) }
|
TypeTrace {
|
||||||
|
cause: cause.clone(),
|
||||||
|
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -282,7 +285,10 @@ impl<'tcx> ToTrace<'tcx> for &'tcx Const<'tcx> {
|
|||||||
a: Self,
|
a: Self,
|
||||||
b: Self,
|
b: Self,
|
||||||
) -> TypeTrace<'tcx> {
|
) -> TypeTrace<'tcx> {
|
||||||
TypeTrace { cause: cause.clone(), values: Consts(ExpectedFound::new(a_is_expected, a, b)) }
|
TypeTrace {
|
||||||
|
cause: cause.clone(),
|
||||||
|
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -340,7 +346,7 @@ impl<'tcx> ToTrace<'tcx> for ty::ProjectionTy<'tcx> {
|
|||||||
let b_ty = tcx.mk_projection(b.item_def_id, b.substs);
|
let b_ty = tcx.mk_projection(b.item_def_id, b.substs);
|
||||||
TypeTrace {
|
TypeTrace {
|
||||||
cause: cause.clone(),
|
cause: cause.clone(),
|
||||||
values: Types(ExpectedFound::new(a_is_expected, a_ty, b_ty)),
|
values: Terms(ExpectedFound::new(a_is_expected, a_ty.into(), b_ty.into())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1582,18 +1582,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
None => (None, Mismatch::Fixed("type"), false),
|
None => (None, Mismatch::Fixed("type"), false),
|
||||||
Some(values) => {
|
Some(values) => {
|
||||||
let (is_simple_error, exp_found) = match values {
|
let (is_simple_error, exp_found) = match values {
|
||||||
ValuePairs::Types(exp_found) => {
|
ValuePairs::Terms(infer::ExpectedFound {
|
||||||
let is_simple_err =
|
expected: ty::Term::Ty(expected),
|
||||||
exp_found.expected.is_simple_text() && exp_found.found.is_simple_text();
|
found: ty::Term::Ty(found),
|
||||||
OpaqueTypesVisitor::visit_expected_found(
|
}) => {
|
||||||
self.tcx,
|
let is_simple_err = expected.is_simple_text() && found.is_simple_text();
|
||||||
exp_found.expected,
|
OpaqueTypesVisitor::visit_expected_found(self.tcx, expected, found, span)
|
||||||
exp_found.found,
|
.report(diag);
|
||||||
span,
|
|
||||||
)
|
|
||||||
.report(diag);
|
|
||||||
|
|
||||||
(is_simple_err, Mismatch::Variable(exp_found))
|
(
|
||||||
|
is_simple_err,
|
||||||
|
Mismatch::Variable(infer::ExpectedFound { expected, found }),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
ValuePairs::TraitRefs(_) => (false, Mismatch::Fixed("trait")),
|
ValuePairs::TraitRefs(_) => (false, Mismatch::Fixed("trait")),
|
||||||
_ => (false, Mismatch::Fixed("type")),
|
_ => (false, Mismatch::Fixed("type")),
|
||||||
@ -1624,7 +1624,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
};
|
};
|
||||||
if let Some((sp, msg)) = secondary_span {
|
if let Some((sp, msg)) = secondary_span {
|
||||||
if swap_secondary_and_primary {
|
if swap_secondary_and_primary {
|
||||||
let terr = if let Some(infer::ValuePairs::Types(infer::ExpectedFound {
|
let terr = if let Some(infer::ValuePairs::Terms(infer::ExpectedFound {
|
||||||
expected,
|
expected,
|
||||||
..
|
..
|
||||||
})) = values
|
})) = values
|
||||||
@ -2036,9 +2036,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
FailureCode::Error0308(failure_str) => {
|
FailureCode::Error0308(failure_str) => {
|
||||||
let mut err = struct_span_err!(self.tcx.sess, span, E0308, "{}", failure_str);
|
let mut err = struct_span_err!(self.tcx.sess, span, E0308, "{}", failure_str);
|
||||||
if let ValuePairs::Types(ty::error::ExpectedFound { expected, found }) =
|
if let Some((expected, found)) = trace.values.ty() {
|
||||||
trace.values
|
|
||||||
{
|
|
||||||
match (expected.kind(), found.kind()) {
|
match (expected.kind(), found.kind()) {
|
||||||
(ty::Tuple(_), ty::Tuple(_)) => {}
|
(ty::Tuple(_), ty::Tuple(_)) => {}
|
||||||
// If a tuple of length one was expected and the found expression has
|
// If a tuple of length one was expected and the found expression has
|
||||||
@ -2124,9 +2122,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
values: ValuePairs<'tcx>,
|
values: ValuePairs<'tcx>,
|
||||||
) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> {
|
) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> {
|
||||||
match values {
|
match values {
|
||||||
infer::Types(exp_found) => self.expected_found_str_ty(exp_found),
|
|
||||||
infer::Regions(exp_found) => self.expected_found_str(exp_found),
|
infer::Regions(exp_found) => self.expected_found_str(exp_found),
|
||||||
infer::Consts(exp_found) => self.expected_found_str(exp_found),
|
|
||||||
infer::Terms(exp_found) => self.expected_found_str_term(exp_found),
|
infer::Terms(exp_found) => self.expected_found_str_term(exp_found),
|
||||||
infer::TraitRefs(exp_found) => {
|
infer::TraitRefs(exp_found) => {
|
||||||
let pretty_exp_found = ty::error::ExpectedFound {
|
let pretty_exp_found = ty::error::ExpectedFound {
|
||||||
@ -2155,18 +2151,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expected_found_str_ty(
|
|
||||||
&self,
|
|
||||||
exp_found: ty::error::ExpectedFound<Ty<'tcx>>,
|
|
||||||
) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> {
|
|
||||||
let exp_found = self.resolve_vars_if_possible(exp_found);
|
|
||||||
if exp_found.references_error() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
Some(self.cmp(exp_found.expected, exp_found.found))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn expected_found_str_term(
|
fn expected_found_str_term(
|
||||||
&self,
|
&self,
|
||||||
exp_found: ty::error::ExpectedFound<ty::Term<'tcx>>,
|
exp_found: ty::error::ExpectedFound<ty::Term<'tcx>>,
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
|
use crate::infer::error_reporting::nice_region_error::NiceRegionError;
|
||||||
use crate::infer::lexical_region_resolve::RegionResolutionError;
|
use crate::infer::lexical_region_resolve::RegionResolutionError;
|
||||||
use crate::infer::{SubregionOrigin, Subtype, ValuePairs};
|
use crate::infer::{SubregionOrigin, Subtype};
|
||||||
use crate::traits::ObligationCauseCode::CompareImplMethodObligation;
|
use crate::traits::ObligationCauseCode::CompareImplMethodObligation;
|
||||||
use rustc_errors::ErrorReported;
|
use rustc_errors::ErrorReported;
|
||||||
use rustc_hir as hir;
|
use rustc_hir as hir;
|
||||||
@ -34,16 +34,16 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
|
|||||||
{
|
{
|
||||||
if let (&Subtype(ref sup_trace), &Subtype(ref sub_trace)) = (&sup_origin, &sub_origin) {
|
if let (&Subtype(ref sup_trace), &Subtype(ref sub_trace)) = (&sup_origin, &sub_origin) {
|
||||||
if let (
|
if let (
|
||||||
ValuePairs::Types(sub_expected_found),
|
sub_expected_found @ Some((sub_expected, sub_found)),
|
||||||
ValuePairs::Types(sup_expected_found),
|
sup_expected_found @ Some(_),
|
||||||
CompareImplMethodObligation { trait_item_def_id, .. },
|
CompareImplMethodObligation { trait_item_def_id, .. },
|
||||||
) = (&sub_trace.values, &sup_trace.values, sub_trace.cause.code())
|
) = (&sub_trace.values.ty(), &sup_trace.values.ty(), sub_trace.cause.code())
|
||||||
{
|
{
|
||||||
if sup_expected_found == sub_expected_found {
|
if sup_expected_found == sub_expected_found {
|
||||||
self.emit_err(
|
self.emit_err(
|
||||||
var_origin.span(),
|
var_origin.span(),
|
||||||
sub_expected_found.expected,
|
sub_expected,
|
||||||
sub_expected_found.found,
|
sub_found,
|
||||||
*trait_item_def_id,
|
*trait_item_def_id,
|
||||||
);
|
);
|
||||||
return Some(ErrorReported);
|
return Some(ErrorReported);
|
||||||
|
@ -368,14 +368,26 @@ pub struct InferCtxt<'a, 'tcx> {
|
|||||||
/// See the `error_reporting` module for more details.
|
/// See the `error_reporting` module for more details.
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable)]
|
||||||
pub enum ValuePairs<'tcx> {
|
pub enum ValuePairs<'tcx> {
|
||||||
Types(ExpectedFound<Ty<'tcx>>),
|
|
||||||
Regions(ExpectedFound<ty::Region<'tcx>>),
|
Regions(ExpectedFound<ty::Region<'tcx>>),
|
||||||
Consts(ExpectedFound<&'tcx ty::Const<'tcx>>),
|
|
||||||
Terms(ExpectedFound<ty::Term<'tcx>>),
|
Terms(ExpectedFound<ty::Term<'tcx>>),
|
||||||
TraitRefs(ExpectedFound<ty::TraitRef<'tcx>>),
|
TraitRefs(ExpectedFound<ty::TraitRef<'tcx>>),
|
||||||
PolyTraitRefs(ExpectedFound<ty::PolyTraitRef<'tcx>>),
|
PolyTraitRefs(ExpectedFound<ty::PolyTraitRef<'tcx>>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'tcx> ValuePairs<'tcx> {
|
||||||
|
pub fn ty(&self) -> Option<(Ty<'tcx>, Ty<'tcx>)> {
|
||||||
|
if let ValuePairs::Terms(ExpectedFound {
|
||||||
|
expected: ty::Term::Ty(expected),
|
||||||
|
found: ty::Term::Ty(found),
|
||||||
|
}) = self
|
||||||
|
{
|
||||||
|
Some((expected, found))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// The trace designates the path through inference that we took to
|
/// The trace designates the path through inference that we took to
|
||||||
/// encounter an error or subtyping constraint.
|
/// encounter an error or subtyping constraint.
|
||||||
///
|
///
|
||||||
@ -1791,7 +1803,10 @@ impl<'tcx> TypeTrace<'tcx> {
|
|||||||
a: Ty<'tcx>,
|
a: Ty<'tcx>,
|
||||||
b: Ty<'tcx>,
|
b: Ty<'tcx>,
|
||||||
) -> TypeTrace<'tcx> {
|
) -> TypeTrace<'tcx> {
|
||||||
TypeTrace { cause: cause.clone(), values: Types(ExpectedFound::new(a_is_expected, a, b)) }
|
TypeTrace {
|
||||||
|
cause: cause.clone(),
|
||||||
|
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn consts(
|
pub fn consts(
|
||||||
@ -1800,7 +1815,10 @@ impl<'tcx> TypeTrace<'tcx> {
|
|||||||
a: &'tcx ty::Const<'tcx>,
|
a: &'tcx ty::Const<'tcx>,
|
||||||
b: &'tcx ty::Const<'tcx>,
|
b: &'tcx ty::Const<'tcx>,
|
||||||
) -> TypeTrace<'tcx> {
|
) -> TypeTrace<'tcx> {
|
||||||
TypeTrace { cause: cause.clone(), values: Consts(ExpectedFound::new(a_is_expected, a, b)) }
|
TypeTrace {
|
||||||
|
cause: cause.clone(),
|
||||||
|
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1378,26 +1378,11 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
|
|||||||
normalized_ty,
|
normalized_ty,
|
||||||
data.term,
|
data.term,
|
||||||
) {
|
) {
|
||||||
values = Some(match (normalized_ty, data.term) {
|
values = Some(infer::ValuePairs::Terms(ExpectedFound::new(
|
||||||
(ty::Term::Ty(normalized_ty), ty::Term::Ty(ty)) => {
|
is_normalized_ty_expected,
|
||||||
infer::ValuePairs::Types(ExpectedFound::new(
|
normalized_ty,
|
||||||
is_normalized_ty_expected,
|
data.term,
|
||||||
normalized_ty,
|
)));
|
||||||
ty,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
(ty::Term::Const(normalized_ct), ty::Term::Const(ct)) => {
|
|
||||||
infer::ValuePairs::Consts(ExpectedFound::new(
|
|
||||||
is_normalized_ty_expected,
|
|
||||||
normalized_ct,
|
|
||||||
ct,
|
|
||||||
))
|
|
||||||
}
|
|
||||||
(_, _) => span_bug!(
|
|
||||||
obligation.cause.span,
|
|
||||||
"found const or type where other expected"
|
|
||||||
),
|
|
||||||
});
|
|
||||||
err_buf = error;
|
err_buf = error;
|
||||||
err = &err_buf;
|
err = &err_buf;
|
||||||
}
|
}
|
||||||
|
@ -377,9 +377,9 @@ fn compare_predicate_entailment<'tcx>(
|
|||||||
&mut diag,
|
&mut diag,
|
||||||
&cause,
|
&cause,
|
||||||
trait_err_span.map(|sp| (sp, "type in trait".to_owned())),
|
trait_err_span.map(|sp| (sp, "type in trait".to_owned())),
|
||||||
Some(infer::ValuePairs::Types(ExpectedFound {
|
Some(infer::ValuePairs::Terms(ExpectedFound {
|
||||||
expected: trait_fty,
|
expected: trait_fty.into(),
|
||||||
found: impl_fty,
|
found: impl_fty.into(),
|
||||||
})),
|
})),
|
||||||
&terr,
|
&terr,
|
||||||
false,
|
false,
|
||||||
@ -1068,9 +1068,9 @@ crate fn compare_const_impl<'tcx>(
|
|||||||
&mut diag,
|
&mut diag,
|
||||||
&cause,
|
&cause,
|
||||||
trait_c_span.map(|span| (span, "type in trait".to_owned())),
|
trait_c_span.map(|span| (span, "type in trait".to_owned())),
|
||||||
Some(infer::ValuePairs::Types(ExpectedFound {
|
Some(infer::ValuePairs::Terms(ExpectedFound {
|
||||||
expected: trait_ty,
|
expected: trait_ty.into(),
|
||||||
found: impl_ty,
|
found: impl_ty.into(),
|
||||||
})),
|
})),
|
||||||
&terr,
|
&terr,
|
||||||
false,
|
false,
|
||||||
|
@ -4,8 +4,8 @@ error[E0308]: mismatched types
|
|||||||
LL | foo(());
|
LL | foo(());
|
||||||
| ^^^ lifetime mismatch
|
| ^^^ lifetime mismatch
|
||||||
|
|
|
|
||||||
= note: expected type `&'a ()`
|
= note: expected reference `&'a ()`
|
||||||
found type `&()`
|
found type `&()`
|
||||||
note: the lifetime requirement is introduced here
|
note: the lifetime requirement is introduced here
|
||||||
--> $DIR/higher-ranked-projection.rs:15:33
|
--> $DIR/higher-ranked-projection.rs:15:33
|
||||||
|
|
|
|
||||||
|
@ -23,8 +23,8 @@ error[E0308]: mismatched types
|
|||||||
LL | take_foo(|a: &i32| a);
|
LL | take_foo(|a: &i32| a);
|
||||||
| ^^^^^^^^ lifetime mismatch
|
| ^^^^^^^^ lifetime mismatch
|
||||||
|
|
|
|
||||||
= note: expected type `&i32`
|
= note: expected reference `&i32`
|
||||||
found type `&i32`
|
found reference `&i32`
|
||||||
note: the anonymous lifetime #1 defined here doesn't meet the lifetime requirements
|
note: the anonymous lifetime #1 defined here doesn't meet the lifetime requirements
|
||||||
--> $DIR/issue-79187-2.rs:9:14
|
--> $DIR/issue-79187-2.rs:9:14
|
||||||
|
|
|
|
||||||
@ -42,8 +42,8 @@ error[E0308]: mismatched types
|
|||||||
LL | take_foo(|a: &i32| -> &i32 { a });
|
LL | take_foo(|a: &i32| -> &i32 { a });
|
||||||
| ^^^^^^^^ lifetime mismatch
|
| ^^^^^^^^ lifetime mismatch
|
||||||
|
|
|
|
||||||
= note: expected type `&i32`
|
= note: expected reference `&i32`
|
||||||
found type `&i32`
|
found reference `&i32`
|
||||||
note: the anonymous lifetime #1 defined here doesn't meet the lifetime requirements
|
note: the anonymous lifetime #1 defined here doesn't meet the lifetime requirements
|
||||||
--> $DIR/issue-79187-2.rs:10:14
|
--> $DIR/issue-79187-2.rs:10:14
|
||||||
|
|
|
|
||||||
|
Loading…
Reference in New Issue
Block a user