diff options
| author | bors <bors@rust-lang.org> | 2015-07-27 11:49:45 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-07-27 11:49:45 +0000 |
| commit | d019a49ac86322703e1daad0ebca393856185b32 (patch) | |
| tree | f18c72c13589929c437e02d69f19bbc3c0565600 /src | |
| parent | 3351afeecffcc9ebaeb1188a5cde976da8e4a5aa (diff) | |
| parent | 21b514ff3040527e290d79a27d591b1b31301f68 (diff) | |
| download | rust-d019a49ac86322703e1daad0ebca393856185b32.tar.gz rust-d019a49ac86322703e1daad0ebca393856185b32.zip | |
Auto merge of #27315 - eefriedman:improper-ctypes-void-ret, r=alexcrichton
Fixes issue #27302.
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc_lint/builtin.rs | 21 | ||||
| -rw-r--r-- | src/test/compile-fail/lint-ctypes.rs | 3 |
2 files changed, 18 insertions, 6 deletions
diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 6289d505881..751224e7286 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -436,6 +436,16 @@ fn is_repr_nullable_ptr<'tcx>(variants: &Vec<Rc<ty::VariantInfo<'tcx>>>) -> bool false } +fn ast_ty_to_normalized<'tcx>(tcx: &ty::ctxt<'tcx>, + id: ast::NodeId) + -> Ty<'tcx> { + let tty = match tcx.ast_ty_to_ty_cache.borrow().get(&id) { + Some(&t) => t, + None => panic!("ast_ty_to_ty_cache was incomplete after typeck!") + }; + infer::normalize_associated_type(tcx, &tty) +} + impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { /// Check if the given type is "ffi-safe" (has a stable, well-defined /// representation which can be exported to C code). @@ -638,11 +648,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { } fn check_def(&mut self, sp: Span, id: ast::NodeId) { - let tty = match self.cx.tcx.ast_ty_to_ty_cache.borrow().get(&id) { - Some(&t) => t, - None => panic!("ast_ty_to_ty_cache was incomplete after typeck!") - }; - let tty = infer::normalize_associated_type(self.cx.tcx, &tty); + let tty = ast_ty_to_normalized(self.cx.tcx, id); match ImproperCTypesVisitor::check_type_for_ffi(self, &mut FnvHashSet(), tty) { FfiResult::FfiSafe => {} @@ -707,7 +713,10 @@ impl LintPass for ImproperCTypes { check_ty(cx, &*input.ty); } if let ast::Return(ref ret_ty) = decl.output { - check_ty(cx, &**ret_ty); + let tty = ast_ty_to_normalized(cx.tcx, ret_ty.id); + if !tty.is_nil() { + check_ty(cx, &ret_ty); + } } } diff --git a/src/test/compile-fail/lint-ctypes.rs b/src/test/compile-fail/lint-ctypes.rs index 614f8e6fde8..4daba86679d 100644 --- a/src/test/compile-fail/lint-ctypes.rs +++ b/src/test/compile-fail/lint-ctypes.rs @@ -26,6 +26,7 @@ pub type I32Pair = (i32, i32); pub struct ZeroSize; pub type RustFn = fn(); pub type RustBadRet = extern fn() -> Box<u32>; +pub type CVoidRet = (); extern { pub fn bare_type1(size: isize); //~ ERROR: found Rust type @@ -52,6 +53,8 @@ extern { pub fn good6(s: StructWithProjectionAndLifetime); pub fn good7(fptr: extern fn() -> ()); pub fn good8(fptr: extern fn() -> !); + pub fn good9() -> (); + pub fn good10() -> CVoidRet; } fn main() { |
