shrink const infer error

This commit is contained in:
Bastian Kauschke 2020-09-14 09:45:02 +02:00
parent 56d8a933b3
commit dd57275c3e
10 changed files with 57 additions and 10 deletions

View File

@ -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");

View 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`.

View 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`.

View 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
}

View File

@ -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

View File

@ -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