Skip to content

Commit f3321b1

Browse files
committed
Lint for the reserved ABI of bool
The ABI of bool is reserved, see these links: * rust-lang/rfcs#954 (comment) * #46156 (comment) * rust-lang/rfcs#992 Currently the improper_ctypes lint is inconsistent with that position by treating bools as if they had a specified ABI. To fix this inconsistency, this changes treatment of bools by the lint. This might break some code, so possibly it has to be phased in slowly...
1 parent 63739ab commit f3321b1

File tree

6 files changed

+50
-1
lines changed

6 files changed

+50
-1
lines changed

src/librustc_binaryen/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
//! only supports one operation, creating a module from LLVM's assembly format
1616
//! and then serializing that module to a wasm module.
1717
18+
#![deny(warnings)]
19+
20+
// We are the compiler, so we can use anything for FFI.
21+
// Don't do this at home :)
22+
#![allow(improper_ctypes)]
23+
1824
extern crate libc;
1925

2026
use std::slice;

src/librustc_lint/types.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,13 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
561561
stable ABI")
562562
}
563563

564+
ty::TyBool => {
565+
FfiUnsafe("found Rust type `bool` in foreign module, \
566+
while its ABI is reserved for future change")
567+
}
568+
564569
// Primitive types with a stable representation.
565-
ty::TyBool | ty::TyInt(..) | ty::TyUint(..) | ty::TyFloat(..) | ty::TyNever => FfiSafe,
570+
ty::TyInt(..) | ty::TyUint(..) | ty::TyFloat(..) | ty::TyNever => FfiSafe,
566571

567572
ty::TySlice(_) => {
568573
FfiUnsafe("found Rust slice type in foreign module, \

src/librustc_llvm/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
#![allow(non_snake_case)]
1414
#![allow(dead_code)]
1515

16+
// We are the compiler, so we can use anything for FFI.
17+
// Don't do this at home :)
18+
#![allow(improper_ctypes)]
19+
1620
#![doc(html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
1721
html_favicon_url = "https://doc.rust-lang.org/favicon.ico",
1822
html_root_url = "https://doc.rust-lang.org/nightly/")]
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![deny(improper_ctypes)]
12+
#![allow(dead_code)]
13+
14+
extern {
15+
fn zf(x: bool); //~ ERROR found Rust type `bool` in foreign module
16+
}
17+
18+
pub fn main() { }

src/test/ui/lint/unreachable_pub-pub_crate.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ warning: unreachable `pub` item
122122
|
123123
= help: or consider exporting it for use by other crates
124124

125+
warning: found Rust type `bool` in foreign module, while its ABI is reserved for future change
126+
--> $DIR/unreachable_pub-pub_crate.rs:52:30
127+
|
128+
52 | pub fn catalyze() -> bool;
129+
| ^^^^
130+
|
131+
= note: #[warn(improper_ctypes)] on by default
132+
125133
warning: unreachable `pub` item
126134
--> $DIR/unreachable_pub-pub_crate.rs:52:9
127135
|

src/test/ui/lint/unreachable_pub.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ warning: unreachable `pub` item
122122
|
123123
= help: or consider exporting it for use by other crates
124124

125+
warning: found Rust type `bool` in foreign module, while its ABI is reserved for future change
126+
--> $DIR/unreachable_pub.rs:47:30
127+
|
128+
47 | pub fn catalyze() -> bool;
129+
| ^^^^
130+
|
131+
= note: #[warn(improper_ctypes)] on by default
132+
125133
warning: unreachable `pub` item
126134
--> $DIR/unreachable_pub.rs:47:9
127135
|

0 commit comments

Comments
 (0)