Previously, even if no expected errors were supplied, if a test execution failed
then supplied error patterns would not be checked. This commit modifies the
conditional that determines whether error patterns or expected errors are checked
to remedy this.
Further, this commit modifies the error pattern checking logic so that each pattern
is checked against all lines of the string. This is required for UI tests as the
stderr is in JSON format - all on one line - so in the previous implementation when the
first pattern was found on the first line (which was actually the entire error) then
no other patterns would be found on subsequent lines (as there weren't any).
unsized ManuallyDrop
I think this matches what @eddyb had in https://github.com/rust-lang/rust/pull/52711 originally.
~~However, I have never added a `CoerceUnsized` before so I am not sure if I did this right. I copied the `unstable` attribute on the `impl` from elsewhere, but AFAIK it is useless because `impl`'s are insta-stable... so shouldn't this rather say "stable since 1.30"?~~
This is insta-stable and hence requires FCP, at least.
Fixes https://github.com/rust-lang/rust/issues/47034
#[feature(uniform_paths)]: allow `use x::y;` to resolve through `self::x`, not just `::x`.
_Branch originally by @cramertj, based on @petrochenkov's [description on the internals forum](https://internals.rust-lang.org/t/relative-paths-in-rust-2018/7883/30?u=petrochenkov)._
_(note, however, that the approach has significantly changed since)_
Implements `#[feature(uniform_paths)]` from #53130, by treating unqualified `use` paths as maybe-relative. That is, `use x::y;`, where `x` is a plain identifier (not a keyword), is no longer the same as `use :❌:y;`, and before picking an external crate named `x`, it first looks for an item named `x` in the same module (i.e. `self::x`) and prefers that local item instead.
Such a "maybe-relative" `x` can only resolve to an external crate if it's listed in "`extern_prelude`" (i.e. `core` / `std` and all the crates passed to `--extern`; the latter includes Cargo dependencies) - this is the same condition as being able to refer to the external crate from an unqualified, non-`use` path.
All other crates must be explicitly imported with an absolute path, e.g. `use :❌:y;`
To detect an ambiguity between the external crate and the local item with the same name, a "canary" import (e.g. `use self::x as _;`), tagged with the `is_uniform_paths_canary` flag, is injected. As the initial implementation is not sophisticated enough to handle all possible ways in which `self::x` could appear (e.g. from macro expansion), this also guards against accidentally picking the external crate, when it might actually get "shadowed" later.
Also, more canaries are injected for each block scope around the `use`, as `self::x` cannot resolve to any items named `x` in those scopes, but non-`use` paths can, and that could be confusing or even backwards-incompatible.
Errors are emitted only if the main "canary" import succeeds while an external crate exists (or if any of the block-scoped ones succeed at all), and ambiguities have custom error reporting, e.g.:
```rust
#![feature(uniform_paths)]
pub mod foo {
use std::io;
pub mod std { pub mod io {} }
}
```
```rust
error: import from `std` is ambiguous
--> test.rs:3:9
|
3 | use std::io;
| ^^^ could refer to external crate `::std`
4 | pub mod std { pub mod io {} }
| ----------------------------- could also refer to `self::std`
|
= help: write `::std` or `self::std` explicitly instead
= note: relative `use` paths enabled by `#![feature(uniform_paths)]`
```
Another example, this time with a block-scoped item shadowing a module-scoped one:
```rust
#![feature(uniform_paths)]
enum Foo { A, B }
fn main() {
enum Foo {}
use Foo::*;
}
```
```rust
error: import from `Foo` is ambiguous
--> test.rs:5:9
|
4 | enum Foo {}
| ----------- shadowed by block-scoped `Foo`
5 | use Foo::*;
| ^^^
|
= help: write `::Foo` or `self::Foo` explicitly instead
= note: relative `use` paths enabled by `#![feature(uniform_paths)]`
```
Additionally, this PR, because replacing "the `finalize_import` hack" was a blocker:
* fixes#52140
* fixes#52141
* fixes#52705
cc @aturon @joshtriplett
Fix a few regressions from enabling macro modularization
The first commit restores the old behavior for some minor unstable stuff (`rustc_*` and `derive_*` attributes) and adds a new feature gate for arbitrary tokens in non-macro attributes.
The second commit fixes https://github.com/rust-lang/rust/issues/53205
The third commit fixes https://github.com/rust-lang/rust/issues/53144.
Same technique is used as for other things blocking expansion progress - if something causes indeterminacy too often, then prohibit it.
In this case referring to crate-local macro-expanded `#[macro_export]` macros via module-relative paths is prohibited, see comments in code for more details.
cc https://github.com/rust-lang/rust/pull/50911
Emit error for pattern arguments in trait methods
The error and check for this already existed, but the parser didn't try to parse trait method arguments as patterns, so the error was never emitted. This surfaces the error, so we get better errors than simple parse errors.
This improves the error message described in https://github.com/rust-lang/rust/issues/53046.
r? @petrochenkov
Rollup of 15 pull requests
Successful merges:
- #52955 (Update compiler test documentation)
- #53019 (Don't collect() when size_hint is useless)
- #53025 (Consider changing assert! to debug_assert! when it calls visit_with)
- #53059 (Remove explicit returns where unnecessary)
- #53165 ( Add aarch64-unknown-netbsd target)
- #53210 (Deny future duplication of rustc-ap-syntax)
- #53223 (A few cleanups for rustc_data_structures)
- #53230 ([nll] enable feature(nll) on various crates for bootstrap: part 4)
- #53231 (Add let keyword doc)
- #53240 (Add individual documentation for <integer>`.swap_bytes`/.`reverse_bits`)
- #53253 (Remove unwanted console log)
- #53264 (Show that Command can be reused and remodified)
- #53267 (Fix styles)
- #53273 (Add links to std::char::REPLACEMENT_CHARACTER from docs.)
- #53283 (wherein we suggest float for integer literals where a float was expected)
Failed merges:
r? @ghost
wherein we suggest float for integer literals where a float was expected
@sunjay pointed out that this is a nice thing that we could do.
Resolves#53280.
r? @estebank
Add links to std::char::REPLACEMENT_CHARACTER from docs.
There are a few places where we mention the replacement character in the
docs, and it could be helpful for users to utilize the constant which is
available in the standard library, so let’s link to it!
Show that Command can be reused and remodified
The prior documentation did not make it clear this was possible.
I wanted to make the `list_dir` example work on Windows, but I don't know if passing "/" will error or show the root of the current volume (e.g. `C:`).
r? @GuillaumeGomez
A few cleanups for rustc_data_structures
- remove a redundant `clone()`
- make some calls to `.iter()` implicit
- collapse/simplify a few operations
- remove some explicit `return`s
- make `SnapshotMap::{commit, rollback_to}` take references
- remove unnecessary struct field names
- change `transmute()`s in `IdxSet::{from_slice, from_slice_mut}` to casts
- remove some unnecessary lifetime annotations
- split 2 long literals
Consider changing assert! to debug_assert! when it calls visit_with
The perf run from #52956 revealed that there were 3 benchmarks that benefited most from changing `assert!`s to `debug_assert!`s:
- issue #46449: avg -4.7% for -check
- deeply-nested (AKA #38528): avg -3.4% for -check
- regression #31157: avg -3.2% for -check
I analyzed their fixing PRs and decided to look for potentially heavy assertions in the files they modified. I noticed that all of the non-trivial ones contained indirect calls to `visit_with()`.
It might be a good idea to consider changing `assert!` to `debug_assert!` in those places in order to get the performance wins shown by the benchmarks.
Don't collect() when size_hint is useless
This adjusts PRs #52738 and #52697 by falling back to calculating capacity and extending or pushing in a loop where `collect()` can't be trusted to calculate the right capacity.
It is a performance win.
Update compiler test documentation
Update the compiler test documentation to document ignore-gdb-version
and min-system-llvm-version; and expand the min-gdb-version,
min-lldb-version, and min-llvm-version documentation a little.