about summary refs log tree commit diff
path: root/compiler/rustc_passes/src
AgeCommit message (Collapse)AuthorLines
2024-08-17Emit an error for invalid use of the linkage attributeShina-1/+23
2024-08-14Auto merge of #128812 - nnethercote:shrink-TyKind-FnPtr, r=compiler-errorsbors-6/+11
Shrink `TyKind::FnPtr`. By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI. r? `@compiler-errors`
2024-08-12Rollup merge of #128886 - GrigorenkoPV:untranslatable-diagnostic, r=nnethercoteGuillaume Gomez-5/+2
Get rid of some `#[allow(rustc::untranslatable_diagnostic)]` `@rustbot` label +A-translation cc https://github.com/rust-lang/rust/issues/100717
2024-08-11Rollup merge of #128762 - fmease:use-more-slice-pats, r=compiler-errorsMatthias Krüger-5/+3
Use more slice patterns inside the compiler Nothing super noteworthy. Just replacing the common 'fragile' pattern of "length check followed by indexing or unwrap" with slice patterns for legibility and 'robustness'. r? ghost
2024-08-10rustc_passes: make some messages in check_attr translatablePavel Grigorenko-4/+2
2024-08-10rustc_passes: remove a redundant `#[allow(rustc::untranslatable_diagnostic)]`Pavel Grigorenko-1/+0
2024-08-09Shrink `TyKind::FnPtr`.Nicholas Nethercote-6/+11
By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI.
2024-08-07Rollup merge of #128552 - s7tya:check-no-sanitize-attribute-pos, r=BoxyUwUTrevor Gross-1/+6
Emit an error for invalid use of the `#[no_sanitize]` attribute fixes #128487. Currently, the use of the `#[no_sanitize]` attribute for Mod, Impl,... is incorrectly permitted. This PR will correct this issue by generating errors, and I've also added some UI test cases for it. Referenced #128458. As far as I know, the `#[no_sanitize]` attribute can only be used with functions, so I changed that part to `Fn` and `Method` using `check_applied_to_fn_or_method`. However, I couldn't find explicit documentation on this, so I could be mistaken...
2024-08-07Use more slice patterns inside the compilerLeón Orell Valerian Liehr-5/+3
2024-08-06Don't Suggest Labeling `const` and `unsafe` BlocksVeera-14/+26
2024-08-06check_attr: treat cfg_attr like cfg许杰友 Jieyou Xu (Joe)-0/+1
2024-08-05Emit an error for invalid use of the `#[no_sanitize]` attributeShina-1/+6
2024-08-04check_attr: cover multi-segment attributes on specific check arms许杰友 Jieyou Xu (Joe)-71/+73
PR #128581 introduced an assertion that all builtin attributes are actually checked via `CheckAttrVisitor` and aren't accidentally usable on completely unrelated HIR nodes. Unfortunately, the check had correctness problems. The match on attribute path segments looked like ```rust,ignore [sym::should_panic] => /* check is implemented */ match BUILTIN_ATTRIBUTE_MAP.get(name) { // checked below Some(BuiltinAttribute { type_: AttributeType::CrateLevel, .. }) => {} Some(_) => { if !name.as_str().starts_with("rustc_") { span_bug!( attr.span, "builtin attribute {name:?} not handled by `CheckAttrVisitor`" ) } } None => (), } ``` However, it failed to account for edge cases such as an attribute whose: 1. path segments *starts* with a builtin attribute such as `should_panic` 2. which does not start with `rustc_`, and 3. is also an `AttributeType::Normal` attribute upon registration with the builtin attribute map These conditions when all satisfied cause the span bug to be issued for e.g. `#[should_panic::skip]` because the `[sym::should_panic]` arm is not matched (since it's `[sym::should_panic, sym::skip]`). See <https://github.com/rust-lang/rust/issues/128622>.
2024-08-03Rollup merge of #128581 - jieyouxu:checked-attr, r=nnethercoteMatthias Krüger-2/+71
Assert that all attributes are actually checked via `CheckAttrVisitor` and aren't accidentally usable on completely unrelated HIR nodes ``@oli-obk's`` #128444 with unreachable case removed to avoid that PR bitrotting away. Based on #128402. This PR will make adding a new attribute ICE on any use of that attribute unless it gets a handler added in `rustc_passes::CheckAttrVisitor`. r? ``@nnethercote`` (since you were the reviewer of the original PR)
2024-08-03Revert "Rollup merge of #125572 - mu001999-contrib:dead/enhance, r=pnkfelix"Michael Goulet-93/+28
This reverts commit 13314df21b0bb0cdd02c6760581d1b9f1052fa7e, reversing changes made to 6e534c73c35f569492ed5fb5f349075d58ed8b7e.
2024-08-03Revert "Rollup merge of #126315 - mu001999-contrib:fix/126289, r=petrochenkov"Michael Goulet-1/+1
This reverts commit 977c5fd419ade52467f7de79d5bfc25c0c893275, reversing changes made to 24c94f0e4f5aa333c665fbbba423172c30176624.
2024-08-03Revert "Rollup merge of #126618 - mu001999-contrib:dead/enhance, r=pnkfelix"Michael Goulet-25/+16
This reverts commit 2724aeaaeb127a8073e39461caacbe21a128ce7b, reversing changes made to d929a42a664c026167800801b26d734db925314f.
2024-08-03Revert "Rollup merge of #127107 - mu001999-contrib:dead/enhance-2, r=pnkfelix"Michael Goulet-12/+28
This reverts commit 31fe9628cf830a08e7194a446f66c668aaea86e9, reversing changes made to f20307851ead9fbbb9fa88bbffb3258a069230a6.
2024-08-03Revert "Rollup merge of #127017 - mu001999-contrib:dead/enhance, r=pnkfelix"Michael Goulet-22/+10
This reverts commit a70dc297a899b76793a14c5705f6ec78fd7a57a7, reversing changes made to ceae37188b9f1be527bb16c9d657a161be7dbbe3.
2024-08-03Revert "Rollup merge of #128104 - mu001999-contrib:fix/128053, r=petrochenkov"Michael Goulet-19/+17
This reverts commit 91b18a058c4661f82e420b633dc0a3e1ccd14b88, reversing changes made to 9aedec9313dc8ecf9bdcb5f09c4eb0ad8b9a4875.
2024-08-03Assert that all attributes are actually checked via `CheckAttrVisitor` and ↵Oli Scherer-2/+71
aren't accidentally usable on completely unrelated HIR nodes Co-authored-by: Jieyou Xu <jieyouxu@outlook.com>
2024-07-31Emit an error if `#[optimize]` is applied to an incompatible itemclubby789-0/+26
2024-07-31Rollup merge of #128402 - oli-obk:checked_attrs, r=compiler-errorsMatthias Krüger-367/+179
Attribute checking simplifications remove an unused boolean and then merge two big matches into one I was reviewing some attributes and realized we don't really check this list against the list of builtin attributes, so we "may" totally be missing some attributes that we should be checking (like the `coroutine` attribute, which you can just apply to random stuff) ```rust #![feature(coroutines)] #[coroutine] struct Foo; ``` just compiles for example. Unless we check that the fallthrough match arm is never reached for builtin attributes, we're just going to keep forgetting to add them here, too. I can do that without the changes in this PR, but it seemed like a nice cleanup
2024-07-30Rollup merge of #128380 - folkertdev:naked-compatible-doc-comment, r=bjorn3Matthias Krüger-0/+6
make `///` doc comments compatible with naked functions tracking issue: https://github.com/rust-lang/rust/issues/90957 reported in https://github.com/rust-lang/rust/pull/127853#issuecomment-2257323333 it turns out `/// doc comment` and `#[doc = "doc comment"]` are represented differently, at least at the point where we perform the check for what should be allowed. The `///` style doc comment is now also allowed. r? ``@bjorn3`` cc ``@hsanzg``
2024-07-30Attribute checking simplificationsOli Scherer-367/+179
remove an unused boolean and then merge two big matches into one
2024-07-30make `///` doc comments compatible with naked functionsFolkert-0/+6
2024-07-29Rollup merge of #128104 - mu001999-contrib:fix/128053, r=petrochenkovMatthias Krüger-17/+19
Not lint pub structs without pub constructors intentionally Fixes #128053
2024-07-29Reformat `use` declarations.Nicholas Nethercote-52/+50
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-28Rollup merge of #127853 - folkertdev:naked-function-error-messages, r=bjorn3Matthias Krüger-35/+77
`#[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-27Rollup merge of #128207 - folkertdev:asm-parser-generalize, r=AmanieuTrevor Gross-4/+1
improve error message when `global_asm!` uses `asm!` options specifically, what was error: expected one of `)`, `att_syntax`, or `raw`, found `preserves_flags` --> $DIR/bad-options.rs:45:25 | LL | global_asm!("", options(preserves_flags)); | ^^^^^^^^^^^^^^^ expected one of `)`, `att_syntax`, or `raw` is now error: the `preserves_flags` option cannot be used with `global_asm!` --> $DIR/bad-options.rs:45:25 | LL | global_asm!("", options(preserves_flags)); | ^^^^^^^^^^^^^^^ the `preserves_flags` option is not meaningful for global-scoped inline assembly mirroring the phrasing of the [reference](https://doc.rust-lang.org/reference/inline-assembly.html#options). This is also a bit of a refactor for a future `naked_asm!` macro (for use in `#[naked]` functions). Currently this sort of error can come up when switching from inline to global asm, or when a user just isn't that experienced with assembly. With `naked_asm!` added to the mix hitting this error is more likely.
2024-07-27allow `#[target_feature]` on `#[naked]` functionsFolkert-1/+1
2024-07-27switch to an allowlist approachFolkert-6/+43
- merge error codes - use attribute name that is incompatible in error message - add test for conditional incompatible attribute - add `linkage` to the allowlist
2024-07-26Not lint pub structs without pub constructors if containing fields of unit, ↵mu001999-17/+19
never type, PhantomData and positional ZST
2024-07-26Rollup merge of #127017 - mu001999-contrib:dead/enhance, r=pnkfelixTrevor Gross-10/+22
Extend rules of dead code analysis for impls for adts to impls for types refer to adts The rules of dead code analysis for impl blocks can be extended to self types which refer to adts. So that we can lint the following unused struct and trait: ```rust struct Foo; //~ ERROR struct `Foo` is never constructed trait Trait { //~ ERROR trait `Trait` is never used fn foo(&self) {} } impl Trait for &Foo {} ``` r? `@pnkfelix`
2024-07-25improve error message when `global_asm!` uses `asm!` optionsFolkert-4/+1
2024-07-25Rollup merge of #128138 - folkertdev:asm-option-allowlist, r=lcnrMatthias Krüger-12/+9
`#[naked]`: use an allowlist for allowed options on `asm!` in naked functions tracking issue: https://github.com/rust-lang/rust/issues/90957 this is mostly just a refactor, but using an allowlist (rather than a denylist) for which asm options are allowed in naked functions is a little safer. These options are disallowed because naked functions are effectively global asm, but defined using inline asm.
2024-07-24use an allow list for allowed asm options in naked functionsFolkert-12/+9
2024-07-21Move all error reporting into rustc_trait_selectionMichael Goulet-2/+2
2024-07-16hir: Create `hir::ConstArgKind` enumNoah Lev-1/+1
This will allow lowering const params to a dedicated enum variant, rather than to an `AnonConst` that is later examined during `ty` lowering.
2024-07-16improve error message when `#[naked]` is used with `#[track-caller] and ↵Folkert-13/+15
`#[target-feature]``
2024-07-16improve error message when `#[naked]` is used with `#[inline]`Folkert-34/+37
2024-07-10Report usage of lib features in ast validationMichael Goulet-14/+0
2024-07-08Move trait selection error reporting to its own top-level moduleMichael Goulet-2/+2
2024-07-05Rollup merge of #127107 - mu001999-contrib:dead/enhance-2, r=pnkfelixMichael Goulet-28/+12
Improve dead code analysis Fixes #120770 1. check impl items later if self ty is private although the trait method is public, cause we must use the ty firstly if it's private 2. mark the adt live if it appears in pattern, like generic argument, this implies the use of the adt 3. based on the above, we can handle the case that private adts impl Default, so that we don't need adding rustc_trivial_field_reads on Default, and the logic in should_ignore_item r? ``@pnkfelix``
2024-07-04Auto merge of #123781 - RalfJung:miri-fn-identity, r=oli-obkbors-1/+1
Miri function identity hack: account for possible inlining Having a non-lifetime generic is not the only reason a function can be duplicated. Another possibility is that the function may be eligible for cross-crate inlining. So also take into account the inlining attribute in this Miri hack for function pointer identity. That said, `cross_crate_inlinable` will still sometimes return true even for `inline(never)` functions: - when they are `DefKind::Ctor(..) | DefKind::Closure` -- I assume those cannot be `InlineAttr::Never` anyway? - when `cross_crate_inline_threshold == InliningThreshold::Always` so maybe this is still not quite the right criterion to use for function pointer identity.
2024-07-04Improve dead code analysismu001999-28/+12
2024-07-03Rollup merge of #127092 - compiler-errors:rtn-dots-redux, r=estebankMatthias Krüger-1/+1
Change return-type-notation to use `(..)` Aligns the syntax with the current wording of [RFC 3654](https://github.com/rust-lang/rfcs/pull/3654). Also implements rustfmt support (along with making a match exhaustive). Tracking: * https://github.com/rust-lang/rust/issues/109417
2024-07-03Auto merge of #125507 - compiler-errors:type-length-limit, r=lcnrbors-1/+1
Re-implement a type-size based limit r? lcnr This PR reintroduces the type length limit added in #37789, which was accidentally made practically useless by the caching changes to `Ty::walk` in #72412, which caused the `walk` function to no longer walk over identical elements. Hitting this length limit is not fatal unless we are in codegen -- so it shouldn't affect passes like the mir inliner which creates potentially very large types (which we observed, for example, when the new trait solver compiles `itertools` in `--release` mode). This also increases the type length limit from `1048576 == 2 ** 20` to `2 ** 24`, which covers all of the code that can be reached with craterbot-check. Individual crates can increase the length limit further if desired. Perf regression is mild and I think we should accept it -- reinstating this limit is important for the new trait solver and to make sure we don't accidentally hit more type-size related regressions in the future. Fixes #125460
2024-07-02Instance::resolve -> Instance::try_resolve, and other nitsMichael Goulet-1/+1
2024-07-02Miri function identity hack: account for possible inliningRalf Jung-1/+1