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

Better error message for inner attribute following doc comment #34676

Merged
merged 1 commit into from
Jul 16, 2016

Conversation

aravind-pg
Copy link
Contributor

Before it was always just "an inner attribute is not permitted in this context", whereas now we add a special case for when an inner attr follows an outer attr. If the outer attr is a doc comment, then the error is "an inner attr is not permitted following a doc comment", and otherwise it's "an inner attr is not permitted following an outer attribute". In all other cases it's still "an inner attribute is not permitted in this context".

Note that the public API and behaviour of parse_attribute is unchanged. Also, all new names are very open to bikeshedding -- they're arguably clunky.

Fixes #34516. cc @brson

@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 @nikomatsakis (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.

@brson brson assigned brson and unassigned nikomatsakis Jul 6, 2016
@brson
Copy link
Contributor

brson commented Jul 6, 2016

Thanks @aravind-pg! This looks good to me. My only reservation is the text "an inner attr is not permitted following a doc comment". Technically what's invalid is following an outer doc comment - there are both inner and outer doc comments. Although raising the distinction is potentially confusion, I think it's probably better to be explicit about it. Can you update the text to say "outer doc comment"?

f? @mikedilger @Manishearth @jonathandturner trying to make a confusing parse error understandable.

@aravind-pg
Copy link
Contributor Author

Makes sense, updated now.

@Manishearth
Copy link
Member

inner/outer attrs aren't a well-known term, could we also display notes explaining what each is?

@aravind-pg
Copy link
Contributor Author

Sure. Any suggestions on what the notes should be so as to be friendly to users? Given that in this error message we're distinguishing general outer attributes from outer doc comments anyway, maybe something very explicit like the following?

  • "an inner attribute is one of the form #![foo] in mod bar { #![foo] }, modifying the item enclosing it (mod bar in our example), whereas an outer attribute is one of the form #[foo] in #[foo] struct Baz, modifying the item following it (struct Baz in our example)".

Alternatively maybe we should just link to https://doc.rust-lang.org/book/attributes.html. I'd like that better actually.

@Manishearth
Copy link
Member

Sounds good. I prefer things like this to be inline.

@aravind-pg
Copy link
Contributor Author

Added notes now, may need further wordsmithing, PTAL.

(`mod` bar in our example)")
.note("an outer attribute is either of the form `#[foo]` in \
`#[foo] struct Baz` or is an outer doc comment, modifying \
the item following it (`struct Baz` in our example)")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a lot of spew. Let's try to condense a bit. First, let's remove the 'help'. I think with the new explanation it is pretty useless.

For the 'note' it would be good to indicate that inner attributes can be comments and are usually encountered at the crate level.

What about this: "inner attributes and doc comments, like #![no_std] or //! My crate, annotate the enclosing item, and are usually found at the crate root. Outer attributes and doc comments, like #[test] and /// My function, annotate the following item."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I do agree that this is a lot of spew, unfortunately. But I also think the 'help' is pretty useful here since it is actually actionable, and especially so for a beginner.

Your suggestion for the note sounds pretty good to me, and I'm happy to change mine, but I have a vague worry that the sentence structure doesn't quite emphasize the "enclosing vs. following" distinction enough (when used as adjectives like that it somehow seems they don't stand out enough, if that makes any sense). Maybe it would be good to get the opinion of @steveklabnik on this? Also @Manishearth since he was the one who suggested the note.

Also, would you like it to be two separate notes or one long sentence/note?

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 prefer one note if possible.

Copy link
Member

Choose a reason for hiding this comment

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

Fix it to be a single note and r=me

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. And should the 'help' stay or go?

Copy link
Member

Choose a reason for hiding this comment

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

keep it

@aravind-pg
Copy link
Contributor Author

Updated with @brson's suggested note now, with a minor change (s/following item/item following them, because otherwise it reads like it might be referring to something following the note itself. Similarly s/enclosing item/item enclosing them). Should be good to go now?

.help("place inner attribute at the top of the module or \
block")
.note("inner attributes and doc comments, like `#![no_std]` or \
`//! My crate`, annotate the item enclosing them, and are \
usually found at the crate root. Outer attributes and doc \
Copy link
Member

Choose a reason for hiding this comment

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

Inner attributes are also often found at the start of files for any module at all, not just the crate root, no?

Maybe it would be simpler to just say "usually found at the start of Rust source files", which would cover both crate roots and non-root modules housed in their own files?

Copy link
Contributor

@brson brson Jul 12, 2016

Choose a reason for hiding this comment

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

Agreed. @aravind-pg can you make one more update?

I also strongly feel that the help is redundant now. Help says 'place inner attribute at X'; note says 'inner attributes annotate the item enclosing them'. The two statements are semantically similar. If there is important information missing from the note then the wording can be tweaked slightly. I'd like to remove the help.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, on second thought this is a rare error, so one extra note isn't going to matter much. I do think it would be cleaner to say what we're trying to say in once sentence than two.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not completely clear what your final call is here. I can definitely get rid of the help, not strongly attached to it by any means. Will also make the change that @pnkfelix pointed out.

@aravind-pg
Copy link
Contributor Author

Updated to remove the help and make the change that @pnkfelix suggested.

@brson
Copy link
Contributor

brson commented Jul 15, 2016

@bors r+

Thanks @aravind-pg !

@bors
Copy link
Contributor

bors commented Jul 15, 2016

📌 Commit 8f6dba9 has been approved by brson

@aravind-pg
Copy link
Contributor Author

Fixed trailing whitespace tidy error.

@bors r=brson

@Manishearth
Copy link
Member

@bors-servo r=brson

only reviewers can do that 😄

@bors
Copy link
Contributor

bors commented Jul 16, 2016

📌 Commit ff95ba3 has been approved by brson

@Manishearth
Copy link
Member

Er.

@bors r=brson

@bors
Copy link
Contributor

bors commented Jul 16, 2016

💡 This pull request was already approved, no need to approve it again.

@bors
Copy link
Contributor

bors commented Jul 16, 2016

📌 Commit ff95ba3 has been approved by brson

@aravind-pg
Copy link
Contributor Author

Haha yeah I figured, was just about to pop by #rust-internals to ask someone. Also, kinda cool that @bors-servo can stand in like that for @bors, huh.

@Manishearth
Copy link
Member

Homu/bors has a very simple parser that just throws out things it doesn't understand. As long as the line starts with bors, in Rust's case, it is fine. On servo it has to start with bors-servo.

I'm involved in both projects so I often ping the wrong bot. This works on Rust, but not servo.

@bors
Copy link
Contributor

bors commented Jul 16, 2016

⌛ Testing commit ff95ba3 with merge c4788c2...

bors added a commit that referenced this pull request Jul 16, 2016
Better error message for inner attribute following doc comment

Before it was always just "an inner attribute is not permitted in this context", whereas now we add a special case for when an inner attr follows an outer attr. If the outer attr is a doc comment, then the error is "an inner attr is not permitted following a doc comment", and otherwise it's "an inner attr is not permitted following an outer attribute". In all other cases it's still  "an inner attribute is not permitted in this context".

Note that the public API and behaviour of `parse_attribute` is unchanged. Also, all new names are very open to bikeshedding -- they're arguably clunky.

Fixes #34516. cc @brson
@bors bors merged commit ff95ba3 into rust-lang:master Jul 16, 2016
@aravind-pg aravind-pg deleted the inner-attr branch July 16, 2016 20:15
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.

7 participants