about summary refs log tree commit diff
path: root/compiler/rustc_passes/src
AgeCommit message (Collapse)AuthorLines
2024-07-02chore: remove duplicate wordshattizai-1/+1
2024-06-29Rollup merge of #127118 - surechen:fix_126789, r=jieyouxuMatthias Krüger-3/+10
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/+10
`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-51/+7
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-51/+7
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-30/+2
2024-06-19Rollup merge of #124580 - gurry:124556-suggest-remove-tuple-field, r=jackh726León Orell Valerian Liehr-19/+58
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/+30
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/+31
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.
2024-06-05Also support generic constantsOli Scherer-9/+9
2024-06-05Don't walk the bodies of free constants for reachability.Oli Scherer-4/+14
2024-06-05Detect pub structs never constructed and unused associated constants in traitsr0cky-28/+93
2024-06-04Closures are recursively reachableTomasz Miąsko-0/+1
2024-06-03Opt-in diagnostics reporting to avoid doing extra work in the new solverMichael Goulet-2/+2
2024-05-31Rollup merge of #125635 - fmease:mv-type-binding-assoc-item-constraint, ↵Matthias Krüger-4/+4
r=compiler-errors Rename HIR `TypeBinding` to `AssocItemConstraint` and related cleanup Rename `hir::TypeBinding` and `ast::AssocConstraint` to `AssocItemConstraint` and update all items and locals using the old terminology. Motivation: The terminology *type binding* is extremely outdated. "Type bindings" not only include constraints on associated *types* but also on associated *constants* (feature `associated_const_equality`) and on RPITITs of associated *functions* (feature `return_type_notation`). Hence the word *item* in the new name. Furthermore, the word *binding* commonly refers to a mapping from a binder/identifier to a "value" for some definition of "value". Its use in "type binding" made sense when equality constraints (e.g., `AssocTy = Ty`) were the only kind of associated item constraint. Nowadays however, we also have *associated type bounds* (e.g., `AssocTy: Bound`) for which the term *binding* doesn't make sense. --- Old terminology (HIR, rustdoc): ``` `TypeBinding`: (associated) type binding ├── `Constraint`: associated type bound └── `Equality`: (associated) equality constraint (?) ├── `Ty`: (associated) type binding └── `Const`: associated const equality (constraint) ``` Old terminology (AST, abbrev.): ``` `AssocConstraint` ├── `Bound` └── `Equality` ├── `Ty` └── `Const` ``` New terminology (AST, HIR, rustdoc): ``` `AssocItemConstraint`: associated item constraint ├── `Bound`: associated type bound └── `Equality`: associated item equality constraint OR associated item binding (for short) ├── `Ty`: associated type equality constraint OR associated type binding (for short) └── `Const`: associated const equality constraint OR associated const binding (for short) ``` r? compiler-errors
2024-05-30Rename HIR `TypeBinding` to `AssocItemConstraint` and related cleanupLeón Orell Valerian Liehr-4/+4
2024-05-29Make `body_owned_by` return the body directly.Oli Scherer-11/+10
Almost all callers want this anyway, and now we can use it to also return fed bodies
2024-05-29Don't require `visit_body` to take a lifetime that must outlive the function ↵Oli Scherer-2/+2
call
2024-05-28Create const block DefIds in typeck instead of ast loweringOli Scherer-21/+25
2024-05-23Auto merge of #125434 - nnethercote:rm-more-extern-tracing, r=jackh726bors-5/+4
Remove more `#[macro_use] extern crate tracing` Because explicit importing of macros via use items is nicer (more standard and readable) than implicit importing via `#[macro_use]`. Continuing the work from #124511 and #124914. r? `@jackh726`
2024-05-23Rollup merge of #122382 - mu001999:dead_code/enhance, r=petrochenkovLeón Orell Valerian Liehr-16/+33
Detect unused structs which implement private traits Fixes #122361
2024-05-23Rollup merge of #124976 - petrochenkov:usedcrates, r=oli-obkMatthias Krüger-4/+4
rustc: Use `tcx.used_crates(())` more And explain when it should be used. Addresses comments from https://github.com/rust-lang/rust/pull/121167.
2024-05-23Remove `#[macro_use] extern crate tracing` from `rustc_passes`.Nicholas Nethercote-5/+4