Skip to content

Commit bc80859

Browse files
authored
Unrolled build for rust-lang#121586
Rollup merge of rust-lang#121586 - gurry:121532-ice-unwrap-on-none, r=cjgillot Don't use `unwrap()` in `ArrayIntoIter` lint when typeck fails Fixes rust-lang#121532
2 parents 34aab62 + fa75571 commit bc80859

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

compiler/rustc_lint/src/array_into_iter.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,15 @@ impl<'tcx> LateLintPass<'tcx> for ArrayIntoIter {
7070

7171
// Check if the method call actually calls the libcore
7272
// `IntoIterator::into_iter`.
73-
let def_id = cx.typeck_results().type_dependent_def_id(expr.hir_id).unwrap();
74-
match cx.tcx.trait_of_item(def_id) {
75-
Some(trait_id) if cx.tcx.is_diagnostic_item(sym::IntoIterator, trait_id) => {}
76-
_ => return,
77-
};
73+
let trait_id = cx
74+
.typeck_results()
75+
.type_dependent_def_id(expr.hir_id)
76+
.and_then(|did| cx.tcx.trait_of_item(did));
77+
if trait_id.is_none()
78+
|| !cx.tcx.is_diagnostic_item(sym::IntoIterator, trait_id.unwrap())
79+
{
80+
return;
81+
}
7882

7983
// As this is a method call expression, we have at least one argument.
8084
let receiver_ty = cx.typeck_results().expr_ty(receiver_arg);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Regression test for #121532
2+
// Checks the we don't ICE in ArrayIntoIter
3+
// lint when typeck has failed
4+
5+
// Typeck fails for the arg type as
6+
// `Self` makes no sense here
7+
fn func(a: Self::ItemsIterator) { //~ ERROR failed to resolve: `Self` is only available in impls, traits, and type definitions
8+
a.into_iter();
9+
}
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0433]: failed to resolve: `Self` is only available in impls, traits, and type definitions
2+
--> $DIR/ice-array-into-iter-lint-issue-121532.rs:7:12
3+
|
4+
LL | fn func(a: Self::ItemsIterator) {
5+
| ^^^^ `Self` is only available in impls, traits, and type definitions
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0433`.

0 commit comments

Comments
 (0)