about summary refs log tree commit diff
path: root/compiler/rustc_passes/src
AgeCommit message (Collapse)AuthorLines
2021-02-24Properly account for non-shorthand pattern field in unused variable lintEsteban Küber-5/+10
Fix #82488
2021-02-25Address review commentsAmanieu d'Antras-0/+17
2021-02-23Add #[rustc_legacy_const_generics]Amanieu d'Antras-0/+75
2021-02-23Rollup merge of #82297 - tmiasko:write-only, r=oli-obkDylan DPC-11/+17
Consider auto derefs before warning about write only fields Changes from #81473 extended the dead code lint with an ability to detect fields that are written to but never read from. The implementation skips over fields on the left hand side of an assignment, without marking them as live. A field access might involve an automatic dereference and de-facto read the field. Conservatively mark expressions with deref adjustments as live to avoid generating false positive warnings. Closes #81626.
2021-02-23Rollup merge of #82258 - tmiasko:foreign-hir-stats, r=davidtwcoDylan DPC-0/+5
Implement -Z hir-stats for nested foreign items An attempt to compute HIR stats for crates with nested foreign items results in an ICE. ```rust fn main() { extern "C" { fn f(); } } ``` ``` thread 'rustc' panicked at 'visit_nested_xxx must be manually implemented in this visitor' ``` Provide required implementation of visitor method.
2021-02-21remove redundant wrapping of return types of allow_internal_unstable() and ↵Matthias Krüger-1/+1
rustc_allow_const_fn_unstable()
2021-02-19Rollup merge of #82238 - petrochenkov:nocratemod, r=Aaron1011Dylan DPC-10/+0
ast: Keep expansion status for out-of-line module items I.e. whether a module `mod foo;` is already loaded from a file or not. This is a pre-requisite to correctly treating inner attributes on such modules (https://github.com/rust-lang/rust/issues/81661). With this change AST structures for `mod` items diverge even more for AST structure for the crate root, which previously used `ast::Mod`. Therefore this PR removes `ast::Mod` from `ast::Crate` in the first commit, these two things are sufficiently different from each other, at least at syntactic level. Customization points for visiting a "`mod` item or crate root" were also removed from AST visitors (`fn visit_mod`). `ast::Mod` itself was refactored away in the second commit in favor of `ItemKind::Mod(Unsafe, ModKind)`.
2021-02-19Consider auto derefs before warning about write only fieldsTomasz Miąsko-11/+17
Changes from 81473 extended the dead code lint with an ability to detect fields that are written to but never read from. The implementation skips over fields on the left hand side of an assignment, without marking them as live. A field access might involve an automatic dereference and de-facto read the field. Conservatively mark expressions with deref adjustments as live to avoid generating false positive warnings.
2021-02-18Rollup merge of #82256 - eddyb:time-passes-stderr, r=varkorDylan DPC-6/+6
Print -Ztime-passes (and misc stats/logs) on stderr, not stdout. I've tried not to change anything that looked similar to `rustc --print`, where people might use automation, and/or any "bulk" prints, such as dumping an entire Graphviz (`dot`) graph on stdout. The reason I want `-Ztime-passes` to be on stderr like debug logging is I can get a complete (and correctly interleaved) view just by looking at stderr, which is merely a convenience when running `rustc`/Cargo directly, but even more important when it's nested in a build script, as Cargo will split the build script output into stdout (named `output`) and `stderr`.
2021-02-18Print -Ztime-passes (and misc stats/logs) on stderr, not stdout.Eduard-Mihai Burtescu-6/+6
2021-02-18ast: Stop using `Mod` in `Crate`Vadim Petrochenkov-10/+0
Crate root is sufficiently different from `mod` items, at least at syntactic level. Also remove customization point for "`mod` item or crate root" from AST visitors.
2021-02-18Implement -Z hir-stats for nested foreign itemsTomasz Miąsko-0/+5
An attempt to compute HIR stats for crates with nested foreign items results in an ICE. ``` fn main() { extern "C" { fn f(); } } ``` ``` thread 'rustc' panicked at 'visit_nested_xxx must be manually implemented in this visitor' ``` Provide required implementation of visitor method.
2021-02-17replace if-let and while-let with `if let` and `while let`Takayuki Maeda-1/+1
2021-02-15Use less HirId when referring to items.Camille GILLOT-8/+7
2021-02-15Only store a LocalDefId in hir::MacroDef.Camille GILLOT-5/+5
2021-02-15Index Modules using their LocalDefId.Camille GILLOT-6/+3
2021-02-15Only store a LocalDefId in hir::ForeignItem.Camille GILLOT-11/+15
2021-02-15Only store a LocalDefId in hir::ImplItem.Camille GILLOT-19/+18
2021-02-15Only store a LocalDefId in hir::TraitItem.Camille GILLOT-9/+15
2021-02-15Only store a LocalDefId in hir::Item.Camille GILLOT-43/+38
Items are guaranteed to be HIR owner.
2021-02-15Use ItemId as a strongly typed index.Camille GILLOT-2/+2
2021-02-14Rollup merge of #80920 - rylev:check_attr-refactor, r=davidtwcoDylan DPC-11/+17
Visit more targets when validating attributes This begins to address #80048, allowing for additional validation of attributes. There are more refactorings that can be done, though I think they should be tackled in additional PRs: * ICE when a builtin attribute is encountered that is not checked * Move some of the attr checking done `ast_validation` into `rustc_passes` * note that this requires a bit of additional refactoring, especially of extern items which currently parse attributes (and thus are a part of the AST) but do not possess attributes in their HIR representation. * Rename `Target` to `AttributeTarget` * Refactor attribute validation completely to go through `Visitor::visit_attribute`. * This would require at a minimum passing `Target` into this method which might be too big of a refactoring to be worth it. * It's also likely not possible to do all the validation this way as some validation requires knowing what other attributes a target has. r? `@davidtwco`
2021-02-10Tweak stability attribute diagnostic outputEsteban Küber-17/+19
2021-02-10Inherit `#[stable(..)]` annotations in enum variants and fields from its itemEsteban Küber-12/+38
2021-02-09Visit more targets when checking attrsRyan Levick-11/+17
2021-02-09Rename HIR UnOp variantsÖmer Sinan Ağacan-1/+1
This renames the variants in HIR UnOp from enum UnOp { UnDeref, UnNot, UnNeg, } to enum UnOp { Deref, Not, Neg, } Motivations: - This is more consistent with the rest of the code base where most enum variants don't have a prefix. - These variants are never used without the `UnOp` prefix so the extra `Un` prefix doesn't help with readability. E.g. we don't have any `UnDeref`s in the code, we only have `UnOp::UnDeref`. - MIR `UnOp` type variants don't have a prefix so this is more consistent with MIR types. - "un" prefix reads like "inverse" or "reverse", so as a beginner in rustc code base when I see "UnDeref" what comes to my mind is something like "&*" instead of just "*".
2021-02-02Bump rustfmt versionMark Rousskov-1/+2
Also switches on formatting of the mir build module
2021-02-01Fixed #[inline] to be warned in fields, arms, macro defsDanuel-45/+263
Add visitors for checking #[inline] Add visitors for checking #[inline] with struct field Fix test for #[inline] Add visitors for checking #[inline] with #[macro_export] macro Add visitors for checking #[inline] without #[macro_export] macro Add use alias with Visitor Fix lint error Reduce unnecessary variable Co-authored-by: LingMan <LingMan@users.noreply.github.com> Change error to warning Add warning for checking field, arm with #[allow_internal_unstable] Add name resolver Formatting Formatting Fix error fixture Add checking field, arm, macro def
2021-01-28Add missing braceOli Scherer-1/+1
2021-01-29Simplify base_exprSeo Sanghyeon-8/+4
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
2021-01-28Warn write-only fieldsSeo Sanghyeon-0/+19
2021-01-28Rollup merge of #79951 - LeSeulArtichaut:ty-ir, r=nikomatsakisYuki Okushi-2/+2
Refractor a few more types to `rustc_type_ir` In the continuation of #79169, ~~blocked on that PR~~. This PR: - moves `IntVarValue`, `FloatVarValue`, `InferTy` (and friends) and `Variance` - creates the `IntTy`, `UintTy` and `FloatTy` enums in `rustc_type_ir`, based on their `ast` and `chalk_ir` equilavents, and uses them for types in the rest of the compiler. ~~I will split up that commit to make this easier to review and to have a better commit history.~~ EDIT: done, I split the PR in commits of 200-ish lines each r? `````@nikomatsakis````` cc `````@jackh726`````
2021-01-25This should address issue 81294.Felix S. Klock II-1/+1
(No test added. The relevant test *is* ui/panic-handler/weak-lang-item.rs, and this change should make it less flaky.)
2021-01-24Rollup merge of #81310 - tmiasko:in-pattern, r=petrochenkovJonas Schievink-1/+1
Do not mark unit variants as used when in path pattern Record that we are processing a pattern so that code responsible for handling path resolution can correctly decide whether to mark it as used or not. Closes #76788.
2021-01-24Auto merge of #80919 - cjgillot:defkey-span, r=oli-obkbors-0/+1
Generate metadata by iterating on DefId instead of traversing the HIR tree 1/N Sample from #80347.
2021-01-23Allow to query the HIR crate node.Camille GILLOT-0/+1
2021-01-23Do not mark unit variants as used when in path patternTomasz Miąsko-1/+1
Record that we are processing a pattern so that code responsible for handling path resolution can correctly decide whether to mark it as used or not.
2021-01-21Do not suggest using a break label when one is already presentEsteban Küber-6/+11
2021-01-21Tweak error for invalid `break expr`Esteban Küber-20/+56
Point at loop head on invalid `break expr`. Suggest removing `expr` or using label if available.
2021-01-21Add loop head span to hirEsteban Küber-6/+5
2021-01-18Use ty::{IntTy,UintTy,FloatTy} in rustcLeSeulArtichaut-2/+2
2021-01-18Only inherit const stability for methods of `impl const Trait` blocksoli-10/+60
2021-01-14Auto merge of #79328 - c410-f3r:hir-if, r=matthewjasperbors-4/+38
Reintroduce hir::ExprKind::If Basically copied and paste #59288/https://github.com/rust-lang/rust-clippy/pull/4080 with some modifications. The vast majority of tests were fixed and now there are only a few remaining. Since I am still unable to figure out the missing pieces, any help with the following list is welcome. - [ ] **Unnecessary `typeck` exception**: [Cheated on this one to make CI green.](https://github.com/rust-lang/rust/pull/79328/files#diff-3faee9ba23fc54a12b7c43364ba81f8c5660045c7e1d7989a02a0cee1c5b2051) - [x] **Incorrect span**: [Span should reference `then` and `else` separately.](https://github.com/rust-lang/rust/pull/79328/files#diff-cf2c46e82222ee4b1037a68fff8a1af3c4f1de7a6b3fd798aacbf3c0475abe3d) - [x] **New note regarding `assert!`**: [Modified but not "wrong". Maybe can be a good thing?](https://github.com/rust-lang/rust/pull/79328/files#diff-9e0d7c89ed0224e2b62060c957177c27db43c30dfe3c2974cb6b5091cda9cfb5) - [x] **Inverted report location**: [Modified but not "wrong". Locations were inverted.](https://github.com/rust-lang/rust/pull/79328/files#diff-f637ce7c1f68d523a165aa9651765df05e36c4d7d279194b1a6b28b48a323691) - [x] **`src/test/ui/point-to-type-err-cause-on-impl-trait-return.rs` has weird errors**: [Not sure why this is happening.](https://github.com/rust-lang/rust/pull/79328/files#diff-c823c09660f5b112f95e97e8ff71f1797b6c7f37dbb3d16f8e98bbaea8072e95) - [x] **Missing diagnostic**: [???](https://github.com/rust-lang/rust/pull/79328/files#diff-6b8ab09360d725ba4513933827f9796b42ff9522b0690f80b76de067143af2fc)
2021-01-13Auto merge of #79322 - jyn514:refactor-impl, r=estebankbors-8/+11
Separate out a `hir::Impl` struct This makes it possible to pass the `Impl` directly to functions, instead of having to pass each of the many fields one at a time. It also simplifies matches in many cases. See `rustc_save_analysis::dump_visitor::process_impl` or `rustdoc::clean::clean_impl` for a good example of how this makes `impl`s easier to work with. r? `@petrochenkov` maybe?
2021-01-12Separate out a `hir::Impl` structJoshua Nelson-8/+11
This makes it possible to pass the `Impl` directly to functions, instead of having to pass each of the many fields one at a time. It also simplifies matches in many cases.
2021-01-10Fix small typoCamelid-1/+1
transmutting -> transmuting
2021-01-07Reintroduce hir::ExprKind::IfCaio-4/+38
2021-01-06Don't use to_string on SymbolGuillaume Gomez-1/+1
2021-01-04Add an error in case the doc alias is the same as the item it's aliasingGuillaume Gomez-1/+12
2021-01-02reduce borrowing and (de)referencing around match patterns ↵Matthias Krüger-1/+1
(clippy::match_ref_pats)