Skip to content

Commit 5ad0ed5

Browse files
Rollup merge of rust-lang#119944 - compiler-errors:no-match-due-to-gat-bounds, r=fmease
Don't ICE when noting GAT bounds in `report_no_match_method_error` We can encounter `BindingObligation`s from GATs that we should handle in `report_no_match_method_error`. I assume we can encounter them from methods, though I didn't really feel like wasting my time creating a repro. Fixes rust-lang#119942
2 parents 8847bda + 0b45ff5 commit 5ad0ed5

File tree

3 files changed

+96
-6
lines changed

3 files changed

+96
-6
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -825,11 +825,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
825825
"auto trait is invoked with no method error, but no error reported?",
826826
);
827827
}
828-
Some(Node::Item(hir::Item {
829-
ident,
830-
kind: hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..),
831-
..
832-
})) => {
828+
Some(
829+
Node::Item(hir::Item {
830+
ident,
831+
kind: hir::ItemKind::Trait(..) | hir::ItemKind::TraitAlias(..),
832+
..
833+
})
834+
// We may also encounter unsatisfied GAT or method bounds
835+
| Node::TraitItem(hir::TraitItem { ident, .. })
836+
| Node::ImplItem(hir::ImplItem { ident, .. }),
837+
) => {
833838
skip_list.insert(p);
834839
let entry = spanned_predicates.entry(ident.span);
835840
let entry = entry.or_insert_with(|| {
@@ -840,7 +845,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
840845
entry.1.insert((cause_span, "unsatisfied trait bound introduced here"));
841846
entry.2.push(p);
842847
}
843-
Some(node) => unreachable!("encountered `{node:?}`"),
848+
Some(node) => unreachable!("encountered `{node:?}` due to `{cause:#?}`"),
844849
None => (),
845850
}
846851
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use std::ops::Deref;
2+
3+
trait PointerFamily {
4+
type Pointer<T>: Deref<Target = T>;
5+
}
6+
7+
struct RcFamily;
8+
9+
impl PointerFamily for RcFamily {
10+
type Pointer<T> = dyn Deref<Target = T>;
11+
//~^ ERROR the size for values of type `(dyn Deref<Target = T> + 'static)` cannot be known at compilation time
12+
}
13+
14+
enum Node<T, P: PointerFamily> {
15+
Cons(T, P::Pointer<Node<T, P>>),
16+
Nil,
17+
}
18+
19+
type RcNode<T> = Node<T, RcFamily>;
20+
21+
impl<T, P: PointerFamily> Node<T, P>
22+
where
23+
P::Pointer<Node<T, P>>: Sized,
24+
{
25+
fn new() -> P::Pointer<Self> {
26+
todo!()
27+
}
28+
}
29+
30+
fn main() {
31+
let mut list = RcNode::<i32>::new();
32+
//~^ ERROR the size for values of type `Node<i32, RcFamily>` cannot be known at compilation time
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
error[E0277]: the size for values of type `(dyn Deref<Target = T> + 'static)` cannot be known at compilation time
2+
--> $DIR/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs:10:23
3+
|
4+
LL | type Pointer<T> = dyn Deref<Target = T>;
5+
| ^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
6+
|
7+
= help: the trait `Sized` is not implemented for `(dyn Deref<Target = T> + 'static)`
8+
note: required by a bound in `PointerFamily::Pointer`
9+
--> $DIR/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs:4:5
10+
|
11+
LL | type Pointer<T>: Deref<Target = T>;
12+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `PointerFamily::Pointer`
13+
help: consider relaxing the implicit `Sized` restriction
14+
|
15+
LL | type Pointer<T>: Deref<Target = T> + ?Sized;
16+
| ++++++++
17+
18+
error[E0599]: the size for values of type `Node<i32, RcFamily>` cannot be known at compilation time
19+
--> $DIR/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs:31:35
20+
|
21+
LL | enum Node<T, P: PointerFamily> {
22+
| ------------------------------
23+
| |
24+
| variant or associated item `new` not found for this enum
25+
| doesn't satisfy `Node<i32, RcFamily>: Sized`
26+
...
27+
LL | let mut list = RcNode::<i32>::new();
28+
| ^^^ doesn't have a size known at compile-time
29+
--> $SRC_DIR/core/src/ops/deref.rs:LL:COL
30+
|
31+
= note: doesn't satisfy `_: Sized`
32+
|
33+
note: trait bound `Node<i32, RcFamily>: Sized` was not satisfied
34+
--> $DIR/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs:4:18
35+
|
36+
LL | type Pointer<T>: Deref<Target = T>;
37+
| ------- ^ unsatisfied trait bound introduced here
38+
note: trait bound `(dyn Deref<Target = Node<i32, RcFamily>> + 'static): Sized` was not satisfied
39+
--> $DIR/issue-119942-unsatisified-gat-bound-during-assoc-ty-selection.rs:23:29
40+
|
41+
LL | impl<T, P: PointerFamily> Node<T, P>
42+
| ----------
43+
LL | where
44+
LL | P::Pointer<Node<T, P>>: Sized,
45+
| ^^^^^ unsatisfied trait bound introduced here
46+
note: the trait `Sized` must be implemented
47+
--> $SRC_DIR/core/src/marker.rs:LL:COL
48+
49+
error: aborting due to 2 previous errors
50+
51+
Some errors have detailed explanations: E0277, E0599.
52+
For more information about an error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)