Rollup merge of #137712 - meithecatte:extract-binding-mode, r=oli-obk
Clean up TypeckResults::extract_binding_mode - Remove the `Option` from the result type, as `None` is never returned. - Document the difference from the `BindingMode` in `PatKind::Binding`.
This commit is contained in:
commit
a9f3f02ed7
5 changed files with 45 additions and 45 deletions
|
@ -1683,6 +1683,12 @@ pub enum PatKind<'hir> {
|
|||
/// The `HirId` is the canonical ID for the variable being bound,
|
||||
/// (e.g., in `Ok(x) | Err(x)`, both `x` use the same canonical ID),
|
||||
/// which is the pattern ID of the first `x`.
|
||||
///
|
||||
/// The `BindingMode` is what's provided by the user, before match
|
||||
/// ergonomics are applied. For the binding mode actually in use,
|
||||
/// see [`TypeckResults::extract_binding_mode`].
|
||||
///
|
||||
/// [`TypeckResults::extract_binding_mode`]: ../../rustc_middle/ty/struct.TypeckResults.html#method.extract_binding_mode
|
||||
Binding(BindingMode, HirId, Ident, Option<&'hir Pat<'hir>>),
|
||||
|
||||
/// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`).
|
||||
|
|
|
@ -895,11 +895,10 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
|
|||
match pat.kind {
|
||||
PatKind::Binding(_, canonical_id, ..) => {
|
||||
debug!("walk_pat: binding place={:?} pat={:?}", place, pat);
|
||||
if let Some(bm) = self
|
||||
let bm = self
|
||||
.cx
|
||||
.typeck_results()
|
||||
.extract_binding_mode(tcx.sess, pat.hir_id, pat.span)
|
||||
{
|
||||
.extract_binding_mode(tcx.sess, pat.hir_id, pat.span);
|
||||
debug!("walk_pat: pat.hir_id={:?} bm={:?}", pat.hir_id, bm);
|
||||
|
||||
// pat_ty: the type of the binding being produced.
|
||||
|
@ -907,9 +906,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
|
|||
debug!("walk_pat: pat_ty={:?}", pat_ty);
|
||||
|
||||
let def = Res::Local(canonical_id);
|
||||
if let Ok(ref binding_place) =
|
||||
self.cat_res(pat.hir_id, pat.span, pat_ty, def)
|
||||
{
|
||||
if let Ok(ref binding_place) = self.cat_res(pat.hir_id, pat.span, pat_ty, def) {
|
||||
self.delegate.borrow_mut().bind(binding_place, binding_place.hir_id);
|
||||
}
|
||||
|
||||
|
@ -939,7 +936,6 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
PatKind::Deref(subpattern) => {
|
||||
// A deref pattern is a bit special: the binding mode of its inner bindings
|
||||
// determines whether to borrow *at the level of the deref pattern* rather than
|
||||
|
|
|
@ -319,12 +319,9 @@ impl<'cx, 'tcx> Visitor<'tcx> for WritebackCx<'cx, 'tcx> {
|
|||
match p.kind {
|
||||
hir::PatKind::Binding(..) => {
|
||||
let typeck_results = self.fcx.typeck_results.borrow();
|
||||
if let Some(bm) =
|
||||
typeck_results.extract_binding_mode(self.tcx().sess, p.hir_id, p.span)
|
||||
{
|
||||
let bm = typeck_results.extract_binding_mode(self.tcx().sess, p.hir_id, p.span);
|
||||
self.typeck_results.pat_binding_modes_mut().insert(p.hir_id, bm);
|
||||
}
|
||||
}
|
||||
hir::PatKind::Struct(_, fields, _) => {
|
||||
for field in fields {
|
||||
self.visit_field_id(field.hir_id);
|
||||
|
|
|
@ -394,8 +394,10 @@ impl<'tcx> TypeckResults<'tcx> {
|
|||
matches!(self.type_dependent_defs().get(expr.hir_id), Some(Ok((DefKind::AssocFn, _))))
|
||||
}
|
||||
|
||||
pub fn extract_binding_mode(&self, s: &Session, id: HirId, sp: Span) -> Option<BindingMode> {
|
||||
self.pat_binding_modes().get(id).copied().or_else(|| {
|
||||
/// Returns the computed binding mode for a `PatKind::Binding` pattern
|
||||
/// (after match ergonomics adjustments).
|
||||
pub fn extract_binding_mode(&self, s: &Session, id: HirId, sp: Span) -> BindingMode {
|
||||
self.pat_binding_modes().get(id).copied().unwrap_or_else(|| {
|
||||
s.dcx().span_bug(sp, "missing binding mode");
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1094,7 +1094,6 @@ pub fn capture_local_usage(cx: &LateContext<'_>, e: &Expr<'_>) -> CaptureKind {
|
|||
pat.each_binding_or_first(&mut |_, id, span, _| match cx
|
||||
.typeck_results()
|
||||
.extract_binding_mode(cx.sess(), id, span)
|
||||
.unwrap()
|
||||
.0
|
||||
{
|
||||
ByRef::No if !is_copy(cx, cx.typeck_results().node_type(id)) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue