rollup merge of #23119: nikomatsakis/issue-23116-ref-mut
Don't allow upcasting to a supertype in the type of the match discriminant. Fixes #23116. This is a [breaking-change] in that it closes a type hole that previously existed. r? @pnkfelix
This commit is contained in:
commit
ad41e7cd7a
6 changed files with 116 additions and 10 deletions
|
|
@ -119,6 +119,24 @@ pub fn pat_contains_bindings(dm: &DefMap, pat: &ast::Pat) -> bool {
|
|||
contains_bindings
|
||||
}
|
||||
|
||||
/// Checks if the pattern contains any `ref` or `ref mut` bindings.
|
||||
pub fn pat_contains_ref_binding(dm: &DefMap, pat: &ast::Pat) -> bool {
|
||||
let mut result = false;
|
||||
pat_bindings(dm, pat, |mode, _, _, _| {
|
||||
match mode {
|
||||
ast::BindingMode::BindByRef(_) => { result = true; }
|
||||
ast::BindingMode::BindByValue(_) => { }
|
||||
}
|
||||
});
|
||||
result
|
||||
}
|
||||
|
||||
/// Checks if the patterns for this arm contain any `ref` or `ref mut`
|
||||
/// bindings.
|
||||
pub fn arm_contains_ref_binding(dm: &DefMap, arm: &ast::Arm) -> bool {
|
||||
arm.pats.iter().any(|pat| pat_contains_ref_binding(dm, pat))
|
||||
}
|
||||
|
||||
/// Checks if the pattern contains any patterns that bind something to
|
||||
/// an ident or wildcard, e.g. `foo`, or `Foo(_)`, `foo @ Bar(..)`,
|
||||
pub fn pat_contains_bindings_or_wild(dm: &DefMap, pat: &ast::Pat) -> bool {
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ use middle::mem_categorization as mc;
|
|||
use middle::region;
|
||||
use middle::resolve_lifetime;
|
||||
use middle::infer;
|
||||
use middle::pat_util;
|
||||
use middle::stability;
|
||||
use middle::subst::{self, ParamSpace, Subst, Substs, VecPerParamSpace};
|
||||
use middle::traits;
|
||||
|
|
@ -2684,6 +2685,14 @@ impl<'tcx> ctxt<'tcx> {
|
|||
{
|
||||
self.ty_param_defs.borrow()[node_id].clone()
|
||||
}
|
||||
|
||||
pub fn pat_contains_ref_binding(&self, pat: &ast::Pat) -> bool {
|
||||
pat_util::pat_contains_ref_binding(&self.def_map, pat)
|
||||
}
|
||||
|
||||
pub fn arm_contains_ref_binding(&self, arm: &ast::Arm) -> bool {
|
||||
pat_util::arm_contains_ref_binding(&self.def_map, arm)
|
||||
}
|
||||
}
|
||||
|
||||
// Interns a type/name combination, stores the resulting box in cx.interner,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue