Skip to content

Commit 77cd5b5

Browse files
Rollup merge of #78249 - lcnr:ct-infer-origin, r=varkor
improve const infer error For type inference we probably have to be careful about subtyping and stuff but considering that subtyping shouldn't be relevant for constants I don't really see a reason why we may not want to reuse the const origin here. r? `@varkor`
2 parents 6b2ed99 + e1c524c commit 77cd5b5

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

compiler/rustc_middle/src/infer/unify_key.rs

+8-17
Original file line numberDiff line numberDiff line change
@@ -175,19 +175,15 @@ impl<'tcx> UnifyKey for ty::ConstVid<'tcx> {
175175
impl<'tcx> UnifyValue for ConstVarValue<'tcx> {
176176
type Error = (&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>);
177177

178-
fn unify_values(value1: &Self, value2: &Self) -> Result<Self, Self::Error> {
179-
let (val, span) = match (value1.val, value2.val) {
178+
fn unify_values(&value1: &Self, &value2: &Self) -> Result<Self, Self::Error> {
179+
Ok(match (value1.val, value2.val) {
180180
(ConstVariableValue::Known { .. }, ConstVariableValue::Known { .. }) => {
181181
bug!("equating two const variables, both of which have known values")
182182
}
183183

184184
// If one side is known, prefer that one.
185-
(ConstVariableValue::Known { .. }, ConstVariableValue::Unknown { .. }) => {
186-
(value1.val, value1.origin.span)
187-
}
188-
(ConstVariableValue::Unknown { .. }, ConstVariableValue::Known { .. }) => {
189-
(value2.val, value2.origin.span)
190-
}
185+
(ConstVariableValue::Known { .. }, ConstVariableValue::Unknown { .. }) => value1,
186+
(ConstVariableValue::Unknown { .. }, ConstVariableValue::Known { .. }) => value2,
191187

192188
// If both sides are *unknown*, it hardly matters, does it?
193189
(
@@ -200,16 +196,11 @@ impl<'tcx> UnifyValue for ConstVarValue<'tcx> {
200196
// universe is the minimum of the two universes, because that is
201197
// the one which contains the fewest names in scope.
202198
let universe = cmp::min(universe1, universe2);
203-
(ConstVariableValue::Unknown { universe }, value1.origin.span)
199+
ConstVarValue {
200+
val: ConstVariableValue::Unknown { universe },
201+
origin: value1.origin,
202+
}
204203
}
205-
};
206-
207-
Ok(ConstVarValue {
208-
origin: ConstVariableOrigin {
209-
kind: ConstVariableOriginKind::ConstInference,
210-
span: span,
211-
},
212-
val,
213204
})
214205
}
215206
}

src/test/ui/const-generics/infer/issue-77092.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
22
--> $DIR/issue-77092.rs:13:26
33
|
44
LL | println!("{:?}", take_array_from_mut(&mut arr, i));
5-
| ^^^^^^^^^^^^^^^^^^^ cannot infer the value of the constant `{_: usize}`
5+
| ^^^^^^^^^^^^^^^^^^^ cannot infer the value of const parameter `N` declared on the function `take_array_from_mut`
66

77
error: aborting due to previous error
88

0 commit comments

Comments
 (0)