Skip to content

Commit be6b3c1

Browse files
committed
remove checks that are now performed during macro expansion of naked_asm!
1 parent 06dfdbe commit be6b3c1

File tree

3 files changed

+8
-65
lines changed

3 files changed

+8
-65
lines changed

Diff for: compiler/rustc_passes/messages.ftl

-6
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,6 @@ passes_naked_functions_asm_block =
489489
.label_multiple_asm = multiple `naked_asm!` invocations are not allowed in naked functions
490490
.label_non_asm = not allowed in naked functions
491491
492-
passes_naked_functions_asm_options =
493-
asm options unsupported in naked functions: {$unsupported_options}
494-
495492
passes_naked_functions_incompatible_attribute =
496493
attribute incompatible with `#[naked]`
497494
.label = the `{$attr}` attribute is incompatible with `#[naked]`
@@ -501,9 +498,6 @@ passes_naked_functions_must_naked_asm =
501498
the `asm!` macro is not allowed in naked functions
502499
.suggestion = consider using the `naked_asm!` macro instead
503500
504-
passes_naked_functions_operands =
505-
only `const` and `sym` operands are supported in naked functions
506-
507501
passes_no_link =
508502
attribute should be applied to an `extern crate` item
509503
.label = not an `extern crate` item

Diff for: 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 {

Diff for: compiler/rustc_passes/src/naked_functions.rs

+8-44
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::query::Providers;
109
use rustc_middle::ty::TyCtxt;
1110
use rustc_session::lint::builtin::UNDEFINED_NAKED_FUNCTION_ABI;
@@ -14,8 +13,8 @@ use rustc_span::{BytePos, Span};
1413
use rustc_target::spec::abi::Abi;
1514

1615
use crate::errors::{
17-
NakedFunctionsAsmBlock, NakedFunctionsAsmOptions, NakedFunctionsMustNakedAsm,
18-
NakedFunctionsOperands, NoPatterns, ParamsNotAllowed, UndefinedNakedFunctionAbi,
16+
NakedFunctionsAsmBlock, NakedFunctionsMustNakedAsm, NoPatterns, ParamsNotAllowed,
17+
UndefinedNakedFunctionAbi,
1918
};
2019

2120
pub(crate) fn provide(providers: &mut Providers) {
@@ -114,7 +113,7 @@ impl<'tcx> Visitor<'tcx> for CheckParameters<'tcx> {
114113

115114
/// Checks that function body contains a single inline assembly block.
116115
fn check_asm<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &'tcx hir::Body<'tcx>) {
117-
let mut this = CheckInlineAssembly { tcx, items: Vec::new() };
116+
let mut this = CheckInlineAssembly { items: Vec::new() };
118117
this.visit_body(body);
119118
if let [(ItemKind::NakedAsm | ItemKind::Err, _)] = this.items[..] {
120119
// Ok.
@@ -160,8 +159,7 @@ fn check_asm<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &'tcx hir::Body<
160159
}
161160
}
162161

163-
struct CheckInlineAssembly<'tcx> {
164-
tcx: TyCtxt<'tcx>,
162+
struct CheckInlineAssembly {
165163
items: Vec<(ItemKind, Span)>,
166164
}
167165

@@ -173,8 +171,8 @@ enum ItemKind {
173171
Err,
174172
}
175173

176-
impl<'tcx> CheckInlineAssembly<'tcx> {
177-
fn check_expr(&mut self, expr: &'tcx hir::Expr<'tcx>, span: Span) {
174+
impl CheckInlineAssembly {
175+
fn check_expr<'tcx>(&mut self, expr: &'tcx hir::Expr<'tcx>, span: Span) {
178176
match expr.kind {
179177
ExprKind::ConstBlock(..)
180178
| ExprKind::Array(..)
@@ -215,7 +213,6 @@ impl<'tcx> CheckInlineAssembly<'tcx> {
215213
}
216214
rustc_ast::AsmMacro::NakedAsm => {
217215
self.items.push((ItemKind::NakedAsm, span));
218-
self.check_inline_asm(asm, span);
219216
}
220217
rustc_ast::AsmMacro::GlobalAsm => {
221218
// not allowed in this position
@@ -232,42 +229,9 @@ impl<'tcx> CheckInlineAssembly<'tcx> {
232229
}
233230
}
234231
}
235-
236-
fn check_inline_asm(&self, asm: &'tcx hir::InlineAsm<'tcx>, span: Span) {
237-
let unsupported_operands: Vec<Span> = asm
238-
.operands
239-
.iter()
240-
.filter_map(|&(ref op, op_sp)| match op {
241-
InlineAsmOperand::Const { .. }
242-
| InlineAsmOperand::SymFn { .. }
243-
| InlineAsmOperand::SymStatic { .. } => None,
244-
InlineAsmOperand::In { .. }
245-
| InlineAsmOperand::Out { .. }
246-
| InlineAsmOperand::InOut { .. }
247-
| InlineAsmOperand::SplitInOut { .. }
248-
| InlineAsmOperand::Label { .. } => Some(op_sp),
249-
})
250-
.collect();
251-
if !unsupported_operands.is_empty() {
252-
self.tcx.dcx().emit_err(NakedFunctionsOperands { unsupported_operands });
253-
}
254-
255-
let unsupported_options = asm.options.difference(InlineAsmOptions::NAKED_OPTIONS);
256-
if !unsupported_options.is_empty() {
257-
self.tcx.dcx().emit_err(NakedFunctionsAsmOptions {
258-
span,
259-
unsupported_options: unsupported_options
260-
.human_readable_names()
261-
.into_iter()
262-
.map(|name| format!("`{name}`"))
263-
.collect::<Vec<_>>()
264-
.join(", "),
265-
});
266-
}
267-
}
268232
}
269233

270-
impl<'tcx> Visitor<'tcx> for CheckInlineAssembly<'tcx> {
234+
impl<'tcx> Visitor<'tcx> for CheckInlineAssembly {
271235
fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt<'tcx>) {
272236
match stmt.kind {
273237
StmtKind::Item(..) => {}

0 commit comments

Comments
 (0)