-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Move E0379 check from typeck to ast validation #35480
Conversation
@@ -94,7 +94,7 @@ impl<'a> MacResult for ParserAnyMacro<'a> { | |||
let mut parser = self.parser.borrow_mut(); | |||
match parser.token { | |||
token::Eof => break, | |||
_ => ret.push(panictry!(parser.parse_impl_item())) | |||
_ => ret.push(panictry!(parser.parse_impl_item(false))) |
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.
Someone should double-check this - make_items
should cover the case for macro trait impl fns and trait fns, so when make_impl_items
is called, we can be certain that this is going to be a plain impl (i.e. impl without traits), hence this here is false.
@KiChjang |
a552d03
to
7912ae2
Compare
Moved the error from the parser to the ast validator. |
@@ -819,14 +819,10 @@ pub fn check_item_body<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, it: &'tcx hir::Item) { | |||
check_const(ccx, trait_item.span, &expr, trait_item.id) | |||
} | |||
hir::MethodTraitItem(ref sig, Some(ref body)) => { |
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.
can you add an assertion here that the fn is not const? (and maybe a comment pointing out that this is checked in the AST validator?)
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.
But that will cause ICEs in erroneous code - the error in the validation pass is not fatal and compilation continues until type checking is done.
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.
Yes, this would cause an ICE with const unsafe fn
.
Yes, that is generally in the parser (and, in that context, it's ok to do subtraction of this kind, though always a bit sketchy -- but in any case there we know that macro expansion hasn't happened yet, so the spans of different files and so forth are not mixed up). If you look in the parser, you'll see that it tracks If we wanted to track the span of just this keyword, then, I would probably change the AST to have |
OK, sorry, forget the assertions, you're right :) |
In that case, can you just add some comments? |
Meh, I guess that's not necessary. |
(To be clear, I'd still like to see the "span munging" changed.) |
Just a heads up, I've changed my mind. I'll be incorporating the changes to make |
Okay, I've made it so that all |
@KiChjang this all looks good; one thought is that if you convert the test into a What do you think? |
Adding a span to constness seems pretty random. Why does it have a span while |
@petrochenkov - there can be multiple PRs that address different issues, so a later PR could add a span to cc @nikomatsakis - since we were just chatting about AST nodes getting spans. There may be a cost, which hopefully we can detect and address it if any exists, but the ergonomics of being able to have the spans and give better error messages is helpful. |
@nikomatsakis I'm fine with adding them to this PR, but I think we'll need to make it so that everyone working on #35233 should also write UI tests, if they have tightened the spans for some errors. |
@petrochenkov we are already somewhat inconsistent about where we include spans -- e.g., we sometimes put spans on identifiers, sometimes not. It seems... ok to me. |
@@ -5775,7 +5783,9 @@ impl<'a> Parser<'a> { | |||
// FUNCTION ITEM | |||
self.bump(); | |||
let (ident, item_, extra_attrs) = | |||
self.parse_item_fn(Unsafety::Normal, Constness::NotConst, Abi::Rust)?; | |||
self.parse_item_fn(Unsafety::Normal, | |||
dummy_spanned(Constness::NotConst), |
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.
Also here.
Dummy spans removed from |
@bors r+ |
📌 Commit 9fae2f3 has been approved by |
Rebased. |
Huh, looks like a test in the
|
Fixed the unit test in the latest force-push. |
@bors r+ rollup |
📌 Commit b5b667d has been approved by |
@bors r=nikomatsakis |
💡 This pull request was already approved, no need to approve it again.
|
📌 Commit b5b667d has been approved by |
@bors r- |
Move E0379 check from typeck to ast validation Part of rust-lang#35233. Extension of rust-lang#35338, rust-lang#35364. Fixes rust-lang#35404.
Batch up libsyntax breaking changes Batch of the following syntax-[breaking-change] changes: - #35591: Add a field `span: Span` to `ast::Generics`. - #35618: Remove variant `Mod` of `ast::PathListItemKind` and refactor the remaining variant `ast::PathListKind::Ident` to a struct `ast::PathListKind_`. - #35480: Change uses of `Constness` in the AST to `Spanned<Constness>`. - c.f. `MethodSig`, `ItemKind` - #35728: Refactor `cx.pat_enum()` into `cx.pat_tuple_struct()` and `cx.pat_path()`. - #35850: Generalize the elements of lists in attributes from `MetaItem` to a new type `NestedMetaItem` that can represent a `MetaItem` or a literal. - #35917: Remove traits `AttrMetaMethods`, `AttributeMethods`, and `AttrNestedMetaItemMethods`. - Besides removing imports of these traits, this won't cause fallout. - Add a variant `Union` to `ItemKind` to future proof for `union` (c.f. #36016). - Remove inherent methods `attrs` and `fold_attrs` of `Annotatable`. - Use methods `attrs` and `map_attrs` of `HasAttrs` instead. r? @Manishearth
Part of #35233.
Extension of #35338, #35364.
Fixes #35404.
r? @jonathandturner