Rollup merge of #150031 - yaahc:derive-helper-ambig-assert, r=petrochenkov

assert impossible branch is impossible

The second half of this boolean or expression should not be possible with the current visitation implementation.

Reasoning:

- Innermost res will always be the first candidate visited.
- the first scopes visited are `derive_helper` candidates, followed by a single step at `derive_helper_compat`: ee447067/compiler/rustc_resolve/src/ident.rs (L180-L192)
  - if there are candidates for both kinds the derive_helper candidate will always be innermost
  - there can only be one derive_helper_compat candidate
- The first branch handles cases where the first candidate is a `derive_helper_compat`
- if the first candidate is not a `derive_helper_compat` (as enforced by the first branch) and it is not a `derive_helper` (as enforced by the end of the second boolean expression) then then the first candidate and all subsequent candidates must be from later scope types, res cannot possibly be a `derive_helper_compat`

r? ``@petrochenkov``
This commit is contained in:
Stuart Cook 2025-12-16 14:40:47 +11:00 committed by GitHub
commit 06bc79bb60
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -743,10 +743,10 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let ambiguity_error_kind = if is_builtin(innermost_res) || is_builtin(res) {
Some(AmbiguityKind::BuiltinAttr)
} else if innermost_res == derive_helper_compat
|| res == derive_helper_compat && innermost_res != derive_helper
{
} else if innermost_res == derive_helper_compat {
Some(AmbiguityKind::DeriveHelper)
} else if res == derive_helper_compat && innermost_res != derive_helper {
span_bug!(orig_ident.span, "impossible inner resolution kind")
} else if innermost_flags.contains(Flags::MACRO_RULES)
&& flags.contains(Flags::MODULE)
&& !self.disambiguate_macro_rules_vs_modularized(innermost_binding, binding)