Auto merge of #27315 - eefriedman:improper-ctypes-void-ret, r=alexcrichton
Fixes issue #27302.
This commit is contained in:
commit
d019a49ac8
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user