Skip to content

-Znext-solver Prevent committing unfulfilled unsized coercion#152444

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
ShoyuVanilla:unsized-recursion-limit
Feb 13, 2026
Merged

-Znext-solver Prevent committing unfulfilled unsized coercion#152444
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
ShoyuVanilla:unsized-recursion-limit

Conversation

@ShoyuVanilla
Copy link
Member

@rustbot
Copy link
Collaborator

rustbot commented Feb 10, 2026

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Feb 10, 2026
.add(0.0)
.add(0.0)
.add(0.0)
.add(0.0)
Copy link
Member Author

@ShoyuVanilla ShoyuVanilla Feb 10, 2026

Choose a reason for hiding this comment

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

Added some more .add calls from adwin's original code to make it sure this exceeds the default recursion limit (10)

@rust-log-analyzer

This comment has been minimized.

@ShoyuVanilla ShoyuVanilla force-pushed the unsized-recursion-limit branch from 1751d10 to e93b68c Compare February 10, 2026 16:40
Comment on lines 444 to 450
if self.depth < visitor.config().max_depth {
try_visit!(visitor.visit_goal(self));
} else {
return visitor.on_recursion_limit();
}

V::Result::output()
Copy link
Contributor

Choose a reason for hiding this comment

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

that can be simplified

fn on_recursion_limit(&mut self) -> Self::Result {
// This prevents accidentally committing unfulfilled unsized coercions while trying to find
// the error source for diagnostics.
// See https://github.com/rust-lang/trait-system-refactor-initiative/issues/266.
Copy link
Contributor

Choose a reason for hiding this comment

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

i think this breaks the following snippet if we encounter it in the Certainty::Maybe recursion

struct W<T: ?Sized>(T);
type Four<T: ?Sized> = W<W<W<W<T>>>>;
type Sixteen<T: ?Sized> = Four<Four<Four<Four<T>>>>;
fn ret<T>(x: T) -> Sixteen<T> {
    todo!();
}
fn please_coerce() {
    let mut y = Default::default();
    let x = ret(y);
    let _: &Sixteen<dyn Send> = &x;
    y = 1u32;
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, I missed the case that we could visit nested goal here 😅

} else if let Some(cand) = goal.unique_applicable_candidate()
&& cand.shallow_certainty() == Certainty::Yes
{
cand.visit_nested_no_probe(self)

@ShoyuVanilla ShoyuVanilla force-pushed the unsized-recursion-limit branch from e93b68c to 96d2318 Compare February 11, 2026 06:27
@rustbot
Copy link
Collaborator

rustbot commented Feb 11, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Copy link
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

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

comment nit, then r=me

View changes since this review

struct CoerceVisitor<'a, 'tcx> {
fcx: &'a FnCtxt<'a, 'tcx>,
span: Span,
// Whether the coercion is impossible and just continuing to visit to locate the error source.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Whether the coercion is impossible and just continuing to visit to locate the error source.
/// Whether the coercion is impossible. If so we someties still try to
/// coerce in these cases to emit better errors. This impacts changes the
/// behavior when hitting the recursion limit.

@lcnr
Copy link
Contributor

lcnr commented Feb 12, 2026

@bors delegate+

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 12, 2026

✌️ @ShoyuVanilla, you can now approve this pull request!

If @lcnr told you to "r=me" after making some further change, then please make that change and post @bors r=lcnr.

@ShoyuVanilla ShoyuVanilla force-pushed the unsized-recursion-limit branch from 96d2318 to 069c78f Compare February 12, 2026 15:38
@rust-log-analyzer

This comment has been minimized.

@ShoyuVanilla ShoyuVanilla force-pushed the unsized-recursion-limit branch from 069c78f to 891acbd Compare February 12, 2026 15:57
@ShoyuVanilla
Copy link
Member Author

@bors r=lcnr rollup

@rust-bors
Copy link
Contributor

rust-bors bot commented Feb 12, 2026

📌 Commit 891acbd has been approved by lcnr

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 12, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Feb 12, 2026
…it, r=lcnr

`-Znext-solver` Prevent committing unfulfilled unsized coercion

Fixes rust-lang/trait-system-refactor-initiative#266

r? lcnr
rust-bors bot pushed a commit that referenced this pull request Feb 12, 2026
…uwer

Rollup of 11 pull requests

Successful merges:

 - #146901 (Support AVRTiny devices in AVR inline assembly)
 - #150988 (Improve code suggestion for incorrect macro_rules! usage)
 - #152422 (Change query proc macro to be more rust-analyzer friendly)
 - #152496 (Fix multi-cgu+debug builds using autodiff by delaying autodiff till lto)
 - #152520 (Don't use `DepContext` in `rustc_middle::traits::cache`)
 - #152528 (Support serializing CodegenContext)
 - #152082 (Move tests)
 - #152444 (`-Znext-solver` Prevent committing unfulfilled unsized coercion)
 - #152486 (remove redundant backchain attribute in codegen)
 - #152529 (sparc64: enable abi compatibility test)
 - #152548 (reject inline const patterns pre-expansion)
Zalathar added a commit to Zalathar/rust that referenced this pull request Feb 13, 2026
…it, r=lcnr

`-Znext-solver` Prevent committing unfulfilled unsized coercion

Fixes rust-lang/trait-system-refactor-initiative#266

r? lcnr
rust-bors bot pushed a commit that referenced this pull request Feb 13, 2026
Rollup of 18 pull requests

Successful merges:

 - #150551 (Compute localized outlives constraints lazily)
 - #150752 (Update libc to v0.2.181)
 - #150988 (Improve code suggestion for incorrect macro_rules! usage)
 - #152422 (Change query proc macro to be more rust-analyzer friendly)
 - #152496 (Fix multi-cgu+debug builds using autodiff by delaying autodiff till lto)
 - #152514 (Collect active query jobs into struct `QueryJobMap`)
 - #152520 (Don't use `DepContext` in `rustc_middle::traits::cache`)
 - #152528 (Support serializing CodegenContext)
 - #152082 (Move tests)
 - #152232 (Add must_use for FileTimes)
 - #152329 (Simplify parallel! macro)
 - #152444 (`-Znext-solver` Prevent committing unfulfilled unsized coercion)
 - #152486 (remove redundant backchain attribute in codegen)
 - #152519 (Fix feature gating for new `try bikeshed` expressions)
 - #152529 (sparc64: enable abi compatibility test)
 - #152548 (reject inline const patterns pre-expansion)
 - #152550 (Port #[prelude_import] to the attribute parser)
 - #152552 (Add 2048-bit HvxVectorPair support to Hexagon SIMD ABI checks)
rust-bors bot pushed a commit that referenced this pull request Feb 13, 2026
Rollup of 17 pull requests

Successful merges:

 - #150551 (Compute localized outlives constraints lazily)
 - #150988 (Improve code suggestion for incorrect macro_rules! usage)
 - #152422 (Change query proc macro to be more rust-analyzer friendly)
 - #152496 (Fix multi-cgu+debug builds using autodiff by delaying autodiff till lto)
 - #152514 (Collect active query jobs into struct `QueryJobMap`)
 - #152520 (Don't use `DepContext` in `rustc_middle::traits::cache`)
 - #152528 (Support serializing CodegenContext)
 - #152082 (Move tests)
 - #152232 (Add must_use for FileTimes)
 - #152329 (Simplify parallel! macro)
 - #152444 (`-Znext-solver` Prevent committing unfulfilled unsized coercion)
 - #152486 (remove redundant backchain attribute in codegen)
 - #152519 (Fix feature gating for new `try bikeshed` expressions)
 - #152529 (sparc64: enable abi compatibility test)
 - #152548 (reject inline const patterns pre-expansion)
 - #152550 (Port #[prelude_import] to the attribute parser)
 - #152552 (Add 2048-bit HvxVectorPair support to Hexagon SIMD ABI checks)

Failed merges:

 - #152515 (Extract `DepKindVTable` constructors to their own module)
@rust-bors rust-bors bot merged commit 0c0af5c into rust-lang:main Feb 13, 2026
11 checks passed
@rustbot rustbot added this to the 1.95.0 milestone Feb 13, 2026
rust-timer added a commit that referenced this pull request Feb 13, 2026
Rollup merge of #152444 - ShoyuVanilla:unsized-recursion-limit, r=lcnr

`-Znext-solver` Prevent committing unfulfilled unsized coercion

Fixes rust-lang/trait-system-refactor-initiative#266

r? lcnr
@ShoyuVanilla ShoyuVanilla deleted the unsized-recursion-limit branch February 13, 2026 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler 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

Development

Successfully merging this pull request may close these issues.

unsize coercions diagnosics path can be triggered for valid code

4 participants