From 5ccf8175a8ae5f6aaff30bb2330a5f05ec89028d Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 23 Aug 2012 17:02:41 -0700 Subject: [PATCH] don't consider use of `@fn` to be region-param'd --- src/rustc/middle/region.rs | 19 ++++++++++++++++ .../regions-infer-at-fn-not-param.rs | 22 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/test/compile-fail/regions-infer-at-fn-not-param.rs diff --git a/src/rustc/middle/region.rs b/src/rustc/middle/region.rs index e9364e1762d..17d4eaa5984 100644 --- a/src/rustc/middle/region.rs +++ b/src/rustc/middle/region.rs @@ -655,6 +655,25 @@ fn determine_rp_in_ty(ty: @ast::ty, _ => {} } + // temporary hack: right now, fn() is short for &fn(), but @(fn()) + // is `@fn()`, so catch this and set anon_implies_rp to none in + // that case + match ty.node { + ast::ty_box(mt) | ast::ty_uniq(mt) => { + match mt.ty.node { + ast::ty_fn(ast::proto_bare, _, _) | + ast::ty_fn(ast::proto_block, _, _) => { + do cx.with(cx.item_id, false) { + visit_mt(mt, cx, visitor); + } + return; + } + _ => {} + } + } + _ => {} + } + match ty.node { ast::ty_box(mt) | ast::ty_uniq(mt) | ast::ty_vec(mt) | ast::ty_rptr(_, mt) | ast::ty_ptr(mt) => { diff --git a/src/test/compile-fail/regions-infer-at-fn-not-param.rs b/src/test/compile-fail/regions-infer-at-fn-not-param.rs new file mode 100644 index 00000000000..385372f5c43 --- /dev/null +++ b/src/test/compile-fail/regions-infer-at-fn-not-param.rs @@ -0,0 +1,22 @@ +struct param1 { + g: &fn(); +} + +struct param2 { + g: fn(); +} + +struct not_param1 { + g: @fn(); +} + +struct not_param2 { + g: @fn(); +} + +fn take1(p: param1) -> param1 { p } //~ ERROR mismatched types +fn take2(p: param2) -> param2 { p } //~ ERROR mismatched types +fn take3(p: not_param1) -> not_param1 { p } +fn take4(p: not_param2) -> not_param2 { p } + +fn main() {}