-
Notifications
You must be signed in to change notification settings - Fork 13.3k
rustdoc: handle cross-crate RPITITs correctly #113956
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
Merged
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -474,11 +474,14 @@ fn subst_and_check_impossible_predicates<'tcx>( | |
result | ||
} | ||
|
||
/// Checks whether a trait's method is impossible to call on a given impl. | ||
/// Checks whether a trait's associated item is impossible to reference on a given impl. | ||
/// | ||
/// This only considers predicates that reference the impl's generics, and not | ||
/// those that reference the method's generics. | ||
fn is_impossible_method(tcx: TyCtxt<'_>, (impl_def_id, trait_item_def_id): (DefId, DefId)) -> bool { | ||
fn is_impossible_associated_item( | ||
tcx: TyCtxt<'_>, | ||
(impl_def_id, trait_item_def_id): (DefId, DefId), | ||
) -> bool { | ||
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. Ofc, we could just defensively check at the start if the assoc item |
||
struct ReferencesOnlyParentGenerics<'tcx> { | ||
tcx: TyCtxt<'tcx>, | ||
generics: &'tcx ty::Generics, | ||
|
@@ -556,7 +559,7 @@ pub fn provide(providers: &mut Providers) { | |
specializes: specialize::specializes, | ||
subst_and_check_impossible_predicates, | ||
check_tys_might_be_eq: misc::check_tys_might_be_eq, | ||
is_impossible_method, | ||
is_impossible_associated_item, | ||
..*providers | ||
}; | ||
} |
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
35 changes: 35 additions & 0 deletions
35
tests/rustdoc/inline_cross/auxiliary/ret-pos-impl-trait-in-trait.rs
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#![feature(return_position_impl_trait_in_trait)] | ||
|
||
pub trait Trait { | ||
fn create() -> impl Iterator<Item = u64> { | ||
std::iter::empty() | ||
} | ||
} | ||
|
||
pub struct Basic; | ||
pub struct Intermediate; | ||
pub struct Advanced; | ||
|
||
impl Trait for Basic { | ||
// method provided by the trait | ||
} | ||
|
||
impl Trait for Intermediate { | ||
fn create() -> std::ops::Range<u64> { // concrete return type | ||
0..1 | ||
} | ||
} | ||
|
||
impl Trait for Advanced { | ||
fn create() -> impl Iterator<Item = u64> { // opaque return type | ||
std::iter::repeat(0) | ||
} | ||
} | ||
|
||
// Regression test for issue #113929: | ||
|
||
pub trait Def { | ||
fn def<T>() -> impl Default {} | ||
} | ||
|
||
impl Def for () {} |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#![crate_name = "user"] | ||
// aux-crate:rpitit=ret-pos-impl-trait-in-trait.rs | ||
// edition:2021 | ||
|
||
// Test that we can correctly render cross-crate RPITITs. | ||
// In particular, check that we don't render the internal associated type generated by | ||
// their desugaring. We count the number of associated items and ensure that it is exactly one. | ||
// This is more robust than checking for the absence of the associated type. | ||
|
||
// @has user/trait.Trait.html | ||
// @has - '//*[@id="method.create"]' 'fn create() -> impl Iterator<Item = u64>' | ||
// The class "method" is used for all three kinds of associated items at the time of writing. | ||
// @count - '//*[@id="main-content"]//section[@class="method"]' 1 | ||
pub use rpitit::Trait; | ||
|
||
// @has user/struct.Basic.html | ||
// @has - '//*[@id="method.create"]' 'fn create() -> impl Iterator<Item = u64>' | ||
// @count - '//*[@id="trait-implementations-list"]//*[@class="impl-items"]' 1 | ||
pub use rpitit::Basic; | ||
|
||
// @has user/struct.Intermediate.html | ||
// @has - '//*[@id="method.create"]' 'fn create() -> Range<u64>' | ||
// @count - '//*[@id="trait-implementations-list"]//*[@class="impl-items"]' 1 | ||
pub use rpitit::Intermediate; | ||
|
||
// @has user/struct.Advanced.html | ||
// @has - '//*[@id="method.create"]' 'fn create() -> impl Iterator<Item = u64>' | ||
// @count - '//*[@id="trait-implementations-list"]//*[@class="impl-items"]' 1 | ||
pub use rpitit::Advanced; | ||
|
||
// Regression test for issue #113929: | ||
|
||
// @has user/trait.Def.html | ||
// @has - '//*[@id="method.def"]' 'fn def<T>() -> impl Default' | ||
pub use rpitit::Def; |
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.
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've renamed this since the previous name confused me quite a bit at first, I wasn't sure if the ICE happened due to the RPITIT-method or due to the synthetic RPITIT assoc type. It can handle every kind of associated item just fine (even generic consts I assume) and rustdoc does use the query for every kind already.
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.
Yeah, it used to be used during codegen to skip monomorphizing methods that have impossible to solve predicates, but now it's used for other things.edit: nvm I was confusing it with another "is impossible" method. Yeah, idk why it was named like that.