-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Proof of Concept: add #[defines]
attribute and require it for all type-alias-impl-trait sites that register a hidden type
#128440
base: master
Are you sure you want to change the base?
Conversation
self.tcx.dcx().emit_err(TaitForwardCompat2 { | ||
let guar = self.tcx.dcx().emit_err(TaitForwardCompat2 { | ||
span: self | ||
.tcx | ||
.def_ident_span(item_def_id) | ||
.unwrap_or_else(|| self.tcx.def_span(item_def_id)), | ||
opaque_type_span: self.tcx.def_span(self.def_id), | ||
opaque_type: self.tcx.def_path_str(self.def_id), | ||
}); | ||
// TODO: land this change as a separate PR on master, it works on its own. | ||
// Avoid "opaque type not constrained" errors on the opaque itself. | ||
self.found = Some(ty::OpaqueHiddenType { | ||
span: DUMMY_SP, | ||
ty: Ty::new_error(self.tcx, guar), | ||
}); |
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.
This change should be a fairly trivial PR on its own (just removes some redundant errors)
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #128481) made this pull request unmergeable. Please resolve the merge conflicts. |
} | ||
MetaItemKind::NameValue(_) => vec![], | ||
} | ||
} |
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.
Is this function ever used?
The ids used to identify defines
paths are created with next_node_id
in resolver, so they do not match ids kept in meta-item paths (if such ids are filled to non-dummy values at all).
// TODO: error reporting and tests that go through these code paths | ||
PathResult::Module(_) => todo!(), | ||
PathResult::NonModule(partial_res) => { | ||
let id = self.r.next_node_id(); |
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.
Are these ids necessary?
Probably simpler to push the resolutions straight to self.r.defines.entry(attr.id)
, without doing record_partial_res
.
match self.resolve_path( | ||
&Segment::from_path(&item.path), | ||
Some(Namespace::TypeNS), | ||
None, |
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.
This is not a speculative resolution, so there should be Some
here, but the real fix would be using smart_resolve_path
instead of resolve_path
above.
fn check_defines(&self, attr: &Attribute, span: Span, target: Target) -> bool { | ||
match target { | ||
Target::Fn | ||
| Target::Closure |
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.
The closure case is not processed in resolve.
Simple paths in attributes are not as bad as rust-lang/rfcs#3659, but still sort of meh, but probably acceptable. We don't currently have any resolved paths (staying after macro expansion) in attributes in the proper language. |
Also, |
…ler-errors Avoid `opaque type not constrained` errors in the presence of other errors pulled out of rust-lang#128440 These errors carry no new information if the opaque type was actually used in a constraining (but erroneous) way somewhere.
Rollup merge of rust-lang#133850 - oli-obk:push-xryukktpyooq, r=compiler-errors Avoid `opaque type not constrained` errors in the presence of other errors pulled out of rust-lang#128440 These errors carry no new information if the opaque type was actually used in a constraining (but erroneous) way somewhere.
…ng from the signature to the list of opaques that are being defined
statics still need work
The job Click to see the possible cause of the failure (guessed by this bot)
|
☔ The latest upstream changes (presumably #134492) made this pull request unmergeable. Please resolve the merge conflicts. |
This PR is not meant to be merged (I will not be pushing changes in the next 4 months), but serves as a starting point for anyone wanting to make progress on this. It should hopefully be simple to rebase and not require you to edit 200+ tests, as these edits are done here and you can just cherry pick them out (no need for attribution, just squash as you want)
I left TODOs for everything that I think needs to be done.
#[defines()]
), the latter opting out of impl-trait-in-assoc types automatic opaque collection in the signature (or in general, any#[defines(SomeOhterTait)]
attribute behaving as an override for the default collection, too).An interesting follow-up could also be to automatically fill in RPITs into that list in ast lowering, so that
opaque_types_defined_by
doesn't need to walk for RPITs anymore.@petrochenkov can you have a look at the resolver changes so that anyone picking this up will know what to change?