Skip to content

"source trait is private" error with writeln! only when println! isn't used #27669

Closed
@gsingh93

Description

@gsingh93

This error is related to #22050, not sure if it's a dupe. Some of the following code snippets rely on the term library (but the issue seems to be in Rust, not term).

The following builds fine:

fn foo() {
    let mut s = String::new();
    writeln!(s, "foo").unwrap();
}

This gives an error:

extern crate term;

fn foo() {
    let mut t = term::stdout().unwrap();
    writeln!(t, "foo").unwrap();
}

Output:

lib.rs:5:5: 5:23 error: source trait is private
lib.rs:5     writeln!(t, "foo").unwrap();

This is the error mentioned in #22050. Importing std::io::Write fixes the error. However, if println is used, we get no errors:

extern crate term;

fn foo() {
    let mut t = term::stdout().unwrap();
    writeln!(t, "foo").unwrap();
    println!("foo");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions