Skip to content

add TypingMode::Borrowck#138785

Merged
bors merged 3 commits intorust-lang:masterfrom
lcnr:typing-mode-borrowck
Apr 4, 2025
Merged

add TypingMode::Borrowck#138785
bors merged 3 commits intorust-lang:masterfrom
lcnr:typing-mode-borrowck

Conversation

@lcnr
Copy link
Contributor

@lcnr lcnr commented Mar 21, 2025

Shares the first commit with #138499, doesn't really matter which PR to land first 😊 😁

Introduces TypingMode::Borrowck which unlike TypingMode::Analysis, uses the hidden type computed by HIR typeck as the initial value of opaques instead of an unconstrained infer var. This is a part of rust-lang/types-team#129.

Using this new TypingMode is unfortunately a breaking change for now, see tests/ui/impl-trait/non-defining-uses/as-projection-term.rs. Using an inference variable as the initial value results in non-defining uses in the defining scope. We therefore only enable it if with -Znext-solver=globally or -Ztyping-mode-borrowck

To do that the PR contains the following changes:

  • TypeckResults::concrete_opaque_type are already mapped to the definition of the opaque type
    • writeback now checks that the non-lifetime parameters of the opaque are universal
    • for this, fn check_opaque_type_parameter_valid is moved from rustc_borrowck to rustc_trait_selection
  • we add a new query type_of_opaque_hir_typeck which, using the same visitors as MIR typeck, attempts to merge the hidden types from HIR typeck from all defining scopes
    • done by adding a DefiningScopeKind flag to toggle between using borrowck and HIR typeck
    • the visitors stop checking that the MIR type matches the HIR type. This is trivial as the HIR type are now used as the initial hidden types of the opaque. This check is useful as a safeguard when not using TypingMode::Borrowck, but adding it to the new structure is annoying and it's not soundness critical, so I intend to not add it back.
  • add a TypingMode::Borrowck which behaves just like TypingMode::Analysis except when normalizing opaque types
    • it uses type_of_opaque_hir_typeck(opaque) as the initial value after replacing its regions with new inference vars
    • it uses structural lookup in the new solver

fixes #112201, fixes #132335, fixes #137751

r? @compiler-errors @oli-obk

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-tidy Area: The tidy tool merged-by-bors This PR was explicitly merged by bors. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

8 participants