Avoid stack overflow in FindExprBySpan
Fixesrust-lang/rust#153583.
Deeply nested `?` desugarings can build a very deep HIR expression spine.
When `FindExprBySpan` walks that expression during error reporting, the
recursive `visit_expr` traversal can overflow the stack before rustc emits the
actual diagnostic.
This wraps the recursive expression walk in `ensure_sufficient_stack`, which
lets the compiler report the expected E0277 instead of crashing.
Added a UI regression test for a deeply nested `?` chain.
Fix ICE in next-solver dyn-compatibility check
The next solver treated error-containing dispatchability goals as proven and misclassified the trait as dyn compatible. Short-circuit receivers with type errors so object-method confirmation stays on the normal error path.
Tracking issue: rust-lang/rust#130516Closes: rust-lang/rust#151311
The next solver treated error-containing dispatchability goals as proven and misclassified the trait as dyn compatible. Short-circuit receivers with type errors so object-method confirmation stays on the normal error path.
`ty::Alias` refactor
This PR changes the following alias-related types from this:
```rust
pub enum AliasTyKind {
Projection,
Inherent,
Opaque,
Free,
}
pub struct AliasTy<I: Interner> {
pub args: I::GenericArgs,
pub def_id: I::DefId,
}
pub enum TyKind<I: Interner> {
...
Alias(AliasTyKind, AliasTy<I>),
}
```
Into this:
```rust
pub enum AliasTyKind<I: Interner> {
Projection { def_id: I::DefId },
Inherent { def_id: I::DefId },
Opaque { def_id: I::DefId },
Free { def_id: I::DefId },
}
pub struct AliasTy<I: Interner> {
pub args: I::GenericArgs,
pub kind: AliasTyKind<I>,
}
pub enum TyKind<I: Interner> {
...
Alias(AliasTy<I>),
}
```
... and then does a thousand other changes to accommodate for this change everywhere.
This brings us closer to being able to have `AliasTyKind`s which don't require a `DefId` (and thus can be more easily created, etc). Although notably we depend on both `AliasTyKind -> DefId` and `DefId -> AliasTyKind` conversions in a bunch of places still.
r? lcnr
----
A lot of these changes were done either by search & replace (via `ast-grep`) or on auto pilot, so I'm not quite sure I didn't mess up somewhere, but at least tests pass...
Change api of formatting diagnostic attribute strings.
As of recently a lot of people are creating new diagnostic attributes, but skipping its methods and doing things like `directive.message.as_ref().map(|e| e.1.format(&args)),` instead, but that skips the `tracing` instrumentation of diagnostic attribute formatting. The first commit forces people to use the right method for that.
The name `OnUnimplementedNote` also hasn't been accurate for some time.
fixed generics of crate node ICE
when `note_and_explain_type_err` is called during dyn-compatibility checking, the `body_owner_def_id` can be `CRATE_DEF_ID` because `ObligationCause::dummy()` uses it as a placeholder when there is no real body owner. calling `generics_of `on `CRATE_DEF_ID `caused an ICE because the crate root is a module and modules don't have generics. the fix guards all `generics_of` call sites by checking whether `body_owner_def_id` is `CRATE_DEF_ID` before attempting to look up generics, and skips the type parameter span labeling in that case.
i also added regression test with original ice reproduce
fixesrust-lang/rust#152335
Remove rustc_on_unimplemented's append_const_msg
This does nothing because it is unreachable within the compiler. It also doesn't seem that useful since all the traits it was on are `const` now.
Will make pr to rustc-dev-guide docs later.
Improve shadowed private field diagnostics
Fixesrust-lang/rust#149546
I tried to extend the diagnostic to more scenarios, like method call, type mismatch errors.
r? @estebank
opaque_generic_const_args -> generic_const_args
This is part of a larger rework/plan of how to move forward with GCA. Please comment here, or message/ping me or @BoxyUwU if you have questions about the future of oGCA/GCA!
For ease of review, the first commit is renaming, and the second commit is removing the opaque parts.
fyi @camelid
r? @BoxyUwU
Compute the result of a projection type with region errors
Fixes: rust-lang/rust#152682
With the old trait solver, `type_known_to_meet_bound_modulo_regions()` isn't really operating "modulo regions" if there are any region errors, since `normalize` will just return a type error to the trait solver if given a ty with a region error, which then starts cascading when there are so many assumptions.
So I think it would be good to erase regions if there are any region errors before we normalize the type when collecting predicates for confirmation.
That said, I somehow feel like this is kind of ad-hoc... I'd really appreciate if someone more familiar with this code could take a closer look :3
Skip suggestions pointing to macro def for assert_eq
Fixesrust-lang/rust#146204
It's better to suggest:
```console
help: consider borrowing here
--> src/main.rs:3:16
|
3| assert_ne!(&buf, b"----");
| +
```
but i don't want to give a too heuristic but not general enough fix, let suppress them.
Fix regression when dealing with generics/values with unresolved inference
Follow up for rust-lang/rust#151703, fixing regression caused in rollup rust-lang/rust#152825
Forgot to handle generics & unresolved inference variables (as in `get_safe_transmute_error_and_reason`) in my previous PR. This followup checks for them before trying to normalize.
I am not completely sure its right approach to have this check cloned but as `select_transmute_obligation_for_reporting` fn just chooses obligation and doesn't actually return an error, this check shouldn't be removed from `get_safe_transmute_error_and_reasnon`. If there is any better solution, let me kmow.
Fixes: rust-lang/rust#153755
r? @jdonszelmann
Avoid ICE when param-env normalization leaves unresolved inference variables
Fixesrust-lang/rust#153354
Because the impl is already ill-formed, those variables are not fully constrained, so zfully_resolve` fails. We previously treated that as an immediate compiler bug with `span_bug!`, which caused an ICE on invalid input.
Tweak wording of E0275 WF errors
Modify the main error message to read better:
```
error[E0275]: overflow evaluating whether `&'a mut Bar` is well-formed
```