Skip to content

Commit a0fb992

Browse files
committed
Fix AnonConst ICE
Add test Apply suggestions Switch to match Apply cargofmt
1 parent 84826fe commit a0fb992

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

compiler/rustc_typeck/src/collect/type_of.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
172172
// We've encountered an `AnonConst` in some path, so we need to
173173
// figure out which generic parameter it corresponds to and return
174174
// the relevant type.
175-
let (arg_index, segment) = path
175+
let filtered = path
176176
.segments
177177
.iter()
178178
.filter_map(|seg| seg.args.map(|args| (args.args, seg)))
@@ -181,10 +181,17 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<
181181
.filter(|arg| arg.is_const())
182182
.position(|arg| arg.id() == hir_id)
183183
.map(|index| (index, seg))
184-
})
185-
.unwrap_or_else(|| {
186-
bug!("no arg matching AnonConst in path");
187184
});
185+
let (arg_index, segment) = match filtered {
186+
None => {
187+
tcx.sess.delay_span_bug(
188+
tcx.def_span(def_id),
189+
"no arg matching AnonConst in path",
190+
);
191+
return None;
192+
}
193+
Some(inner) => inner,
194+
};
188195

189196
// Try to use the segment resolution if it is valid, otherwise we
190197
// default to the path resolution.

src/test/ui/typeck/issue-91267.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn main() {
2+
0: u8<e<5>=e>
3+
//~^ ERROR: cannot find type `e` in this scope [E0412]
4+
//~| ERROR: associated type bindings are not allowed here [E0229]
5+
//~| ERROR: mismatched types [E0308]
6+
}

src/test/ui/typeck/issue-91267.stderr

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0412]: cannot find type `e` in this scope
2+
--> $DIR/issue-91267.rs:2:16
3+
|
4+
LL | 0: u8<e<5>=e>
5+
| ^
6+
| |
7+
| not found in this scope
8+
| help: maybe you meant to write an assignment here: `let e`
9+
10+
error[E0229]: associated type bindings are not allowed here
11+
--> $DIR/issue-91267.rs:2:11
12+
|
13+
LL | 0: u8<e<5>=e>
14+
| ^^^^^^ associated type not allowed here
15+
16+
error[E0308]: mismatched types
17+
--> $DIR/issue-91267.rs:2:5
18+
|
19+
LL | fn main() {
20+
| - expected `()` because of default return type
21+
LL | 0: u8<e<5>=e>
22+
| ^^^^^^^^^^^^^ expected `()`, found `u8`
23+
24+
error: aborting due to 3 previous errors
25+
26+
Some errors have detailed explanations: E0229, E0308, E0412.
27+
For more information about an error, try `rustc --explain E0229`.

0 commit comments

Comments
 (0)