Skip to content

Commit 10fa482

Browse files
committed
remove checks that are now performed during macro expansion of naked_asm!
1 parent bc0a954 commit 10fa482

File tree

3 files changed

+8
-66
lines changed

3 files changed

+8
-66
lines changed

compiler/rustc_passes/messages.ftl

-6
Original file line numberDiff line numberDiff line change
@@ -492,9 +492,6 @@ passes_naked_functions_asm_block =
492492
.label_multiple_asm = multiple `naked_asm!` invocations are not allowed in naked functions
493493
.label_non_asm = not allowed in naked functions
494494
495-
passes_naked_functions_asm_options =
496-
asm options unsupported in naked functions: {$unsupported_options}
497-
498495
passes_naked_functions_incompatible_attribute =
499496
attribute incompatible with `#[naked]`
500497
.label = the `{$attr}` attribute is incompatible with `#[naked]`
@@ -504,9 +501,6 @@ passes_naked_functions_must_naked_asm =
504501
the `asm!` macro is not allowed in naked functions
505502
.suggestion = consider using the `naked_asm!` macro instead
506503
507-
passes_naked_functions_operands =
508-
only `const` and `sym` operands are supported in naked functions
509-
510504
passes_no_link =
511505
attribute should be applied to an `extern crate` item
512506
.label = not an `extern crate` item

compiler/rustc_passes/src/errors.rs

-15
Original file line numberDiff line numberDiff line change
@@ -1186,21 +1186,6 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for NakedFunctionsAsmBlock {
11861186
}
11871187
}
11881188

1189-
#[derive(Diagnostic)]
1190-
#[diag(passes_naked_functions_operands, code = E0787)]
1191-
pub(crate) struct NakedFunctionsOperands {
1192-
#[primary_span]
1193-
pub unsupported_operands: Vec<Span>,
1194-
}
1195-
1196-
#[derive(Diagnostic)]
1197-
#[diag(passes_naked_functions_asm_options, code = E0787)]
1198-
pub(crate) struct NakedFunctionsAsmOptions {
1199-
#[primary_span]
1200-
pub span: Span,
1201-
pub unsupported_options: String,
1202-
}
1203-
12041189
#[derive(Diagnostic)]
12051190
#[diag(passes_naked_functions_must_naked_asm, code = E0787)]
12061191
pub(crate) struct NakedFunctionsMustNakedAsm {

compiler/rustc_passes/src/naked_functions.rs

+8-45
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
//! Checks validity of naked functions.
22
3-
use rustc_ast::InlineAsmOptions;
43
use rustc_hir as hir;
54
use rustc_hir::def::DefKind;
65
use rustc_hir::def_id::{LocalDefId, LocalModDefId};
76
use rustc_hir::intravisit::Visitor;
8-
use rustc_hir::{ExprKind, HirIdSet, InlineAsmOperand, StmtKind};
7+
use rustc_hir::{ExprKind, HirIdSet, StmtKind};
98
use rustc_middle::hir::nested_filter::OnlyBodies;
109
use rustc_middle::query::Providers;
1110
use rustc_middle::ty::TyCtxt;
@@ -15,9 +14,8 @@ use rustc_span::{BytePos, Span};
1514
use rustc_target::spec::abi::Abi;
1615

1716
use crate::errors::{
18-
NakedAsmOutsideNakedFn, NakedFunctionsAsmBlock, NakedFunctionsAsmOptions,
19-
NakedFunctionsMustNakedAsm, NakedFunctionsOperands, NoPatterns, ParamsNotAllowed,
20-
UndefinedNakedFunctionAbi,
17+
NakedAsmOutsideNakedFn, NakedFunctionsAsmBlock, NakedFunctionsMustNakedAsm, NoPatterns,
18+
ParamsNotAllowed, UndefinedNakedFunctionAbi,
2119
};
2220

2321
pub(crate) fn provide(providers: &mut Providers) {
@@ -119,7 +117,7 @@ impl<'tcx> Visitor<'tcx> for CheckParameters<'tcx> {
119117

120118
/// Checks that function body contains a single inline assembly block.
121119
fn check_asm<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &'tcx hir::Body<'tcx>) {
122-
let mut this = CheckInlineAssembly { tcx, items: Vec::new() };
120+
let mut this = CheckInlineAssembly { items: Vec::new() };
123121
this.visit_body(body);
124122
if let [(ItemKind::NakedAsm | ItemKind::Err, _)] = this.items[..] {
125123
// Ok.
@@ -165,8 +163,7 @@ fn check_asm<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &'tcx hir::Body<
165163
}
166164
}
167165

168-
struct CheckInlineAssembly<'tcx> {
169-
tcx: TyCtxt<'tcx>,
166+
struct CheckInlineAssembly {
170167
items: Vec<(ItemKind, Span)>,
171168
}
172169

@@ -178,8 +175,8 @@ enum ItemKind {
178175
Err,
179176
}
180177

181-
impl<'tcx> CheckInlineAssembly<'tcx> {
182-
fn check_expr(&mut self, expr: &'tcx hir::Expr<'tcx>, span: Span) {
178+
impl CheckInlineAssembly {
179+
fn check_expr<'tcx>(&mut self, expr: &'tcx hir::Expr<'tcx>, span: Span) {
183180
match expr.kind {
184181
ExprKind::ConstBlock(..)
185182
| ExprKind::Array(..)
@@ -220,7 +217,6 @@ impl<'tcx> CheckInlineAssembly<'tcx> {
220217
}
221218
rustc_ast::AsmMacro::NakedAsm => {
222219
self.items.push((ItemKind::NakedAsm, span));
223-
self.check_inline_asm(asm, span);
224220
}
225221
rustc_ast::AsmMacro::GlobalAsm => {
226222
// not allowed in this position
@@ -237,42 +233,9 @@ impl<'tcx> CheckInlineAssembly<'tcx> {
237233
}
238234
}
239235
}
240-
241-
fn check_inline_asm(&self, asm: &'tcx hir::InlineAsm<'tcx>, span: Span) {
242-
let unsupported_operands: Vec<Span> = asm
243-
.operands
244-
.iter()
245-
.filter_map(|&(ref op, op_sp)| match op {
246-
InlineAsmOperand::Const { .. }
247-
| InlineAsmOperand::SymFn { .. }
248-
| InlineAsmOperand::SymStatic { .. } => None,
249-
InlineAsmOperand::In { .. }
250-
| InlineAsmOperand::Out { .. }
251-
| InlineAsmOperand::InOut { .. }
252-
| InlineAsmOperand::SplitInOut { .. }
253-
| InlineAsmOperand::Label { .. } => Some(op_sp),
254-
})
255-
.collect();
256-
if !unsupported_operands.is_empty() {
257-
self.tcx.dcx().emit_err(NakedFunctionsOperands { unsupported_operands });
258-
}
259-
260-
let unsupported_options = asm.options.difference(InlineAsmOptions::NAKED_OPTIONS);
261-
if !unsupported_options.is_empty() {
262-
self.tcx.dcx().emit_err(NakedFunctionsAsmOptions {
263-
span,
264-
unsupported_options: unsupported_options
265-
.human_readable_names()
266-
.into_iter()
267-
.map(|name| format!("`{name}`"))
268-
.collect::<Vec<_>>()
269-
.join(", "),
270-
});
271-
}
272-
}
273236
}
274237

275-
impl<'tcx> Visitor<'tcx> for CheckInlineAssembly<'tcx> {
238+
impl<'tcx> Visitor<'tcx> for CheckInlineAssembly {
276239
fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt<'tcx>) {
277240
match stmt.kind {
278241
StmtKind::Item(..) => {}

0 commit comments

Comments
 (0)