File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
compiler/rustc_passes/src Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,9 @@ impl<'tcx> Visitor<'tcx> for CheckCustomAbi<'tcx> {
8888 }
8989 }
9090
91+ // Because `extern "custom"` functions don't accept any parameter, and functions are
92+ // only methods when some variation on `self` is their first argument, methods cannot
93+ // use `extern "custom"` in a valid program.
9194 ExprKind :: MethodCall ( _, receiver, _, span) => {
9295 let opt_def_id = self
9396 . tcx
@@ -99,6 +102,7 @@ impl<'tcx> Visitor<'tcx> for CheckCustomAbi<'tcx> {
99102 ( span, sig. abi )
100103 } )
101104 }
105+
102106 _ => None ,
103107 } ;
104108
Original file line number Diff line number Diff line change @@ -47,6 +47,15 @@ trait BitwiseNot {
4747
4848impl BitwiseNot for Thing { }
4949
50+ #[ unsafe( naked) ]
51+ unsafe extern "C" fn const_generic < const N : u64 > ( ) {
52+ naked_asm ! (
53+ "mov rax, {}" ,
54+ "ret" ,
55+ const N ,
56+ ) ;
57+ }
58+
5059pub fn main ( ) {
5160 let mut x: u64 = 21 ;
5261 unsafe { asm ! ( "call {}" , sym double, inout( "rax" ) x) } ;
@@ -71,4 +80,12 @@ pub fn main() {
7180 }
7281
7382 assert_eq ! ( caller( double, 2 ) , 4 ) ;
83+
84+ let x: u64 ;
85+ unsafe { asm ! ( "call {}" , sym const_generic:: <42 >, out( "rax" ) x) } ;
86+ assert_eq ! ( x, 42 ) ;
87+
88+ let x: u64 ;
89+ unsafe { asm ! ( "call {}" , sym const_generic:: <84 >, out( "rax" ) x) } ;
90+ assert_eq ! ( x, 84 ) ;
7491}
You can’t perform that action at this time.
0 commit comments