debug!("(resolving block) leaving block");
}
- fn fresh_binding(&mut self,
- ident: Ident,
- pat_id: NodeId,
- outer_pat_id: NodeId,
- pat_src: PatternSource,
- bindings: &mut IdentMap<NodeId>)
- -> Res {
- // Add the binding to the local ribs, if it
- // doesn't already exist in the bindings map. (We
- // must not add it if it's in the bindings map
- // because that breaks the assumptions later
- // passes make about or-patterns.)
+ fn resolve_pattern(
+ &mut self,
+ pat: &Pat,
+ pat_src: PatternSource,
+ // Maps idents to the node ID for the outermost pattern that binds them.
+ bindings: &mut IdentMap<NodeId>,
+ ) {
+ // Visit all direct subpatterns of this pattern.
+ let outer_pat_id = pat.id;
+ pat.walk(&mut |pat| {
+ debug!("resolve_pattern pat={:?} node={:?}", pat, pat.node);
+ match pat.node {
+ PatKind::Ident(bmode, ident, ref sub) => {
+ // First try to resolve the identifier as some existing entity,
+ // then fall back to a fresh binding.
+ let has_sub = sub.is_some();
+ let res = self.try_resolve_as_non_binding(pat_src, pat, bmode, ident, has_sub)
+ .unwrap_or_else(|| {
+ self.fresh_binding(ident, pat.id, outer_pat_id, pat_src, bindings)
+ });
+ self.r.record_partial_res(pat.id, PartialRes::new(res));
+ }
+ PatKind::TupleStruct(ref path, ..) => {
+ self.smart_resolve_path(pat.id, None, path, PathSource::TupleStruct);
+ }
+ PatKind::Path(ref qself, ref path) => {
+ self.smart_resolve_path(pat.id, qself.as_ref(), path, PathSource::Pat);
+ }
+ PatKind::Struct(ref path, ..) => {
+ self.smart_resolve_path(pat.id, None, path, PathSource::Struct);
+ }
+ _ => {}
+ }
+ true
+ });
+
+ visit::walk_pat(self, pat);
+ }
+
+ fn fresh_binding(
+ &mut self,
+ ident: Ident,
+ pat_id: NodeId,
+ outer_pat_id: NodeId,
+ pat_src: PatternSource,
+ bindings: &mut IdentMap<NodeId>,
+ ) -> Res {
+ // Add the binding to the local ribs, if it doesn't already exist in the bindings map.
+ // (We must not add it if it's in the bindings map because that breaks the assumptions
+ // later passes make about or-patterns.)
let ident = ident.modern_and_legacy();
let mut res = Res::Local(pat_id);
match bindings.get(&ident).cloned() {
// `Variant(a, a)`, error
self.r.report_error(
ident.span,
- ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(
- &ident.as_str())
+ ResolutionError::IdentifierBoundMoreThanOnceInSamePattern(&ident.as_str()),
);
}
Some(..) if pat_src == PatternSource::FnParam => {
// `fn f(a: u8, a: u8)`, error
self.r.report_error(
ident.span,
- ResolutionError::IdentifierBoundMoreThanOnceInParameterList(
- &ident.as_str())
+ ResolutionError::IdentifierBoundMoreThanOnceInParameterList(&ident.as_str()),
);
}
Some(..) if pat_src == PatternSource::Match ||
&mut self.ribs[ns].last_mut().unwrap().bindings
}
- fn resolve_pattern(
- &mut self,
- pat: &Pat,
- pat_src: PatternSource,
- // Maps idents to the node ID for the outermost pattern that binds them.
- bindings: &mut IdentMap<NodeId>,
- ) {
- // Visit all direct subpatterns of this pattern.
- let outer_pat_id = pat.id;
- pat.walk(&mut |pat| {
- debug!("resolve_pattern pat={:?} node={:?}", pat, pat.node);
- match pat.node {
- PatKind::Ident(bmode, ident, ref sub) => {
- // First try to resolve the identifier as some existing entity,
- // then fall back to a fresh binding.
- let has_sub = sub.is_some();
- let res = self.try_resolve_as_non_binding(pat_src, pat, bmode, ident, has_sub)
- .unwrap_or_else(|| {
- self.fresh_binding(ident, pat.id, outer_pat_id, pat_src, bindings)
- });
- self.r.record_partial_res(pat.id, PartialRes::new(res));
- }
- PatKind::TupleStruct(ref path, ..) => {
- self.smart_resolve_path(pat.id, None, path, PathSource::TupleStruct);
- }
- PatKind::Path(ref qself, ref path) => {
- self.smart_resolve_path(pat.id, qself.as_ref(), path, PathSource::Pat);
- }
- PatKind::Struct(ref path, ..) => {
- self.smart_resolve_path(pat.id, None, path, PathSource::Struct);
- }
- _ => {}
- }
- true
- });
-
- visit::walk_pat(self, pat);
- }
-
fn try_resolve_as_non_binding(
&mut self,
pat_src: PatternSource,