-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add stability tags to ImportItem. #83900
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 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0c736e9
Add stability tags to ImportItem.
41f49aa
Added a test.
1e2ab99
Give import items their own CSS class.
fca088a
Now also displays portability tags.
e2a77b3
Test Deprecated, Portability, and Unstable.
c975fe2
Put attrs in a Box for memory efficiency.
torhovland 64a68ae
No longer need to add attrs to ImportSource.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -477,6 +477,7 @@ fn build_module( | |
}], | ||
}, | ||
did: None, | ||
attrs: None, | ||
}, | ||
true, | ||
)), | ||
|
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
48 changes: 48 additions & 0 deletions
48
src/test/rustdoc/reexport-stability-tags-deprecated-and-portability.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,48 @@ | ||
#![crate_name = "foo"] | ||
#![feature(doc_cfg)] | ||
|
||
pub mod tag { | ||
#[deprecated(since = "0.1.8", note = "Use bar() instead")] | ||
pub trait Deprecated {} | ||
|
||
#[doc(cfg(feature = "sync"))] | ||
pub trait Portability {} | ||
|
||
#[deprecated(since = "0.1.8", note = "Use bar() instead")] | ||
#[doc(cfg(feature = "sync"))] | ||
pub trait Both {} | ||
|
||
pub trait None {} | ||
} | ||
|
||
// @has foo/mod1/index.html | ||
pub mod mod1 { | ||
// @has - '//code' 'pub use tag::Deprecated;' | ||
// @has - '//span' 'Deprecated' | ||
// @!has - '//span' 'sync' | ||
pub use tag::Deprecated; | ||
} | ||
|
||
// @has foo/mod2/index.html | ||
pub mod mod2 { | ||
// @has - '//code' 'pub use tag::Portability;' | ||
// @!has - '//span' 'Deprecated' | ||
// @has - '//span' 'sync' | ||
pub use tag::Portability; | ||
} | ||
|
||
// @has foo/mod3/index.html | ||
pub mod mod3 { | ||
// @has - '//code' 'pub use tag::Both;' | ||
// @has - '//span' 'Deprecated' | ||
// @has - '//span' 'sync' | ||
pub use tag::Both; | ||
} | ||
|
||
// @has foo/mod4/index.html | ||
pub mod mod4 { | ||
// @has - '//code' 'pub use tag::None;' | ||
// @!has - '//span' 'Deprecated' | ||
// @!has - '//span' 'sync' | ||
pub use tag::None; | ||
} |
61 changes: 61 additions & 0 deletions
61
src/test/rustdoc/reexport-stability-tags-unstable-and-portability.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,61 @@ | ||
#![crate_name = "foo"] | ||
#![feature(doc_cfg)] | ||
#![feature(staged_api)] | ||
#![stable(feature = "rust1", since = "1.0.0")] | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub mod tag { | ||
#[unstable(feature = "humans", issue = "none")] | ||
pub trait Unstable {} | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[doc(cfg(feature = "sync"))] | ||
pub trait Portability {} | ||
|
||
#[unstable(feature = "humans", issue = "none")] | ||
#[doc(cfg(feature = "sync"))] | ||
pub trait Both {} | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub trait None {} | ||
} | ||
|
||
// @has foo/mod1/index.html | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub mod mod1 { | ||
// @has - '//code' 'pub use tag::Unstable;' | ||
// @has - '//span' 'Experimental' | ||
// @!has - '//span' 'sync' | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub use tag::Unstable; | ||
} | ||
|
||
// @has foo/mod2/index.html | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub mod mod2 { | ||
// @has - '//code' 'pub use tag::Portability;' | ||
// @!has - '//span' 'Experimental' | ||
// @has - '//span' 'sync' | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub use tag::Portability; | ||
} | ||
|
||
// @has foo/mod3/index.html | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub mod mod3 { | ||
// @has - '//code' 'pub use tag::Both;' | ||
// @has - '//span' 'Experimental' | ||
// @has - '//span' 'sync' | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub use tag::Both; | ||
} | ||
|
||
// @has foo/mod4/index.html | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub mod mod4 { | ||
// @has - '//code' 'pub use tag::None;' | ||
// @!has - '//span' 'Experimental' | ||
// @!has - '//span' 'sync' | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub use tag::None; | ||
} |
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.
Why add
attrs
as a new field? You can look this up on-demand.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.
@jyn514 Because if I understand correctly, I would have to do
in
print_item.rs
, and it didn't seem appropriate to callclean()
methods at that stage, not least becauseclean()
expects aDocContext
, and we don't have that inprint_item.rs
.Let me know if you see a better way!
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.
Got it, thanks. At this point, I think I would extract a free function in
clean::types
forstability_class
so you only have to pass in the DefId of the item, not a wholeclean::Item
. Note thatstability_class
never uses the attributes, only the DefId. I would rather not make rustdoc slower just because the API is bad.You'll have to also extract free functions for
stability
,deprecation
, andis_fake
; all that seems fine.cc #83183
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 could do that, but I would still have to pass in
attrs
, and it also wouldn't solve the issue with the fakeItem
. You see, the problem isn't so much withstability_class
, but rather withextra_info_tags
. It really does seem to need anItem
withattrs
on it.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.
Hmm, ok. I guess this is a larger refactor than really belongs in this PR, I opened #84304.
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.
Aha, there's a simpler way:
impl Clean for [ast::Attribute]
doesn't use DocContext at all:rust/src/librustdoc/clean/mod.rs
Line 242 in b021bee
So you can remove the
attrs
field and calllet attrs = Box::new(Attributes::from_ast(tcx.sess().diagnostic(), tcx.get_attrs(def_id), None));
on-demand instead.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.
OK, should be good now.