about summary refs log tree commit diff
AgeCommit message (Collapse)AuthorLines
2022-04-04Fix list lengthEsteban Kuber-1/+225
2022-04-04Suggest dereferncing when possible in E0277, fix #87437Esteban Kuber-41/+121
2022-04-04Fix #90970, doesn't address #87437Esteban Kuber-6/+115
2022-04-04Mention implementers of unsatisfied traitEsteban Kuber-183/+690
When encountering an unsatisfied trait bound, if there are no other suggestions, mention all the types that *do* implement that trait: ``` error[E0277]: the trait bound `f32: Foo` is not satisfied --> $DIR/impl_wf.rs:22:6 | LL | impl Baz<f32> for f32 { } | ^^^^^^^^ the trait `Foo` is not implemented for `f32` | = help: the following other types implement trait `Foo`: Option<T> i32 str note: required by a bound in `Baz` --> $DIR/impl_wf.rs:18:31 | LL | trait Baz<U: ?Sized> where U: Foo { } | ^^^ required by this bound in `Baz` ``` Mention implementers of traits in `ImplObligation`s. Do not mention other `impl`s for closures, ranges and `?`.
2022-04-04Auto merge of #95555 - nnethercote:parse_tt-new-representation, r=petrochenkovbors-335/+290
A new matcher representation for use in `parse_tt` By transforming the matcher into a different form, `parse_tt` can run faster and be easier to understand. r? `@petrochenkov`
2022-04-04Auto merge of #95119 - OliverMD:method_suggestions, r=davidtwcobors-10/+104
Improve method name suggestions Attempts to improve method name suggestions when a matching method name is not found. The approach taken is use the Levenshtein distance and account for substrings having a high distance but can sometimes be very close to the intended method (eg. empty vs is_empty). resolves #94747
2022-04-04Auto merge of #95636 - pietroalbini:pa-version-1.62.0, r=pietroalbinibors-1/+1
Bump version number to 1.62.0
2022-04-04bump version to 1.62.0Pietro Albini-1/+1
2022-04-04Reorder match arms in `parse_tt_inner`.Nicholas Nethercote-31/+31
To match the order the variants are declared in.
2022-04-04A new matcher representation for use in `parse_tt`.Nicholas Nethercote-334/+289
`parse_tt` currently traverses a `&[TokenTree]` to do matching. But this is a bad representation for the traversal. - `TokenTree` is nested, and there's a bunch of expensive and fiddly state required to handle entering and exiting nested submatchers. - There are three positions (sequence separators, sequence Kleene ops, and end of the matcher) that are represented by an index that exceeds the end of the `&[TokenTree]`, which is clumsy and error-prone. This commit introduces a new representation called `MatcherLoc` that is designed specifically for matching. It fixes all the above problems, making the code much easier to read. A `&[TokenTree]` is converted to a `&[MatcherLoc]` before matching begins. Despite the cost of the conversion, it's still a net performance win, because various pieces of traversal state are computed once up-front, rather than having to be recomputed repeatedly during the macro matching. Some improvements worth noting. - `parse_tt_inner` is *much* easier to read. No more having to compare `idx` against `len` and read comments to understand what the result means. - The handling of `Delimited` in `parse_tt_inner` is now trivial. - The three end-of-sequence cases in `parse_tt_inner` are now handled in three separate match arms, and the control flow is much simpler. - `nameize` is no longer recursive. - There were two places that issued "missing fragment specifier" errors: one in `parse_tt_inner()`, and one in `nameize()`. Presumably the latter was never executed. There's now a single place issuing these errors, in `compute_locs()`. - The number of heap allocations done for a `check full` build of `async-std-1.10.0` (an extreme example of heavy macro use) drops from 11.8M to 2.6M, and most of these occur outside of macro matching. - The size of `MatcherPos` drops from 64 bytes to 16 bytes. Small enough that it no longer needs boxing, which partly accounts for the reduction in allocations. - The rest of the drop in allocations is due to the removal of `MatcherKind`, because we no longer need to record anything for the parent matcher when entering a submatcher. - Overall it reduces code size by 45 lines.
2022-04-04Auto merge of #95031 - compiler-errors:param-env-cache, r=Aaron1011bors-12/+20
Do not use `ParamEnv::and` when building a cache key from a param-env and trait eval candidate Do not use `ParamEnv::and` to cache a param-env with a selection/evaluation candidate. This is because if the param-env is `RevealAll` mode, and the candidate looks global (i.e. it has erased regions, which can show up when we normalize a projection type under a binder<sup>1</sup>), then when we use `ParamEnv::and` to pair the candidate and the param-env for use as a cache key, we will throw away the param-env's caller bounds, and we'll end up caching a candidate that we inferred from the param-env with a empty param-env, which may cause cache-hit later when we have an empty param-env, and possibly mess with normalization like we see in the referenced issue during codegen. Not sure how to trigger this with a more structured test, but changing `check-pass` to `build-pass` triggers the case that https://github.com/rust-lang/rust/issues/94903 detected. <sup>1.</sup> That is, we will replace the late-bound region with a placeholder, which gets canonicalized and turned into an infererence variable, which gets erased during region freshening right before we cache the result. Sorry, it's quite a few steps. Fixes #94903 r? `@Aaron1011` (or reassign as you see fit)
2022-04-04Auto merge of #95606 - petrochenkov:linkregr, r=wesleywiserbors-1/+6
linker: Implicitly link native libs as whole-archive in some more cases Partially revert changes from https://github.com/rust-lang/rust/pull/93901 to address regressions like https://github.com/rust-lang/rust/issues/95561. Fixes https://github.com/rust-lang/rust/issues/95561 r? `@wesleywiser`
2022-04-03Auto merge of #95619 - bjorn3:inline_location_caller, r=scottmcmbors-0/+1
Mark Location::caller() as #[inline] This function gets compiled to a single register move as it actually gets it's return value passed in as argument.
2022-04-03Auto merge of #95624 - Dylan-DPC:rollup-r8w7ui3, r=Dylan-DPCbors-1308/+1421
Rollup of 5 pull requests Successful merges: - #95202 (Reduce the cost of loading all built-ins targets) - #95553 (Don't emit non-asm contents error for naked function composed of errors) - #95613 (Fix rustdoc attribute display) - #95617 (Fix &mut invalidation in ptr::swap doctest) - #95618 (core: document that the align_of* functions return the alignment in bytes) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-04-03Rollup merge of #95618 - adamse:master, r=dtolnayDylan DPC-5/+8
core: document that the align_of* functions return the alignment in bytes
2022-04-03Rollup merge of #95617 - saethlin:swap-test-invalidation, r=Dylan-DPCDylan DPC-2/+3
Fix &mut invalidation in ptr::swap doctest Under Stacked Borrows with raw pointer tagging, the previous code was UB because the code which creates the the second pointer borrows the array through a tag in the borrow stacks below the Unique tag that our first pointer is based on, thus invalidating the first pointer. This is not definitely a bug and may never be real UB, but I desperately want people to write code that conforms to SB with raw pointer tagging so that I can write good diagnostics. The alternative aliasing models aren't possible to diagnose well due to state space explosion. Therefore, it would be super cool if the standard library nudged people towards writing code that is valid with respect to SB with raw pointer tagging. The diagnostics that I want to write are implemented in a branch of Miri and the one for this case is below: ``` error: Undefined Behavior: attempting a read access using <2170> at alloc1068[0x0], but that tag does not exist in the borrow stack for this location --> /home/ben/rust/library/core/src/intrinsics.rs:2103:14 | 2103 | unsafe { copy_nonoverlapping(src, dst, count) } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | attempting a read access using <2170> at alloc1068[0x0], but that tag does not exist in the borrow stack for this location | this error occurs as part of an access at alloc1068[0x0..0x8] | = help: this indicates a potential bug in the program: it performed an invalid operation, but the rules it violated are still experimental = help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information help: <2170> was created due to a retag at offsets [0x0..0x10] --> ../libcore/src/ptr/mod.rs:640:9 | 8 | let x = array[0..].as_mut_ptr() as *mut [u32; 2]; // this is `array[0..2]` | ^^^^^^^^^^^^^^^^^^^^^^^ help: <2170> was later invalidated due to a retag at offsets [0x0..0x10] --> ../libcore/src/ptr/mod.rs:641:9 | 9 | let y = array[2..].as_mut_ptr() as *mut [u32; 2]; // this is `array[2..4]` | ^^^^^ = note: inside `std::intrinsics::copy_nonoverlapping::<[u32; 2]>` at /home/ben/rust/library/core/src/intrinsics.rs:2103:14 = note: inside `std::ptr::swap::<[u32; 2]>` at /home/ben/rust/library/core/src/ptr/mod.rs:685:9 note: inside `main::_doctest_main____libcore_src_ptr_mod_rs_635_0` at ../libcore/src/ptr/mod.rs:12:5 --> ../libcore/src/ptr/mod.rs:644:5 | 12 | ptr::swap(x, y); | ^^^^^^^^^^^^^^^ note: inside `main` at ../libcore/src/ptr/mod.rs:15:3 --> ../libcore/src/ptr/mod.rs:647:3 | 15 | } _doctest_main____libcore_src_ptr_mod_rs_635_0() } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace error: aborting due to previous error ```
2022-04-03Rollup merge of #95613 - GuillaumeGomez:fix-rustdoc-attr-display, r=notriddleDylan DPC-1/+13
Fix rustdoc attribute display Fixes #81482. r? `@notriddle`
2022-04-03Rollup merge of #95553 - jam1garner:naked-function-compile-error, r=tmiaskoDylan DPC-4/+60
Don't emit non-asm contents error for naked function composed of errors ## Motivation For naked functions an error is emitted when they are composed of anything other than a single asm!() block. However, this error triggers in a couple situations in which it adds no additional information or is actively misleading. One example is if you do have an asm!() block but simply one with a syntax error: ```rust #[naked] unsafe extern "C" fn compiler_errors() { asm!(invalid_syntax) } ``` This results in two errors, one for the syntax error itself and another telling you that you need an asm block in your function: ```rust error[E0787]: naked functions must contain a single asm block --> src/main.rs:6:1 | 6 | / unsafe extern "C" fn naked_compile_error() { 7 | | asm!(blah) 8 | | } | |_^ ``` This issue also comes up when [utilizing `compile_error!()` for improving your diagnostics](https://twitter.com/steveklabnik/status/1509538243020218372), such as raising a compiler error when compiling for an unsupported target. ## Implementation The rules this PR implements are as follows: 1. If any non-erroneous non-asm statement is included, an error will still occur 2. If multiple asm statements are included, an error will still occur 3. If 0 or 1 asm statements are present, as well as any non-zero number of erroneous statements, then this error will *not* be raised as it is likely either redundant or incorrect The rule of thumb is effectively "if an error is present and its correction could change things, don't raise an error".
2022-04-03Rollup merge of #95202 - Urgau:check-cfg-perf-well-known-values, r=petrochenkovDylan DPC-1296/+1337
Reduce the cost of loading all built-ins targets This PR started by measuring the exact slowdown of checking of well known conditional values. Than this PR implemented some technics to reduce the cost of loading all built-ins targets. cf. https://github.com/rust-lang/rust/issues/82450#issuecomment-1073992323
2022-04-03Fix &mut invalidation in ptr::swap doctestBen Kimock-2/+3
Under Stacked Borrows with raw pointer tagging, the previous code was UB because the code which creates the the second pointer borrows the array through a tag in the borrow stacks below the Unique tag that our first pointer is based on, thus invalidating the first pointer. This is not definitely a bug and may never be real UB, but I desperately want people to write code that conforms to SB with raw pointer tagging so that I can write good diagnostics. The alternative aliasing models aren't possible to diagnose well due to state space explosion. Therefore, it would be super cool if the standard library nudged people towards writing code that is valid with respect to SB with raw pointer tagging.
2022-04-03Cleanup after some refactoring in rustc_targetLoïc BRANSTETT-112/+79
2022-04-03Replace LinkArgs with Cow<'static, str>Loïc BRANSTETT-11/+12
2022-04-03Replace every Vec in Target(Options) with it's Cow equivalentLoïc BRANSTETT-53/+117
2022-04-03Replace every `String` in Target(Options) with `Cow<'static, str>`Loïc BRANSTETT-1243/+1252
2022-04-03Auto merge of #95610 - createyourpersonalaccount:derefmut-docfix, r=Dylan-DPCbors-1/+1
Improve doc example of DerefMut It is more illustrative, after using `*x` to modify the field, to show in the assertion that the field has indeed been modified.
2022-04-03Mark Location::caller() as #[inline]bjorn3-0/+1
This function gets compiled to a single register move as it actually gets it's return value passed in as argument.
2022-04-03core: document that the align_of* functions return the alignment in bytesAdam Sandberg Ericsson-5/+8
2022-04-03Auto merge of #92686 - saethlin:unsafe-debug-asserts, r=Amanieubors-128/+123
Add debug assertions to some unsafe functions As suggested by https://github.com/rust-lang/rust/issues/51713 ~~Some similar code calls `abort()` instead of `panic!()` but aborting doesn't work in a `const fn`, and the intrinsic for doing dispatch based on whether execution is in a const is unstable.~~ This picked up some invalid uses of `get_unchecked` in the compiler, and fixes them. I can confirm that they do in fact pick up invalid uses of `get_unchecked` in the wild, though the user experience is less-than-awesome: ``` Running unittests (target/x86_64-unknown-linux-gnu/debug/deps/rle_decode_fast-04b7918da2001b50) running 6 tests error: test failed, to rerun pass '--lib' Caused by: process didn't exit successfully: `/home/ben/rle-decode-helper/target/x86_64-unknown-linux-gnu/debug/deps/rle_decode_fast-04b7918da2001b50` (signal: 4, SIGILL: illegal instruction) ``` ~~As best I can tell these changes produce a 6% regression in the runtime of `./x.py test` when `[rust] debug = true` is set.~~ Latest commit (https://github.com/rust-lang/rust/pull/92686/commits/6894d559bdb4365243b3f4bf73f18e4b1bed04d1) brings the additional overhead from this PR down to 0.5%, while also adding a few more assertions. I think this actually covers all the places in `core` that it is reasonable to check for safety requirements at runtime. Thoughts?
2022-04-03Improve method name suggestionsOliver Downard-10/+104
Attempts to improve method name suggestions when a matching method name is not found. The approach taken is use the Levenshtein distance and account for substrings having a high distance but can sometimes be very close to the intended method (eg. empty vs is_empty).
2022-04-03Add test for attribute display in rustdocGuillaume Gomez-0/+7
2022-04-03Fix display of attributes in rustdocGuillaume Gomez-1/+6
2022-04-03Auto merge of #90791 - drmorr0:drmorr-memcmp-cint-cfg, r=petrochenkovbors-4/+22
make memcmp return a value of c_int_width instead of i32 This is an attempt to fix #32610 and #78022, namely, that `memcmp` always returns an `i32` regardless of the platform. I'm running into some issues and was hoping I could get some help. Here's what I've been attempting so far: 1. Build the stage0 compiler with all the changes _expect_ for the changes in `library/core/src/slice/cmp.rs` and `compiler/rustc_codegen_llvm/src/context.rs`; this is because `target_c_int_width` isn't passed through and recognized as a valid config option yet. I'm building with `./x.py build --stage 0 library/core library/proc_macro compiler/rustc` 2. Next I add in the `#[cfg(c_int_width = ...)]` params to `cmp.rs` and `context.rs` and build the stage 1 compiler by running `./x.py build --keep-stage 0 --stage 1 library/core library/proc_macro compiler/rustc`. This step now runs successfully. 3. Lastly, I try to build the test program for AVR mentioned in #78022 with `RUSTFLAGS="--emit llvm-ir" cargo build --release`, and look at the resulting llvm IR, which still shows: ``` ... %11 = call addrspace(1) i32 `@memcmp(i8*` nonnull %5, i8* nonnull %10, i16 5) #7, !dbg !1191 %.not = icmp eq i32 %11, 0, !dbg !1191 ... ; Function Attrs: nounwind optsize declare i32 `@memcmp(i8*,` i8*, i16) local_unnamed_addr addrspace(1) #4 ``` Any ideas what I'm missing here? Alternately, if this is totally the wrong approach I'm open to other suggestions. cc `@Rahix`
2022-04-03Auto merge of #85321 - cjgillot:mir-cycle, r=bjorn3bors-17/+12
Use DefPathHash instead of HirId to break inlining cycles. The `DefPathHash` is stable across incremental compilation sessions, so provides a total order on `LocalDefId`. Using it instead of `HirId` ensures the MIR inliner has the same behaviour for incremental and non-incremental compilation. A downside is that the cycle tie break is not as predictable is with `HirId`.
2022-04-03Auto merge of #88672 - camelid:inc-parser-sugg, r=davidtwcobors-1/+514
Suggest `i += 1` when we see `i++` or `++i` Closes #83502 (for `i++` and `++i`; `--i` should be covered by #82987, and `i--` is tricky to handle). This is a continuation of #83536. r? `@estebank`
2022-04-03Improve doc example of DerefMutNikolaos Chatzikonstantinou-1/+1
It is more illustrative, after using `*x` to modify the field, to show in the assertion that the field has indeed been modified.
2022-04-02make memcmp return a value of c_int_width instead of i32David Morrison-4/+22
2022-04-02Auto merge of #95590 - GuillaumeGomez:multi-line-attr-handling-doctest, ↵bors-8/+84
r=notriddle Fix multiline attributes handling in doctests Fixes #55713. I needed to have access to the `unclosed_delims` field in order to check that the attribute was completely parsed and didn't have missing parts, so I created a getter for it. r? `@notriddle`
2022-04-03linker: Implicitly link native libs as whole-archive in some more casesVadim Petrochenkov-1/+6
2022-04-02Less manipulation of the callee_def_id.Camille GILLOT-5/+6
2022-04-02Use only local hash.Camille GILLOT-2/+2
2022-04-02Use DefPathHash instead of HirId to break cycles.Camille GILLOT-14/+8
2022-04-02Auto merge of #95600 - Dylan-DPC:rollup-580y2ra, r=Dylan-DPCbors-11/+113
Rollup of 4 pull requests Successful merges: - #95587 (Remove need for associated_type_bounds in std.) - #95589 (Include a header in .rlink files) - #95593 (diagnostics: add test case for bogus T:Sized suggestion) - #95597 (Refer to u8 by absolute path in expansion of thread_local) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-04-02Rollup merge of #95597 - dtolnay:threadlocalu8, r=Dylan-DPCDylan DPC-3/+18
Refer to u8 by absolute path in expansion of thread_local The standard library's `thread_local!` macro previously referred to `u8` just as `u8`, resolving to whatever `u8` existed in the type namespace at the call site. This PR replaces those with `$crate::primitive::u8` which always refers to `std::primitive::u8` regardless of what's in scope at the call site. Unambiguously naming primitives inside macro-generated code is the reason that std::primitive was introduced in the first place. <details> <summary>Here is the error message prior to this PR ⬇️</summary> ```console error[E0308]: mismatched types --> src/main.rs:6:1 | 6 | / std::thread_local! { 7 | | pub static A: i32 = f(); 8 | | pub static B: i32 = const { 0 }; 9 | | } | |_^ expected struct `u8`, found integer | = note: this error originates in the macro `$crate::__thread_local_inner` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types --> src/main.rs:6:1 | 6 | / std::thread_local! { 7 | | pub static A: i32 = f(); 8 | | pub static B: i32 = const { 0 }; 9 | | } | | ^ | | | | |_expected struct `u8`, found integer | this expression has type `u8` | = note: this error originates in the macro `$crate::__thread_local_inner` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types --> src/main.rs:6:1 | 6 | / std::thread_local! { 7 | | pub static A: i32 = f(); 8 | | pub static B: i32 = const { 0 }; 9 | | } | |_^ expected `u8`, found struct `u8` | = note: expected raw pointer `*mut u8` (`u8`) found raw pointer `*mut u8` (struct `u8`) = note: this error originates in the macro `$crate::__thread_local_inner` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types --> src/main.rs:6:1 | 6 | / std::thread_local! { 7 | | pub static A: i32 = f(); 8 | | pub static B: i32 = const { 0 }; 9 | | } | |_^ expected `u8`, found struct `u8` | = note: expected fn pointer `unsafe extern "C" fn(*mut u8)` found fn item `unsafe extern "C" fn(*mut u8) {destroy}` = note: this error originates in the macro `$crate::__thread_local_inner` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0308]: mismatched types --> src/main.rs:6:1 | 6 | / std::thread_local! { 7 | | pub static A: i32 = f(); 8 | | pub static B: i32 = const { 0 }; 9 | | } | | ^ | | | | |_expected struct `u8`, found integer | expected due to this type | = note: this error originates in the macro `$crate::__thread_local_inner` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0369]: binary operation `==` cannot be applied to type `u8` --> src/main.rs:6:1 | 6 | / std::thread_local! { 7 | | pub static A: i32 = f(); 8 | | pub static B: i32 = const { 0 }; 9 | | } | | ^ | | | | |_u8 | {integer} | note: an implementation of `PartialEq<_>` might be missing for `u8` --> src/main.rs:4:1 | 4 | struct u8; | ^^^^^^^^^^ must implement `PartialEq<_>` = note: this error originates in the macro `$crate::assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider annotating `u8` with `#[derive(PartialEq)]` | 4 | #[derive(PartialEq)] | error[E0277]: `u8` doesn't implement `Debug` --> src/main.rs:6:1 | 6 | / std::thread_local! { 7 | | pub static A: i32 = f(); 8 | | pub static B: i32 = const { 0 }; 9 | | } | |_^ `u8` cannot be formatted using `{:?}` | = help: the trait `Debug` is not implemented for `u8` = note: add `#[derive(Debug)]` to `u8` or manually `impl Debug for u8` = note: this error originates in the macro `$crate::assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) ``` </details>
2022-04-02Rollup merge of #95593 - notriddle:notriddle/size-of-in-const-context, ↵Dylan DPC-0/+24
r=compiler-errors diagnostics: add test case for bogus T:Sized suggestion Closes #69228
2022-04-02Rollup merge of #95589 - Kobzol:rlink-header, r=bjorn3Dylan DPC-5/+67
Include a header in .rlink files I couldn't find the right place where to put tests. Is there some location that tests `.rlink` creation and loading? I only found `src/test/run-make-fulldeps/separate-link/Makefile`, but I'm not sure how to check the error message in the Makefile. Fixes: https://github.com/rust-lang/rust/issues/95297 r? `@bjorn3`
2022-04-02Rollup merge of #95587 - m-ou-se:std-remove-associated-type-bounds, r=Dylan-DPCDylan DPC-3/+4
Remove need for associated_type_bounds in std.
2022-04-02Add test for multi-line attribute handling in doctestsGuillaume Gomez-0/+18
2022-04-02Fix doctest multi-line mod attributes handlingGuillaume Gomez-8/+66
2022-04-02Refer to u8 by absolute path in expansion of thread_localDavid Tolnay-3/+3
2022-04-02Add test of thread_local! breaking on redefined u8David Tolnay-0/+15