Skip to content

check WF of HRTB args even if there are escaping bound vars - #162454

Open
sjwang05 wants to merge 1 commit into
rust-lang:mainfrom
sjwang05:trait-arg-wf
Open

sjwang05 wants to merge 1 commit into
rust-lang:mainfrom
sjwang05:trait-arg-wf

Conversation

@sjwang05

@sjwang05 sjwang05 commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

We previously retained only Terms that didn't have escaping bound vars when collecting WF obligations, leading us to wrongly accepting code like this:

trait Bound {}

struct W<'a, T: Bound>(&'a T);

fn wf<T>() where for<'a> W<'a, T>: Sized {}

as T: Bound does not hold in wf's where-clauses. Immediately turning this into a hard error caused substantial crater breakage (#122501), so for now we collect these kinds of obligations separately and prove them in a forked param env, emitting an FCW if the proof fails and there are no other errors from wfchecking.

cc https://rust-lang.zulipchat.com/#narrow/channel/618216-t-types.2Fcall-for-participation/topic/check.20WF.20of.20trait.20args.20even.20with.20escaping.20bound.20vars/with/621059871
cc #162200

@rustbot

rustbot commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

changes to the core type system

cc @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 Sep 8, 2026
@rustbot

rustbot commented Sep 8, 2026

Copy link
Copy Markdown
Collaborator

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 20 candidates

);
}
}
};

@sjwang05 sjwang05 Sep 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm a bit unhappy with how messy the diag formatting code here is, but I couldn't think of a better way 🤔

View changes since the review


let errors = infcx.resolve_regions_with_outlives_env(&outlives_env, tcx.def_span(body_def_id));
if errors.is_empty() {
check_escaping_bound_vars_fcw();

@sjwang05 sjwang05 Sep 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

A bit concerned about perf since this runs on the Ok paths, even though we have the fcw_obligations.is_empty check, and I don't expect to encounter such obligations in practice very much

View changes since the review

@theemathas theemathas added needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. T-types Relevant to the types team, which will review and decide on the PR/issue. needs-crater This change needs a crater run to check for possible breakage in the ecosystem. labels Sep 8, 2026
@lcnr

lcnr commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

can you change the FCW to also point to the self-type when applicable, rn the diagnostic is kinda meh

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Sep 8, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Sep 8, 2026
check WF of HRTB args even if there are escaping bound vars
@rust-bors

rust-bors Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 147db73 (147db73b7d06617e530e16c926faf196f536caa4)
Base parent: 745de6e (745de6eca673de5329ec68f2689629a5ca45ab35)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown

Finished benchmarking commit (147db73): comparison URL.

Overall result: ❌ regressions - please read:

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

Next, please: If you can, justify the regressions found in this try perf run in writing along with @rustbot label: +perf-regression-triaged. If not, fix the regressions and do another perf run. Neutral or positive results will clear the label automatically.

@bors rollup=never rustc-perf
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
0.3% [0.1%, 0.6%] 38
Regressions ❌
(secondary)
0.4% [0.2%, 0.9%] 27
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [0.1%, 0.6%] 38

Max RSS (memory usage)

Results (primary 0.4%, secondary -2.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.5% [0.4%, 0.7%] 6
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.4% [-0.4%, -0.4%] 1
Improvements ✅
(secondary)
-2.7% [-2.7%, -2.7%] 1
All ❌✅ (primary) 0.4% [-0.4%, 0.7%] 7

Cycles

Results (primary 0.1%, secondary 0.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.8% [0.4%, 2.0%] 8
Regressions ❌
(secondary)
4.6% [4.6%, 4.6%] 1
Improvements ✅
(primary)
-0.8% [-1.1%, -0.6%] 6
Improvements ✅
(secondary)
-3.7% [-3.7%, -3.7%] 1
All ❌✅ (primary) 0.1% [-1.1%, 2.0%] 14

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 478.441s -> 478.264s (-0.04%)
Artifact size: 403.53 MiB -> 403.70 MiB (0.04%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Sep 8, 2026
@sjwang05
sjwang05 force-pushed the trait-arg-wf branch 2 times, most recently from 450440a to 4fb816e Compare September 11, 2026 06:17
@sjwang05

Copy link
Copy Markdown
Contributor Author

Changed it so now the span looks something like this:

LL | fn warns<T>() where for<'a> W<'a, T>: Sized {}
   |                     ^^^^^^^^^^^^^^^^^^^^^^^

instead of just the bound

@rustbot

rustbot commented Sep 18, 2026

Copy link
Copy Markdown
Collaborator

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.

@rust-log-analyzer

This comment has been minimized.

@davidtwco

Copy link
Copy Markdown
Member

r? @lcnr

@rustbot rustbot assigned lcnr and unassigned davidtwco Sep 23, 2026
@lcnr

lcnr commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

crater run is happening in #162986

@lcnr lcnr added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 1, 2026
@rust-bors

rust-bors Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #163735) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

@sjwang05

Copy link
Copy Markdown
Contributor Author

crater results here: #162986 (comment)

499 of the 546 failures are from the #![warn(future_incompatible)] attr conflicting with setting our lint as forbid-by-default in the crater run, so the full list of real failures is as follows. I've tried to group them by the patterns with which each fails.

Missing 'static bounds:

14 crates

Missing Sized bounds:

9 crates

Missing trait bounds other than Sized, such as missing T: Trait in fn requires<T>(bar: Foo<T>) with Foo<T: Trait>.

9 crates

Missing lifetime bounds, such as omitting 'b: 'a with &'a Foo<'b>:

15 crates

furthermore, upon checking some of the crater results locally, I found that these 4 crates also hit the FCW, even though they didn't show up in the crater results:

This branch has not been deployed

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

Labels

needs-crater This change needs a crater run to check for possible breakage in the ecosystem. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. perf-regression Performance regression. S-blocked Status: Blocked on something else such as an RFC or other implementation work. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants