Skip to content

Commit f85b0c4

Browse files
committed
Remove use of unwrap() from save-analysis
1 parent 79cd224 commit f85b0c4

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

src/librustc_save_analysis/lib.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -533,14 +533,17 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
533533
match self.tables.expr_ty_adjusted(&hir_node).kind {
534534
ty::Adt(def, _) if !def.is_enum() => {
535535
let variant = &def.non_enum_variant();
536-
let index = self.tcx.find_field_index(ident, variant).unwrap();
537-
filter!(self.span_utils, ident.span);
538-
let span = self.span_from_span(ident.span);
539-
return Some(Data::RefData(Ref {
540-
kind: RefKind::Variable,
541-
span,
542-
ref_id: id_from_def_id(variant.fields[index].did),
543-
}));
536+
if let Some(index) = self.tcx.find_field_index(ident, variant) {
537+
filter!(self.span_utils, ident.span);
538+
let span = self.span_from_span(ident.span);
539+
return Some(Data::RefData(Ref {
540+
kind: RefKind::Variable,
541+
span,
542+
ref_id: id_from_def_id(variant.fields[index].did),
543+
}));
544+
}
545+
546+
None
544547
}
545548
ty::Tuple(..) => None,
546549
_ => {

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

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// compile-flags: -Zsave-analysis
2+
13
struct Cat {
24
meows : usize,
35

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
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:8
33
|
44
LL | nyan.speak = || println!("meow");
55
| ^^^^^
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:8
1111
|
1212
LL | nyan.speak += || println!("meow");
1313
| ^^^^^

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

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// compile-flags: -Zsave-analysis
2+
13
mod my_mod {
24
pub struct MyStruct {
35
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:17: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:20: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:23: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:25: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:26:16
2727
|
2828
LL | let nope = my_struct.priv_field;
2929
| ^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)