about summary refs log tree commit diff
path: root/compiler/rustc_passes
AgeCommit message (Collapse)AuthorLines
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-14/+16
`#[target-feature]``
2024-07-16improve error message when `#[naked]` is used with `#[inline]`Folkert-40/+42
2024-07-10Report usage of lib features in ast validationMichael Goulet-17/+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
2024-07-02chore: remove duplicate wordshattizai-1/+1
2024-06-29Rollup merge of #127118 - surechen:fix_126789, r=jieyouxuMatthias Krüger-3/+11
Show `used attribute`'s kind for user when find it isn't applied to a `static` variable. For example : ```rust extern "C" { #[used] //~ ERROR attribute must be applied to a `static` variable static FOO: i32; // show the kind of this item to help user understand why the error is reported. } ``` fixes #126789
2024-06-29Show `used attribute`'s kind for user when find it isn't applied to a ↵surechen-3/+11
`static` variable. fixes #126789
2024-06-28Revert "Rollup merge of #126938 - RalfJung:link_section, r=compiler-errors"Rémy Rakic-2/+10
This reverts commit 5c4ede88c61e746ed5c852d7a7e38ab1a824ae52, reversing changes made to 95332b89187bb6a0c910574cfeff1933b619565a.
2024-06-28Change RTN to use .. againMichael Goulet-1/+1
2024-06-27Extend rules of dead code analysis for impls for adts to impls for types ↵mu001999-10/+22
refer to adts
2024-06-27Rollup merge of #126721 - Zalathar:nested-cov-attr, r=oli-obkJacob Pratt-3/+6
coverage: Make `#[coverage(..)]` apply recursively to nested functions This PR makes the (currently-unstable) `#[coverage(off)]` and `#[coverage(on)]` attributes apply recursively to all nested functions/closures, instead of just the function they are directly attached to. Those attributes can now also be applied to modules and to impl/impl-trait blocks, where they have no direct effect, but will be inherited by all enclosed functions/closures/methods that don't override the inherited value. --- Fixes #126625.
2024-06-26Rollup merge of #126938 - RalfJung:link_section, r=compiler-errorsMatthias Krüger-10/+2
miri: make sure we can find link_section statics even for the local crate Miri needs some way to iterate all the exported functions and "used" statics of all crates. For dependency crates, this already works fine since we can overwrite the query resonsible for computing `exported_symbols`, but it turns out for local binary crates this does not work: for binaries, `reachable_set` skips a lot of its logic and only checks `contains_extern_indicator()` and `RUSTC_STD_INTERNAL_SYMBOL`. Other flags like `CodegenFnAttrFlags::USED` are entirely ignored. This PR proposes to use the same check, `has_custom_linkage`, in binaries that we already use to drive the main workqueue of the reachability recursive traversal. I have no idea why binaries used a slightly different check that ignores `USED` -- was that deliberate or does it just not matter most of the time?
2024-06-26coverage: Allow `#[coverage(..)]` on `impl` and `mod`Zalathar-3/+6
These attributes apply to all enclosed functions/methods/closures, unless explicitly overridden by another coverage attribute.
2024-06-25Auto merge of #126951 - matthiaskrgr:rollup-xg0o4mc, r=matthiaskrgrbors-16/+25
Rollup of 7 pull requests Successful merges: - #126618 (Mark assoc tys live only if the corresponding trait is live) - #126746 (Deny `use<>` for RPITITs) - #126868 (not use offset when there is not ends with brace) - #126884 (Do not ICE when suggesting dereferencing closure arg) - #126893 (Eliminate the distinction between PREC_POSTFIX and PREC_PAREN precedence level) - #126915 (Don't suggest awaiting in closure patterns) - #126943 (De-duplicate all consecutive native libs regardless of their options) r? `@ghost` `@rustbot` modify labels: rollup
2024-06-25Rollup merge of #126302 - mu001999-contrib:ignore/default, r=michaelwoeristerMatthias Krüger-0/+25
Detect unused structs which derived Default <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> --> Fixes #98871
2024-06-25Rollup merge of #126618 - mu001999-contrib:dead/enhance, r=pnkfelixMatthias Krüger-16/+25
Mark assoc tys live only if the corresponding trait is live r? ````@pnkfelix````
2024-06-25Detect unused structs which derived Defaultmu001999-0/+25
2024-06-25miri: make sure we can find link_section statics even for the local crateRalf Jung-10/+2
2024-06-24Rollup merge of #126682 - Zalathar:coverage-attr, r=lcnrMichael Goulet-63/+10
coverage: Overhaul validation of the `#[coverage(..)]` attribute This PR makes sweeping changes to how the (currently-unstable) coverage attribute is validated: - Multiple coverage attributes on the same item/expression are now treated as an error. - The attribute must always be `#[coverage(off)]` or `#[coverage(on)]`, and the error messages for this are more consistent. - A trailing comma is still allowed after off/on, since that's part of the normal attribute syntax. - Some places that silently ignored a coverage attribute now produce an error instead. - These cases were all clearly bugs. - Some places that ignored a coverage attribute (with a warning) now produce an error instead. - These were originally added as lints, but I don't think it makes much sense to knowingly allow new attributes to be used in meaningless places. - Some of these errors might soon disappear, if it's easy to extend recursive coverage attributes to things like modules and impl blocks. --- One of the goals of this PR is to lay a more solid foundation for making the coverage attribute recursive, so that it applies to all nested functions/closures instead of just the one it is directly attached to. Fixes #126658. This PR incorporates #126659, which adds more tests for validation of the coverage attribute. `@rustbot` label +A-code-coverage
2024-06-24Rollup merge of #124460 - long-long-float:show-notice-about-enum-with-debug, ↵Michael Goulet-0/+19
r=pnkfelix Show notice about "never used" of Debug for enum Close #123068 If an ADT implements `Debug` trait and it is not used, the compiler says a note that indicates intentionally ignored during dead code analysis as [this note](https://github.com/rust-lang/rust/blob/2207179a591f5f252885a94ab014dafeb6e8e9e8/tests/ui/lint/dead-code/unused-variant.stderr#L9). However this node is not shown for variants that have fields in enum. This PR fixes to show the note.
2024-06-24coverage: Always error on `#[coverage(..)]` in unexpected placesZalathar-63/+10
This upgrades some warnings to errors, and also catches cases where the attribute was silently ignored.
2024-06-23Add hard error and migration lint for unsafe attrscarbotaniuman-34/+2
2024-06-21Fix remaining casesMichael Goulet-9/+9
2024-06-19Rollup merge of #124580 - gurry:124556-suggest-remove-tuple-field, r=jackh726León Orell Valerian Liehr-19/+67
Suggest removing unused tuple fields if they are the last fields Fixes #124556 We now check if dead/unused fields are the last fields of the tuple and suggest their removal instead of suggesting them to be changed to `()`.
2024-06-18Use a dedicated type instead of a reference for the diagnostic contextOli Scherer-10/+10
This paves the way for tracking more state (e.g. error tainting) in the diagnostic context handle
2024-06-18Mark assoc tys live only if the trait is livemu001999-16/+25
2024-06-17Rework precise capturing syntaxMichael Goulet-2/+2
2024-06-16Show notice about "never used" for enumlong-long-float-0/+19
2024-06-13Rollup merge of #126315 - mu001999-contrib:fix/126289, r=petrochenkovMatthias Krüger-1/+1
Add pub struct with allow(dead_code) into worklist <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> --> Fixes #126289
2024-06-12Rollup merge of #126276 - mu001999-contrib:dead/enhance, r=fee1-deadMichael Goulet-2/+2
Detect pub structs never constructed even though they impl pub trait with assoc constants Extend dead code analysis to impl items of pub assoc constants. <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> -->
2024-06-12Detect pub structs never constructed even though they impl pub trait with ↵r0cky-2/+2
assoc constants
2024-06-12Add pub struct with allow(dead_code) into worklistr0cky-1/+1
2024-06-12Use `tidy` to sort crate attributes for all compiler crates.Nicholas Nethercote-2/+4
We already do this for a number of crates, e.g. `rustc_middle`, `rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`. For the ones we don't, in many cases the attributes are a mess. - There is no consistency about order of attribute kinds (e.g. `allow`/`deny`/`feature`). - Within attribute kind groups (e.g. the `feature` attributes), sometimes the order is alphabetical, and sometimes there is no particular order. - Sometimes the attributes of a particular kind aren't even grouped all together, e.g. there might be a `feature`, then an `allow`, then another `feature`. This commit extends the existing sorting to all compiler crates, increasing consistency. If any new attribute line is added there is now only one place it can go -- no need for arbitrary decisions. Exceptions: - `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`, because they have no crate attributes. - `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's ignored in `rustfmt.toml`).
2024-06-11reachable computation: clarify comments around constsRalf Jung-6/+9
2024-06-07Rollup merge of #125572 - mu001999-contrib:dead/enhance, r=pnkfelixMatthias Krüger-28/+93
Detect pub structs never constructed and unused associated constants <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> --> Lints never constructed public structs. If we don't provide public methods to construct public structs with private fields, and don't construct them in the local crate. They would be never constructed. So that we can detect such public structs. --- Update: Also lints unused associated constants in traits.
2024-06-07Rollup merge of #124214 - carbotaniuman:parse_unsafe_attrs, r=michaelwoeristerMatthias Krüger-2/+34
Parse unsafe attributes Initial parse implementation for #123757 This is the initial work to parse unsafe attributes, which is represented as an extra `unsafety` field in `MetaItem` and `AttrItem`. There's two areas in the code where it appears that parsing is done manually and not using the parser stuff, and I'm not sure how I'm supposed to thread the change there.
2024-06-07Revert "Create const block DefIds in typeck instead of ast lowering"Oli Scherer-25/+21
This reverts commit ddc5f9b6c1f21da5d4596bf7980185a00984ac42.
2024-06-06Fix formattingcarbotaniuman-1/+0
2024-06-06Fix buildcarbotaniuman-1/+1
2024-06-06Error on unsafe on non-unsafe attributecarbotaniuman-2/+35
2024-06-06Revert "Rollup merge of #124976 - petrochenkov:usedcrates, r=oli-obk"Rémy Rakic-4/+4
This reverts commit eda4a35f365535af72118118a3597edf5a13c12d, reversing changes made to eb6b35b5bcb3c2a594cb29cd478aeb2893f49d30.