about summary refs log tree commit diff
path: root/src/libcore
AgeCommit message (Collapse)AuthorLines
2020-06-27Rollup merge of #73672 - nellshamrell:async-fix, r=estebankManish Goregaokar-0/+1
Adds a clearer message for when the async keyword is missing from a f… …unction This is a somewhat simple fix for #66731. Under the current version of Rust, if a user has a rust file that looks like this: ```rust fn boo (){} async fn foo() { boo().await; } fn main() { } ``` And they attempt to run it, they will receive an error message that looks like this: ```bash error: incorrect use of `await` --> test.rs:4:14 | 4 | boo.await(); | ^^ help: `await` is not a method call, remove the parentheses error[E0277]: the trait bound `fn() {boo}: std::future::Future` is not satisfied --> test.rs:4:5 | 4 | boo.await(); | ^^^^^^^^^ the trait `std::future::Future` is not implemented for `fn() {boo}` error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0277`. ``` This is not very clear. With the changes made in this PR, when a user compiles and runs that same rust code, they will receive an error message that looks like this: ```bash error[E0277]: `()` is not a future. --> test.rs:4:5 | 4 | boo().await; | ^^^^^^^^^^^ `()` is not a future | = help: the trait `std::future::Future` is not implemented for `()` = note: required by `std::future::Future::poll` ``` In the future, I think we should make this error message even clearer, perhaps through a solution like the one described in [this comment](https://github.com/rust-lang/rust/issues/66731#issuecomment-644394287). However, as that potentially involves a major change proposal, I would rather get this change in now and make the error message a little clearer while an MCP is drafted and discussed. Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
2020-06-28Rename the lint to clashing_extern_declarations.jumbatm-2/+2
Also, run RustFmt on the clashing_extern_fn test case and update stderrs.
2020-06-27Forward Hash::write_iN to Hash::write_uNNikita Popov-5/+5
2020-06-26Rollup merge of #73738 - nbdd0121:comment, r=nikomatsakisManish Goregaokar-5/+0
Remove irrelevant comment Iterator is no longer a lang item since 216e72f8d9499d012e23bc4563215e693fcb4f35.
2020-06-26Rollup merge of #73579 - RalfJung:doc-missing-links, r=shepmasterManish Goregaokar-2/+4
add missing doc links The doc comments contain ``[`size_of_val`]`` but the link target was missing.
2020-06-26Make `likely` and `unlikely` constGary Guo-0/+3
They are gated by internal feature gate const_likely
2020-06-26Rollup merge of #73707 - LeSeulArtichaut:patch-3, r=kennytmManish Goregaokar-0/+2
Fix links in `SliceIndex` documentation See [this doc](https://doc.rust-lang.org/nightly/std/slice/trait.SliceIndex.html#tymethod.get_unchecked) whose links aren't active because of this missing newline.
2020-06-25Rollup merge of #73673 - ehuss:fix-ptr-docs, r=oli-obkManish Goregaokar-4/+0
Fix ptr doc warnings. #73398 added some stray backtick lines which cause warnings when the docs are built.
2020-06-25Rollup merge of #73418 - doctorn:variants-intrinsic, r=kennytmManish Goregaokar-0/+46
Add unstable `core::mem::variant_count` intrinsic Adds a new `const fn` intrinsic which can be used to determine the number of variants in an `enum`. I've shown this to a couple of people and they invariably ask 'why on earth?', but there's actually a very neat use case: At the moment, if you want to create an opaque array type that's indexed by an `enum` with one element for each variant, you either have to hard-code the number of variants, add a `LENGTH` variant or use a `Vec`, none of which are suitable in general (number of variants could change; pattern matching `LENGTH` becomes frustrating; might not have `alloc`). By including this intrinsic, it becomes possible to write the following: ```rust #[derive(Copy, Clone)] enum OpaqueIndex { A = 0, B, C, } struct OpaqueVec<T>(Box<[T; std::mem::num_variants::<OpaqueIndex>()]>); impl<T> std::ops::Index<OpaqueIndex> for OpaqueVec<T> { type Output = T; fn index(&self, idx: OpaqueIndex) -> &Self::Output { &self.0[idx as usize] } } ``` (We even have a use cases for this in `rustc` and I plan to use it to re-implement the lang-items table.)
2020-06-25Adds a clearer message for when the async keyword is missing from a functionNell Shamrell-0/+1
Signed-off-by: Nell Shamrell <nellshamrell@gmail.com>
2020-06-25Remove irrelevant commentGary Guo-5/+0
2020-06-25Auto merge of #72717 - poliorcetics:try-from-int-to-nzint, r=dtolnaybors-0/+58
Add TryFrom<{int}> for NonZero{int} Adds `TryFrom<{int}> for NonZero{int}`. It uses the existing `NonZero{int}::new()` and `Option::ok_or()` functions, meaning the checks are not repeated. I also added tests, I tried to follow the convention I saw in the test file. I also used `#[stable(feature = "nzint_try_from_int_conv", since = "1.46.0")]`, but I have no idea if the feature/version are correctly named or even correct.
2020-06-24Implement associated lang itemsAaron Hill-0/+1
Fixes #70718 This commit allows making associated items (e.g. associated functions and types) into lang items via the `#[lang]` attribute. This allows such items to be accessed directly, rather than by iterating over the parent item's associated items. I've added `FnOnce::Output` as a lang item, and updated one old usage to use the new lang item. The remaining uses can be updated separately.
2020-06-24Fix links in `SliceIndex` documentationLeSeulArtichaut-0/+2
2020-06-24Fix testsNathan Corbyn-0/+1
2020-06-24Fix testsNathan Corbyn-0/+2
2020-06-24Implement intrinsicNathan Corbyn-0/+43
2020-06-23Fix ptr doc warnings.Eric Huss-4/+0
2020-06-23Rollup merge of #73614 - lcnr:patch-4, r=Dylan-DPCManish Goregaokar-1/+1
fix `intrinsics::needs_drop` docs
2020-06-23Rollup merge of #73398 - oli-obk:const_raw_ptr_cmp, r=varkor,RalfJung,nagisaManish Goregaokar-3/+163
A way forward for pointer equality in const eval r? @varkor on the first commit and @RalfJung on the second commit cc #53020
2020-06-22fix `intrinsics::needs_drop` docsBastian Kauschke-1/+1
2020-06-22add: testsVillSnow-0/+41
2020-06-22update: doc commentVillSnow-1/+3
2020-06-21improve grammarRalf Jung-2/+2
Co-authored-by: Bastian Kauschke <bastian_kauschke@hotmail.de>
2020-06-21deprecate wrapping_offset_fromRalf Jung-0/+13
2020-06-21tweak wordingRalf Jung-2/+2
2020-06-21add missing doc linksRalf Jung-0/+2
2020-06-21fix: doc testVillSnow-3/+3
2020-06-21Add partition_pointVillSnow-0/+38
2020-06-21Auto merge of #70946 - jumbatm:clashing-extern-decl, r=nagisabors-0/+3
Add a lint to catch clashing `extern` fn declarations. Closes #69390. Adds lint `clashing_extern_decl` to detect when, within a single crate, an extern function of the same name is declared with different types. Because two symbols of the same name cannot be resolved to two different functions at link time, and one function cannot possibly have two types, a clashing extern declaration is almost certainly a mistake. This lint does not run between crates because a project may have dependencies which both rely on the same extern function, but declare it in a different (but valid) way. For example, they may both declare an opaque type for one or more of the arguments (which would end up distinct types), or use types that are valid conversions in the language the extern fn is defined in. In these cases, we can't say that the clashing declaration is incorrect. r? @eddyb
2020-06-20Rollup merge of #73411 - ehuss:bump-stage0, r=Mark-SimulacrumManish Goregaokar-2/+6
Update bootstrap to rustc 1.45.0-beta.2 (1dc0f6d8e 2020-06-15) Pulls in changes from #73326. Closes #73286
2020-06-20Fix broken inner_deref doc tests.Eric Huss-2/+6
2020-06-20Revise according to reviewJon Gjengset-21/+19
2020-06-20Doctests need featureJon Gjengset-0/+2
2020-06-20core/time: Add Duration methods for zeroJon Gjengset-1/+42
This patch adds two methods to `Duration`. The first, `Duration::zero`, provides a `const` constructor for getting an zero-length duration. This is also what `Default` provides (this was clarified in the docs), though `default` is not `const`. The second, `Duration::is_zero`, returns true if a `Duration` spans no time (i.e., because its components are all zero). Previously, the way to do this was either to compare both `as_secs` and `subsec_nanos` to 0, to compare against `Duration::new(0, 0)`, or to use the `u128` method `as_nanos`, none of which were particularly elegant.
2020-06-20Address review commentsOliver Scherer-42/+13
2020-06-20Satisfy tidyOliver Scherer-1/+1
2020-06-20Add ClashingExternDecl lint.jumbatm-0/+3
This lint checks that all declarations for extern fns of the same name are declared with the same types.
2020-06-19Rollup merge of #71899 - cuviper:try_find_map, r=dtolnayManish Goregaokar-11/+18
Refactor `try_find` a little ~~This works like `find_map`, but mapping to a `Try` type. It stops when `Ok` is `Some(value)`, with an additional short-circuit on `Try::Error`. This is similar to the unstable `try_find`, but has the advantage of being able to directly return the user's `R: Try` type directly, rather than converting to `Result`.~~ (removed -- `try_find_map` was declined in review) This PR also refactors `try_find` a little to match style. The `E` type parameter was unnecessary, so it's now removed. The folding closure now has reduced parametricity on just `T = Self::Item`, rather than the whole `Self` iterator type. There's otherwise no functional change in this.
2020-06-19Rollup merge of #71420 - RalfJung:specialization-incomplete, r=matthewjasperManish Goregaokar-1/+1
Specialization is unsound As discussed in https://github.com/rust-lang/rust/issues/31844#issuecomment-617013949, it might be a good idea to warn users of specialization that the feature they are using is unsound. I also expanded the "incomplete feature" warning to link the user to the tracking issue.
2020-06-19Refactor `try_find` a littleJosh Stone-11/+18
The `E` type parameter was unnecessary, so it's now removed. The folding closure now has reduced parametricity on just `T = Self::Item`, rather than the whole `Self` iterator type. There's otherwise no functional change in this.
2020-06-19Rollup merge of #71568 - hbina:document_unsafety_slice_sort, r=joshtriplettManish Goregaokar-3/+70
Document unsafety in slice/sort.rs Let me know if these documentations are accurate c: I don't think I am capable enough to document the safety of `partition_blocks`, however. Related issue #66219
2020-06-19Tidy got confused on `rustc_const_unstable` `issue`sOliver Scherer-4/+4
2020-06-19Add fuzzy pointer comparison intrinsicsOliver Scherer-2/+191
2020-06-19Rollup merge of #73054 - RalfJung:dont-panic, r=Mark-SimulacrumRalf Jung-12/+33
memory access sanity checks: abort instead of panic Suggested by @Mark-Simulacrum, this should help reduce the performance impact of these checks.
2020-06-19Rollup merge of #73011 - richkadel:llvm-count-from-mir-pass, r=tmandryRalf Jung-0/+7
first stage of implementing LLVM code coverage This PR replaces #70680 (WIP toward LLVM Code Coverage for Rust) since I am re-implementing the Rust LLVM code coverage feature in a different part of the compiler (in MIR pass(es) vs AST). This PR updates rustc with `-Zinstrument-coverage` option that injects the llvm intrinsic `instrprof.increment()` for code generation. This initial version only injects counters at the top of each function, and does not yet implement the required coverage map. Upcoming PRs will add the coverage map, and add more counters and/or counter expressions for each conditional code branch. Rust compiler MCP https://github.com/rust-lang/compiler-team/issues/278 Relevant issue: #34701 - Implement support for LLVMs code coverage instrumentation ***[I put together some development notes here, under a separate branch.](https://github.com/richkadel/rust/blob/cfa0b21d34ee64e4ebee226101bd2ef0c6757865/src/test/codegen/coverage-experiments/README-THIS-IS-TEMPORARY.md)***
2020-06-19Rollup merge of #73142 - ehuss:std-benches, r=dtolnayRalf Jung-0/+3
Ensure std benchmarks get tested. This ensures that the std benchmarks don't break in the future. Currently they aren't compiled or tested on CI, so they can easily bitrot. Testing a benchmark runs it with one iteration. Adding these should only add a few seconds to CI. Closes #54176 Closes #61913
2020-06-18Use step_unchecked more liberallyCAD97-12/+12
2020-06-18Rollup merge of #73447 - lzutao:stabilize-result_as_deref, r=dtolnayManish Goregaokar-16/+40
Improve document for `Result::as_deref(_mut)` methods cc #50264
2020-06-18Rollup merge of #73425 - poliorcetics:zeroed-functions-pointers, r=dtolnayManish Goregaokar-5/+7
Mention functions pointers in the documentation Fixes #51615. This mentions function pointers in the documentation for `core::mem::zeroed`, adding them to the list of types that are **always** wrong when zeroed, with `&T` and `&mut T`. @rustbot modify labels: T-doc, C-enhancement, T-libs