Skip to content

Idea: Unintentional borrowing with &str return. #305

Closed
@bluss

Description

@bluss

This can happen, where the user uses string literals but unintentionally borrows self.

fn foo(&self) -> Result<(), &str> { Err("error") }

The lint should suggest &'static str in the return type to avoid false borrowing, if the function body uses &'static str. I guess Error::description(&self) -> &str is an exception, the borrowing is mandated by the trait.

Metadata

Metadata

Assignees

Labels

A-lintArea: New lintsE-mediumCall for participation: Medium difficulty level problem and requires some initial experience.T-middleType: Probably requires verifiying types

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions