Skip to contentSlop Block

require-explicit-return

ErrorAutomatic fix

End functions and block closures with return value;. ast-grep scan --update-all fixes it.

fn port() -> u16 {	3000Use an explicit return for this value}

After ast-grep scan --update-all

fn port() -> u16 {	3000	return 3000;}
fn find(id: &UserID) -> Result<User> {	let user = load(id)?;	Ok(user)Use an explicit return for this value}

After ast-grep scan --update-all

fn find(id: &UserID) -> Result<User> {	let user = load(id)?;	Ok(user)	return Ok(user);}
fn status(code: u16) -> &'static str {	match code {Use an explicit return for this value		200 => "ok",		_ => "error",	}}

After ast-grep scan --update-all

fn status(code: u16) -> &'static str {	match code {	return match code {		200 => "ok",		_ => "error",	}	};}
fn empty() -> Vec<u8> {	vec![]Use an explicit return for this value}

After ast-grep scan --update-all

fn empty() -> Vec<u8> {	vec![]	return vec![];}
fn run() {	connection.transaction(async |transaction| {		save(transaction).await?;		Ok(())Use an explicit return for this value	});}

After ast-grep scan --update-all

fn run() {	connection.transaction(async |transaction| {		save(transaction).await?;		Ok(())		return Ok(());	});}
// ast-grep-ignore: require-explicit-return-rust

How to fix

Every function and block closure ends with return value;.