-
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
improve error message for "expected ~[T]
but found a ~-box pattern"
#10148
Comments
FWIW, all vector matches are unadorned, e.g. the following all print match ~[1i] { [1i] => true, _ => false }
match @[1i] { [1i] => true, _ => false }
match &[1i] { [1i] => true, _ => false } so matching with a pattern like (I do think that either we should have the matches have sigils (e.g. to match strings), or the error message should be more useful.) |
I would love it if we just dropped |
Same with strings:
results in "mismatched types: expected Using rust pre-nightly from 92f6b92 Edit (Had copied, the wrong error message before, corrected) |
That second error sounds wrong because the types in the brackets don't match the real types. But I think that is a different issue (not sure if there is an issue filed). This issue will either go away or change (hopefully be easier to fix) when DST is finished (#12938) |
Ah yes, you're right. I copied the wrong error message while playing around. rustc complains that I corrected my earlier comment. |
Fixed in #18171. |
Do not panic when analyzing the malformed origin of a format string Fixes rust-lang#10148. This will trigger only when generating format strings while accepting weird things in a procedural macro and setting the span to something which is not a string. changelog: none
Consider this code:
When I attempt to compile it (rustc 0.9-pre (97cd495 2013-10-02 01:16:31 -0700)), I get an error like this:
I do not find the message above useful. My main reaction is: "The whole pattern
~[b]
does look like a so-called ~-box pattern to me, which seems like it should fit the needs of a~[int]
."After inspecting the source code for
_match.rs
, I think the issue is that I need to explicitly borrowa
and then match against&[b]
, like so:though I do not understand why the above compiles, since I would have thought that borrowing a
~[int]
via&a
would mean I should use match clauses of the form e.g.&~[b]
, not&[b]
.In any case, we need a better error message here, preferably one that cross-references further discussion elsewhere, such as an appropriate (hypothetical) section of the rust.md manual. Note that the current rust.md documentation on
match
does not suffice to explain what to do here.The text was updated successfully, but these errors were encountered: