create a region-map for types in generics
Fixes #28181 This may fix #28151
This commit is contained in:
parent
1661947014
commit
16f75f773d
3 changed files with 31 additions and 9 deletions
|
@ -317,7 +317,10 @@ impl RegionMaps {
|
||||||
self.intern_code_extent(e, DUMMY_CODE_EXTENT)
|
self.intern_code_extent(e, DUMMY_CODE_EXTENT)
|
||||||
}
|
}
|
||||||
pub fn lookup_code_extent(&self, e: CodeExtentData) -> CodeExtent {
|
pub fn lookup_code_extent(&self, e: CodeExtentData) -> CodeExtent {
|
||||||
self.code_extent_interner.borrow()[&e]
|
match self.code_extent_interner.borrow().get(&e) {
|
||||||
|
Some(&d) => d,
|
||||||
|
None => panic!("unknown code extent {:?}", e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
pub fn node_extent(&self, n: ast::NodeId) -> CodeExtent {
|
pub fn node_extent(&self, n: ast::NodeId) -> CodeExtent {
|
||||||
self.lookup_code_extent(CodeExtentData::Misc(n))
|
self.lookup_code_extent(CodeExtentData::Misc(n))
|
||||||
|
@ -1069,7 +1072,7 @@ fn resolve_item(visitor: &mut RegionResolutionVisitor, item: &hir::Item) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_fn(visitor: &mut RegionResolutionVisitor,
|
fn resolve_fn(visitor: &mut RegionResolutionVisitor,
|
||||||
_: FnKind,
|
kind: FnKind,
|
||||||
decl: &hir::FnDecl,
|
decl: &hir::FnDecl,
|
||||||
body: &hir::Block,
|
body: &hir::Block,
|
||||||
sp: Span,
|
sp: Span,
|
||||||
|
@ -1102,6 +1105,7 @@ fn resolve_fn(visitor: &mut RegionResolutionVisitor,
|
||||||
};
|
};
|
||||||
|
|
||||||
visit::walk_fn_decl(visitor, decl);
|
visit::walk_fn_decl(visitor, decl);
|
||||||
|
visit::walk_fn_kind(visitor, kind);
|
||||||
|
|
||||||
// The body of the every fn is a root scope.
|
// The body of the every fn is a root scope.
|
||||||
visitor.cx = Context {
|
visitor.cx = Context {
|
||||||
|
|
|
@ -580,13 +580,8 @@ pub fn walk_fn_decl<'v, V: Visitor<'v>>(visitor: &mut V, function_declaration: &
|
||||||
walk_fn_ret_ty(visitor, &function_declaration.output)
|
walk_fn_ret_ty(visitor, &function_declaration.output)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V,
|
pub fn walk_fn_kind<'v, V: Visitor<'v>>(visitor: &mut V,
|
||||||
function_kind: FnKind<'v>,
|
function_kind: FnKind<'v>) {
|
||||||
function_declaration: &'v FnDecl,
|
|
||||||
function_body: &'v Block,
|
|
||||||
_span: Span) {
|
|
||||||
walk_fn_decl(visitor, function_declaration);
|
|
||||||
|
|
||||||
match function_kind {
|
match function_kind {
|
||||||
FnKind::ItemFn(_, generics, _, _, _, _) => {
|
FnKind::ItemFn(_, generics, _, _, _, _) => {
|
||||||
visitor.visit_generics(generics);
|
visitor.visit_generics(generics);
|
||||||
|
@ -597,7 +592,15 @@ pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V,
|
||||||
}
|
}
|
||||||
FnKind::Closure(..) => {}
|
FnKind::Closure(..) => {}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn walk_fn<'v, V: Visitor<'v>>(visitor: &mut V,
|
||||||
|
function_kind: FnKind<'v>,
|
||||||
|
function_declaration: &'v FnDecl,
|
||||||
|
function_body: &'v Block,
|
||||||
|
_span: Span) {
|
||||||
|
walk_fn_decl(visitor, function_declaration);
|
||||||
|
walk_fn_kind(visitor, function_kind);
|
||||||
visitor.visit_block(function_body)
|
visitor.visit_block(function_body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
15
src/test/run-pass/issue-28181.rs
Normal file
15
src/test/run-pass/issue-28181.rs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
fn bar<F>(f: F) -> usize where F: Fn([usize; 1]) -> usize { f([2]) }
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
bar(|u| { u[0] });
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue