Skip to content

std::io::Empty that is never read from #11400

Open
@Centri3

Description

@Centri3

What it does

If Empty is constructed yet its implementations of Read/BufRead are never required, we should suggest Sink instead which conveys this purpose better.

We also need to make sure some access does not require a trait outside of std that Sink doesn't implement.

Advantage

  • This restricts it from being read from in the future, if that's undesirable.

Drawbacks

  • This restricts it from being read from in the future, if that's desirable.

Example

use std::io::{prelude::*, empty};

fn b<T: Read>(t: &T) {}

fn a() {
    let mut empty_unused = empty();
    empty_unused.write(&[0]);

    let mut empty_used1 = empty();
    empty_used1.write(&[0]);
    empty_used1.read(&mut []);
    
    let mut empty_used2 = empty();
    b(&empty_used2);
}

Could be written as:

use std::io::{prelude::*, empty, sink};

fn b<T: Read>(t: &T) {}

fn a() {
    let mut empty_unused = sink();
    empty_unused.write(&[0]);

    let mut empty_used1 = empty();
    empty_used1.write(&[0]);
    empty_used1.read(&mut []);
    
    let mut empty_used2 = empty();
    b(&empty_used2);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions