1
Fork 0

Add error message suggestion for missing noreturn in naked function

This commit is contained in:
jam1garner 2022-03-31 18:14:01 -04:00
parent 03314912f1
commit b657cb5577
2 changed files with 39 additions and 1 deletions

View file

@ -1,7 +1,7 @@
//! Checks validity of naked functions.
use rustc_ast::{Attribute, InlineAsmOptions};
use rustc_errors::struct_span_err;
use rustc_errors::{struct_span_err, Applicability};
use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId;
use rustc_hir::intravisit::{FnKind, Visitor};
@ -274,12 +274,25 @@ impl<'tcx> CheckInlineAssembly<'tcx> {
}
if !asm.options.contains(InlineAsmOptions::NORETURN) {
let last_span = asm
.operands
.last()
.map_or_else(|| asm.template_strs.last().unwrap().2, |op| op.1)
.shrink_to_hi();
struct_span_err!(
self.tcx.sess,
span,
E0787,
"asm in naked functions must use `noreturn` option"
)
.span_suggestion(
last_span,
"consider specifying that the asm block is responsible \
for returning, if desired",
String::from(", options(noreturn)"),
Applicability::MachineApplicable,
)
.emit();
}
}