From 0c89183e8080430b49f45ddaae9b8e2775034d5e Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Tue, 27 Aug 2013 12:24:50 -0700 Subject: [PATCH] rustc: Fix cstack lint for default methods. Closes #8753 --- src/librustc/middle/stack_check.rs | 12 ++++++++++++ src/test/compile-fail/lint-cstack.rs | 24 ++++++++++++++++++++++++ src/test/run-pass/lint-cstack.rs | 27 +++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 src/test/compile-fail/lint-cstack.rs create mode 100644 src/test/run-pass/lint-cstack.rs diff --git a/src/librustc/middle/stack_check.rs b/src/librustc/middle/stack_check.rs index 569c6dfde0c..7ab6cfcdf7b 100644 --- a/src/librustc/middle/stack_check.rs +++ b/src/librustc/middle/stack_check.rs @@ -80,6 +80,18 @@ fn stack_check_item(v: StackCheckVisitor, visit::walk_method_helper(&mut v, method, new_cx); } } + ast::item_trait(_, _, ref methods) => { + for method in methods.iter() { + match *method { + ast::provided(@ref method) => { + let safe_stack = fixed_stack_segment(method.attrs); + let new_cx = Context {safe_stack: safe_stack, ..in_cx}; + visit::walk_method_helper(&mut v, method, new_cx); + } + ast::required(*) => () + } + } + } _ => { visit::walk_item(&mut v, item, in_cx); } diff --git a/src/test/compile-fail/lint-cstack.rs b/src/test/compile-fail/lint-cstack.rs new file mode 100644 index 00000000000..11fe02eaef5 --- /dev/null +++ b/src/test/compile-fail/lint-cstack.rs @@ -0,0 +1,24 @@ +// Copyright 2013 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +extern { + fn rust_get_test_int() -> std::libc::intptr_t; +} + +trait A { + fn foo() { + unsafe { + rust_get_test_int(); //~ ERROR invoking non-Rust fn + } + } +} + +fn main() { +} diff --git a/src/test/run-pass/lint-cstack.rs b/src/test/run-pass/lint-cstack.rs new file mode 100644 index 00000000000..b9e61b47e22 --- /dev/null +++ b/src/test/run-pass/lint-cstack.rs @@ -0,0 +1,27 @@ +// Copyright 2013 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::libc; + +extern { + fn rust_get_test_int() -> libc::intptr_t; +} + +trait A { + #[fixed_stack_segment] + fn foo() { + unsafe { + rust_get_test_int(); + } + } +} + +fn main() { +}