From 148a6c1a38e5f4ed92127717390a2df058967b5b Mon Sep 17 00:00:00 2001 From: Stefan Plantikow Date: Tue, 22 Nov 2011 19:51:05 +0100 Subject: [PATCH] comp: allowed the declaration of pure fn's in native mods This is especially useful for the native calls in std::math This commit does NOT yet point to new snapshots --- src/comp/middle/typeck.rs | 1 + src/comp/syntax/parse/parser.rs | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 0858833af6d..64bce9da750 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -1501,6 +1501,7 @@ fn require_pure_call(ccx: @crate_ctxt, caller_purity: ast::purity, ast::pure_fn. { alt ccx.tcx.def_map.find(callee.id) { some(ast::def_fn(_, ast::pure_fn.)) { ret; } + some(ast::def_native_fn(_, ast::pure_fn.)) { ret; } _ { ccx.tcx.sess.span_err (sp, "pure function calls function not known to be pure"); diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index e33572d4575..13136a8d7ed 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -1975,6 +1975,9 @@ fn parse_native_item(p: parser, attrs: [ast::attribute]) -> ret parse_item_native_type(p, attrs); } else if eat_word(p, "fn") { ret parse_item_native_fn(p, attrs, ast::impure_fn); + } else if eat_word(p, "pure") { + expect_word(p, "fn"); + ret parse_item_native_fn(p, attrs, ast::pure_fn); } else if eat_word(p, "unsafe") { expect_word(p, "fn"); ret parse_item_native_fn(p, attrs, ast::unsafe_fn);