Skip to content

Conversation

@Rageking8
Copy link
Contributor

Fixes #101540

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Sep 15, 2022
@rust-highfive
Copy link
Contributor

r? @TaKO8Ki

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 15, 2022
@Rageking8
Copy link
Contributor Author

First time contributing to an open source project, please guide me step by step if there are any mistakes made in this PR. Thanks.

@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@TaKO8Ki TaKO8Ki left a comment

Choose a reason for hiding this comment

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

Sorry for the late response. I left some comments.

Comment on lines +1727 to +1729
} else if self.check_keyword(kw::Struct) {
let kw_token = self.token.clone();
let item = self.parse_item(ForceCollect::No)?;
Copy link
Member

Choose a reason for hiding this comment

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

Could you use Parser::parse_item_struct instead?

Copy link
Member

@TaKO8Ki TaKO8Ki Sep 22, 2022

Choose a reason for hiding this comment

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

The implementation would eventually look something like the following:

// create a snapshot by using `Parser::ccreate_snapshot_for_diagnostic` at line 1707
// ..
} else if self.eat_keyword(kw::Struct) {
    match self.parse_item_struct() {
        Ok((ident, _)) => {
            let mut err = self.struct_span_err(
                lo.with_hi(ident.span.hi()),
                &format!("structs are not allowed in {adt_ty} definitions"),
            );
            err.help("consider creating a new `struct` definition instead of nesting");
            err
        }
        Err(err) => {
            err.cancel();
            self.restore_snapshot(snapshot);
            self.expected_ident_found()
        }
    }
}

);
err.span_suggestion(
item.unwrap().span,
&format!("consider creating a new `struct` definition instead of nesting"),
Copy link
Member

Choose a reason for hiding this comment

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

Could you just use &str?

Suggested change
&format!("consider creating a new `struct` definition instead of nesting"),
"consider creating a new `struct` definition instead of nesting",

Comment on lines +1734 to +1739
err.span_suggestion(
item.unwrap().span,
&format!("consider creating a new `struct` definition instead of nesting"),
"",
Applicability::MaybeIncorrect,
);
Copy link
Member

Choose a reason for hiding this comment

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

I think this suggestion should be like the following:

Suggested change
err.span_suggestion(
item.unwrap().span,
&format!("consider creating a new `struct` definition instead of nesting"),
"",
Applicability::MaybeIncorrect,
);
err.span_help("consider creating a new `struct` definition instead of nesting");

@TaKO8Ki
Copy link
Member

TaKO8Ki commented Sep 22, 2022

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 22, 2022
@Rageking8
Copy link
Contributor Author

Rageking8 commented Sep 22, 2022

The recent miri to subtree thing kinda messed up my git stuff (I am new to git). Will do this in a separate PR.

@Rageking8 Rageking8 closed this Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add note that struct declaration within a struct is not allowed

5 participants