about summary refs log tree commit diff
path: root/compiler
AgeCommit message (Collapse)AuthorLines
2021-08-25Fix debugger stepping behavior around `match` expressionsWesley Wiser-12/+65
Previously, we would set up the source lines for `match` expressions so that the code generated to perform the test of the scrutinee was matched to the line of the arm that required the test and then jump from the arm block to the "next" block was matched to all of the lines in the `match` expression. While that makes sense, it has the side effect of causing strange stepping behavior in debuggers. I've changed the source information so that all of the generated tests are sourced to `match {scrutinee}` and the jumps are sourced to the last line of the block they are inside. This resolves the weird stepping behavior in all debuggers and resolves some instances of "ambiguous symbol" errors in WinDbg preventing the user from setting breakpoints at `match` expressions.
2021-08-25Auto merge of #87937 - LeSeulArtichaut:active-if-let-guards, r=nagisabors-1/+1
Don't mark `if_let_guard` as an incomplete feature I don't think there is any reason for `if_let_guard` to be an incomplete feature, and I think the reason they were marked in the first place was simply because they weren't implemented at all. r? `@pnkfelix` cc tracking issue #51114
2021-08-25Auto merge of #85344 - cbeuw:remap-across-cwd, r=michaelwoeristerbors-5/+14
Correctly handle remapping from path containing the current directory with trailing paths If we have a `auxiliary/lib.rs`, and we generate the metadata with `--remap-path-prefix $PWD/auxiliary=xyz`, the path to `$PWD/auxiliary/lib.rs` won't be correctly remapped in the metadata. This is because internally, path to the working directory itself and relative paths to files under the working directory are remapped separately (hence neither are affected since neither has `$PWD/auxiliary` as prefix), but the concatenation between the working directory and the relative path is not remapped. This PR fixes that.
2021-08-25Auto merge of #87875 - asquared31415:generic-lang-items, r=cjgillotbors-239/+199
Improve detection of generics on lang items Adds detection for the required generics for all lang items. Many lang items require an exact or minimum amount of generic arguments and if they don't exist, the compiler will ICE. This does not add any additional validation about bounds on generics or any other lang item restrictions. Fixes one of the ICEs in #87573 cc `@FabianWolff`
2021-08-25Auto merge of #84333 - tmiasko:liveness-yield, r=tmandrybors-3/+11
Improve liveness analysis for generators Liveness analysis for generators assumes that execution always continues normally after a yield point, not accounting for the fact that generator could be dropped before completion. If generators captures any variables by reference, those variables could be used within a generator, or when the generator completes, but also after each yield point in the case the generator is dropped. Account for the case when generator is dropped after yielding, but before running to the completion. This effectively considers all variables captured by reference to be used after a yield point. Fixes #84292.
2021-08-25Auto merge of #88242 - bonega:allocation_range, r=oli-obkbors-82/+116
Use custom wrap-around type instead of RangeInclusive Two reasons: 1. More memory is allocated than necessary for `valid_range` in `Scalar`. The range is not used as an iterator and `exhausted` is never used. 2. `contains`, `count` etc. methods in `RangeInclusive` are doing very unhelpful(and dangerous!) things when used as a wrap-around range. - In general this PR wants to limit potentially confusing methods, that have a low probability of working. Doing a local perf run, every metric shows improvement except for instructions. Max-rss seem to have a very consistent improvement. Sorry - newbie here, probably doing something wrong.
2021-08-24Auto merge of #88271 - sexxi-goose:liveness, r=nikomatsakisbors-30/+6
2229: Consider varaiables mentioned in closure as used Fixes: https://github.com/rust-lang/project-rfc-2229/issues/57 r? `@nikomatsakis`
2021-08-24Auto merge of #88266 - nikomatsakis:issue-87879, r=jackh726bors-8/+35
resolve type variables after checking casts r? `@jackh726` Fixes #87814 Fixes #88118 Supercedes #87879 (cc `@ldm0)`
2021-08-24use convention for with_* methodsAndreas Liljeqvist-7/+9
2021-08-24Auto merge of #87472 - inquisitivecrystal:stabilize-force-warn, ↵bors-22/+6
r=Mark-Simulacrum Stabilize and document `--force-warn` This PR will stabilize and document the `--force-warn` command line option. It is currently a draft, pending an FCP. I've taken the liberty of tidying up the lint level command line options a bit as part of this. The changes are quite minor and should only affect rustc's help output. I'm making them here because they're trivial and, in one case, necessary to unify the way `--force-warn` with the way the other options are displayed. I also want to mention that `@rylev` has done a ton of work on moving this along and deserves most of the credit. I'm just the one who landed up writing this particular PR. Resolves #86516.
2021-08-24Stabilize `force-warn`inquisitivecrystal-11/+1
2021-08-24Tidy up lint command line flagsinquisitivecrystal-11/+5
2021-08-24Auto merge of #87900 - jackh726:issue-87429, r=nikomatsakisbors-12/+95
Use bound vars for GAT params in param_env in check_type_bounds Fixes #87429
2021-08-24Auto merge of #87699 - ubamrein:use-iphone-deployment-target-for-llvm, ↵bors-3/+9
r=petrochenkov Allow specifying an deployment target version for all iOS llvm targets Closes: https://github.com/rust-lang/rust/issues/79408 This pull requests adds the same procedure to define the iOS-version for the LLVM-target as was used for the simulator target and the desktop target. This then closes the original problem mentioned in the above issue. The problem with incompatible bitcode remains, but is probably not easy fixable. I realised that something is still not right. Try to fix that. r? `@petrochenkov`
2021-08-24Improve liveness analysis for generatorsTomasz Miąsko-3/+11
Liveness analysis for generators assumes that execution always continues normally after a yield point, not accounting for the fact that generator could be dropped before completion. If generators captures any variables by reference, those variables could be used within a generator, or when the generator completes, but also after each yield point in the case the generator is dropped. Account for the case when generator is dropped after yielding, but before running to the completion. This effectively considers all variables captured by reference to be used after a yield point.
2021-08-24Force inline: small functions and single call-siteAndreas Liljeqvist-2/+4
2021-08-24allow specifying an ios version for the llvm targetPatrick Amrein-3/+9
2021-08-24Auto merge of #87739 - Aaron1011:remove-used-attrs, r=wesleywiserbors-409/+436
Remove `Session.used_attrs` and move logic to `CheckAttrVisitor` Instead of updating global state to mark attributes as used, we now explicitly emit a warning when an attribute is used in an unsupported position. As a side effect, we are to emit more detailed warning messages (instead of just a generic "unused" message). `Session.check_name` is removed, since its only purpose was to mark the attribute as used. All of the callers are modified to use `Attribute.has_name` Additionally, `AttributeType::AssumedUsed` is removed - an 'assumed used' attribute is implemented by simply not performing any checks in `CheckAttrVisitor` for a particular attribute. We no longer emit unused attribute warnings for the `#[rustc_dummy]` attribute - it's an internal attribute used for tests, so it doesn't mark sense to treat it as 'unused'. With this commit, a large source of global untracked state is removed.
2021-08-24Auto merge of #85556 - FabianWolff:issue-85071, r=estebank,jackh726bors-31/+72
Warn about unreachable code following an expression with an uninhabited type This pull request fixes #85071. The issue is that liveness analysis currently is "smarter" than reachability analysis when it comes to detecting uninhabited types: Unreachable code is detected during type checking, where full type information is not yet available. Therefore, the check for type inhabitedness is quite crude: https://github.com/rust-lang/rust/blob/fc81ad22c453776de16acf9938976930cf8c9401/compiler/rustc_typeck/src/check/expr.rs#L202-L205 i.e. it only checks for `!`, but not other, non-trivially uninhabited types, such as empty enums, structs containing an uninhabited type, etc. By contrast, liveness analysis, which runs after type checking, can benefit from the more sophisticated `tcx.is_ty_uninhabited_from()`: https://github.com/rust-lang/rust/blob/fc81ad22c453776de16acf9938976930cf8c9401/compiler/rustc_passes/src/liveness.rs#L981 https://github.com/rust-lang/rust/blob/fc81ad22c453776de16acf9938976930cf8c9401/compiler/rustc_passes/src/liveness.rs#L996 This can lead to confusing warnings when a variable is reported as unused, but the use of the variable is not reported as unreachable. For instance: ```rust enum Foo {} fn f() -> Foo {todo!()} fn main() { let x = f(); let _ = x; } ``` currently leads to ``` warning: unused variable: `x` --> t1.rs:5:9 | 5 | let x = f(); | ^ help: if this is intentional, prefix it with an underscore: `_x` | = note: `#[warn(unused_variables)]` on by default warning: 1 warning emitted ``` which is confusing, because `x` _appears_ to be used in line 6. With my changes, I get: ``` warning: unreachable expression --> t1.rs:6:13 | 5 | let x = f(); | --- any code following this expression is unreachable 6 | let _ = x; | ^ unreachable expression | = note: `#[warn(unreachable_code)]` on by default note: this expression has type `Foo`, which is uninhabited --> t1.rs:5:13 | 5 | let x = f(); | ^^^ warning: unused variable: `x` --> t1.rs:5:9 | 5 | let x = f(); | ^ help: if this is intentional, prefix it with an underscore: `_x` | = note: `#[warn(unused_variables)]` on by default warning: 2 warnings emitted ``` My implementation is slightly inelegant because unreachable code warnings can now be issued in two different places (during type checking and during liveness analysis), but I think it is the solution with the least amount of unnecessary code duplication, given that the new warning integrates nicely with liveness analysis, where unreachable code is already implicitly detected for the purpose of finding unused variables.
2021-08-23Auto merge of #83302 - camsteffen:write-piece-unchecked, r=dtolnaybors-7/+23
Get piece unchecked in `write` We already use specialized `zip`, but it seems like we can do a little better by not checking `pieces` length at all. `Arguments` constructors are now unsafe. So the `format_args!` expansion now includes an `unsafe` block. <details> <summary>Local Bench Diff</summary> ```text name before ns/iter after ns/iter diff ns/iter diff % speedup fmt::write_str_macro1 22,967 19,718 -3,249 -14.15% x 1.16 fmt::write_str_macro2 35,527 32,654 -2,873 -8.09% x 1.09 fmt::write_str_macro_debug 571,953 575,973 4,020 0.70% x 0.99 fmt::write_str_ref 9,579 9,459 -120 -1.25% x 1.01 fmt::write_str_value 9,573 9,572 -1 -0.01% x 1.00 fmt::write_u128_max 176 173 -3 -1.70% x 1.02 fmt::write_u128_min 138 134 -4 -2.90% x 1.03 fmt::write_u64_max 139 136 -3 -2.16% x 1.02 fmt::write_u64_min 129 135 6 4.65% x 0.96 fmt::write_vec_macro1 24,401 22,273 -2,128 -8.72% x 1.10 fmt::write_vec_macro2 37,096 35,602 -1,494 -4.03% x 1.04 fmt::write_vec_macro_debug 588,291 589,575 1,284 0.22% x 1.00 fmt::write_vec_ref 9,568 9,732 164 1.71% x 0.98 fmt::write_vec_value 9,516 9,625 109 1.15% x 0.99 ``` </details>
2021-08-232229: Consider varaiables mentioned in closure as usedAman Arora-30/+6
2021-08-23x.py fmtNiko Matsakis-7/+5
2021-08-23Add comment and extra testjackh726-1/+27
2021-08-23When checking associated type bounds, use bound vars for GAT params in param_envjackh726-12/+69
2021-08-23Auto merge of #88265 - m-ou-se:rollup-soymv20, r=m-ou-sebors-191/+278
Rollup of 6 pull requests Successful merges: - #87976 (Account for tabs when highlighting multiline code suggestions) - #88174 (Clarify some wording in Rust 2021 lint docs) - #88188 (Greatly improve limitation handling on parallel rustdoc GUI test run) - #88230 (Fix typos “a”→“an”) - #88232 (Add notes to macro-not-found diagnostics to point out how things with the same name were not a match.) - #88259 (Do not mark `-Z thir-unsafeck` as unsound anymore) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-08-23useful debug printoutsNiko Matsakis-13/+31
The changes to dumping expressions seem particularly useful
2021-08-23fix apparent typo in resolving variablesNiko Matsakis-1/+1
2021-08-23select obligations after `check_casts`liudingming-4/+15
Otherwise, we can get into a situation where you have a subtype obligation `#1 <: #2` pending, #1 is constrained by `check_casts`, but #2` is unaffected. Co-authored-by: Niko Matsakis <niko@alum.mit.edu>
2021-08-23Rollup merge of #88259 - LeSeulArtichaut:complete-thir-unsafeck, r=oli-obkMara Bos-1/+1
Do not mark `-Z thir-unsafeck` as unsound anymore The initial implementation of the THIR unsafety checker is now complete (rust-lang/project-thir-unsafeck#7). r? `@oli-obk`
2021-08-23Rollup merge of #88232 - m-ou-se:macro-name-imported-but-not-macro, r=estebankMara Bos-0/+52
Add notes to macro-not-found diagnostics to point out how things with the same name were not a match. This adds notes like: ``` error: cannot find derive macro `Serialize` in this scope --> $DIR/issue-88206.rs:22:10 | LL | #[derive(Serialize)] | ^^^^^^^^^ | note: `Serialize` is imported here, but it is not a derive macro --> $DIR/issue-88206.rs:17:11 | LL | use hey::{Serialize, Deserialize}; | ^^^^^^^^^ ``` Fixes https://github.com/rust-lang/rust/issues/88206 Includes https://github.com/rust-lang/rust/pull/88229 r? `@estebank`
2021-08-23Rollup merge of #88230 - steffahn:a_an, r=oli-obkMara Bos-155/+155
Fix typos “a”→“an” Fix typos in comments; found using a regex to find some easy instance of incorrect usage of a vs. an. While automation was used to find these, every change was checked manually. Changes in submodules get separate PRs: * https://github.com/rust-lang/stdarch/pull/1201 * https://github.com/rust-lang/cargo/pull/9821 * https://github.com/rust-lang/miri/pull/1874 * https://github.com/rust-lang/rls/pull/1746 * https://github.com/rust-analyzer/rust-analyzer/pull/9984 _folks @ rust-analyzer are fast at merging…_ * https://github.com/rust-analyzer/rust-analyzer/pull/9985 * https://github.com/rust-analyzer/rust-analyzer/pull/9987 * https://github.com/rust-analyzer/rust-analyzer/pull/9989 _For `clippy`, I don’t know if the changes should better better be moved to a PR to the original repo._ <hr> This has some overlap with #88226, but neither is a strict superset of the other. If you want multiple commits, I can split it up; in that case, make sure to suggest a criterion for splitting.
2021-08-23Rollup merge of #88174 - camelid:clarify-rust-2021-lint-docs, r=m-ou-seMara Bos-9/+13
Clarify some wording in Rust 2021 lint docs Also added some inline code styling.
2021-08-23Rollup merge of #87976 - estebank:fix-suggestion-span-coloring, r=m-ou-seMara Bos-26/+57
Account for tabs when highlighting multiline code suggestions Address `'\t'` case in #87972. Before: ![Screen Shot 2021-08-12 at 8 52 27 AM](https://user-images.githubusercontent.com/1606434/129228214-e5cfd203-9aa8-41c7-acd9-ce255ef8a21e.png) After: ![Screen Shot 2021-08-12 at 8 52 15 AM](https://user-images.githubusercontent.com/1606434/129228236-57c951fc-c8cf-4901-989f-b9b5aa5eebca.png)
2021-08-23Auto merge of #87676 - sexxi-goose:truncate_unique, r=nikomatsakisbors-60/+150
2229: Handle MutBorrow/UniqueImmBorrow better We only want to use UniqueImmBorrow when the capture place is truncated and we drop Deref of a MutRef. r? `@nikomatsakis` Fixes: https://github.com/rust-lang/project-rfc-2229/issues/56
2021-08-23Improve wording of macro-not-found-but-name-exists note.Mara Bos-8/+18
2021-08-23Show what things are, but also what they are not.Mara Bos-1/+7
2021-08-23Don't confuse the user with notes about tool modules.Mara Bos-5/+5
2021-08-23Clarify what attribute and derive macros look like.Mara Bos-1/+2
2021-08-23Say what things are, instead of what they are not.Mara Bos-10/+9
2021-08-23Silence confusing 'unused import' warnings.Mara Bos-0/+3
2021-08-23Look for macro names in all namespaces for diagnostics.Mara Bos-19/+34
2021-08-23Add note to 'macro not found' to point to identically-named imports.Mara Bos-1/+19
2021-08-23Auto merge of #87661 - FabianWolff:issue-87461, r=estebankbors-22/+39
Improve error reporting for closure return type mismatches Fixes #87461.
2021-08-23review commentsEsteban Kuber-5/+26
2021-08-23Detect incorrect number of lang item genericsasquared31415-239/+199
2021-08-23Simplify zero checkAndreas Liljeqvist-1/+1
2021-08-23add `with_start` and `with_end`Andreas Liljeqvist-6/+14
2021-08-23implement debug in similar way to RangeInclusiveAndreas Liljeqvist-1/+8
2021-08-23Do not mark `-Z thir-unsafeck` as unsound anymoreLéo Lanteri Thauvin-1/+1
2021-08-23Rename to WrappingRangeAndreas Liljeqvist-22/+19