granite-rust/compiler
bors 19c250aa12 Auto merge of #103293 - est31:untwist_and_drop_order, r=nagisa
Remove drop order twist of && and || and make them associative

Previously a short circuiting binop chain (chain of && or ||s) would drop the temporaries created by the first element after all the other elements, and otherwise follow evaluation order. So `f(1).g() && f(2).g() && f(3).g() && f(4).g()` would drop the temporaries in the order `2,3,4,1`. This made `&&` and `||` non-associative regarding drop order. In other words, adding ()'s to the expression would change drop order: `f(1).g() && (f(2).g() && f(3).g()) && f(4).g()` for example would drop in the order `3,2,4,1`.

As, except for the bool result, there is no data returned by the sub-expressions of the short circuiting binops, we can safely discard of any temporaries created by the sub-expr. Previously, code was already putting the rhs's into terminating scopes, but missed it for the lhs's.

This commit addresses this "twist". We now also put the lhs into a terminating scope. The drop order of the above expressions becomes `1,2,3,4`.

There might be code relying on the current order, and therefore I'd recommend doing a crater run to gauge the impact. I'd argue that such code is already quite wonky as it is one `foo() &&` addition away from breaking. ~~For the impact, I don't expect any *build* failures, as the compiler gets strictly more tolerant: shortening the lifetime of temporaries only expands the list of programs the compiler accepts as valid. There might be *runtime* failures caused by this change however.~~ Edit: both build and runtime failures are possible, e.g. see the example provided by dtolnay [below](https://github.com/rust-lang/rust/pull/103293#issuecomment-1285341113). Edit2: the crater run has finished and [results](https://github.com/rust-lang/rust/pull/103293#issuecomment-1292275203) are that there is only one build failure which is easy to fix with a +/- 1 line diff.

I've included a testcase that now compiles thanks to this patch.

The breakage is also limited to drop order relative to conditionals in the && chain: that is, in code like this:

```Rust
let hello = foo().hi() && bar().world();
println!("hi");
```

we already drop the temporaries of `foo().hi()` before we reach "hi".

I'd ideally have this PR merged before let chains are stabilized. If this PR is taking too long, I'd love to have a more restricted version of this change limited to `&&`'s in let chains: the `&&`'s of such chains are quite special anyways as they accept `let` bindings, in there the `&&` is therefore more a part of the "if let chain" construct than a construct of its own.

Fixes #103107

Status: waiting on [this accepted FCP](https://github.com/rust-lang/rust/pull/103293#issuecomment-1293411354) finishing.
2022-12-04 14:03:12 +00:00
..
rustc rustc: Use unix_sigpipe instead of rustc_driver::set_sigpipe_handler 2022-10-02 17:49:36 +02:00
rustc_abi Rollup merge of #105050 - WaffleLapkin:uselessrefign, r=jyn514 2022-12-03 17:37:42 +01:00
rustc_apfloat Add diagnostic translation lints to crates that don't emit them 2022-08-18 19:29:02 +01:00
rustc_arena rustc_arena: remove a couple of ref patterns 2022-11-22 18:49:29 +00:00
rustc_ast Rollup merge of #105142 - nbdd0121:inline_const, r=petrochenkov 2022-12-04 11:38:51 +01:00
rustc_ast_lowering Rollup merge of #104199 - SarthakSingh31:issue-97417-1, r=cjgillot 2022-12-03 17:37:41 +01:00
rustc_ast_passes Auto merge of #104861 - nnethercote:attr-cleanups, r=petrochenkov 2022-12-01 07:13:45 +00:00
rustc_ast_pretty Rollup merge of #105050 - WaffleLapkin:uselessrefign, r=jyn514 2022-12-03 17:37:42 +01:00
rustc_attr Rename NestedMetaItem::[Ll]iteral as NestedMetaItem::[Ll]it. 2022-11-28 15:18:53 +11:00
rustc_baked_icu_data Update crate documentation of rustc_baked_icu_data crate 2022-11-18 14:46:36 -08:00
rustc_borrowck Create format_args as late as possible 2022-12-01 08:49:51 +00:00
rustc_builtin_macros Rollup merge of #104614 - Nilstrieb:type-ascribe!, r=TaKO8Ki 2022-12-02 08:28:08 +01:00
rustc_codegen_cranelift Auto merge of #97485 - bjorn3:new_archive_writer, r=wesleywiser 2022-12-03 15:07:39 +00:00
rustc_codegen_gcc Auto merge of #97485 - bjorn3:new_archive_writer, r=wesleywiser 2022-12-03 15:07:39 +00:00
rustc_codegen_llvm Auto merge of #105218 - matthiaskrgr:rollup-8d3k08n, r=matthiaskrgr 2022-12-03 21:25:45 +00:00
rustc_codegen_ssa Auto merge of #97485 - bjorn3:new_archive_writer, r=wesleywiser 2022-12-03 15:07:39 +00:00
rustc_const_eval Rollup merge of #105136 - RalfJung:deref-promotion-comment, r=oli-obk 2022-12-02 08:28:10 +01:00
rustc_data_structures Auto merge of #105218 - matthiaskrgr:rollup-8d3k08n, r=matthiaskrgr 2022-12-03 21:25:45 +00:00
rustc_driver Remove -Zno-interleave-lints. 2022-12-02 13:59:28 +11:00
rustc_error_codes Auto merge of #103491 - cjgillot:self-rpit, r=oli-obk 2022-11-21 12:17:03 +00:00
rustc_error_messages Rewrite LLVM's archive writer in Rust 2022-11-26 19:35:32 +00:00
rustc_errors Remove useless borrows and derefs 2022-12-01 17:34:43 +00:00
rustc_expand Rollup merge of #104199 - SarthakSingh31:issue-97417-1, r=cjgillot 2022-12-03 17:37:41 +01:00
rustc_feature Stabilize native library modifier verbatim 2022-11-27 22:36:32 +03:00
rustc_fs_util Remove useless borrows and derefs 2022-12-01 17:34:43 +00:00
rustc_graphviz Remove useless borrows and derefs 2022-12-01 17:34:43 +00:00
rustc_hir Rollup merge of #105050 - WaffleLapkin:uselessrefign, r=jyn514 2022-12-03 17:37:42 +01:00
rustc_hir_analysis Auto merge of #103293 - est31:untwist_and_drop_order, r=nagisa 2022-12-04 14:03:12 +00:00
rustc_hir_pretty Rollup merge of #104199 - SarthakSingh31:issue-97417-1, r=cjgillot 2022-12-03 17:37:41 +01:00
rustc_hir_typeck Rollup merge of #104856 - luqmana:associated-const-bad-suggestion, r=compiler-errors 2022-12-04 11:38:50 +01:00
rustc_incremental Prefer doc comments over //-comments in compiler 2022-11-27 11:19:04 +00:00
rustc_index move things from rustc_target::abi to rustc_abi 2022-11-24 16:26:13 +03:30
rustc_infer Rollup merge of #105188 - compiler-errors:verbose-ty-err, r=TaKO8Ki 2022-12-03 12:51:30 +09:00
rustc_interface Remove -Zno-interleave-lints. 2022-12-02 13:59:28 +11:00
rustc_lexer Auto merge of #104507 - WaffleLapkin:asderefsyou, r=wesleywiser 2022-11-24 00:17:35 +00:00
rustc_lint Auto merge of #104863 - nnethercote:reduce-lint-macros, r=cjgillot 2022-12-02 15:31:15 +00:00
rustc_lint_defs Make deref_into_dyn_supertrait lint the impl and not the usage 2022-11-23 15:40:27 +00:00
rustc_llvm Use LLVM for getting symbols from COFF bigobj files 2022-11-26 19:35:32 +00:00
rustc_log Use IsTerminal in rustc_log 2022-10-16 15:10:40 +01:00
rustc_macros Remove useless borrows and derefs 2022-12-01 17:34:43 +00:00
rustc_metadata Make inferred_outlives_crate return Clause 2022-11-29 12:01:58 -03:00
rustc_middle Auto merge of #105121 - oli-obk:simpler-cheaper-dump_mir, r=nnethercote 2022-12-04 05:47:10 +00:00
rustc_mir_build Auto merge of #105121 - oli-obk:simpler-cheaper-dump_mir, r=nnethercote 2022-12-04 05:47:10 +00:00
rustc_mir_dataflow Create format_args as late as possible 2022-12-01 08:49:51 +00:00
rustc_mir_transform Auto merge of #105121 - oli-obk:simpler-cheaper-dump_mir, r=nnethercote 2022-12-04 05:47:10 +00:00
rustc_monomorphize Prefer doc comments over //-comments in compiler 2022-11-27 11:19:04 +00:00
rustc_parse Rollup merge of #104199 - SarthakSingh31:issue-97417-1, r=cjgillot 2022-12-03 17:37:41 +01:00
rustc_parse_format shift no characters when using raw string literals 2022-11-15 14:28:20 +09:00
rustc_passes rustc_hir: Change representation of import paths to support multiple resolutions 2022-12-01 18:51:05 +03:00
rustc_plugin_impl Migrate all diagnostics 2022-10-23 10:09:44 +02:00
rustc_privacy Auto merge of #99798 - JulianKnodt:ac1, r=BoxyUwU 2022-11-25 22:56:59 +00:00
rustc_query_impl Auto merge of #104940 - cjgillot:query-feed-simple, r=oli-obk 2022-11-30 17:20:14 +00:00
rustc_query_system Fill in def_span when creating def ids. 2022-12-01 10:33:28 +00:00
rustc_resolve fix #105069, Add AmbiguityError for inconsistent resolution for an import 2022-12-03 22:28:35 +08:00
rustc_save_analysis rustc_hir: Change representation of import paths to support multiple resolutions 2022-12-01 18:51:05 +03:00
rustc_serialize rename {max=>largest}_max_leb128_len 2022-11-29 17:58:09 +00:00
rustc_session Rollup merge of #105050 - WaffleLapkin:uselessrefign, r=jyn514 2022-12-03 17:37:42 +01:00
rustc_smir Only keep one version of ImplicitSelfKind. 2022-09-13 19:18:23 +02:00
rustc_span Rollup merge of #105050 - WaffleLapkin:uselessrefign, r=jyn514 2022-12-03 17:37:42 +01:00
rustc_symbol_mangling Rollup merge of #104786 - WaffleLapkin:amp-mut-help, r=compiler-errors 2022-11-26 17:47:23 +01:00
rustc_target Rollup merge of #105123 - BlackHoleFox:fixing-the-macos-deployment, r=oli-obk 2022-12-04 11:38:51 +01:00
rustc_trait_selection Rollup merge of #104199 - SarthakSingh31:issue-97417-1, r=cjgillot 2022-12-03 17:37:41 +01:00
rustc_traits Make ObligationCtxt::normalize take cause by borrow 2022-11-28 17:35:40 +00:00
rustc_transmute Auto merge of #103831 - chenyukang:yukang/fix-103751-ice, r=nagisa 2022-11-05 13:48:30 +00:00
rustc_ty_utils Auto merge of #105012 - WaffleLapkin:into, r=oli-obk 2022-11-29 13:28:44 +00:00
rustc_type_ir Remove some unnecessary slicing 2022-11-21 20:38:55 +00:00