-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Use smaller def span for functions #75465
Merged
Merged
Changes from all commits
Commits
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 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 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 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 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 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 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 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 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 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 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 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 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 | ||||
---|---|---|---|---|---|---|
|
@@ -227,7 +227,7 @@ impl<'a> Parser<'a> { | |||||
(Ident::invalid(), ItemKind::Use(P(tree))) | ||||||
} else if self.check_fn_front_matter() { | ||||||
// FUNCTION ITEM | ||||||
let (ident, sig, generics, body) = self.parse_fn(attrs, req_name)?; | ||||||
let (ident, sig, generics, body) = self.parse_fn(attrs, req_name, lo)?; | ||||||
(ident, ItemKind::Fn(def(), sig, generics, body)) | ||||||
} else if self.eat_keyword(kw::Extern) { | ||||||
if self.eat_keyword(kw::Crate) { | ||||||
|
@@ -1492,21 +1492,31 @@ impl<'a> Parser<'a> { | |||||
&mut self, | ||||||
attrs: &mut Vec<Attribute>, | ||||||
req_name: ReqName, | ||||||
sig_lo: Span, | ||||||
) -> PResult<'a, (Ident, FnSig, Generics, Option<P<Block>>)> { | ||||||
let header = self.parse_fn_front_matter()?; // `const ... fn` | ||||||
let ident = self.parse_ident()?; // `foo` | ||||||
let mut generics = self.parse_generics()?; // `<'a, T, ...>` | ||||||
let decl = self.parse_fn_decl(req_name, AllowPlus::Yes)?; // `(p: u8, ...)` | ||||||
generics.where_clause = self.parse_where_clause()?; // `where T: Ord` | ||||||
let body = self.parse_fn_body(attrs)?; // `;` or `{ ... }`. | ||||||
Ok((ident, FnSig { header, decl }, generics, body)) | ||||||
|
||||||
let mut sig_hi = self.prev_token.span; | ||||||
let body = self.parse_fn_body(attrs, &mut sig_hi)?; // `;` or `{ ... }`. | ||||||
let fn_sig_span = sig_lo.to(sig_hi); | ||||||
Ok((ident, FnSig { header, decl, span: fn_sig_span }, generics, body)) | ||||||
} | ||||||
|
||||||
/// Parse the "body" of a function. | ||||||
/// This can either be `;` when there's no body, | ||||||
/// or e.g. a block when the function is a provided one. | ||||||
fn parse_fn_body(&mut self, attrs: &mut Vec<Attribute>) -> PResult<'a, Option<P<Block>>> { | ||||||
fn parse_fn_body( | ||||||
&mut self, | ||||||
attrs: &mut Vec<Attribute>, | ||||||
sig_hi: &mut Span, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same issue as above |
||||||
) -> PResult<'a, Option<P<Block>>> { | ||||||
let (inner_attrs, body) = if self.check(&token::Semi) { | ||||||
// Include the trailing semicolon in the span of the signature | ||||||
*sig_hi = self.token.span; | ||||||
Comment on lines
+1518
to
+1519
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
self.bump(); // `;` | ||||||
(Vec::new(), None) | ||||||
} else if self.check(&token::OpenDelim(token::Brace)) || self.token.is_whole_block() { | ||||||
|
This file contains 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 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 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 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 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 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 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 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
7 changes: 2 additions & 5 deletions
7
src/test/ui/associated-types/higher-ranked-projection.good.stderr
This file contains 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 |
---|---|---|
@@ -1,11 +1,8 @@ | ||
error: fatal error triggered by #[rustc_error] | ||
--> $DIR/higher-ranked-projection.rs:24:1 | ||
| | ||
LL | / fn main() { | ||
LL | | foo(()); | ||
LL | | | ||
LL | | } | ||
| |_^ | ||
LL | fn main() { | ||
| ^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
Oops, something went wrong.
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.
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.
This will introduce a duplicate check for
token::Semi
- I wanted to make sure that the determination ofsig_hi
always stays in sync with the actual parsing logic.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, fair enough it's not critical