-
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
librustc_middle: change query functions to accept impl Into<$K> type #70956
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,6 +195,12 @@ impl fmt::Debug for DefId { | |
} | ||
} | ||
|
||
impl From<LocalDefId> for DefId { | ||
fn from(local_def_id: LocalDefId) -> DefId { | ||
local_def_id.to_def_id() | ||
} | ||
} | ||
Comment on lines
+198
to
+202
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another reason to not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am new to all of this and my opinion probably does not matter much but using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I was imagining an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think |
||
|
||
rustc_data_structures::define_id_collections!(DefIdMap, DefIdSet, DefId); | ||
|
||
/// A LocalDefId is equivalent to a DefId with `krate == LOCAL_CRATE`. Since | ||
|
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.
I'd make some new methods that call the existing ones in this file to avoid making these generic. We want to make sure that
ensure_query
andget_query
is only instantiated inrustc_middle.
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.
Just that i understand; the proposal here is to add new methods only for methods where the key is a
DefId
and give them a name similar to the original one but with a prefix (for example). We would end up with methods likelocal_generics_of
forLocalDefId
instead ofgenerics_of
forDefId
?If so, all callers that have a
LocalDefId
would have to use the new methods, and then there is not much benefit compared to calling.to_def_id()
everywhere. All code will have to be changed anyway, either to call the new methods or to call.to_def_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.
I believe they want the caller of
ensure_query
to remain monomorphic and for you to introduce a generic wrapper around it that calls.into()
on the query param before passing it to the monomorphic version.