-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Support const args in type dependent paths #71154
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9d34bf5
impl type_of for const args in ty dependent paths
lcnr 7186628
add fn enclosing_body_owner to hir
lcnr c625d2c
propagate param def id during typeck
lcnr 88cf2bf
update rustdoc
lcnr 3df37a4
update clippy
lcnr 2c6e561
update mir-opt tests
lcnr cc7a6d1
add tests for type dependent paths
lcnr 19d9fd5
fix ice on unknown const arg parent
lcnr 0b5aa1b
manually impl more traits for WithOptParam
lcnr 29ffa55
add test for extern crates
lcnr ae74817
cleanup
lcnr 2ada8e3
wip
lcnr ae7828a
who told you this was unsound!
lcnr a23a444
fix rebase
lcnr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,25 @@ rustc_queries! { | |
desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) } | ||
} | ||
|
||
/// Computes the `DefId` of the corresponding const parameter in case the `key` is a | ||
/// const argument and returns `None` otherwise. | ||
/// | ||
/// ```rust | ||
/// let a = foo::<7>(); | ||
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. This is a clear example :) |
||
/// // ^ Calling `const_param_of` for this argument, | ||
/// | ||
/// fn foo<const N: usize>() | ||
/// // ^ returns this `DefId`. | ||
/// | ||
/// fn bar() { | ||
/// // ^ While calling `const_param_of` for other bodies returns `None`. | ||
/// } | ||
/// ``` | ||
query const_param_of(key: DefId) -> Option<DefId> { | ||
cache_on_disk_if { key.is_local() } | ||
desc { |tcx| "computing the const parameter of `{}`", tcx.def_path_str(key) } | ||
} | ||
|
||
/// Records the type of every item. | ||
query type_of(key: DefId) -> Ty<'tcx> { | ||
desc { |tcx| "computing type of `{}`", tcx.def_path_str(key) } | ||
|
@@ -185,50 +204,50 @@ rustc_queries! { | |
/// Maps DefId's that have an associated `mir::Body` to the result | ||
/// of the MIR const-checking pass. This is the set of qualifs in | ||
/// the final value of a `const`. | ||
query mir_const_qualif(key: DefId) -> mir::ConstQualifs { | ||
desc { |tcx| "const checking `{}`", tcx.def_path_str(key) } | ||
cache_on_disk_if { key.is_local() } | ||
query mir_const_qualif(key: ty::WithOptParam<DefId>) -> mir::ConstQualifs { | ||
desc { |tcx| "const checking `{}`", tcx.def_path_str(key.did) } | ||
cache_on_disk_if { key.did.is_local() } | ||
} | ||
|
||
/// Fetch the MIR for a given `DefId` right after it's built - this includes | ||
/// unreachable code. | ||
query mir_built(key: LocalDefId) -> Steal<mir::Body<'tcx>> { | ||
query mir_built(key: ty::WithOptParam<LocalDefId>) -> Steal<mir::Body<'tcx>> { | ||
storage(ArenaCacheSelector<'tcx>) | ||
desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.to_def_id()) } | ||
desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) } | ||
} | ||
|
||
/// Fetch the MIR for a given `DefId` up till the point where it is | ||
/// ready for const qualification. | ||
/// | ||
/// See the README for the `mir` module for details. | ||
query mir_const(key: DefId) -> Steal<mir::Body<'tcx>> { | ||
desc { |tcx| "processing MIR for `{}`", tcx.def_path_str(key) } | ||
query mir_const(key: ty::WithOptParam<DefId>) -> Steal<mir::Body<'tcx>> { | ||
desc { |tcx| "processing MIR for `{}`", tcx.def_path_str(key.did) } | ||
storage(ArenaCacheSelector<'tcx>) | ||
no_hash | ||
} | ||
|
||
query mir_drops_elaborated_and_const_checked(key: LocalDefId) -> Steal<mir::Body<'tcx>> { | ||
query mir_drops_elaborated_and_const_checked(key: ty::WithOptParam<LocalDefId>) -> Steal<mir::Body<'tcx>> { | ||
storage(ArenaCacheSelector<'tcx>) | ||
no_hash | ||
desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.to_def_id()) } | ||
desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) } | ||
} | ||
|
||
query mir_validated(key: LocalDefId) -> | ||
query mir_validated(key: ty::WithOptParam<LocalDefId>) -> | ||
( | ||
Steal<mir::Body<'tcx>>, | ||
Steal<IndexVec<mir::Promoted, mir::Body<'tcx>>> | ||
) { | ||
storage(ArenaCacheSelector<'tcx>) | ||
no_hash | ||
desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) } | ||
desc { |tcx| "processing `{}`", tcx.def_path_str(key.did.to_def_id()) } | ||
} | ||
|
||
/// MIR after our optimization passes have run. This is MIR that is ready | ||
/// for codegen. This is also the only query that can fetch non-local MIR, at present. | ||
query optimized_mir(key: DefId) -> mir::Body<'tcx> { | ||
desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) } | ||
query optimized_mir(key: ty::WithOptParam<DefId>) -> mir::Body<'tcx> { | ||
desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key.did) } | ||
storage(ArenaCacheSelector<'tcx>) | ||
cache_on_disk_if { key.is_local() } | ||
cache_on_disk_if { key.did.is_local() } | ||
} | ||
|
||
query coverage_data(key: DefId) -> mir::CoverageData { | ||
|
@@ -237,10 +256,10 @@ rustc_queries! { | |
cache_on_disk_if { key.is_local() } | ||
} | ||
|
||
query promoted_mir(key: DefId) -> IndexVec<mir::Promoted, mir::Body<'tcx>> { | ||
desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) } | ||
query promoted_mir(key: ty::WithOptParam<DefId>) -> IndexVec<mir::Promoted, mir::Body<'tcx>> { | ||
desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key.did) } | ||
storage(ArenaCacheSelector<'tcx>) | ||
cache_on_disk_if { key.is_local() } | ||
cache_on_disk_if { key.did.is_local() } | ||
} | ||
} | ||
|
||
|
@@ -450,8 +469,8 @@ rustc_queries! { | |
|
||
TypeChecking { | ||
/// The result of unsafety-checking this `DefId`. | ||
query unsafety_check_result(key: LocalDefId) -> mir::UnsafetyCheckResult { | ||
desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) } | ||
query unsafety_check_result(key: ty::WithOptParam<LocalDefId>) -> mir::UnsafetyCheckResult { | ||
desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.did.to_def_id()) } | ||
cache_on_disk_if { true } | ||
storage(ArenaCacheSelector<'tcx>) | ||
} | ||
|
@@ -531,8 +550,8 @@ rustc_queries! { | |
desc { "type-checking all item bodies" } | ||
} | ||
|
||
query typeck_tables_of(key: LocalDefId) -> &'tcx ty::TypeckTables<'tcx> { | ||
desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) } | ||
query typeck_tables_of(key: ty::WithOptParam<LocalDefId>) -> &'tcx ty::TypeckTables<'tcx> { | ||
desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.did.to_def_id()) } | ||
cache_on_disk_if { true } | ||
} | ||
query diagnostic_only_typeck_tables_of(key: LocalDefId) -> &'tcx ty::TypeckTables<'tcx> { | ||
|
@@ -568,11 +587,11 @@ rustc_queries! { | |
BorrowChecking { | ||
/// Borrow-checks the function body. If this is a closure, returns | ||
/// additional requirements that the closure's creator must verify. | ||
query mir_borrowck(key: LocalDefId) -> mir::BorrowCheckResult<'tcx> { | ||
query mir_borrowck(key: ty::WithOptParam<LocalDefId>) -> mir::BorrowCheckResult<'tcx> { | ||
storage(ArenaCacheSelector<'tcx>) | ||
desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) } | ||
desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.did.to_def_id()) } | ||
cache_on_disk_if(tcx, opt_result) { | ||
tcx.is_closure(key.to_def_id()) | ||
tcx.is_closure(key.did.to_def_id()) | ||
|| opt_result.map_or(false, |r| !r.concrete_opaque_types.is_empty()) | ||
} | ||
} | ||
|
@@ -1434,9 +1453,9 @@ rustc_queries! { | |
/// from `Ok(None)` to avoid misleading diagnostics when an error | ||
/// has already been/will be emitted, for the original cause | ||
query resolve_instance( | ||
key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)> | ||
key: ty::ParamEnvAnd<'tcx, (ty::WithOptParam<DefId>, SubstsRef<'tcx>)> | ||
) -> Result<Option<ty::Instance<'tcx>>, ErrorReported> { | ||
desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) } | ||
desc { "resolving instance `{}`", ty::Instance::new(key.value.0.did, key.value.1) } | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.