Skip to content

Commit 40ab18d

Browse files
committed
improve const infer error
1 parent a9cd294 commit 40ab18d

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

compiler/rustc_middle/src/infer/unify_key.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,17 @@ impl<'tcx> UnifyValue for ConstVarValue<'tcx> {
176176
type Error = (&'tcx ty::Const<'tcx>, &'tcx ty::Const<'tcx>);
177177

178178
fn unify_values(value1: &Self, value2: &Self) -> Result<Self, Self::Error> {
179-
let (val, span) = match (value1.val, value2.val) {
179+
let (val, origin) = 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.
185185
(ConstVariableValue::Known { .. }, ConstVariableValue::Unknown { .. }) => {
186-
(value1.val, value1.origin.span)
186+
(value1.val, value1.origin)
187187
}
188188
(ConstVariableValue::Unknown { .. }, ConstVariableValue::Known { .. }) => {
189-
(value2.val, value2.origin.span)
189+
(value2.val, value2.origin)
190190
}
191191

192192
// If both sides are *unknown*, it hardly matters, does it?
@@ -200,17 +200,11 @@ impl<'tcx> UnifyValue for ConstVarValue<'tcx> {
200200
// universe is the minimum of the two universes, because that is
201201
// the one which contains the fewest names in scope.
202202
let universe = cmp::min(universe1, universe2);
203-
(ConstVariableValue::Unknown { universe }, value1.origin.span)
203+
(ConstVariableValue::Unknown { universe }, value1.origin)
204204
}
205205
};
206206

207-
Ok(ConstVarValue {
208-
origin: ConstVariableOrigin {
209-
kind: ConstVariableOriginKind::ConstInference,
210-
span: span,
211-
},
212-
val,
213-
})
207+
Ok(ConstVarValue { origin, val })
214208
}
215209
}
216210

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)