-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Suggest solutions for fn foo(&foo: Foo)
#38605
Changes from 2 commits
5598f35
f2dd75c
563ecc1
59d7d4c
d723e02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
struct Foo { | ||
} | ||
|
||
fn foo(&foo: Foo) { // illegal syntax | ||
} | ||
|
||
fn bar(foo: Foo) { // legal | ||
} | ||
|
||
fn qux(foo: &Foo) { // legal | ||
} | ||
|
||
fn zar(&foo: &Foo) { // legal | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-38371.rs:14:8 | ||
| | ||
14 | fn foo(&foo: Foo) { // illegal syntax | ||
| ^^^^ expected struct `Foo`, found reference | ||
| | ||
= note: expected type `Foo` | ||
= note: found type `&_` | ||
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. I don't think we have to fix this here necessarily, but I feel like these 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. For a while I've been thinking wether it would make sense to make the
If you feel there'd be value on that, I could create an issue and start a PR for it. 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. I agree that looks better 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. |
||
= help: did you mean `foo: &Foo`? | ||
|
||
error: aborting due to previous error | ||
|
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.
One concern -- what happens in more extreme cases? I think we should check that the inner pattern (represented by
inner
, here) is a binding pattern, so as not to trigger for something likefn foo(&&bar: &u32)
orfn foo(&[bar]: &u32)
. Suggesting&bar: &&u32
and[bar]: &&u32
respectively doesn't seem all that helpful (that is what we will do, right?)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.
I tried adding these cases to the test and the results where:
without changes to the code.
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.
So, the first one is a case of needing a feature-gate, but I'm surprised by the second one. What does
&&bar: &Foo
do? I can't tell why the help doesn't trigger here...?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.
Neither can I. I've never even thought about trying to use something like
(&&bar: &u32)
.I figured as much. Last time I looked at this I couldn't find the appropriate feature gate, but just googled again and found it. I added the test back.
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.
Maybe I'll pull your branch and build it locally and try to figure out what is going on then. I mean the tests look pretty good but I'd rather not enable misleading output if we can help it. Might take a day or two though.