Move Sized check before first error is created
This commit is contained in:
parent
12ab6bfafd
commit
6711313f76
4 changed files with 38 additions and 41 deletions
|
@ -1958,6 +1958,37 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
if predicate.references_error() {
|
if predicate.references_error() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is kind of a hack: it frequently happens that some earlier
|
||||||
|
// error prevents types from being fully inferred, and then we get
|
||||||
|
// a bunch of uninteresting errors saying something like "<generic
|
||||||
|
// #0> doesn't implement Sized". It may even be true that we
|
||||||
|
// could just skip over all checks where the self-ty is an
|
||||||
|
// inference variable, but I was afraid that there might be an
|
||||||
|
// inference variable created, registered as an obligation, and
|
||||||
|
// then never forced by writeback, and hence by skipping here we'd
|
||||||
|
// be ignoring the fact that we don't KNOW the type works
|
||||||
|
// out. Though even that would probably be harmless, given that
|
||||||
|
// we're only talking about builtin traits, which are known to be
|
||||||
|
// inhabited. We used to check for `self.tcx.sess.has_errors()` to
|
||||||
|
// avoid inundating the user with unnecessary errors, but we now
|
||||||
|
// check upstream for type errors and don't add the obligations to
|
||||||
|
// begin with in those cases.
|
||||||
|
if self.tcx.lang_items().sized_trait() == Some(trait_ref.def_id()) {
|
||||||
|
if !self.is_tainted_by_errors() {
|
||||||
|
self.emit_inference_failure_err(
|
||||||
|
body_id,
|
||||||
|
span,
|
||||||
|
trait_ref.self_ty().skip_binder().into(),
|
||||||
|
vec![],
|
||||||
|
ErrorCode::E0282,
|
||||||
|
false,
|
||||||
|
)
|
||||||
|
.emit();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Typically, this ambiguity should only happen if
|
// Typically, this ambiguity should only happen if
|
||||||
// there are unresolved type inference variables
|
// there are unresolved type inference variables
|
||||||
// (otherwise it would suggest a coherence
|
// (otherwise it would suggest a coherence
|
||||||
|
@ -1997,37 +2028,6 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is kind of a hack: it frequently happens that some earlier
|
|
||||||
// error prevents types from being fully inferred, and then we get
|
|
||||||
// a bunch of uninteresting errors saying something like "<generic
|
|
||||||
// #0> doesn't implement Sized". It may even be true that we
|
|
||||||
// could just skip over all checks where the self-ty is an
|
|
||||||
// inference variable, but I was afraid that there might be an
|
|
||||||
// inference variable created, registered as an obligation, and
|
|
||||||
// then never forced by writeback, and hence by skipping here we'd
|
|
||||||
// be ignoring the fact that we don't KNOW the type works
|
|
||||||
// out. Though even that would probably be harmless, given that
|
|
||||||
// we're only talking about builtin traits, which are known to be
|
|
||||||
// inhabited. We used to check for `self.tcx.sess.has_errors()` to
|
|
||||||
// avoid inundating the user with unnecessary errors, but we now
|
|
||||||
// check upstream for type errors and don't add the obligations to
|
|
||||||
// begin with in those cases.
|
|
||||||
if self.tcx.lang_items().sized_trait() == Some(trait_ref.def_id()) {
|
|
||||||
if !self.is_tainted_by_errors() {
|
|
||||||
self.emit_inference_failure_err(
|
|
||||||
body_id,
|
|
||||||
span,
|
|
||||||
trait_ref.self_ty().skip_binder().into(),
|
|
||||||
vec![],
|
|
||||||
ErrorCode::E0282,
|
|
||||||
false,
|
|
||||||
)
|
|
||||||
.emit();
|
|
||||||
}
|
|
||||||
err.cancel();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
let obligation = Obligation::new(
|
let obligation = Obligation::new(
|
||||||
obligation.cause.clone(),
|
obligation.cause.clone(),
|
||||||
obligation.param_env,
|
obligation.param_env,
|
||||||
|
|
|
@ -2,9 +2,8 @@ error[E0282]: type annotations needed
|
||||||
--> $DIR/branches3.rs:8:10
|
--> $DIR/branches3.rs:8:10
|
||||||
|
|
|
|
||||||
LL | |s| s.len()
|
LL | |s| s.len()
|
||||||
| ^
|
| ^ - type must be known at this point
|
||||||
|
|
|
|
||||||
= note: type must be known at this point
|
|
||||||
help: consider giving this closure parameter an explicit type
|
help: consider giving this closure parameter an explicit type
|
||||||
|
|
|
|
||||||
LL | |s: _| s.len()
|
LL | |s: _| s.len()
|
||||||
|
@ -14,9 +13,8 @@ error[E0282]: type annotations needed
|
||||||
--> $DIR/branches3.rs:15:10
|
--> $DIR/branches3.rs:15:10
|
||||||
|
|
|
|
||||||
LL | |s| s.len()
|
LL | |s| s.len()
|
||||||
| ^
|
| ^ - type must be known at this point
|
||||||
|
|
|
|
||||||
= note: type must be known at this point
|
|
||||||
help: consider giving this closure parameter an explicit type
|
help: consider giving this closure parameter an explicit type
|
||||||
|
|
|
|
||||||
LL | |s: _| s.len()
|
LL | |s: _| s.len()
|
||||||
|
@ -26,9 +24,8 @@ error[E0282]: type annotations needed
|
||||||
--> $DIR/branches3.rs:23:10
|
--> $DIR/branches3.rs:23:10
|
||||||
|
|
|
|
||||||
LL | |s| s.len()
|
LL | |s| s.len()
|
||||||
| ^
|
| ^ - type must be known at this point
|
||||||
|
|
|
|
||||||
= note: type must be known at this point
|
|
||||||
help: consider giving this closure parameter an explicit type
|
help: consider giving this closure parameter an explicit type
|
||||||
|
|
|
|
||||||
LL | |s: _| s.len()
|
LL | |s: _| s.len()
|
||||||
|
@ -38,9 +35,8 @@ error[E0282]: type annotations needed
|
||||||
--> $DIR/branches3.rs:30:10
|
--> $DIR/branches3.rs:30:10
|
||||||
|
|
|
|
||||||
LL | |s| s.len()
|
LL | |s| s.len()
|
||||||
| ^
|
| ^ - type must be known at this point
|
||||||
|
|
|
|
||||||
= note: type must be known at this point
|
|
||||||
help: consider giving this closure parameter an explicit type
|
help: consider giving this closure parameter an explicit type
|
||||||
|
|
|
|
||||||
LL | |s: _| s.len()
|
LL | |s: _| s.len()
|
||||||
|
|
|
@ -2,9 +2,8 @@ error[E0282]: type annotations needed
|
||||||
--> $DIR/closures_in_branches.rs:7:10
|
--> $DIR/closures_in_branches.rs:7:10
|
||||||
|
|
|
|
||||||
LL | |x| x.len()
|
LL | |x| x.len()
|
||||||
| ^
|
| ^ - type must be known at this point
|
||||||
|
|
|
|
||||||
= note: type must be known at this point
|
|
||||||
help: consider giving this closure parameter an explicit type
|
help: consider giving this closure parameter an explicit type
|
||||||
|
|
|
|
||||||
LL | |x: _| x.len()
|
LL | |x: _| x.len()
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
error[E0283]: type annotations needed
|
error[E0283]: type annotations needed
|
||||||
--> $DIR/fallback.rs:24:5
|
--> $DIR/fallback.rs:24:5
|
||||||
|
|
|
|
||||||
|
LL | fn unconstrained_foo() -> Wrapper<Foo> {
|
||||||
|
| ------------ type must be known at this point
|
||||||
LL | Wrapper::Second
|
LL | Wrapper::Second
|
||||||
| ^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the enum `Wrapper`
|
| ^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the enum `Wrapper`
|
||||||
|
|
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue