Content-Length: 24473 | pFad | https://doc.rust-lang.org/std/pin/../cmp/../fs/../iter/../../../std/../../error_codes/./E0317.html

E0317 - Error codes index

Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Error code E0317

An if expression is missing an else block.

Erroneous code example:

#![allow(unused)]
fn main() {
let x = 5;
let a = if x == 5 {
    1
};
}

This error occurs when an if expression without an else block is used in a context where a type other than () is expected. In the previous code example, the let expression was expecting a value but since there was no else, no value was returned.

An if expression without an else block has the type (), so this is a type error. To resolve it, add an else block having the same type as the if block.

So to fix the previous code example:

#![allow(unused)]
fn main() {
let x = 5;
let a = if x == 5 {
    1
} else {
    2
};
}








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://doc.rust-lang.org/std/pin/../cmp/../fs/../iter/../../../std/../../error_codes/./E0317.html

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy