-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
For this error:
error[E0277]: the trait bound `std::option::Option<&Symbol>: std::ops::FnOnce<()>` is not satisfied
--> JackCompiler.rs:302:19
|
302 | let b = a.or_else(self.subroutine_symbols.get(name));
| ^^^^^^^ the trait `std::ops::FnOnce<()>` is not implemented for `std::option::Option<&Symbol>`
error: aborting due to previous error
The compiler can suggest adding a closure here. I'm honestly not sure what the issue is myself and I find optional and result chaining very difficult to use in Rust as compared to a language like Swift. However, changing it to a closure by adding "|| " fixed the error for me.
estebank
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
estebank commentedon Jul 26, 2018
The traits
Fn
:rust/src/libcore/ops/function.rs
Line 70 in fefe816
FnOnce
:rust/src/libcore/ops/function.rs
Line 216 in fefe816
and
FnMut
:rust/src/libcore/ops/function.rs
Line 143 in fefe816
need to have a
#[rustc_on_unimplemented]
attribute added, with anote
suggesting the use of a closure and a short explanation of why the attempted code doesn't work.lorian7392 commentedon Aug 3, 2018
i'm a noob, but I would like to take this on if nobody else is working on that.
lorian7392 commentedon Aug 11, 2018
Hello @estebank , I am sorry that I have not worked before, because this time is working overtime.Now I built the compiler and tried adding the #[rustc_on_unimplemented] property, but I have some questions.
How does (crate_local, label='xxxx', note='xxx') in #[rustc_on_unimplemented] work? Is there any relevant information? Because I use the method in the example, but it doesn't work. Thank you very much for your help.
estebank commentedon Aug 11, 2018
crate_local
filtering was added here. The machinery that parsesrustc_on_unmplemented
now lives here.[
crate_local
is a flag added inerror_reporting.rs
only if the current evaluated scope is part of the local crate](rust/src/librustc/traits/error_reporting.rs
Lines 394 to 396 in 0aa8d03
crate_local
rule was inrustc_on_unimplemented
, then the following message/label/note will be shown. This is done so we can suggest code changes that are only valid if you have access to the source and we don't suggest, for example, changing code in Diesel, Serde or another dependency. These flags, IIRC, only work withon
, as in#[rustc_on_unimlpemented(on(crate_local, note="the note"))]
.Try first annotating with
#[rustc_on_unimplemented(note="test")]
to see if anything actually comes up, as I am now worried that there might be some special handling of closure traits.Regardless, you can filter on any of the type arguments (including
Self
) as well, in the following way:#[rustc_on_unimlpemented(note="regular note", on(Args="()", note="the note if Fn<()>"))]
.The documentation for the feature is at https://doc.rust-lang.org/unstable-book/language-features/on-unimplemented.html, but it is a bit out of date.
estebank commentedon Aug 11, 2018
Extended the documentation a bit in #53279.
lorian7392 commentedon Aug 12, 2018
hi @estebank . i try first annotating with #[rustc_on_unimplemented(note="test")] , but it not work. and
#[rustc_on_unimplemented = "test"] can work
estebank commentedon Aug 12, 2018
@LuGuoHuas I took a look to see what was needed and arrived at this #53296
Rollup merge of rust-lang#53296 - estebank:suggest-closure, r=KodrAus