shrink const infer error
This commit is contained in:
parent
56d8a933b3
commit
dd57275c3e
@ -8,7 +8,7 @@ use rustc_hir::{Body, Expr, ExprKind, FnRetTy, HirId, Local, Pat};
|
||||
use rustc_middle::hir::map::Map;
|
||||
use rustc_middle::ty::print::Print;
|
||||
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
|
||||
use rustc_middle::ty::{self, DefIdTree, Ty};
|
||||
use rustc_middle::ty::{self, DefIdTree, InferConst, Ty};
|
||||
use rustc_span::source_map::DesugaringKind;
|
||||
use rustc_span::symbol::kw;
|
||||
use rustc_span::Span;
|
||||
@ -569,12 +569,15 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||
local_visitor.visit_expr(expr);
|
||||
}
|
||||
|
||||
let span = if let ty::ConstKind::Infer(InferConst::Var(vid)) = ct.val {
|
||||
self.inner.borrow_mut().const_unification_table().probe_value(vid).origin.span
|
||||
} else {
|
||||
local_visitor.target_span
|
||||
};
|
||||
|
||||
let error_code = error_code.into();
|
||||
let mut err = self.tcx.sess.struct_span_err_with_code(
|
||||
local_visitor.target_span,
|
||||
"type annotations needed",
|
||||
error_code,
|
||||
);
|
||||
let mut err =
|
||||
self.tcx.sess.struct_span_err_with_code(span, "type annotations needed", error_code);
|
||||
|
||||
err.note("unable to infer the value of a const parameter");
|
||||
|
||||
|
11
src/test/ui/const-generics/infer/method-chain.full.stderr
Normal file
11
src/test/ui/const-generics/infer/method-chain.full.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/method-chain.rs:21:33
|
||||
|
|
||||
LL | Foo.bar().bar().bar().bar().baz();
|
||||
| ^^^
|
||||
|
|
||||
= note: unable to infer the value of a const parameter
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
11
src/test/ui/const-generics/infer/method-chain.min.stderr
Normal file
11
src/test/ui/const-generics/infer/method-chain.min.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/method-chain.rs:21:33
|
||||
|
|
||||
LL | Foo.bar().bar().bar().bar().baz();
|
||||
| ^^^
|
||||
|
|
||||
= note: unable to infer the value of a const parameter
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0282`.
|
22
src/test/ui/const-generics/infer/method-chain.rs
Normal file
22
src/test/ui/const-generics/infer/method-chain.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// revisions: full min
|
||||
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
struct Foo;
|
||||
|
||||
impl Foo {
|
||||
fn bar(self) -> Foo {
|
||||
Foo
|
||||
}
|
||||
|
||||
fn baz<const N: usize>(self) -> Foo {
|
||||
println!("baz: {}", N);
|
||||
Foo
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
Foo.bar().bar().bar().bar().baz(); //~ ERROR type annotations needed
|
||||
}
|
@ -1,8 +1,8 @@
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/uninferred-consts.rs:14:5
|
||||
--> $DIR/uninferred-consts.rs:14:9
|
||||
|
|
||||
LL | Foo.foo();
|
||||
| ^^^^^^^^^
|
||||
| ^^^
|
||||
|
|
||||
= note: unable to infer the value of a const parameter
|
||||
|
@ -1,8 +1,8 @@
|
||||
error[E0282]: type annotations needed
|
||||
--> $DIR/uninferred-consts.rs:14:5
|
||||
--> $DIR/uninferred-consts.rs:14:9
|
||||
|
|
||||
LL | Foo.foo();
|
||||
| ^^^^^^^^^
|
||||
| ^^^
|
||||
|
|
||||
= note: unable to infer the value of a const parameter
|
||||
|
Loading…
x
Reference in New Issue
Block a user