Skip to content

Make output type in ast::FnDecl optional #21099

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

Merged
merged 1 commit into from
Jan 19, 2015
Merged

Conversation

sanxiyn
Copy link
Member

@sanxiyn sanxiyn commented Jan 13, 2015

This avoids having ast::Ty nodes which have no counterpart in the source.

@rust-highfive
Copy link
Contributor

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

if let ast::Return(ref ty) = decl.output {
match ty.node {
ast::TyTup(ref tys) if tys.is_empty() => {
return self.maybe_print_comment(ty.span.lo);
Copy link
Member

Choose a reason for hiding this comment

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

Just making sure, but was it intentional to lose the maybe_print_comment? (not that I know what it does...)

Copy link
Member

Choose a reason for hiding this comment

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

(same in two spots above as well)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that prints comments that may appear at that spot in the source.

Copy link
Member Author

Choose a reason for hiding this comment

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

It was intentional. As far as I can tell, this does not break anything. For example, fn f() /*1*/ {} still prints correctly.

@sanxiyn
Copy link
Member Author

sanxiyn commented Jan 15, 2015

I checked callers of FunctionRetTy::span, and the only problem I could come up with was this:

trait T {}
fn main() { let _: T = (|| loop {})(); }

which causes:

test.rs:2:28: 2:32 error: the trait `core::marker::Sized` is not implemented for the type `T`
test.rs:2 fn main() { let _: T = (|| loop {})(); }
                                     ^~~~

The error is that the return type of the closure is unsized. After this patch, rustc will highlight the beginning of the crate instead of (incorrect) loop. If one writes out || -> _ in full, span is correct at _ both before and after the patch.

@alexcrichton
Copy link
Member

Thanks for investigating that! Perhaps instead of Option<T> it could store a custom enum where the "none variant" has a span attached to it?

@sanxiyn
Copy link
Member Author

sanxiyn commented Jan 15, 2015

What span should I attach? The whole point is there is no correct span.

@alexcrichton
Copy link
Member

It looks like the parser just currently uses something along the lines of self.span, it's probably more useful to at least get the error closer to the expression rather than the start of the file (even if it's not 100% accurate)

@sanxiyn
Copy link
Member Author

sanxiyn commented Jan 18, 2015

Completely re-done with a custom enum.

@alexcrichton
Copy link
Member

@bors: r+ 3f0cc80

@bors
Copy link
Collaborator

bors commented Jan 19, 2015

⌛ Testing commit 3f0cc80 with merge e5ae40f...

@bors
Copy link
Collaborator

bors commented Jan 19, 2015

💔 Test failed - auto-mac-64-nopt-t

@alexcrichton
Copy link
Member

@bors: retry

bors added a commit that referenced this pull request Jan 19, 2015
This avoids having ast::Ty nodes which have no counterpart in the source.
@bors
Copy link
Collaborator

bors commented Jan 19, 2015

⌛ Testing commit 3f0cc80 with merge 135cac8...

@bors
Copy link
Collaborator

bors commented Jan 19, 2015

@bors bors merged commit 3f0cc80 into rust-lang:master Jan 19, 2015
@sanxiyn sanxiyn deleted the opt-return-ty branch January 19, 2015 10:33
@@ -297,11 +297,8 @@ fn is_test_fn(cx: &TestCtxt, i: &ast::Item) -> bool {
match &i.node {
&ast::ItemFn(ref decl, _, _, ref generics, _) => {
let no_output = match decl.output {
ast::Return(ref ret_ty) => match ret_ty.node {
Copy link
Contributor

Choose a reason for hiding this comment

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

Removing this variant seems to have broken quickcheck, because the function returned by item_fn seems to use ast::Return, not ast::DefaultReturn. Is this something that needs to be fixed on quickcheck's end, or was the switch from ast::Return(..) => true to => false unintentional?

Copy link
Member Author

Choose a reason for hiding this comment

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

It was intentional, but that is an unfortunate side effect. It can be fixed on quickcheck's end. Whether it needs to be I am less sure, rustc certainly could be more accepting here. Probably both should be fixed.

@sanxiyn
Copy link
Member Author

sanxiyn commented Jan 25, 2015

rustc side will be fixed by #21504.

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.

6 participants