Fix ICE with let...else and ref mut · Dylan-DPC/rust@bf7c32a (original) (raw)

`@@ -45,12 +45,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {

`

45

45

`let item_msg;

`

46

46

`let reason;

`

47

47

`let mut opt_source = None;

`

48

``

`-

let access_place_desc = self.describe_place(access_place.as_ref());

`

``

48

`+

let access_place_desc = self.describe_any_place(access_place.as_ref());

`

49

49

`debug!("report_mutability_error: access_place_desc={:?}", access_place_desc);

`

50

50

``

51

51

`match the_place_err {

`

52

52

`PlaceRef { local, projection: [] } => {

`

53

``

`` -

item_msg = format!("{}", access_place_desc.unwrap());

``

``

53

`+

item_msg = access_place_desc;

`

54

54

`if access_place.as_local().is_some() {

`

55

55

` reason = ", as it is not declared as mutable".to_string();

`

56

56

`} else {

`

`@@ -83,7 +83,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {

`

83

83

`// If we deref an immutable ref then the suggestion here doesn't help.

`

84

84

`return;

`

85

85

`} else {

`

86

``

`` -

item_msg = format!("{}", access_place_desc.unwrap());

``

``

86

`+

item_msg = access_place_desc;

`

87

87

`if self.is_upvar_field_projection(access_place.as_ref()).is_some() {

`

88

88

` reason = ", as it is not declared as mutable".to_string();

`

89

89

`} else {

`

`@@ -96,17 +96,17 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {

`

96

96

`PlaceRef { local, projection: [ProjectionElem::Deref] }

`

97

97

`if self.body.local_decls[local].is_ref_for_guard() =>

`

98

98

`{

`

99

``

`` -

item_msg = format!("{}", access_place_desc.unwrap());

``

``

99

`+

item_msg = access_place_desc;

`

100

100

` reason = ", as it is immutable for the pattern guard".to_string();

`

101

101

`}

`

102

102

`PlaceRef { local, projection: [ProjectionElem::Deref] }

`

103

103

`if self.body.local_decls[local].is_ref_to_static() =>

`

104

104

`{

`

105

105

`if access_place.projection.len() == 1 {

`

106

``

`` -

item_msg = format!("immutable static item {}", access_place_desc.unwrap());

``

``

106

`+

item_msg = format!("immutable static item {}", access_place_desc);

`

107

107

` reason = String::new();

`

108

108

`} else {

`

109

``

`` -

item_msg = format!("{}", access_place_desc.unwrap());

``

``

109

`+

item_msg = access_place_desc;

`

110

110

`let local_info = &self.body.local_decls[local].local_info;

`

111

111

`if let Some(box LocalInfo::StaticRef { def_id, .. }) = *local_info {

`

112

112

`let static_name = &self.infcx.tcx.item_name(def_id);

`

`@@ -121,7 +121,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {

`

121

121

` && proj_base.is_empty()

`

122

122

` && !self.upvars.is_empty()

`

123

123

`{

`

124

``

`` -

item_msg = format!("{}", access_place_desc.unwrap());

``

``

124

`+

item_msg = access_place_desc;

`

125

125

`debug_assert!(

`

126

126

`self.body.local_decls[ty::CAPTURE_STRUCT_LOCAL].ty.is_region_ptr()

`

127

127

`);

`

`@@ -147,7 +147,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {

`

147

147

`});

`

148

148

`let pointer_type = source.describe_for_immutable_place(self.infcx.tcx);

`

149

149

` opt_source = Some(source);

`

150

``

`-

if let Some(desc) = access_place_desc {

`

``

150

`+

if let Some(desc) = self.describe_place(access_place.as_ref()) {

`

151

151

`` item_msg = format!("{}", desc);

``

152

152

` reason = match error_access {

`

153

153

`AccessKind::Mutate => format!(", which is behind {}", pointer_type),

`