Skip to content

Commit 60c38ee

Browse files
authored
Rollup merge of rust-lang#69422 - JohnTitor:remove-unwrap, r=Xanewok
Remove use of `unwrap()` from save-analysis Fix rust-lang#69409, fix rust-lang#69416
2 parents f943349 + 5307edc commit 60c38ee

File tree

6 files changed

+43
-35
lines changed

6 files changed

+43
-35
lines changed

src/librustc_save_analysis/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -532,13 +532,16 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
532532
match self.tables.expr_ty_adjusted(&hir_node).kind {
533533
ty::Adt(def, _) if !def.is_enum() => {
534534
let variant = &def.non_enum_variant();
535-
let index = self.tcx.find_field_index(ident, variant).unwrap();
536535
filter!(self.span_utils, ident.span);
537536
let span = self.span_from_span(ident.span);
538537
return Some(Data::RefData(Ref {
539538
kind: RefKind::Variable,
540539
span,
541-
ref_id: id_from_def_id(variant.fields[index].did),
540+
ref_id: self
541+
.tcx
542+
.find_field_index(ident, variant)
543+
.map(|index| id_from_def_id(variant.fields[index].did))
544+
.unwrap_or_else(|| null_id()),
542545
}));
543546
}
544547
ty::Tuple(..) => None,

src/test/ui/assign-to-method.rs

-22
This file was deleted.

src/test/ui/issues/issue-3763.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// compile-flags: -Zsave-analysis
2+
// Also regression test for #69416
3+
14
mod my_mod {
25
pub struct MyStruct {
36
priv_field: isize

src/test/ui/issues/issue-3763.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
error[E0616]: field `priv_field` of struct `my_mod::MyStruct` is private
2-
--> $DIR/issue-3763.rs:15:19
2+
--> $DIR/issue-3763.rs:18:19
33
|
44
LL | let _woohoo = (&my_struct).priv_field;
55
| ^^^^^^^^^^^^^^^^^^^^^^^
66

77
error[E0616]: field `priv_field` of struct `my_mod::MyStruct` is private
8-
--> $DIR/issue-3763.rs:18:19
8+
--> $DIR/issue-3763.rs:21:19
99
|
1010
LL | let _woohoo = (Box::new(my_struct)).priv_field;
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1212

1313
error[E0624]: method `happyfun` is private
14-
--> $DIR/issue-3763.rs:21:18
14+
--> $DIR/issue-3763.rs:24:18
1515
|
1616
LL | (&my_struct).happyfun();
1717
| ^^^^^^^^
1818

1919
error[E0624]: method `happyfun` is private
20-
--> $DIR/issue-3763.rs:23:27
20+
--> $DIR/issue-3763.rs:26:27
2121
|
2222
LL | (Box::new(my_struct)).happyfun();
2323
| ^^^^^^^^
2424

2525
error[E0616]: field `priv_field` of struct `my_mod::MyStruct` is private
26-
--> $DIR/issue-3763.rs:24:16
26+
--> $DIR/issue-3763.rs:27:16
2727
|
2828
LL | let nope = my_struct.priv_field;
2929
| ^^^^^^^^^^^^^^^^^^^^
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// compile-flags: -Zsave-analysis
2+
// Also regression test for #69409
3+
4+
struct Cat {
5+
meows : usize,
6+
how_hungry : isize,
7+
}
8+
9+
impl Cat {
10+
pub fn speak(&self) { self.meows += 1; }
11+
}
12+
13+
fn cat(in_x : usize, in_y : isize) -> Cat {
14+
Cat {
15+
meows: in_x,
16+
how_hungry: in_y
17+
}
18+
}
19+
20+
fn main() {
21+
let nyan : Cat = cat(52, 99);
22+
nyan.speak = || println!("meow"); //~ ERROR attempted to take value of method
23+
nyan.speak += || println!("meow"); //~ ERROR attempted to take value of method
24+
}

src/test/ui/assign-to-method.stderr src/test/ui/methods/assign-to-method.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
error[E0615]: attempted to take value of method `speak` on type `Cat`
2-
--> $DIR/assign-to-method.rs:20:8
2+
--> $DIR/assign-to-method.rs:22:10
33
|
4-
LL | nyan.speak = || println!("meow");
5-
| ^^^^^
4+
LL | nyan.speak = || println!("meow");
5+
| ^^^^^
66
|
77
= help: methods are immutable and cannot be assigned to
88

99
error[E0615]: attempted to take value of method `speak` on type `Cat`
10-
--> $DIR/assign-to-method.rs:21:8
10+
--> $DIR/assign-to-method.rs:23:10
1111
|
12-
LL | nyan.speak += || println!("meow");
13-
| ^^^^^
12+
LL | nyan.speak += || println!("meow");
13+
| ^^^^^
1414
|
1515
= help: methods are immutable and cannot be assigned to
1616

0 commit comments

Comments
 (0)