Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #21456 from ChayimFriedman2/naked-asm
fix: Make `naked_asm!()` always return `!`
Lukas Wirth 3 months ago
parent f8b5330 · parent 76b5a4f · commit 6c4010e
-rw-r--r--crates/hir-ty/src/infer/expr.rs8
-rw-r--r--crates/hir-ty/src/tests/simple.rs14
-rw-r--r--crates/test-utils/src/minicore.rs4
3 files changed, 24 insertions, 2 deletions
diff --git a/crates/hir-ty/src/infer/expr.rs b/crates/hir-ty/src/infer/expr.rs
index 62339779a5..c57d41cc5f 100644
--- a/crates/hir-ty/src/infer/expr.rs
+++ b/crates/hir-ty/src/infer/expr.rs
@@ -8,7 +8,7 @@ use hir_def::{
expr_store::path::{GenericArgs as HirGenericArgs, Path},
hir::{
Array, AsmOperand, AsmOptions, BinaryOp, BindingAnnotation, Expr, ExprId, ExprOrPatId,
- LabelId, Literal, Pat, PatId, Statement, UnaryOp,
+ InlineAsmKind, LabelId, Literal, Pat, PatId, Statement, UnaryOp,
},
resolver::ValueNs,
};
@@ -1037,7 +1037,11 @@ impl<'db> InferenceContext<'_, 'db> {
// FIXME: `sym` should report for things that are not functions or statics.
AsmOperand::Sym(_) => (),
});
- if diverge { self.types.types.never } else { self.types.types.unit }
+ if diverge || asm.kind == InlineAsmKind::NakedAsm {
+ self.types.types.never
+ } else {
+ self.types.types.unit
+ }
}
};
// use a new type variable if we got unknown here
diff --git a/crates/hir-ty/src/tests/simple.rs b/crates/hir-ty/src/tests/simple.rs
index a9a5e96f75..28759bcbae 100644
--- a/crates/hir-ty/src/tests/simple.rs
+++ b/crates/hir-ty/src/tests/simple.rs
@@ -3983,3 +3983,17 @@ fn foo() {
"#]],
);
}
+
+#[test]
+fn naked_asm_returns_never() {
+ check_no_mismatches(
+ r#"
+//- minicore: asm
+
+#[unsafe(naked)]
+extern "C" fn foo() -> ! {
+ core::arch::naked_asm!("");
+}
+ "#,
+ );
+}
diff --git a/crates/test-utils/src/minicore.rs b/crates/test-utils/src/minicore.rs
index c3429356d9..b96b936583 100644
--- a/crates/test-utils/src/minicore.rs
+++ b/crates/test-utils/src/minicore.rs
@@ -1880,6 +1880,10 @@ mod arch {
pub macro global_asm("assembly template", $(operands,)* $(options($(option),*))?) {
/* compiler built-in */
}
+ #[rustc_builtin_macro]
+ pub macro naked_asm("assembly template", $(operands,)* $(options($(option),*))?) {
+ /* compiler built-in */
+ }
}
// endregion:asm