Skip to content

Commit d3a89cd

Browse files
committed
Avoid an ICE in diagnostics
1 parent 09d73fa commit d3a89cd

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

Diff for: compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
698698
),
699699
..
700700
}) => {
701-
let hir::Ty { span, .. } = inputs[local.index() - 1];
701+
let hir::Ty { span, .. } = *inputs.get(local.index() - 1)?;
702702
Some(span)
703703
}
704704
_ => None,

Diff for: tests/ui/borrowck/argument_number_mismatch_ice.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
trait Hello {
2+
fn example(val: ());
3+
}
4+
5+
struct Test1(i32);
6+
7+
impl Hello for Test1 {
8+
fn example(&self, input: &i32) {
9+
//~^ ERROR `&self` declaration in the impl, but not in the trait
10+
*input = self.0;
11+
//~^ ERROR cannot assign to `*input`, which is behind a `&` reference
12+
}
13+
}
14+
15+
fn main() {}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0185]: method `example` has a `&self` declaration in the impl, but not in the trait
2+
--> $DIR/argument_number_mismatch_ice.rs:8:5
3+
|
4+
LL | fn example(val: ());
5+
| -------------------- trait method declared without `&self`
6+
...
7+
LL | fn example(&self, input: &i32) {
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&self` used in impl
9+
10+
error[E0594]: cannot assign to `*input`, which is behind a `&` reference
11+
--> $DIR/argument_number_mismatch_ice.rs:10:9
12+
|
13+
LL | *input = self.0;
14+
| ^^^^^^^^^^^^^^^ `input` is a `&` reference, so the data it refers to cannot be written
15+
16+
error: aborting due to 2 previous errors
17+
18+
Some errors have detailed explanations: E0185, E0594.
19+
For more information about an error, try `rustc --explain E0185`.

0 commit comments

Comments
 (0)