about summary refs log tree commit diff
AgeCommit message (Collapse)AuthorLines
2021-01-12Provide more information for HRTB lifetime errors involving closuresEsteban Küber-25/+392
2021-01-12Auto merge of #78407 - oli-obk:ub_checkable_ctfe, r=RalfJung,pnkfelixbors-220/+556
Make CTFE able to check for UB... ... by not doing any optimizations on the `const fn` MIR used in CTFE. This means we duplicate all `const fn`'s MIR now, once for CTFE, once for runtime. This PR is for checking the perf effect, so we have some data when talking about https://github.com/rust-lang/const-eval/blob/master/rfcs/0000-const-ub.md To do this, we now have two queries for obtaining mir: `optimized_mir` and `mir_for_ctfe`. It is now illegal to invoke `optimized_mir` to obtain the MIR of a const/static item's initializer, an array length, an inline const expression or an enum discriminant initializer. For `const fn`, both `optimized_mir` and `mir_for_ctfe` work, the former returning the MIR that LLVM should use if the function is called at runtime. Similarly it is illegal to invoke `mir_for_ctfe` on regular functions. This is all checked via appropriate assertions and I don't think it is easy to get wrong, as there should be no `mir_for_ctfe` calls outside the const evaluator or metadata encoding. Almost all rustc devs should keep using `optimized_mir` (or `instance_mir` for that matter).
2021-01-12Coverage computation needs access to the MIR, toooli-6/+13
2021-01-12Auto merge of #80517 - wabain:issue-77880-infer-error-try-conversion-msg, ↵bors-168/+292
r=davidtwco Enhance type inference errors involving the `?` operator This patch adds a special-cased note on type inference errors when the error span points to a `?` return. It also makes the primary label for such errors "cannot infer type of `?` error" in cases where before we would have only said "cannot infer type". One beneficiary of this change is async blocks, where we can't explicitly annotate the return type and so may not generate any other help (#77880); this lets us at least print the error type we're converting from and anything we know about the type we can't fully infer. More generally, it signposts that an implicit conversion is happening that may have impeded type inference the user was expecting. We already do something similar for [mismatched type errors](https://github.com/rust-lang/rust/blob/2987785df3d46d5ff144a5c67fbb8f5cca798d78/src/test/ui/try-block/try-block-bad-type.stderr#L7). The check for a relevant `?` operator is built into the existing HIR traversal which looks for places that could be annotated to resolve the error. That means we could identify `?` uses anywhere in the function that output the type we can't infer, but this patch just sticks to adding the note if the primary span given for the error has the operator; if there are other expressions where the type occurs and one of them is selected for the error instead, it's more likely that the `?` operator's implicit conversion isn't the sole cause of the inference failure and that adding an additional diagnostic would just be noise. I added a ui test for one such case. The data about the `?` conversion is passed around in a `UseDiagnostic` enum that in theory could be used to add more of this kind of note in the future. It was also just easier to pass around than something with a more specific name. There are some follow-up refactoring commits for the code that generates the error label, which was already pretty involved and made a bit more complicated by this change.
2021-01-12Auto merge of #80499 - matthiaskrgr:red_clos, r=estebankbors-44/+41
remove redundant closures (clippy::redundant_closure)
2021-01-12Auto merge of #80939 - JohnTitor:rollup-pymns4q, r=JohnTitorbors-98/+142
Rollup of 8 pull requests Successful merges: - #79757 (Replace tabs earlier in diagnostics) - #80600 (Add `MaybeUninit` method `array_assume_init`) - #80880 (Move some tests to more reasonable directories) - #80897 (driver: Use `atty` instead of rolling our own) - #80898 (Add another test case for #79808) - #80917 (core/slice: remove doc comment about scoped borrow) - #80927 (Replace a simple `if let` with the `matches` macro) - #80930 (fix typo in trait method mutability mismatch help) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-01-12Rollup merge of #80930 - euclio:trait-method-mutability-help, r=estebankYuki Okushi-16/+13
fix typo in trait method mutability mismatch help
2021-01-12Rollup merge of #80927 - LingMan:matches, r=estebankYuki Okushi-2/+1
Replace a simple `if let` with the `matches` macro `@rustbot` modify labels +C-cleanup +T-compiler
2021-01-12Rollup merge of #80917 - epilys:patch-1, r=jyn514Yuki Okushi-8/+5
core/slice: remove doc comment about scoped borrow There's no need to scope the borrow in the doc example due to NLL. [Playground link](https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20main()%20%7B%0A%20%20%20%20let%20mut%20v%20%3D%20%5B1%2C%200%2C%203%2C%200%2C%205%2C%206%5D%3B%0A%0A%20%20%20%20let%20(left%2C%20right)%20%3D%20v.split_at_mut(2)%3B%0A%20%20%20%20assert_eq!(left%2C%20%5B1%2C%200%5D)%3B%0A%20%20%20%20assert_eq!(right%2C%20%5B3%2C%200%2C%205%2C%206%5D)%3B%0A%20%20%20%20left%5B1%5D%20%3D%202%3B%0A%20%20%20%20right%5B1%5D%20%3D%204%3B%0A%0A%20%20%20%20assert_eq!(v%2C%20%5B1%2C%202%2C%203%2C%204%2C%205%2C%206%5D)%3B%0A%7D%0A) where changed code compiles
2021-01-12Rollup merge of #80898 - JohnTitor:vecdeque-another-case, r=lcnrYuki Okushi-0/+15
Add another test case for #79808 Taken from #80293. Closes #80293 r? `@lcnr`
2021-01-12Rollup merge of #80897 - camelid:atty, r=jyn514Yuki Okushi-33/+4
driver: Use `atty` instead of rolling our own Fixes #80888. Rationale: - `atty` is widely used in the Rust ecosystem - We already use it (in `rustc_errors` and other places) - We shouldn't be rolling our own TTY detector when there's a widely-used, well-tested package that we can use
2021-01-12Rollup merge of #80880 - c410-f3r:tests-tests-tests, r=petrochenkovYuki Okushi-10/+0
Move some tests to more reasonable directories The idea is to move `issues`/`ui` tests in small batches r? `@petrochenkov`
2021-01-12Rollup merge of #80600 - CoffeeBlend:maybe_uninit_array_assume_init, r=dtolnayYuki Okushi-0/+56
Add `MaybeUninit` method `array_assume_init` When initialising an array element-by-element, the conversion to the initialised array is done through `mem::transmute`, which is both ugly and does not work with const generics (see #61956). This PR proposes the associated method `array_assume_init`, matching the style of `slice_assume_init_*`: ```rust unsafe fn array_assume_init<T, const N: usize>(array: [MaybeUninit<T>; N]) -> [T; N]; ``` Example: ```rust let mut array: [MaybeUninit<i32>; 3] = MaybeUninit::uninit_array(); array[0].write(0); array[1].write(1); array[2].write(2); // SAFETY: Now safe as we initialised all elements let array: [i32; 3] = unsafe { MaybeUninit::array_assume_init(array) }; ``` Things I'm unsure about: * Should this be a method of array instead? * Should the function be const?
2021-01-12Rollup merge of #79757 - jryans:long-line-tab-handling-early-expand, r=estebankYuki Okushi-29/+48
Replace tabs earlier in diagnostics This replaces tabs earlier in the diagnostics emitting process, which allows various margin calculations to ignore the existence of tabs. It does add a string copy for the source lines that are emitted. Fixes https://github.com/rust-lang/rust/issues/78438 r? `@estebank`
2021-01-12Auto merge of #80463 - tgnottingham:incr_comp_serial_mem_usage, r=oli-obkbors-220/+686
Serialize incr comp structures to file via fixed-size buffer Reduce a large memory spike that happens during serialization by writing the incr comp structures to file by way of a fixed-size buffer, rather than an unbounded vector. Effort was made to keep the instruction count close to that of the previous implementation. However, buffered writing to a file inherently has more overhead than writing to a vector, because each write may result in a handleable error. To reduce this overhead, arrangements are made so that each LEB128-encoded integer can be written to the buffer with only one capacity and error check. Higher-level optimizations in which entire composite structures can be written with one capacity and error check are possible, but would require much more work. The performance is mostly on par with the previous implementation, with small to moderate instruction count regressions. The memory reduction is significant, however, so it seems like a worth-while trade-off.
2021-01-11driver: Use `atty` instead of rolling our ownCamelid-33/+4
Rationale: - `atty` is widely used in the Rust ecosystem - We already use it (in `rustc_errors` and other places) - We shouldn't be rolling our own TTY detector when there's a widely-used, well-tested package that we can use
2021-01-12Auto merge of #76580 - rokob:iss76011, r=estebankbors-17/+34
Suggest async {} for async || {} Fixes #76011 This adds support for adding help diagnostics to the feature gating checks and then uses it for the async_closure gate to add the extra bit of help information as described in the issue.
2021-01-12Replace a simple `if let` with the `matches` macroLingMan-2/+1
2021-01-12Fix implementationCoffeeBlend-1/+1
2021-01-11fix typo in trait method mutability mismatch helpAndy Russell-16/+13
2021-01-12Auto merge of #80928 - JohnTitor:rollup-sgerm3j, r=JohnTitorbors-153/+231
Rollup of 9 pull requests Successful merges: - #79997 (Emit a reactor for cdylib target on wasi) - #79998 (Use correct ABI for wasm32 by default) - #80042 (Split a func into cold/hot parts, reducing binary size) - #80324 (Explain method-call move errors in loops) - #80864 (std/core docs: fix wrong link in PartialEq) - #80870 (resolve: Simplify built-in macro table) - #80885 (rustdoc: Resolve `&str` as `str`) - #80904 (Fix small typo) - #80923 (Merge different function exits) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-01-12Rollup merge of #80923 - LingMan:exits, r=varkorYuki Okushi-7/+2
Merge different function exits `@rustbot` modify labels +C-cleanup +T-compiler
2021-01-12Rollup merge of #80904 - camelid:fix-small-typo, r=jonas-schievinkYuki Okushi-1/+1
Fix small typo transmutting -> transmuting
2021-01-12Rollup merge of #80885 - camelid:intra-doc-str-ref, r=jyn514Yuki Okushi-1/+10
rustdoc: Resolve `&str` as `str` People almost always are referring to `&str`, not `str`, so this will save a manual link resolve in many cases. Note that we already accept `&` (resolves to `reference`) in intra-doc links, so this shouldn't cause breakage. r? `@jyn514`
2021-01-12Rollup merge of #80870 - petrochenkov:bmactable, r=oli-obkYuki Okushi-19/+15
resolve: Simplify built-in macro table We don't use full `SyntaxExtension`s from the table, only `SyntaxExtensionKind`s, and `Ident` in `register_builtin_macro` always had dummy span. This PR removes unnecessary data from the table and related function signatures. Noticed when reviewing #80850.
2021-01-12Rollup merge of #80864 - ericseppanen:master, r=jyn514Yuki Okushi-1/+1
std/core docs: fix wrong link in PartialEq PartialEq doc was attempting to link to ``[`Eq`]`` but instead we got a link to `` `eq` ``. Disambiguate with `trait@Eq`. You can see the bad link [here](https://doc.rust-lang.org/std/cmp/trait.PartialEq.html) (Second sentence, "floating point types implement PartialEq but not Eq").
2021-01-12Rollup merge of #80324 - Aaron1011:loop-move-fn-self, r=oli-obkYuki Okushi-94/+108
Explain method-call move errors in loops PR #73708 added a more detailed explanation of move errors that occur due to a call to a method that takes `self`. This PR extends that logic to work when a move error occurs due to a method call in the previous iteration of a loop.
2021-01-12Rollup merge of #80042 - sivadeilra:cold_bits, r=oli-obkYuki Okushi-6/+20
Split a func into cold/hot parts, reducing binary size I noticed that the Size::bits function is called in many places, and is inlined into them. On x86_64-pc-windows-msvc, this function is inlined 527 times, and compiled separately (non-inlined) 3 times. Each of those inlined calls contains code that panics. This commit moves the `panic!` call into a separate function and marks that function with `#[cold]`. This reduces binary size by 24 KB. Not much, but it's something. Changes like this often reduce pressure on instruction-caches, since it reduces the amount of code that is inlined into hot code paths. Or more precisely, it removes cold code from hot cache lines.
2021-01-12Rollup merge of #79998 - devsnek:wasm32-bindgen-compat, r=alexcrichtonYuki Okushi-4/+5
Use correct ABI for wasm32 by default Introduces `wasm32-unknown-bindgen` for those wishing to use the bindgen compat abi. `wasm32-*` now uses the correct abi by default. Fixes https://github.com/rustwasm/team/issues/291
2021-01-12Rollup merge of #79997 - coolreader18:wasm-reactor, r=alexcrichtonYuki Okushi-20/+69
Emit a reactor for cdylib target on wasi Fixes #79199, and relevant to #73432 Implements wasi reactors, as described in WebAssembly/WASI#13 and [`design/application-abi.md`](https://github.com/WebAssembly/WASI/blob/master/design/application-abi.md) Empty `lib.rs`, `lib.crate-type = ["cdylib"]`: ```shell $ cargo +reactor build --release --target wasm32-wasi Compiling wasm-reactor v0.1.0 (/home/coolreader18/wasm-reactor) Finished release [optimized] target(s) in 0.08s $ wasm-dis target/wasm32-wasi/release/wasm_reactor.wasm >reactor.wat ``` `reactor.wat`: ```wat (module (type $none_=>_none (func)) (type $i32_=>_none (func (param i32))) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) (type $i32_=>_i32 (func (param i32) (result i32))) (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32))) (import "wasi_snapshot_preview1" "fd_prestat_get" (func $__wasi_fd_prestat_get (param i32 i32) (result i32))) (import "wasi_snapshot_preview1" "fd_prestat_dir_name" (func $__wasi_fd_prestat_dir_name (param i32 i32 i32) (result i32))) (import "wasi_snapshot_preview1" "proc_exit" (func $__wasi_proc_exit (param i32))) (import "wasi_snapshot_preview1" "environ_sizes_get" (func $__wasi_environ_sizes_get (param i32 i32) (result i32))) (import "wasi_snapshot_preview1" "environ_get" (func $__wasi_environ_get (param i32 i32) (result i32))) (memory $0 17) (table $0 1 1 funcref) (global $global$0 (mut i32) (i32.const 1048576)) (global $global$1 i32 (i32.const 1049096)) (global $global$2 i32 (i32.const 1049096)) (export "memory" (memory $0)) (export "_initialize" (func $_initialize)) (export "__data_end" (global $global$1)) (export "__heap_base" (global $global$2)) (func $__wasm_call_ctors (call $__wasilibc_initialize_environ_eagerly) (call $__wasilibc_populate_preopens) ) (func $_initialize (call $__wasm_call_ctors) ) (func $malloc (param $0 i32) (result i32) (call $dlmalloc (local.get $0) ) ) ;; lots of dlmalloc, memset/memcpy, & libpreopen code ) ``` I went with repurposing cdylib because I figured that it doesn't make much sense to have a wasi shared library that can't be initialized, and even if someone was using it adding an `_initialize` export is a very small change.
2021-01-11Move some tests to more reasonable directoriesCaio-10/+0
2021-01-11Simplify array_assume_initCoffeeBlend-12/+5
2021-01-11Auto merge of #79012 - tgnottingham:span_data_to_lines_and_cols, r=estebankbors-56/+222
rustc_span: add span_data_to_lines_and_cols to caching source map view
2021-01-11squash! fix wasiGus Caplan-15/+5
2021-01-11new targetGus Caplan-6/+12
2021-01-11Use correct ABI for wasm32 by defaultGus Caplan-1/+6
Introduces `RUSTC_USE_WASM32_BINDGEN_COMPAT_ABI` env var to use the compat ABI if need.
2021-01-11rustc_serialize: fix incorrect signed LEB128 decodingTyson Nottingham-58/+89
The signed LEB128 decoding function used a hardcoded constant of 64 instead of the number of bits in the type of integer being decoded, which resulted in incorrect results for some inputs. Fix this, make the decoding more consistent with the unsigned version, and increase the LEB128 encoding and decoding test coverage.
2021-01-11Serialize incr comp structures to file via fixed-size bufferTyson Nottingham-175/+610
Reduce a large memory spike that happens during serialization by writing the incr comp structures to file by way of a fixed-size buffer, rather than an unbounded vector. Effort was made to keep the instruction count close to that of the previous implementation. However, buffered writing to a file inherently has more overhead than writing to a vector, because each write may result in a handleable error. To reduce this overhead, arrangements are made so that each LEB128-encoded integer can be written to the buffer with only one capacity and error check. Higher-level optimizations in which entire composite structures can be written with one capacity and error check are possible, but would require much more work. The performance is mostly on par with the previous implementation, with small to moderate instruction count regressions. The memory reduction is significant, however, so it seems like a worth-while trade-off.
2021-01-11Auto merge of #75490 - LukasKalbertodt:add-basic-array-methods, r=dtolnaybors-3/+72
Add `[T; N]::each_ref` and `[T; N]::each_mut` This PR adds the methods `each_ref` and `each_mut` to `[T; N]`. The ability to add methods to arrays was added in #75212. These two methods are particularly useful with `map` which was also added in that PR. Tracking issue: #76118 ```rust impl<T, const N: usize> [T; N] { pub fn each_ref(&self) -> [&T; N]; pub fn each_mut(&mut self) -> [&mut T; N]; } ```
2021-01-11--emit=mir now emits both `mir_for_ctfe` and `optimized_mir` for `const fn`oli-11/+86
2021-01-11core/slice: remove doc comment about scoped borrowManos Pitsidianakis-8/+5
There's no need to scope the borrow in the doc example due to NLL. Playground link where changed code compiles https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&code=fn%20main()%20%7B%0A%20%20%20%20let%20mut%20v%20%3D%20%5B1%2C%200%2C%203%2C%200%2C%205%2C%206%5D%3B%0A%0A%20%20%20%20let%20(left%2C%20right)%20%3D%20v.split_at_mut(2)%3B%0A%20%20%20%20assert_eq!(left%2C%20%5B1%2C%200%5D)%3B%0A%20%20%20%20assert_eq!(right%2C%20%5B3%2C%200%2C%205%2C%206%5D)%3B%0A%20%20%20%20left%5B1%5D%20%3D%202%3B%0A%20%20%20%20right%5B1%5D%20%3D%204%3B%0A%0A%20%20%20%20assert_eq!(v%2C%20%5B1%2C%202%2C%203%2C%204%2C%205%2C%206%5D)%3B%0A%7D%0A
2021-01-11Auto merge of #80889 - cjgillot:asa, r=oli-obkbors-12/+4
Do not query the HIR directly in `opt_associated_item`. Papercut found by `@Aaron1011.`
2021-01-11Add `[T; N]::each_ref` and `[T; N]::each_mut`Lukas Kalbertodt-3/+72
These methods work very similarly to `Option`'s methods `as_ref` and `as_mut`. They are useful in several situation, particularly when calling other array methods (like `map`) on the result. Unfortunately, we can't easily call them `as_ref` and `as_mut` as that would shadow those methods on slices, thus being a breaking change (that is likely to affect a lot of code).
2021-01-11Add tracking issue for array_assume_initCoffeeBlend-1/+1
2021-01-11Auto merge of #80905 - JohnTitor:rollup-tmmwmnb, r=JohnTitorbors-45/+76
Rollup of 6 pull requests Successful merges: - #80809 (Use standard formatting for "rust-call" ABI message) - #80872 (Fix typo in source-based-code-coverage.md) - #80878 (Add ABI argument to `find_mir_or_eval_fn`) - #80881 ( Fix intra-doc links to `Self` and `crate` ) - #80887 (log-color: Detect TTY based on stderr, not stdout) - #80892 (rustdoc: Remove `*` intra-doc alias for `pointer`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2021-01-11Rollup merge of #80892 - camelid:intra-doc-remove-star, r=jyn514Yuki Okushi-3/+1
rustdoc: Remove `*` intra-doc alias for `pointer` It's not valid Rust code and it can easily be confused with a wildcard glob pattern or something else. People can always use `pointer` instead, so it's just removing an alias. It hasn't hit stable yet (I think it's still on nightly), so it's okay to remove it. (We can always add it back later if we change our mind too.) r? `@jyn514` cc https://github.com/rust-lang/rust/pull/80885#discussion_r554622737
2021-01-11Rollup merge of #80887 - camelid:fix-log-color-auto, r=RalfJungYuki Okushi-2/+21
log-color: Detect TTY based on stderr, not stdout Fixes #78435 (again). Logging goes to stderr, not stdout, so we should base our automated detection on stderr instead of stdout. Thanks to Ralf Jung for noticing and reporting the bug! r? `@oli-obk` cc `@RalfJung`
2021-01-11Rollup merge of #80881 - jyn514:intra-doc-self, r=GuillaumeGomezYuki Okushi-21/+26
Fix intra-doc links to `Self` and `crate` Closes https://github.com/rust-lang/rust/issues/77732.
2021-01-11Rollup merge of #80878 - unseddd:abi, r=RalfJungYuki Okushi-5/+14
Add ABI argument to `find_mir_or_eval_fn` Add ABI argument for called function in `find_mir_or_eval_fn` and `call_extra_fn`. Useful for comparing with expected ABI in interpreters. Related to [miri/1631](https://github.com/rust-lang/miri/issues/1631) r? `@RalfJung`
2021-01-11Rollup merge of #80872 - eltociear:patch-4, r=jonas-schievinkYuki Okushi-1/+1
Fix typo in source-based-code-coverage.md preceeding -> preceding