improve const infer error
This commit is contained in:
parent
a9cd294cf2
commit
40ab18d97d
2 changed files with 6 additions and 12 deletions
|
@ -176,17 +176,17 @@ impl<'tcx> UnifyValue for ConstVarValue<'tcx> {
|
||||||
type Error = (&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>);
|
type Error = (&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>);
|
||||||
|
|
||||||
fn unify_values(value1: &Self, value2: &Self) -> Result<Self, Self::Error> {
|
fn unify_values(value1: &Self, value2: &Self) -> Result<Self, Self::Error> {
|
||||||
let (val, span) = match (value1.val, value2.val) {
|
let (val, origin) = match (value1.val, value2.val) {
|
||||||
(ConstVariableValue::Known { .. }, ConstVariableValue::Known { .. }) => {
|
(ConstVariableValue::Known { .. }, ConstVariableValue::Known { .. }) => {
|
||||||
bug!("equating two const variables, both of which have known values")
|
bug!("equating two const variables, both of which have known values")
|
||||||
}
|
}
|
||||||
|
|
||||||
// If one side is known, prefer that one.
|
// If one side is known, prefer that one.
|
||||||
(ConstVariableValue::Known { .. }, ConstVariableValue::Unknown { .. }) => {
|
(ConstVariableValue::Known { .. }, ConstVariableValue::Unknown { .. }) => {
|
||||||
(value1.val, value1.origin.span)
|
(value1.val, value1.origin)
|
||||||
}
|
}
|
||||||
(ConstVariableValue::Unknown { .. }, ConstVariableValue::Known { .. }) => {
|
(ConstVariableValue::Unknown { .. }, ConstVariableValue::Known { .. }) => {
|
||||||
(value2.val, value2.origin.span)
|
(value2.val, value2.origin)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If both sides are *unknown*, it hardly matters, does it?
|
// If both sides are *unknown*, it hardly matters, does it?
|
||||||
|
@ -200,17 +200,11 @@ impl<'tcx> UnifyValue for ConstVarValue<'tcx> {
|
||||||
// universe is the minimum of the two universes, because that is
|
// universe is the minimum of the two universes, because that is
|
||||||
// the one which contains the fewest names in scope.
|
// the one which contains the fewest names in scope.
|
||||||
let universe = cmp::min(universe1, universe2);
|
let universe = cmp::min(universe1, universe2);
|
||||||
(ConstVariableValue::Unknown { universe }, value1.origin.span)
|
(ConstVariableValue::Unknown { universe }, value1.origin)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(ConstVarValue {
|
Ok(ConstVarValue { origin, val })
|
||||||
origin: ConstVariableOrigin {
|
|
||||||
kind: ConstVariableOriginKind::ConstInference,
|
|
||||||
span: span,
|
|
||||||
},
|
|
||||||
val,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ error[E0282]: type annotations needed
|
||||||
--> $DIR/issue-77092.rs:13:26
|
--> $DIR/issue-77092.rs:13:26
|
||||||
|
|
|
|
||||||
LL | println!("{:?}", take_array_from_mut(&mut arr, i));
|
LL | println!("{:?}", take_array_from_mut(&mut arr, i));
|
||||||
| ^^^^^^^^^^^^^^^^^^^ cannot infer the value of the constant `{_: usize}`
|
| ^^^^^^^^^^^^^^^^^^^ cannot infer the value of const parameter `N` declared on the function `take_array_from_mut`
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue