diff options
| author | bors <bors@rust-lang.org> | 2021-08-20 02:19:58 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-08-20 02:19:58 +0000 |
| commit | 7611fe438dae91084d17022e705bf64374d5ba4b (patch) | |
| tree | 03dcc117fc7b641555c17f2608d71c317687a239 /compiler | |
| parent | ebedfedcd82678d5b0592227ca5e6ca31a5afb8f (diff) | |
| parent | 9c32b5b3ba4a139e26d30486513929ce16391eec (diff) | |
| download | rust-7611fe438dae91084d17022e705bf64374d5ba4b.tar.gz rust-7611fe438dae91084d17022e705bf64374d5ba4b.zip | |
Auto merge of #88039 - sexxi-goose:fix-87987, r=nikomatsakis
RFC2229 Only compute place if upvars can be resolved Closes https://github.com/rust-lang/rust/issues/87987 This PR fixes an ICE when trying to unwrap an Err. This error appears when trying to convert a PlaceBuilder into Place when upvars can't yet be resolved. We should only try to convert a PlaceBuilder into Place if upvars can be resolved. r? `@nikomatsakis`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_mir_build/src/build/matches/simplify.rs | 38 | ||||
| -rw-r--r-- | compiler/rustc_mir_build/src/build/matches/util.rs | 21 |
2 files changed, 36 insertions, 23 deletions
diff --git a/compiler/rustc_mir_build/src/build/matches/simplify.rs b/compiler/rustc_mir_build/src/build/matches/simplify.rs index 13cfc3695cc..1feb8b0d7a0 100644 --- a/compiler/rustc_mir_build/src/build/matches/simplify.rs +++ b/compiler/rustc_mir_build/src/build/matches/simplify.rs @@ -155,12 +155,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ascription: thir::Ascription { variance, user_ty, user_ty_span }, } => { // Apply the type ascription to the value at `match_pair.place`, which is the - candidate.ascriptions.push(Ascription { - span: user_ty_span, - user_ty, - source: match_pair.place.clone().into_place(self.tcx, self.typeck_results), - variance, - }); + if let Ok(place_resolved) = + match_pair.place.clone().try_upvars_resolved(self.tcx, self.typeck_results) + { + candidate.ascriptions.push(Ascription { + span: user_ty_span, + user_ty, + source: place_resolved.into_place(self.tcx, self.typeck_results), + variance, + }); + } candidate.match_pairs.push(MatchPair::new(match_pair.place, subpattern)); @@ -173,15 +177,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } PatKind::Binding { name, mutability, mode, var, ty, ref subpattern, is_primary: _ } => { - candidate.bindings.push(Binding { - name, - mutability, - span: match_pair.pattern.span, - source: match_pair.place.clone().into_place(self.tcx, self.typeck_results), - var_id: var, - var_ty: ty, - binding_mode: mode, - }); + if let Ok(place_resolved) = + match_pair.place.clone().try_upvars_resolved(self.tcx, self.typeck_results) + { + candidate.bindings.push(Binding { + name, + mutability, + span: match_pair.pattern.span, + source: place_resolved.into_place(self.tcx, self.typeck_results), + var_id: var, + var_ty: ty, + binding_mode: mode, + }); + } if let Some(subpattern) = subpattern.as_ref() { // this is the `x @ P` case; have to keep matching against `P` now diff --git a/compiler/rustc_mir_build/src/build/matches/util.rs b/compiler/rustc_mir_build/src/build/matches/util.rs index 3cf8ae6efd9..88dd76e37c1 100644 --- a/compiler/rustc_mir_build/src/build/matches/util.rs +++ b/compiler/rustc_mir_build/src/build/matches/util.rs @@ -31,15 +31,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { suffix: &'pat [Pat<'tcx>], ) { let tcx = self.tcx; - let (min_length, exact_size) = match place - .clone() - .into_place(tcx, self.typeck_results) - .ty(&self.local_decls, tcx) - .ty - .kind() + let (min_length, exact_size) = if let Ok(place_resolved) = + place.clone().try_upvars_resolved(tcx, self.typeck_results) { - ty::Array(_, length) => (length.eval_usize(tcx, self.param_env), true), - _ => ((prefix.len() + suffix.len()).try_into().unwrap(), false), + match place_resolved + .into_place(tcx, self.typeck_results) + .ty(&self.local_decls, tcx) + .ty + .kind() + { + ty::Array(_, length) => (length.eval_usize(tcx, self.param_env), true), + _ => ((prefix.len() + suffix.len()).try_into().unwrap(), false), + } + } else { + ((prefix.len() + suffix.len()).try_into().unwrap(), false) }; match_pairs.extend(prefix.iter().enumerate().map(|(idx, subpattern)| { |
