Skip to content

Conversation

@dtolnay
Copy link
Contributor

@dtolnay dtolnay commented Oct 15, 2025

Example:

use codespan_reporting::diagnostic::{Diagnostic, Label};
use codespan_reporting::files::SimpleFiles;
use codespan_reporting::term::termcolor::{ColorChoice, StandardStream};
use codespan_reporting::term::{self, Config, WriteStyle};

fn main() {
    let writer = StandardStream::stderr(ColorChoice::Auto);
    repro(&mut writer.lock());
}

fn repro(stderr: &mut dyn WriteStyle) {
    let mut files = SimpleFiles::new();
    let file = files.add("-", "...");

    let mut diagnostic = Diagnostic::error().with_message("...");
    diagnostic.labels.push(Label {
        message: "...".to_owned(),
        ..Label::primary(file, 1..2)
    });

    let config = Config::default();
    let _ = term::emit_to_write_style(stderr, &config, &files, &diagnostic);
}

This used to work in codespan-reporting 0.12.0 (with 2 minor substitutions, term::emit_to_write_style -> term::emit and term::WriteStyle -> term::termcolor::WriteColor) but fails to compile in codespan-reporting 0.13.0 due to missing ?Sized bounds.

error[E0277]: the size for values of type `dyn WriteStyle` cannot be known at compilation time
  --> src/main.rs:22:39
   |
22 |     let _ = term::emit_to_write_style(stderr, &config, &files, &diagnostic);
   |             ------------------------- ^^^^^^ doesn't have a size known at compile-time
   |             |
   |             required by a bound introduced by this call
   |
   = help: the trait `Sized` is not implemented for `dyn WriteStyle`
note: required by an implicit `Sized` bound in `emit_to_write_style`
  --> $CARGO_HOME/registry/src/index.crates.io-1949cf8c6b5b557f/codespan-reporting-0.13.0/src/term/mod.rs:80:63
   |
80 | pub fn emit_to_write_style<'files, F: Files<'files> + ?Sized, W: WriteStyle>(
   |                                                               ^ required by the implicit `Sized` requirement on this type parameter in `emit_to_write_style`

@kaleidawave kaleidawave merged commit a77bee5 into brendanzab:master Oct 17, 2025
8 checks passed
@dtolnay dtolnay deleted the byref branch October 17, 2025 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants