Specify `--print info=file` syntax in `--help`
Closes#139794
I moved the listing of information that can be printed to the help string as it's getting rather long and it makes the `[=FILE]` part easier to see
Use `compiletest-ignore-dir` for bootstrap self-tests
Follow-up to #139705 and #139740.
I did another survey pass over `//@ ignore-test` under `tests/`, and this is the only 2 non-tests that should use `compiletest-ignore-dir`.
r? `@Zalathar` (or compiler/bootstrap)
Add test for issue 34834
closes: #34834
This PR adds a UI test for a case where a trait with an associated type using a higher-ranked trait bound (HRTB) failed to compile in Rust 1.55.0 but succeeded starting from 1.56.0.
```rust
pub trait Provides<'a> {
type Item;
}
pub trait Selector: for<'a> Provides<'a> {
type Namespace: PartialEq + for<'a> PartialEq<<Self as Provides<'a>>::Item>;
fn get_namespace(&self) -> <Self as Provides>::Item;
}
pub struct MySelector;
impl<'a> Provides<'a> for MySelector {
type Item = &'a str;
}
impl Selector for MySelector {
type Namespace = String;
fn get_namespace(&self) -> &str {
unimplemented!()
}
}
fn main() {}
```
* ❌ [compile fail (rustc: 1.55.0)](https://godbolt.org/z/T1jY1Ebo6)
* ⭕ [compile pass (rustc: 1.56.0)](https://godbolt.org/z/e4jo11Ma7)
Avoid unused clones in `Cloned<I>` and `Copied<I>`
Avoid cloning in `Cloned<I>` or copying in `Copied<I>` when elements are only needed by reference or not at all. There is already some precedent for this, given that `__iterator_get_unchecked` is implemented, which can skip elements. The reduced clones are technically observable by a user impl of `Clone`.
r? libs-api
re-use `Sized` fast-path
There's an existing fast path for the `type_op_prove_predicate` predicate, checking for trivially `Sized` types, which can be re-used when evaluating obligations within queries. This should improve performance and was found to be beneficial in #137944.
r? types
Rollup of 8 pull requests
Successful merges:
- #139127 (Fix up partial res of segment in primitive resolution hack)
- #139392 (Detect and provide suggestion for `&raw EXPR`)
- #139767 (Visit place in `BackwardIncompatibleDropHint` statement)
- #139777 (Remove `define_debug_via_print` for `ExistentialProjection`, use regular structural debug impl)
- #139796 (ptr docs: add missing backtics around 'usize')
- #139801 (Add myself to mailmap)
- #139804 (use `realpath` in `bootstrap.py` when creating build-dir)
- #139807 (Improve wording of post-merge report)
r? `@ghost`
`@rustbot` modify labels: rollup
use `realpath` in `bootstrap.py` when creating build-dir
Fixes#139800
r? `@jieyouxu`
My use case for `./build` being a symlink is this: my "default" ~~partition~~ btrfs subvolume is snapshotted/backed up. I don't want to backup target-likes, so I move them to a special subvolume which isn't backed up. `./build` is a symlink into that subvolume. (`build.build-dir` configuration is not fully sufficient, it is still nice to be able to check build files with `ls ./build` or call tools from there)
ptr docs: add missing backtics around 'usize'
We almost always have the backticks, except here... so let's just fix that. Barely worth a PR but it's user-visible docs so here we go.
Remove `define_debug_via_print` for `ExistentialProjection`, use regular structural debug impl
The pretty print impl for `ExistentialProjection` always prints `AssocItem = Ty`:
6e83046233/compiler/rustc_middle/src/ty/print/pretty.rs (L3293-L3299)
We can't change this, b/c it's used for both pretty printing dyn types and for legacy symbol mangling.
Unfortunately, we also use this printing procedure for `Debug` impls. That means that it leaves out the *trait name* and *trait args* when debug printing an `ExistentialProjection` (or an `ExistentialPredicate` which has a variant for `ExistentialProjection`). This leads to awkward situations, like the two seemingly identical existential projection predicates present in a `dyn Trait` type using the definition below:
```rust
trait Super { type Assoc; }
trait Foo: Super<A, Assoc = i32> + Super<B, Assoc = i32> {}
```
Namely, they both just render as `Projection(Assoc = i32)`! This makes debugging `dyn Trait` type system bugs really hard, so let's use the *regular* debug impl for `ExistentialProjection`.
Visit place in `BackwardIncompatibleDropHint` statement
Remove a weird hack from the `LocalUpdater` where we were manually visiting the place stored in a `StatementKind::BackwardIncompatibleDropHint` because the MIR visitor impls weren't doing so.
Also, clean up `BackwardIncompatibleDropHint`s in `CleanupPostBorrowck`, since they're not needed for runtime MIR.
Detect and provide suggestion for `&raw EXPR`
When emitting an error in the parser, and we detect that the previous token was `raw` and we *could* have consumed `const`/`mut`, suggest that this may have been a mistyped raw ref expr. To do this, we add `const`/`mut` to the expected token set when parsing `&raw` as an expression (which does not affect the "good path" of parsing, for the record).
This is kind of a rudimentary error improvement, since it doesn't actually attempt to recover anything, leading to some other knock-on errors b/c we still treat `&raw` as the expression that was parsed... but at least we add the suggestion! I don't think the parser grammar means we can faithfully recover `&raw EXPR` early, i.e. during `parse_expr_borrow`.
Fixes#133231
Fix up partial res of segment in primitive resolution hack
There is a hack in the resolver:
```
// In `a(::assoc_item)*` `a` cannot be a module. If `a` does resolve to a module we
// don't report an error right away, but try to fallback to a primitive type.
```
This fixes up the resolution for primitives which would otherwise resolve to a module, but we weren't also updating the res of the path segment, leading to weird diagnostics.
We explicitly call `self.r.partial_res_map.insert` instead of `record_partial_res` b/c we have recorded a partial res already, and we specifically want to override it.
cc https://github.com/rust-lang/rust/issues/139095#issuecomment-2764371934
Rollup of 9 pull requests
Successful merges:
- #138336 (Improve `-Z crate-attr` diagnostics)
- #139636 (Encode dep node edge count as u32 instead of usize)
- #139666 (cleanup `mir_borrowck`)
- #139695 (compiletest: consistently use `camino::{Utf8Path,Utf8PathBuf}` throughout)
- #139699 (Proactively update coroutine drop shim's phase to account for later passes applied during shim query)
- #139718 (enforce unsafe attributes in pre-2024 editions by default)
- #139722 (Move some things to rustc_type_ir)
- #139760 (UI tests: migrate remaining compile time `error-pattern`s to line annotations when possible)
- #139776 (Switch attrs to `diagnostic::on_unimplemented`)
r? `@ghost`
`@rustbot` modify labels: rollup
UI tests: migrate remaining compile time `error-pattern`s to line annotations when possible
There's a number of cases in which `error-pattern` is still necessary even for compile time checking.
- It checks something that compiler writes directly into stderr as text, and not to the structured json output. This includes some stuff reported during compiler panics, and also diagnostics that happen very early, for example when parsing the command line.
- It checks something that exists only in the full rendered diagnostic test, but not in its structured components, for example code fragments or output of `-Ztrack-diagnostics`. (The latter can probably be converted to structured form though.)
This is continuation of https://github.com/rust-lang/rust/pull/139137.
r? `@jieyouxu`
Move some things to rustc_type_ir
This moves
- `PatternKind`
- `FlagComputation`
- `TypeWalker`
into rustc_type_ir.
Not strictly required for rust-analyzer next-solve integration, but helps with code duplication.
r? types
enforce unsafe attributes in pre-2024 editions by default
New unsafe attributes should emit an error when used without the `unsafe(...)` in all editions.
The `no_mangle`, `link_section` and `export_name` attributes are exceptions, and can still be used without an unsafe in earlier editions. The only attributes for which this change is relevant right now are `#[ffi_const]` and `#[ffi_pure]`.
This change is required for making `#[unsafe(naked)]` sound in pre-2024 editions.
Improve `-Z crate-attr` diagnostics
- Show the `#![ ... ]` in the span (to make it clear that it should not
be included in the CLI argument)
- Show more detailed errors when the crate has valid token trees but
invalid syntax.
Previously, `crate-attr=feature(foo),feature(bar)` would just say
"invalid crate attribute" and point at the comma. Now, it explicitly
says that the comma was unexpected, which is useful when using
`--error-format=short`. It also fixes the column to show the correct
span.
- Recover from parse errors. Previously we would abort immediately on
syntax errors; now we go on to try and type-check the rest of the
crate.
The new diagnostic code also happens to be slightly shorter.
r? diagnostics