Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement feature(precise_capturing_of_types) #138473

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Mar 14, 2025

  1. Set uncaptured ty/ct substs as bivariant. I'm almost certain is still quite broken, and I'll come up with a follow-up PR hopefully soon exercising some of the ways that it doesn't work today (related to the fact that "invariant xform bivariant = invariant").
  2. Validate that uncaptured ty/ct substs don't show up in the hidden type. I also reworked uncaptured ty/ct errors for TAITs. That diagnostic could also be improved tbh.
  3. Add a couple simple tests.

r? lcnr or reassign if you're not interested in reviewing feature work

tracking:

@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 Mar 14, 2025
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.

how does this avoid unconstrained type variables when doing something like

fn foo<T>() -> impl Sized + use<> {}

fn main() {
    let x = foo<u32>(); // opaque<u32>;
    let y = x; // opaque<?unconstrained>
}

@compiler-errors
Copy link
Member Author

it doesn't afaict :> this feature is still pretty broken, that's why it's incomplete

@bors
Copy link
Contributor

bors commented Mar 15, 2025

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

@compiler-errors compiler-errors force-pushed the precise-capturing-of-types branch from d8a6a1d to 233dcff Compare March 18, 2025 15:56
Comment on lines +228 to +245
let guar = if self.uncaptured_args.contains(&ct.into()) {
// FIXME(precise_capturing_of_types): Mention `use<>` list
// and add an structured suggestion.
self.tcx.dcx().struct_span_err(
self.span,
format!("hidden type mentions uncaptured const parameter `{ct}`"),
)
} else {
self.tcx.dcx().struct_span_err(
self.span,
format!(
"const parameter `{ct}` is mentioned in hidden type of \
type alias impl trait, but is not declared in its generic \
args"
),
)
}
.emit_unless(self.ignore_errors);
Copy link
Contributor

Choose a reason for hiding this comment

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

also extract this into a subfn?

@lcnr
Copy link
Contributor

lcnr commented Mar 19, 2025

it doesn't afaict :> this feature is still pretty broken, that's why it's incomplete

do you have a plan for how to fix this? I feel like the feature as is doesn't have much value and worry that we likely can't stabilize it without large changes

however, I don't think the cost of supporting this is meaningfully large, so r=me after nits

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants