about summary refs log tree commit diff
path: root/compiler/rustc_middle
AgeCommit message (Collapse)AuthorLines
2022-02-22Remove unused ordering derivations and bounds for `SimplifiedTypeGen`pierwill-4/+4
2022-02-22Delete Decoder::read_unitMark Rousskov-4/+1
2022-02-22Provide copy-free access to raw Decoder bytesMark Rousskov-3/+3
2022-02-22Auto merge of #94254 - matthiaskrgr:rollup-7llbjhd, r=matthiaskrgrbors-1/+5
Rollup of 7 pull requests Successful merges: - #94169 (Fix several asm! related issues) - #94178 (tidy: fire less "ignoring file length unneccessarily" warnings) - #94179 (solarish current_exe using libc call directly) - #94196 (compiletest: Print process output info with less whitespace) - #94208 (Add the let else tests found missing in the stabilization report) - #94237 (Do not suggest wrapping an item if it has ambiguous un-imported methods) - #94246 (ScalarMaybeUninit is explicitly hexadecimal in its formatting) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-02-22Rollup merge of #94246 - RalfJung:hex, r=oli-obkMatthias Krüger-1/+1
ScalarMaybeUninit is explicitly hexadecimal in its formatting This makes `ScalarMaybeUninit` consistent with `Scalar` after the changes in https://github.com/rust-lang/rust/pull/94189. r? ``@oli-obk``
2022-02-22Rollup merge of #94169 - Amanieu:asm_stuff, r=nagisaMatthias Krüger-0/+4
Fix several asm! related issues This is a combination of several fixes, each split into a separate commit. Splitting these into PRs is not practical since they conflict with each other. Fixes #92378 Fixes #85247 r? ``@nagisa``
2022-02-22change `mir::Constant` in mir dumpslcnr-32/+23
2022-02-21ScalarMaybeUninit is explicitly hexadecimal in its formattingRalf Jung-1/+1
2022-02-21Auto merge of #94225 - matthiaskrgr:rollup-0728x8n, r=matthiaskrgrbors-31/+38
Rollup of 10 pull requests Successful merges: - #91192 (Some improvements to the async docs) - #94143 (rustc_const_eval: adopt let else in more places) - #94156 (Gracefully handle non-UTF-8 string slices when pretty printing) - #94186 (Update pin_static_ref stabilization version.) - #94189 (Implement LowerHex on Scalar to clean up their display in rustdoc) - #94190 (Use Metadata::modified instead of FileTime::from_last_modification_ti…) - #94203 (CTFE engine: Scalar: expose size-generic to_(u)int methods) - #94211 (Better error if the user tries to do assignment ... else) - #94215 (trait system: comments and small nonfunctional changes) - #94220 (Correctly handle miniz_oxide extern crate declaration) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-02-21Rollup merge of #94203 - RalfJung:to_sized_int, r=oli-obkMatthias Krüger-21/+25
CTFE engine: Scalar: expose size-generic to_(u)int methods This matches the size-generic constructors `Scalar::from_(u)int`, and it would have helped in https://github.com/rust-lang/miri/pull/1978. r? `@oli-obk`
2022-02-21Rollup merge of #94189 - GuillaumeGomez:scalar-lower-hex, r=RalfJungMatthias Krüger-8/+12
Implement LowerHex on Scalar to clean up their display in rustdoc Follow-up of https://github.com/rust-lang/rust/pull/94091. r? ````@RalfJung````
2022-02-21Rollup merge of #94156 - tmiasko:pp-str, r=petrochenkovMatthias Krüger-2/+1
Gracefully handle non-UTF-8 string slices when pretty printing Fixes #78520.
2022-02-21Take CodegenFnAttrs into account when validating asm! register operandsAmanieu d'Antras-0/+4
Checking of asm! register operands now properly takes function attributes such as #[target_feature] and #[instruction_set] into account.
2022-02-21Auto merge of #93505 - lcnr:substsref-vs-ty-list, r=michaelwoeristerbors-75/+177
safely `transmute<&List<Ty<'tcx>>, &List<GenericArg<'tcx>>>` This PR has 3 relevant steps which are is split in distinct commits. The first commit now interns `List<Ty<'tcx>>` and `List<GenericArg<'tcx>>` together, potentially reusing memory while allowing free conversions between these two using `List<Ty<'tcx>>::as_substs()` and `SubstsRef<'tcx>::try_as_type_list()`. Using this, we then use `&'tcx List<Ty<'tcx>>` instead of a `SubstsRef<'tcx>` for tuple fields, simplifying a bunch of code. Finally, as tuple fields and other generic arguments now use a different `TypeFoldable<'tcx>` impl, we optimize the impl for `List<Ty<'tcx>>` improving perf by slightly less than 1% in tuple heavy benchmarks.
2022-02-21typolcnr-1/+1
Co-authored-by: Rémy Rakic <remy.rakic+github@gmail.com>
2022-02-21update docs for `simplify_type`lcnr-42/+39
2022-02-21reviewlcnr-1/+10
2022-02-21add comment to `Lift` implslcnr-1/+5
2022-02-21optimize `TypeFoldable` for 2 element tupleslcnr-13/+39
2022-02-21use `List<Ty<'tcx>>` for tupleslcnr-56/+36
2022-02-21safely `transmute<&List<Ty<'tcx>>, &List<GenericArg<'tcx>>>`lcnr-6/+89
2022-02-20Revert "Auto merge of #93800 - b-naber:static-initializers-mir-val, r=oli-obk"Mark Rousskov-23/+9
This reverts commit a240ccd81c74c105b6f5fe84c46f8d36edb7e306, reversing changes made to 393fdc10483da930cdbb00eabc3635030d2e776f. This PR was likely responsible for a relatively large regression in dist-x86_64-msvc-alt builder times, from approximately 1.7 to 2.8 hours, bringing that builder into the pool of the slowest builders we currently have. This seems to be limited to the alt builder due to needing parallel-compiler enabled, likely leading to slow LLVM compilation for some reason.
2022-02-20CTFE engine: Scalar: expose size-generic to_(u)int methodsRalf Jung-21/+25
2022-02-20Preallocate a buffer in FmtPrinterMark Rousskov-1/+3
2022-02-20Always format to internal String in FmtPrinterMark Rousskov-44/+55
This avoids monomorphizing for different parameters, decreasing generic code instantiated downstream from rustc_middle.
2022-02-20Auto merge of #93678 - steffahn:better_unsafe_diagnostics, r=nagisabors-68/+114
Improve `unused_unsafe` lint I’m going to add some motivation and explanation below, particularly pointing the changes in behavior from this PR. _Edit:_ Looking for existing issues, looks like this PR fixes #88260. _Edit2:_ Now also contains code that closes #90776.
2022-02-20Improve `unused_unsafe` lintFrank Steffahn-68/+114
Main motivation: Fixes some issues with the current behavior. This PR is more-or-less completely re-implementing the unused_unsafe lint; it’s also only done in the MIR-version of the lint, the set of tests for the `-Zthir-unsafeck` version no longer succeeds (and is thus disabled, see `lint-unused-unsafe.rs`). On current nightly, ```rs unsafe fn unsf() {} fn inner_ignored() { unsafe { #[allow(unused_unsafe)] unsafe { unsf() } } } ``` doesn’t create any warnings. This situation is not unrealistic to come by, the inner `unsafe` block could e.g. come from a macro. Actually, this PR even includes removal of one unused `unsafe` in the standard library that was missed in a similar situation. (The inner `unsafe` coming from an external macro hides the warning, too.) The reason behind this problem is how the check currently works: * While generating MIR, it already skips nested unsafe blocks (i.e. unsafe nested in other unsafe) so that the inner one is always the one considered unused * To differentiate the cases of no unsafe operations inside the `unsafe` vs. a surrounding `unsafe` block, there’s some ad-hoc magic walking up the HIR to look for surrounding used `unsafe` blocks. There’s a lot of problems with this approach besides the one presented above. E.g. the MIR-building uses checks for `unsafe_op_in_unsafe_fn` lint to decide early whether or not `unsafe` blocks in an `unsafe fn` are redundant and ought to be removed. ```rs unsafe fn granular_disallow_op_in_unsafe_fn() { unsafe { #[deny(unsafe_op_in_unsafe_fn)] { unsf(); } } } ``` ``` error: call to unsafe function is unsafe and requires unsafe block (error E0133) --> src/main.rs:13:13 | 13 | unsf(); | ^^^^^^ call to unsafe function | note: the lint level is defined here --> src/main.rs:11:16 | 11 | #[deny(unsafe_op_in_unsafe_fn)] | ^^^^^^^^^^^^^^^^^^^^^^ = note: consult the function's documentation for information on how to avoid undefined behavior warning: unnecessary `unsafe` block --> src/main.rs:10:5 | 9 | unsafe fn granular_disallow_op_in_unsafe_fn() { | --------------------------------------------- because it's nested under this `unsafe` fn 10 | unsafe { | ^^^^^^ unnecessary `unsafe` block | = note: `#[warn(unused_unsafe)]` on by default ``` Here, the intermediate `unsafe` was ignored, even though it contains a unsafe operation that is not allowed to happen in an `unsafe fn` without an additional `unsafe` block. Also closures were problematic and the workaround/algorithms used on current nightly didn’t work properly. (I skipped trying to fully understand what it was supposed to do, because this PR uses a completely different approach.) ```rs fn nested() { unsafe { unsafe { unsf() } } } ``` ``` warning: unnecessary `unsafe` block --> src/main.rs:10:9 | 9 | unsafe { | ------ because it's nested under this `unsafe` block 10 | unsafe { unsf() } | ^^^^^^ unnecessary `unsafe` block | = note: `#[warn(unused_unsafe)]` on by default ``` vs ```rs fn nested() { let _ = || unsafe { let _ = || unsafe { unsf() }; }; } ``` ``` warning: unnecessary `unsafe` block --> src/main.rs:9:16 | 9 | let _ = || unsafe { | ^^^^^^ unnecessary `unsafe` block | = note: `#[warn(unused_unsafe)]` on by default warning: unnecessary `unsafe` block --> src/main.rs:10:20 | 10 | let _ = || unsafe { unsf() }; | ^^^^^^ unnecessary `unsafe` block ``` *note that this warning kind-of suggests that **both** unsafe blocks are redundant* -------------------------------------------------------------------------------- I also dislike the fact that it always suggests keeping the outermost `unsafe`. E.g. for ```rs fn granularity() { unsafe { unsafe { unsf() } unsafe { unsf() } unsafe { unsf() } } } ``` I prefer if `rustc` suggests removing the more-course outer-level `unsafe` instead of the fine-grained inner `unsafe` blocks, which it currently does on nightly: ``` warning: unnecessary `unsafe` block --> src/main.rs:10:9 | 9 | unsafe { | ------ because it's nested under this `unsafe` block 10 | unsafe { unsf() } | ^^^^^^ unnecessary `unsafe` block | = note: `#[warn(unused_unsafe)]` on by default warning: unnecessary `unsafe` block --> src/main.rs:11:9 | 9 | unsafe { | ------ because it's nested under this `unsafe` block 10 | unsafe { unsf() } 11 | unsafe { unsf() } | ^^^^^^ unnecessary `unsafe` block warning: unnecessary `unsafe` block --> src/main.rs:12:9 | 9 | unsafe { | ------ because it's nested under this `unsafe` block ... 12 | unsafe { unsf() } | ^^^^^^ unnecessary `unsafe` block ``` -------------------------------------------------------------------------------- Needless to say, this PR addresses all these points. For context, as far as my understanding goes, the main advantage of skipping inner unsafe blocks was that a test case like ```rs fn top_level_used() { unsafe { unsf(); unsafe { unsf() } unsafe { unsf() } unsafe { unsf() } } } ``` should generate some warning because there’s redundant nested `unsafe`, however every single `unsafe` block _does_ contain some statement that uses it. Of course this PR doesn’t aim change the warnings on this kind of code example, because the current behavior, warning on all the inner `unsafe` blocks, makes sense in this case. As mentioned, during MIR building all the unsafe blocks *are* kept now, and usage is attributed to them. The way to still generate a warning like ``` warning: unnecessary `unsafe` block --> src/main.rs:11:9 | 9 | unsafe { | ------ because it's nested under this `unsafe` block 10 | unsf(); 11 | unsafe { unsf() } | ^^^^^^ unnecessary `unsafe` block | = note: `#[warn(unused_unsafe)]` on by default warning: unnecessary `unsafe` block --> src/main.rs:12:9 | 9 | unsafe { | ------ because it's nested under this `unsafe` block ... 12 | unsafe { unsf() } | ^^^^^^ unnecessary `unsafe` block warning: unnecessary `unsafe` block --> src/main.rs:13:9 | 9 | unsafe { | ------ because it's nested under this `unsafe` block ... 13 | unsafe { unsf() } | ^^^^^^ unnecessary `unsafe` block ``` in this case is by emitting a `unused_unsafe` warning for all of the `unsafe` blocks that are _within a **used** unsafe block_. The previous code had a little HIR traversal already anyways to collect a set of all the unsafe blocks (in order to afterwards determine which ones are unused afterwards). This PR uses such a traversal to do additional things including logic like _always_ warn for an `unsafe` block that’s inside of another **used** unsafe block. The traversal is expanded to include nested closures in the same go, this simplifies a lot of things. The whole logic around `unsafe_op_in_unsafe_fn` is a little complicated, there’s some test cases of corner-cases in this PR. (The implementation involves differentiating between whether a used unsafe block was used exclusively by operations where `allow(unsafe_op_in_unsafe_fn)` was active.) The main goal was to make sure that code should compile successfully if all the `unused_unsafe`-warnings are addressed _simultaneously_ (by removing the respective `unsafe` blocks) no matter how complicated the patterns of `unsafe_op_in_unsafe_fn` being disallowed and allowed throughout the function are. -------------------------------------------------------------------------------- One noteworthy design decision I took here: An `unsafe` block with `allow(unused_unsafe)` **is considered used** for the purposes of linting about redundant contained unsafe blocks. So while ```rs fn granularity() { unsafe { //~ ERROR: unnecessary `unsafe` block unsafe { unsf() } unsafe { unsf() } unsafe { unsf() } } } ``` warns for the outer `unsafe` block, ```rs fn top_level_ignored() { #[allow(unused_unsafe)] unsafe { #[deny(unused_unsafe)] { unsafe { unsf() } //~ ERROR: unnecessary `unsafe` block unsafe { unsf() } //~ ERROR: unnecessary `unsafe` block unsafe { unsf() } //~ ERROR: unnecessary `unsafe` block } } } ``` warns on the inner ones.
2022-02-20Auto merge of #94062 - Mark-Simulacrum:drop-print-cfg, r=oli-obkbors-81/+72
Move ty::print methods to Drop-based scope guards Primary goal is reducing codegen of the TLS access for each closure, which shaves ~3 seconds of bootstrap time over rustc as a whole.
2022-02-20Delete QueryLookupMark Rousskov-9/+8
This was largely just caching the shard value at this point, which is not particularly useful -- in the use sites the key was being hashed nearby anyway.
2022-02-20Move Sharded maps into each QueryCache implMark Rousskov-1/+1
2022-02-20Implement LowerHex on Scalar to clean up their display in rustdocGuillaume Gomez-8/+12
2022-02-20Gracefully handle non-UTF-8 string slices when pretty printingTomasz Miąsko-2/+1
2022-02-20Rollup merge of #94146 - est31:let_else, r=cjgillotMatthias Krüger-32/+22
Adopt let else in more places Continuation of #89933, #91018, #91481, #93046, #93590, #94011. I have extended my clippy lint to also recognize tuple passing and match statements. The diff caused by fixing it is way above 1 thousand lines. Thus, I split it up into multiple pull requests to make reviewing easier. This is the biggest of these PRs and handles the changes outside of rustdoc, rustc_typeck, rustc_const_eval, rustc_trait_selection, which were handled in PRs #94139, #94142, #94143, #94144.
2022-02-20Rollup merge of #94113 - Mizobrook-kan:issue-94025, r=estebankMatthias Krüger-0/+9
document rustc_middle::mir::Field cc #94025
2022-02-20Rollup merge of #94097 - pierwill:doc-rustc-middle-query, r=cjgillotMatthias Krüger-0/+6
Add module-level docs for `rustc_middle::query`
2022-02-20Rollup merge of #94091 - GuillaumeGomez:rustdoc-const-computed-value, r=oli-obkMatthias Krüger-0/+12
Fix rustdoc const computed value Fixes #85088. It looks like this now (instead of hexadecimal): ![Screenshot from 2022-02-17 17-55-39](https://user-images.githubusercontent.com/3050060/154532115-0f9861a0-406f-4c9c-957f-32bedd8aca7d.png) r? ````@oli-obk````
2022-02-19Adopt let else in more placesest31-32/+22
2022-02-19Stop interning stability.Camille GILLOT-28/+11
2022-02-19Don't render Const computed values in hexadecimal for DisplayGuillaume Gomez-0/+12
2022-02-19switch to limiting the number of init/uninit chunksErik Desjardins-0/+1
2022-02-19Rollup merge of #94086 - tmiasko:char-try-from-scalar-int, r=davidtwcoMatthias Krüger-4/+14
Fix ScalarInt to char conversion to avoid panic for invalid Unicode scalar values
2022-02-19Rollup merge of #94006 - pierwill:upvar-field, r=nikomatsakisMatthias Krüger-2/+2
Use a `Field` in `ConstraintCategory::ClosureUpvar` As part of #90317, we do not want `HirId` to implement `Ord`, `PartialOrd`. This line of code has made that difficult https://github.com/rust-lang/rust/blob/1b27144afc77031ba9c05d86c06c64485589775a/compiler/rustc_borrowck/src/region_infer/mod.rs#L2184 since it sorts a [`ConstraintCategory::ClosureUpvar(HirId)`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.ConstraintCategory.html#variant.ClosureUpvar). This PR makes that variant take a [`Field`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.Field.html) instead. r? `@nikomatsakis`
2022-02-19Rollup merge of #93990 - lcnr:pre-89862-cleanup, r=estebankMatthias Krüger-8/+56
pre #89862 cleanup changes used in #89862 which can be landed without the rest of this PR being finished. r? `@estebank`
2022-02-18Rollup merge of #89892 - Nilstrieb:suggest-return-impl-trait, r=jackh726Matthias Krüger-2/+22
Suggest `impl Trait` return type when incorrectly using a generic return type Address #85991 When there is a type mismatch error and the return type is generic, and that generic parameter is not used in the function parameters, suggest replacing that generic with the `impl Trait` syntax. r? `@estebank`
2022-02-18Suggest `impl Trait` return typeNilstrieb-2/+22
Address #85991 Suggest the `impl Trait` return type syntax if the user tried to return a generic parameter and we get a type mismatch The suggestion is not emitted if the param appears in the function parameters, and only get the bounds that actually involve `T: ` directly It also checks whether the generic param is contained in any where bound (where it isn't the self type), and if one is found (like `Option<T>: Send`), it is not suggested. This also adds `TyS::contains`, which recursively vistits the type and looks if the other type is contained anywhere
2022-02-18Rollup merge of #93634 - matthiaskrgr:clippy_complexity_jan_2022, r=oli-obkMatthias Krüger-3/+3
compiler: clippy::complexity fixes useless_format map_flatten useless_conversion needless_bool filter_next clone_on_copy needless_option_as_deref
2022-02-18Rollup merge of #92683 - jackh726:issue-92033, r=estebankMatthias Krüger-0/+6
Suggest copying trait associated type bounds on lifetime error Closes #92033 Kind of the most simple suggestion to make - we don't try to be fancy. Turns out, it's still pretty useful (the couple existing tests that trigger this error end up fixed - for this error - upon applying the fix). r? ``@estebank`` cc ``@nikomatsakis``
2022-02-18fix some typosMizobrook-kan-2/+2
2022-02-18document rustc_middle::mir::FieldMizobrook-kan-0/+9
2022-02-17Rollup merge of #94011 - est31:let_else, r=lcnrMatthias Krüger-1/+1
Even more let_else adoptions Continuation of #89933, #91018, #91481, #93046, #93590.