about summary refs log tree commit diff
path: root/compiler/rustc_passes/src/naked_functions.rs
AgeCommit message (Collapse)AuthorLines
2025-05-30Move naked fn checks to hir_typeckOli Scherer-204/+0
2025-05-30Change a per-module query to just run on the items it internally filters forOli Scherer-31/+8
2025-05-30Move naked asm check into typeckOli Scherer-29/+1
2025-04-07Add `naked_functions_rustic_abi` feature gateFolkert de Vries-27/+6
2025-03-06Implement .use keyword as an alias of cloneSantiago Pastorino-0/+1
2025-02-17Overhaul the `intravisit::Map` trait.Nicholas Nethercote-2/+2
First of all, note that `Map` has three different relevant meanings. - The `intravisit::Map` trait. - The `map::Map` struct. - The `NestedFilter::Map` associated type. The `intravisit::Map` trait is impl'd twice. - For `!`, where the methods are all unreachable. - For `map::Map`, which gets HIR stuff from the `TyCtxt`. As part of getting rid of `map::Map`, this commit changes `impl intravisit::Map for map::Map` to `impl intravisit::Map for TyCtxt`. It's fairly straightforward except various things are renamed, because the existing names would no longer have made sense. - `trait intravisit::Map` becomes `trait intravisit::HirTyCtxt`, so named because it gets some HIR stuff from a `TyCtxt`. - `NestedFilter::Map` assoc type becomes `NestedFilter::MaybeTyCtxt`, because it's always `!` or `TyCtxt`. - `Visitor::nested_visit_map` becomes `Visitor::maybe_tcx`. I deliberately made the new trait and associated type names different to avoid the old `type Map: Map` situation, which I found confusing. We now have `type MaybeTyCtxt: HirTyCtxt`.
2025-02-17Move some `Map` methods onto `TyCtxt`.Nicholas Nethercote-1/+1
The end goal is to eliminate `Map` altogether. I added a `hir_` prefix to all of them, that seemed simplest. The exceptions are `module_items` which became `hir_module_free_items` because there was already a `hir_module_items`, and `items` which became `hir_free_items` for consistency with `hir_module_free_items`.
2025-02-09compiler: remove rustc_target::spec::abi reexportsJubilee Young-3/+3
2025-01-04turn hir::ItemKind::Fn into a named-field variantRalf Jung-1/+4
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-2/+1
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-12Add unwrap_unsafe_binder and wrap_unsafe_binder macro operatorsMichael Goulet-0/+1
2024-10-06various fixes for `naked_asm!` implementationFolkert de Vries-17/+13
- fix for divergence - fix error message - fix another cranelift test - fix some cranelift things - don't set the NORETURN option for naked asm - fix use of naked_asm! in doc comment - fix use of naked_asm! in run-make test - use `span_bug` in unreachable branch
2024-10-06remove checks that are now performed during macro expansion of `naked_asm!`Folkert de Vries-45/+8
2024-10-06disallow `asm!` in `#[naked]` functionsFolkert de Vries-19/+28
also disallow the `noreturn` option, and infer `naked_asm!` as `!`
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-1/+1
2024-09-10disallow `naked_asm!` outside of `#[naked]` functionsFolkert de Vries-11/+37
2024-07-28Rollup merge of #127853 - folkertdev:naked-function-error-messages, r=bjorn3Matthias Krüger-12/+2
`#[naked]`: report incompatible attributes tracking issue: https://github.com/rust-lang/rust/issues/90957 this is a re-implementation of https://github.com/rust-lang/rust/pull/93809 by ``@bstrie`` which was closed 2 years ago due to inactivity. This PR takes some of the final comments into account, specifically providing a little more context in error messages, and using an allow list to determine which attributes are compatible with `#[naked]`. Notable attributes that are incompatible with `#[naked]` are: * `#[inline]` * `#[track_caller]` * ~~`#[target_feature]`~~ (this is now allowed, see PR discussion) * `#[test]`, `#[ignore]`, `#[should_panic]` These attributes just directly conflict with what `#[naked]` should do. Naked functions are still important for systems programming, embedded, and operating systems, so I'd like to move them forward.
2024-07-25improve error message when `global_asm!` uses `asm!` optionsFolkert-4/+1
2024-07-24use an allow list for allowed asm options in naked functionsFolkert-12/+9
2024-07-16improve error message when `#[naked]` is used with `#[inline]`Folkert-12/+2
2024-04-17Rename `BindingAnnotation` to `BindingMode`Jules Bertholet-2/+1
2024-04-16Avoid lots of `hir::HirId{,Map,Set}` qualifiers.Nicholas Nethercote-3/+3
Because they're a bit redundant.
2024-03-14Rename `hir::StmtKind::Local` into `hir::StmtKind::Let`Guillaume Gomez-1/+1
2024-02-24Add asm label support to AST and HIRGary Guo-1/+2
2024-01-23Rename `TyCtxt::emit_spanned_lint` as `TyCtxt::emit_node_span_lint`.Nicholas Nethercote-1/+1
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-7/+7
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-12Move some methods from `tcx.hir()` to `tcx`zetanumbers-1/+1
Renamings: - find -> opt_hir_node - get -> hir_node - find_by_def_id -> opt_hir_node_by_def_id - get_by_def_id -> hir_node_by_def_id Fix rebase changes using removed methods Use `tcx.hir_node_by_def_id()` whenever possible in compiler Fix clippy errors Fix compiler Apply suggestions from code review Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com> Add FIXME for `tcx.hir()` returned type about its removal Simplify with with `tcx.hir_node_by_def_id`
2023-11-26rustc: `hir().local_def_id_to_hir_id()` -> `tcx.local_def_id_to_hir_id()` ↵Vadim Petrochenkov-1/+1
cleanup
2023-11-21Fix `clippy::needless_borrow` in the compilerNilstrieb-3/+3
`x clippy compiler -Aclippy::all -Wclippy::needless_borrow --fix`. Then I had to remove a few unnecessary parens and muts that were exposed now.
2023-08-14Use `{Local}ModDefId` in many queriesNilstrieb-2/+2
2023-06-26`hir`: Add `Become` expression kindMaybe Waffle-0/+1
2023-05-15Move expansion of query macros in rustc_middle to rustc_middle::queryJohn Kåre Alsaker-1/+1
2023-04-21offset_ofDrMeepster-0/+1
2023-03-21Use local key in providersMichael Goulet-2/+2
2023-03-14Remove box expressions from HIRclubby789-2/+1
2023-02-25Add ErrorGuaranteed to HIR ExprKind::ErrMichael Goulet-1/+1
2022-10-07migrate naked_functions.rs to translateable diagnosticsNathan Stocks-59/+25
2022-10-01Refactor rustc lint APIMaybe Waffle-3/+7
2022-09-02Refactor and re-use BindingAnnotationCameron Steffen-1/+1
2022-08-03Only fetch HIR for naked functions that have the attribute.Camille GILLOT-53/+41
2022-07-07Reword comments and rename HIR visiting methods.Camille GILLOT-1/+1
2022-06-15Rollup merge of #98110 - cjgillot:closure-brace, r=Aaron1011Yuki Okushi-1/+1
Make `ExprKind::Closure` a struct variant. Simple refactor since we both need it to introduce additional fields in `ExprKind::Closure`. r? ``@Aaron1011``
2022-06-13remove unnecessary `to_string` and `String::new`Takayuki Maeda-1/+1
2022-06-12Make `ExprKind::Closure` a struct variant.Camille GILLOT-1/+1
2022-05-20Remove `crate` visibility usage in compilerJacob Pratt-1/+1
2022-05-13rename visit item-like methodsMiguel Guarniz-1/+1
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-05-13remove ItemLikeVisitor and DeepVisitorMiguel Guarniz-4/+1
Signed-off-by: Miguel Guarniz <mi9uel9@gmail.com>
2022-04-14Reimplement lowering of sym operands for asm! so that it also works with ↵Amanieu d'Antras-1/+3
global_asm!
2022-04-03Rollup merge of #95553 - jam1garner:naked-function-compile-error, r=tmiaskoDylan DPC-3/+22
Don't emit non-asm contents error for naked function composed of errors ## Motivation For naked functions an error is emitted when they are composed of anything other than a single asm!() block. However, this error triggers in a couple situations in which it adds no additional information or is actively misleading. One example is if you do have an asm!() block but simply one with a syntax error: ```rust #[naked] unsafe extern "C" fn compiler_errors() { asm!(invalid_syntax) } ``` This results in two errors, one for the syntax error itself and another telling you that you need an asm block in your function: ```rust error[E0787]: naked functions must contain a single asm block --> src/main.rs:6:1 | 6 | / unsafe extern "C" fn naked_compile_error() { 7 | | asm!(blah) 8 | | } | |_^ ``` This issue also comes up when [utilizing `compile_error!()` for improving your diagnostics](https://twitter.com/steveklabnik/status/1509538243020218372), such as raising a compiler error when compiling for an unsupported target. ## Implementation The rules this PR implements are as follows: 1. If any non-erroneous non-asm statement is included, an error will still occur 2. If multiple asm statements are included, an error will still occur 3. If 0 or 1 asm statements are present, as well as any non-zero number of erroneous statements, then this error will *not* be raised as it is likely either redundant or incorrect The rule of thumb is effectively "if an error is present and its correction could change things, don't raise an error".
2022-04-01Reword purpose description of noreturn in naked functionjam1garner-1/+1