-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Some more pattern cleanup and bugfixing #34365
Conversation
let adt = ccx.tcx.intern_adt_def(did, ty::AdtKind::Struct, variants); | ||
if let Some(ctor_id) = ctor_id { | ||
// Make adt definition available through constructor id as well. | ||
ccx.tcx.insert_adt_def(ctor_id, adt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you can go directly from Def::Struct
to ADT definition regardless of where this Def::Struct
is used - in a pattern, expression or a type. Sometimes Def::Struct
denotes a type and sometimes a constructor and previously lookup_adt_def
worked only with Def::Struct
s in type context and panicked otherwise, so workarounds had to be used.
let ty_substituted = self.instantiate_type_scheme(path.span, substs, &type_scheme.ty); | ||
self.write_ty(node_id, ty_substituted); | ||
self.write_substs(node_id, ty::ItemSubsts { | ||
substs: substs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, this is probably a mistake and regression. The substs written are substs before instantiate_type_scheme
, not after.
I.e. for
type Alias<T> = S<T, u16>;
// Inside match
Alias::<u8> { .. }
only u8
is written, not [u8, u16]
.
However, instantiate_path
does the same mistake(?) even without this PR.
The AST part of rust-lang#34365 plugin-[breaking-change] cc rust-lang#31645
☔ The latest upstream changes (presumably #34424) made this pull request unmergeable. Please resolve the merge conflicts. |
Rebased. |
@petrochenkov Sorry about that, @nikomatsakis is on vacation. |
So as I wrote on IRC, I don't think that |
☔ The latest upstream changes (presumably #34552) made this pull request unmergeable. Please resolve the merge conflicts. |
I agree on both counts. It seems OK for this name to be available on stable Rust. |
Lang team meeting: we decided we should try this PR, but with marking the |
@petrochenkov Looks like |
Instead of Def::Err erroneous bindings can get usual definitions that doesn't require special cases later on and have less chances to generate ICE.
…k_pat_path Update definitions in def_map for associated types written in unqualified form (like `Self::Output`) Cleanup finish_resolving_def_to_ty/resolve_ty_and_def_ufcs Make VariantDef's available through constructor IDs
Treat Def::Err correctly in struct patterns Make instantiate_path and instantiate_type a bit closer to each other
Rebased, |
Crater report only shows 4 regressions in code using the unstable @alexcrichton @aturon Can we merge this with the stabilization of |
@eddyb Yep, at this point everybody's signed off on that step. |
@bors r+ |
📌 Commit d27e55c has been approved by |
Some more pattern cleanup and bugfixing The next part of #34095 The most significant fixed mistake is definitions for partially resolved associated types not being updated after full resolution. ``` fn f<T: Fn()>(arg: T::Output) { .... } // <- the definition of T::Output was not updated in def_map ``` For this reason unstable associated types of stable traits, like `FnOnce::Output`, could be used in stable code when written in unqualified form. Now they are properly checked, this is a **[breaking-change]** (pretty minor one, but a crater run would be nice). The fix is not to use unstable library features in stable code, alternatively `FnOnce::Output` can be stabilized. Besides that, paths in struct patterns and expressions `S::A { .. }` are now fully resolved as associated types. Such types cannot be identified as structs at the moment, i.e. the change doesn't make previously invalid code valid, but it improves error diagnostics. Other changes: `Def::Err` is supported better (less chances for ICEs for erroneous code), some incorrect error messages are corrected, some duplicated error messages are not reported, ADT definitions are now available through constructor IDs, everything else is cleanup and code audit. Fixes #34209 Closes #22933 (adds tests) r? @eddyb
The next part of #34095
The most significant fixed mistake is definitions for partially resolved associated types not being updated after full resolution.
For this reason unstable associated types of stable traits, like
FnOnce::Output
, could be used in stable code when written in unqualified form. Now they are properly checked, this is a [breaking-change] (pretty minor one, but a crater run would be nice). The fix is not to use unstable library features in stable code, alternativelyFnOnce::Output
can be stabilized.Besides that, paths in struct patterns and expressions
S::A { .. }
are now fully resolved as associated types. Such types cannot be identified as structs at the moment, i.e. the change doesn't make previously invalid code valid, but it improves error diagnostics.Other changes:
Def::Err
is supported better (less chances for ICEs for erroneous code), some incorrect error messages are corrected, some duplicated error messages are not reported, ADT definitions are now available through constructor IDs, everything else is cleanup and code audit.Fixes #34209
Closes #22933 (adds tests)
r? @eddyb