Skip to content

Commit 430bd39

Browse files
committed
Do not ICE on assoc type with bad placeholder
1 parent aca77cd commit 430bd39

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/librustc_typeck/collect.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -730,7 +730,13 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) {
730730
placeholder_type_error(tcx, None, &[], visitor.0, false);
731731
}
732732

733-
hir::TraitItemKind::Type(_, None) => {}
733+
hir::TraitItemKind::Type(_, None) => {
734+
// #74612: Visit and try to find bad placeholders
735+
// even if there is no concrete type.
736+
let mut visitor = PlaceholderHirTyCollector::default();
737+
visitor.visit_trait_item(trait_item);
738+
placeholder_type_error(tcx, None, &[], visitor.0, false);
739+
}
734740
};
735741

736742
tcx.ensure().predicates_of(def_id);

src/test/ui/typeck/typeck_type_placeholder_item.rs

+2
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ trait Qux {
194194
const D: _ = 42;
195195
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
196196
// type E: _; // FIXME: make the parser propagate the existence of `B`
197+
type F: std::ops::Fn(_);
198+
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
197199
}
198200
impl Qux for Struct {
199201
type A = _;

src/test/ui/typeck/typeck_type_placeholder_item.stderr

+12-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ LL | struct BadStruct2<_, T>(_, T);
2929
| ^ expected identifier, found reserved identifier
3030

3131
error: associated constant in `impl` without body
32-
--> $DIR/typeck_type_placeholder_item.rs:203:5
32+
--> $DIR/typeck_type_placeholder_item.rs:205:5
3333
|
3434
LL | const C: _;
3535
| ^^^^^^^^^^-
@@ -545,6 +545,12 @@ LL | const D: _ = 42;
545545
| not allowed in type signatures
546546
| help: replace `_` with the correct type: `i32`
547547

548+
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
549+
--> $DIR/typeck_type_placeholder_item.rs:197:26
550+
|
551+
LL | type F: std::ops::Fn(_);
552+
| ^ not allowed in type signatures
553+
548554
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
549555
--> $DIR/typeck_type_placeholder_item.rs:40:24
550556
|
@@ -582,33 +588,33 @@ LL | fn clone(&self) -> _ { FnTest9 }
582588
| help: replace with the correct return type: `main::FnTest9`
583589

584590
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
585-
--> $DIR/typeck_type_placeholder_item.rs:199:14
591+
--> $DIR/typeck_type_placeholder_item.rs:201:14
586592
|
587593
LL | type A = _;
588594
| ^ not allowed in type signatures
589595

590596
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
591-
--> $DIR/typeck_type_placeholder_item.rs:201:14
597+
--> $DIR/typeck_type_placeholder_item.rs:203:14
592598
|
593599
LL | type B = _;
594600
| ^ not allowed in type signatures
595601

596602
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
597-
--> $DIR/typeck_type_placeholder_item.rs:203:14
603+
--> $DIR/typeck_type_placeholder_item.rs:205:14
598604
|
599605
LL | const C: _;
600606
| ^ not allowed in type signatures
601607

602608
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
603-
--> $DIR/typeck_type_placeholder_item.rs:206:14
609+
--> $DIR/typeck_type_placeholder_item.rs:208:14
604610
|
605611
LL | const D: _ = 42;
606612
| ^
607613
| |
608614
| not allowed in type signatures
609615
| help: replace `_` with the correct type: `i32`
610616

611-
error: aborting due to 66 previous errors
617+
error: aborting due to 67 previous errors
612618

613619
Some errors have detailed explanations: E0121, E0282, E0403.
614620
For more information about an error, try `rustc --explain E0121`.

0 commit comments

Comments
 (0)