Skip to content
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

Minor librustdoc cleanup and refactoring. #36903

Merged
merged 8 commits into from
Oct 4, 2016
Merged

Conversation

frewsxcv
Copy link
Member

@frewsxcv frewsxcv commented Oct 2, 2016

No description provided.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @steveklabnik (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@frewsxcv
Copy link
Member Author

frewsxcv commented Oct 2, 2016

r? @GuillaumeGomez

@frewsxcv
Copy link
Member Author

frewsxcv commented Oct 2, 2016

I need a sanity check for 19f6130

Here's the new print function it will use:

pub fn path_to_string(p: &hir::Path) -> String {
to_string(|s| s.print_path(p, false, 0))
}

rust/src/librustc/hir/print.rs

Lines 1615 to 1636 in df9fa1a

fn print_path(&mut self,
path: &hir::Path,
colons_before_params: bool,
depth: usize)
-> io::Result<()> {
self.maybe_print_comment(path.span.lo)?;
let mut first = !path.global;
for segment in &path.segments[..path.segments.len() - depth] {
if first {
first = false
} else {
word(&mut self.s, "::")?
}
self.print_name(segment.name)?;
self.print_path_parameters(&segment.parameters, colons_before_params)?;
}
Ok(())
}

Copy link
Contributor

@jseyfried jseyfried left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me modulo comments.

CLikeVariant
} else {
TupleVariant(struct_def.fields().iter().map(|x| x.ty.clean(cx)).collect())
impl VariantKind {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make this an implementation of Clean<VariantKind> for hir::VariantData?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d6fb0c8d6a01beab132f1df7832794401ac92a46

@@ -2682,11 +2668,12 @@ fn name_from_pat(p: &hir::Pat) -> String {
match p.node {
PatKind::Wild => "_".to_string(),
PatKind::Binding(_, ref p, _) => p.node.to_string(),
PatKind::TupleStruct(ref p, ..) | PatKind::Path(None, ref p) => path_to_string(p),
PatKind::TupleStruct(ref p, ..) | PatKind::Path(None, ref p) => p.to_string(),
Copy link
Contributor

@jseyfried jseyfried Oct 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hir::print::State::print_path begins with self.maybe_print_comment(path.span.lo), which might actually print a comment in this case:

fn f(arg1: (), // Some comment
     path::to::TupleStruct(x): path::to::TupleStruct) {
     //^ The `name_from_pat` of this tuple struct pattern might include "// Some comment"
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think I should add an parameter to that function to control whether the comment gets printed or just ditch that commit?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd probably ditch the commit to be on the safe side since I don't understand the pretty printer, especially in edge cases (e.g. it might emit newlines and indents in long patterns).

VariantKind::CLike
} else {
VariantKind::Tuple(
self.fields().iter().map(|x| x.ty.clean(cx)).collect())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this can fit on one line

(ret, ImportList(resolve_use_source(cx, p.clean(cx), self.id),
remaining))
(ret, Import::List(resolve_use_source(cx, p.clean(cx), self.id),
remaining))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this can fit on one line

use clean::{Variant, VariantKind};
if let clean::VariantItem(
Variant { kind: VariantKind::Struct(ref s) } ) = variant.inner
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this would be easier for me to read:

            if let clean::VariantItem(Variant { kind: VariantKind::Struct(ref s) }) =
                variant.inner
            {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or

            if let clean::VariantItem(Variant {
                kind: VariantKind::Struct(ref s)
            }) = variant.inner {

@frewsxcv
Copy link
Member Author

frewsxcv commented Oct 3, 2016

Latest force push removes 19f6130 and makes the suggested style changes.

@jseyfried
Copy link
Contributor

Thanks! @bors r+

@bors
Copy link
Contributor

bors commented Oct 3, 2016

📌 Commit 35d214a has been approved by jseyfried

Manishearth added a commit to Manishearth/rust that referenced this pull request Oct 4, 2016
Minor librustdoc cleanup and refactoring.
bors added a commit that referenced this pull request Oct 4, 2016
Rollup of 12 pull requests

- Successful merges: #36798, #36878, #36902, #36903, #36908, #36916, #36917, #36921, #36928, #36938, #36941, #36951
- Failed merges:
@bors bors merged commit 35d214a into rust-lang:master Oct 4, 2016
critiqjo pushed a commit to critiqjo/rustdoc that referenced this pull request Dec 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants