Skip to content

refactor the normalization in coerce_shared_info#158659

Open
adwinwhite wants to merge 1 commit into
rust-lang:mainfrom
adwinwhite:coerce-shared-info-norm
Open

refactor the normalization in coerce_shared_info#158659
adwinwhite wants to merge 1 commit into
rust-lang:mainfrom
adwinwhite:coerce-shared-info-norm

Conversation

@adwinwhite

@adwinwhite adwinwhite commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

This is pre-requisite of removing eq_structurally_relating_aliases which is part of #155345.

coerce_shared_info is only used in the unstable feature reborrow which provides a CoerceShared trait indicating a mutable borrow can be converted into a shared borrow.

I think using deeply_normalize is more suitable for these identity instantiated types.
No reason to allow ambiguous normalization and use infer vars as normalization result here.

r? lcnr

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 1, 2026
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

---- [ui] tests/ui/reborrow/coerce-shared-normalize-source.rs stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/reborrow/coerce-shared-normalize-source/coerce-shared-normalize-source.stderr`
normalized stderr:
warning: type parameter `T` must be covered by another type when it appears before the first local type (`CustomRef<'_, _>`)
##[warning]  --> $DIR/coerce-shared-normalize-source.rs:29:10
   |
LL | impl<'a, T: 'a> CoerceShared<CustomRef<'a, T>> for CustomMutAlias<'a, T> {}
   |          ^ uncovered type parameter
   |
   = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local,
           and no uncovered type parameters appear before that first local type
   = note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait<T1, ..., Tn> for T0`,
           where `T0` is the first and `Tn` is the last
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #124559 <https://github.com/rust-lang/rust/issues/124559>
   = note: `#[warn(uncovered_param_in_projection)]` (part of `#[warn(future_incompatible)]`) on by default

warning: 1 warning emitted
---
To only update this specific test, also pass `--test-args reborrow/coerce-shared-normalize-source.rs`

error: 1 errors occurred comparing output.
status: exit status: 0
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/reborrow/coerce-shared-normalize-source.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/reborrow/coerce-shared-normalize-source" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
warning: type parameter `T` must be covered by another type when it appears before the first local type (`CustomRef<'_, _>`)
##[warning]  --> /checkout/tests/ui/reborrow/coerce-shared-normalize-source.rs:29:10
   |
LL | impl<'a, T: 'a> CoerceShared<CustomRef<'a, T>> for CustomMutAlias<'a, T> {}
   |          ^ uncovered type parameter
   |
   = note: implementing a foreign trait is only possible if at least one of the types for which it is implemented is local,
           and no uncovered type parameters appear before that first local type
   = note: in this case, 'before' refers to the following order: `impl<..> ForeignTrait<T1, ..., Tn> for T0`,
           where `T0` is the first and `Tn` is the last
   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
   = note: for more information, see issue #124559 <https://github.com/rust-lang/rust/issues/124559>
   = note: `#[warn(uncovered_param_in_projection)]` (part of `#[warn(future_incompatible)]`) on by default

warning: 1 warning emitted
target.peel_refs(),
source_field_span,
)
.is_ok()

@lcnr lcnr Jul 1, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, this code is weird.

  • we don't do this relate in a probe, so if this errors, any e.g. region constraints from it stick around
  • we don't check region constraints here?
  • same with the relate further down, which also doesn't happen in a commit_if_ok and we don't check region constraints here either
  • also, no need to create a new ObligationCtxt in this branch

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i really like the way the EvalCtxt taints itself when encountering an error so that trying to do operations in the same snapshot then ICEs.

This feels very useful to me and I would love to also extend that to InferCtxt in general is harder as we want to continue to collect errors in e.g. typeck even if normalization fails for some part of our type. We just set that type to a ´{type error}` and continue 🤔 unsure whether there's anything to protect users of the type system from mistakes like this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please either fix these issues or add FIXME(the_relevant_feature) here :>

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

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

4 participants