Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ fn is_valid_cmse_inputs<'tcx>(
let fn_sig = tcx.erase_and_anonymize_regions(fn_sig);

for (ty, hir_ty) in fn_sig.inputs().iter().zip(fn_decl.inputs) {
if ty.has_infer_types() {
let err = LayoutError::Unknown(*ty);
return Err((hir_ty.span, tcx.arena.alloc(err)));
}

let layout = tcx
.layout_of(ty::TypingEnv::fully_monomorphized().as_query_input(*ty))
.map_err(|e| (hir_ty.span, e))?;
Expand Down Expand Up @@ -138,6 +143,11 @@ fn is_valid_cmse_output<'tcx>(
return Ok(());
}

if return_type.has_infer_types() {
let err = LayoutError::Unknown(return_type);
return Err(tcx.arena.alloc(err));
}

let typing_env = ty::TypingEnv::fully_monomorphized();
let layout = tcx.layout_of(typing_env.as_query_input(return_type))?;

Expand Down
6 changes: 0 additions & 6 deletions tests/crashes/130104.rs

This file was deleted.

34 changes: 34 additions & 0 deletions tests/ui/cmse-nonsecure/cmse-nonsecure-call/infer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//@ add-minicore
//@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
//@ needs-llvm-components: arm
#![feature(abi_cmse_nonsecure_call, no_core, lang_items)]
#![no_core]

// Infer variables cause panics in layout generation, so the argument/return type is checked for
// whether it contains an infer var, and `LayoutError::Unknown` is emitted if so.
//
// See https://github.com/rust-lang/rust/issues/130104.

extern crate minicore;
use minicore::*;

fn infer_1() {
let _ = mem::transmute::<fn() -> _, extern "cmse-nonsecure-call" fn() -> _>;
//~^ ERROR type annotations needed
}

fn infer_2() {
let _ = mem::transmute::<fn() -> (i32, _), extern "cmse-nonsecure-call" fn() -> (i32, _)>;
//~^ ERROR type annotations needed
}

fn infer_3() {
let _ = mem::transmute::<fn(_: _) -> (), extern "cmse-nonsecure-call" fn(_: _) -> ()>;
//~^ ERROR type annotations needed
}

fn infer_4() {
let _ =
mem::transmute::<fn(_: (i32, _)) -> (), extern "cmse-nonsecure-call" fn(_: (i32, _)) -> ()>;
//~^ ERROR type annotations needed
}
27 changes: 27 additions & 0 deletions tests/ui/cmse-nonsecure/cmse-nonsecure-call/infer.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
error[E0282]: type annotations needed
--> $DIR/infer.rs:16:13
|
LL | let _ = mem::transmute::<fn() -> _, extern "cmse-nonsecure-call" fn() -> _>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `Src` declared on the function `transmute`

error[E0282]: type annotations needed
--> $DIR/infer.rs:21:13
|
LL | let _ = mem::transmute::<fn() -> (i32, _), extern "cmse-nonsecure-call" fn() -> (i32, _)>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `Src` declared on the function `transmute`

error[E0282]: type annotations needed
--> $DIR/infer.rs:26:13
|
LL | let _ = mem::transmute::<fn(_: _) -> (), extern "cmse-nonsecure-call" fn(_: _) -> ()>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `Src` declared on the function `transmute`

error[E0282]: type annotations needed
--> $DIR/infer.rs:32:9
|
LL | mem::transmute::<fn(_: (i32, _)) -> (), extern "cmse-nonsecure-call" fn(_: (i32, _)) -> ()>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `Src` declared on the function `transmute`

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0282`.
36 changes: 36 additions & 0 deletions tests/ui/cmse-nonsecure/cmse-nonsecure-entry/infer.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//@ add-minicore
//@ compile-flags: --target thumbv8m.main-none-eabi --crate-type lib
//@ needs-llvm-components: arm
#![feature(cmse_nonsecure_entry, no_core, lang_items)]
#![no_core]

// Infer variables cause panics in layout generation, so the argument/return type is checked for
// whether it contains an infer var, and `LayoutError::Unknown` is emitted if so.
//
// See https://github.com/rust-lang/rust/issues/130104.

extern crate minicore;
use minicore::*;

fn infer_1() {
let _ = mem::transmute::<fn() -> _, extern "cmse-nonsecure-entry" fn() -> _>;
//~^ ERROR type annotations needed
}

fn infer_2() {
let _ = mem::transmute::<fn() -> (i32, _), extern "cmse-nonsecure-entry" fn() -> (i32, _)>;
//~^ ERROR type annotations needed
}

fn infer_3() {
let _ = mem::transmute::<fn(_: _) -> (), extern "cmse-nonsecure-entry" fn(_: _) -> ()>;
//~^ ERROR type annotations needed
}

fn infer_4() {
let _ = mem::transmute::<
//~^ ERROR type annotations needed
fn(_: (i32, _)) -> (),
extern "cmse-nonsecure-entry" fn(_: (i32, _)) -> (),
>;
}
32 changes: 32 additions & 0 deletions tests/ui/cmse-nonsecure/cmse-nonsecure-entry/infer.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
error[E0282]: type annotations needed
--> $DIR/infer.rs:16:13
|
LL | let _ = mem::transmute::<fn() -> _, extern "cmse-nonsecure-entry" fn() -> _>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `Src` declared on the function `transmute`

error[E0282]: type annotations needed
--> $DIR/infer.rs:21:13
|
LL | let _ = mem::transmute::<fn() -> (i32, _), extern "cmse-nonsecure-entry" fn() -> (i32, _)>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `Src` declared on the function `transmute`

error[E0282]: type annotations needed
--> $DIR/infer.rs:26:13
|
LL | let _ = mem::transmute::<fn(_: _) -> (), extern "cmse-nonsecure-entry" fn(_: _) -> ()>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `Src` declared on the function `transmute`

error[E0282]: type annotations needed
--> $DIR/infer.rs:31:13
|
LL | let _ = mem::transmute::<
| _____________^
LL | |
LL | | fn(_: (i32, _)) -> (),
LL | | extern "cmse-nonsecure-entry" fn(_: (i32, _)) -> (),
LL | | >;
| |_____^ cannot infer type of the type parameter `Src` declared on the function `transmute`

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0282`.
Loading