Skip to content

Commit aa7b5b3

Browse files
authored
Rollup merge of #105283 - compiler-errors:ty-var-in-hir-wfcheck, r=nagisa
Don't call `diagnostic_hir_wf_check` query if we have infer variables Fixes #105260
2 parents 668976b + 64ad337 commit aa7b5b3

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
597597
// can get a better error message by performing HIR-based well-formedness checking.
598598
if let ObligationCauseCode::WellFormed(Some(wf_loc)) =
599599
root_obligation.cause.code().peel_derives()
600+
&& !obligation.predicate.has_non_region_infer()
600601
{
601602
if let Some(cause) = self
602603
.tcx
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// incremental
2+
3+
trait Foo {
4+
type V;
5+
}
6+
7+
trait Callback<T: Foo>: Fn(&Bar<'_, T>, &T::V) {}
8+
9+
struct Bar<'a, T> {
10+
callback: Box<dyn Callback<dyn Callback<Bar<'a, T>>>>,
11+
//~^ ERROR the trait bound `Bar<'a, T>: Foo` is not satisfied
12+
//~| ERROR the trait bound `(dyn Callback<Bar<'a, T>, for<'b, 'c, 'd> Output = ()> + 'static): Foo` is not satisfied
13+
//~| ERROR the size for values of type `(dyn Callback<Bar<'a, T>, for<'b, 'c, 'd> Output = ()> + 'static)` cannot be known at compilation time
14+
}
15+
16+
impl<T: Foo> Bar<'_, Bar<'_, T>> {}
17+
18+
fn main() {}
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error[E0277]: the trait bound `Bar<'a, T>: Foo` is not satisfied
2+
--> $DIR/hir-wf-canonicalized.rs:10:15
3+
|
4+
LL | callback: Box<dyn Callback<dyn Callback<Bar<'a, T>>>>,
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `Bar<'a, T>`
6+
7+
error[E0277]: the trait bound `(dyn Callback<Bar<'a, T>, for<'b, 'c, 'd> Output = ()> + 'static): Foo` is not satisfied
8+
--> $DIR/hir-wf-canonicalized.rs:10:15
9+
|
10+
LL | callback: Box<dyn Callback<dyn Callback<Bar<'a, T>>>>,
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `(dyn Callback<Bar<'a, T>, for<'b, 'c, 'd> Output = ()> + 'static)`
12+
13+
error[E0277]: the size for values of type `(dyn Callback<Bar<'a, T>, for<'b, 'c, 'd> Output = ()> + 'static)` cannot be known at compilation time
14+
--> $DIR/hir-wf-canonicalized.rs:10:15
15+
|
16+
LL | callback: Box<dyn Callback<dyn Callback<Bar<'a, T>>>>,
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
18+
|
19+
= help: the trait `Sized` is not implemented for `(dyn Callback<Bar<'a, T>, for<'b, 'c, 'd> Output = ()> + 'static)`
20+
note: required by a bound in `Bar`
21+
--> $DIR/hir-wf-canonicalized.rs:9:16
22+
|
23+
LL | struct Bar<'a, T> {
24+
| ^ required by this bound in `Bar`
25+
help: consider relaxing the implicit `Sized` restriction
26+
|
27+
LL | struct Bar<'a, T: ?Sized> {
28+
| ++++++++
29+
30+
error: aborting due to 3 previous errors
31+
32+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)