Repository navigation
E0277 explanation when using optional chaining can be improved #49694
Description
Activity
- addedC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-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.
on Jun 29, 2018 The traits
Fn:
rust/src/libcore/ops/function.rs
Line 70 in fefe816
pub trait Fn<Args> : FnMut<Args> { FnOnce:
rust/src/libcore/ops/function.rs
Line 216 in fefe816
pub trait FnOnce<Args> { and
FnMut:
rust/src/libcore/ops/function.rs
Line 143 in fefe816
pub trait FnMut<Args> : FnOnce<Args> { need to have a
#[rustc_on_unimplemented]attribute added, with anotesuggesting the use of a closure and a short explanation of why the attempted code doesn't work.- addedE-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.
on Jul 26, 2018 i'm a noob, but I would like to take this on if nobody else is working on that.
Reacted by Esteban KuberHello @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.crate_localfiltering was added here. The machinery that parsesrustc_on_unmplementednow lives here.[
crate_localis a flag added inerror_reporting.rsonly if the current evaluated scope is part of the local crate](being compiled (in other words, your code). This means that if that flag is present, andrust/src/librustc/traits/error_reporting.rs
Lines 394 to 396 in 0aa8d03
if let Some(true) = self_ty.ty_adt_def().map(|def| def.did.is_local()) { flags.push(("crate_local".to_string(), None)); } crate_localrule 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.
Extended the documentation a bit in #53279.
hi @estebank . i try first annotating with #[rustc_on_unimplemented(note="test")] , but it not work. and
#[rustc_on_unimplemented = "test"] can work@LuGuoHuas I took a look to see what was needed and arrived at this #53296
- added a commit that references this issue
on Aug 20, 2018
For this 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.