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

Reapply "Initial work on formatting headers" #6457

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fee1-dead
Copy link
Member

As per this comment.

This reimplements the header formatting infrastructure to resume porting to this system, if there are comments between header parts, we preserve the original whitespace/comments snippet instead of realigning/reformatting them.

This reverts commit f2c84b5.

Comment on lines +63 to +68
#[derive(Debug)]
pub(crate) struct HeaderPart {
/// snippet of this part without surrounding space
snippet: Cow<'static, str>,
span: Span,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Does the snippet need to be a Cow<'static, str>? Could we make it a Cow<'a, str> or are there lifetime issues that prevent that?

Comment on lines +79 to +82
Self {
snippet: rewrite_ident(context, ident).to_owned().into(),
span: ident.span,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be implemented in terms of HeaderPart::new? Would save you needing to call .into().

Suggested change
Self {
snippet: rewrite_ident(context, ident).to_owned().into(),
span: ident.span,
}
let snippet = rewrite_ident(context, ident).to_owned();
Self::new(snippet, ident.span)

If we can make HeaderPart hold a Cow<'a, str>, then this could probably be written as:

Self::new(rewrite_ident(context, ident), ident.span)

let path = segments_iter.collect::<Vec<_>>().join("::");
let in_str = if is_keyword(&path) { "" } else { "in " };

Cow::from(format!("pub({}{})", in_str, path))
Copy link
Contributor

@ytmimi ytmimi Jan 30, 2025

Choose a reason for hiding this comment

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

Not something that we need to fix right now, but we're potentially missing comments within the visibility modifier. e.g pub( /* comment */ crate /* comment */).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants