From 6943b38e4fd75dfd3c6ff80b96060ec9a39e01e9 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 10 Feb 2012 13:39:15 -0800 Subject: [PATCH] rustc: Add crust functions to the AST --- src/comp/metadata/encoder.rs | 7 ++++++- src/comp/middle/typeck.rs | 4 ++-- src/comp/syntax/ast.rs | 1 + src/comp/syntax/print/pprust.rs | 1 + 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/comp/metadata/encoder.rs b/src/comp/metadata/encoder.rs index 650d1fcf9751..96f283c59223 100644 --- a/src/comp/metadata/encoder.rs +++ b/src/comp/metadata/encoder.rs @@ -312,7 +312,12 @@ fn encode_info_for_mod(ecx: @encode_ctxt, ebml_w: ebml::writer, md: _mod, } fn purity_fn_family(p: purity) -> char { - alt p { unsafe_fn { 'u' } pure_fn { 'p' } impure_fn { 'f' } } + alt p { + unsafe_fn { 'u' } + pure_fn { 'p' } + impure_fn { 'f' } + crust_fn { 'c' } + } } fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index caa4079a9d46..57b0333ada9b 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -1535,7 +1535,7 @@ fn require_unsafe(sess: session, f_purity: ast::purity, sp: span) { fn require_impure(sess: session, f_purity: ast::purity, sp: span) { alt f_purity { ast::unsafe_fn { ret; } - ast::impure_fn { ret; } + ast::impure_fn | ast::crust_fn { ret; } ast::pure_fn { sess.span_err(sp, "Found impure expression in pure function decl"); } @@ -1568,7 +1568,7 @@ fn require_pure_call(ccx: @crate_ctxt, caller_purity: ast::purity, } }; alt (caller_purity, callee_purity) { - (ast::impure_fn, ast::unsafe_fn) { + (ast::impure_fn, ast::unsafe_fn) | (ast::crust_fn, ast::unsafe_fn) { ccx.tcx.sess.span_err(sp, "safe function calls function marked \ unsafe"); } diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index 26a309d37f5c..2ab7059a2a46 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -407,6 +407,7 @@ enum purity { pure_fn, // declared with "pure fn" unsafe_fn, // declared with "unsafe fn" impure_fn, // declared with "fn" + crust_fn, // declared with "crust fn" } enum ret_style { diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 047653cc4c98..b0ed7ceed005 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -1199,6 +1199,7 @@ fn print_fn(s: ps, decl: ast::fn_decl, name: ast::ident, ast::impure_fn { head(s, "fn"); } ast::unsafe_fn { head(s, "unsafe fn"); } ast::pure_fn { head(s, "pure fn"); } + ast::crust_fn { head(s, "crust fn"); } } word(s.s, name); print_type_params(s, typarams);