Skip to content

Regression in macro error spans #33884

@sophiajt

Description

@sophiajt
Contributor

I'm seeing a regression in error spans for this use case:

use std::net::TcpListener;
use std::net::TcpStream;
use std::io::{self, Read, Write};

fn handle_client(stream: TcpStream) -> io::Result<()> {
    stream.write_fmt(format!("message received"))
}

fn main() {
    if let Ok(listener) = TcpListener::bind("127.0.0.1:8080") {
        for incoming in listener.incoming() {
            if let Ok(stream) = incoming {
                handle_client(stream);
            }
        }
    }
}

On 5-19-2016, the error span looks okay:

error: mismatched types [--explain E0308]
 --> macro_errors_small.rs:7:22
7 |>     stream.write_fmt(format!("message received"))
  |>                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `std::fmt::Arguments`, found struct `std::string::String`
macro_errors_small.rs:7:22: 7:49: note: in this expansion of format! (defined in <std macros>)
note: expected type `std::fmt::Arguments<'_>`
note:    found type `std::string::String`

On 5-20-2016, the error span became less helpful:

error: mismatched types [--explain E0308]
 --> <std macros>:2:1
2 |> $ crate :: fmt :: format ( format_args ! ( $ ( $ arg ) * ) ) )
  |> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `std::fmt::Arguments`, found struct `std::string::String`
macro_errors_small.rs:7:22: 7:49: note: in this expansion of format! (defined in <std macros>)
note: expected type `std::fmt::Arguments<'_>`
note:    found type `std::string::String`

It's possible it's related to #33683 (cc @nikomatsakis and @sanxiyn) but I haven't done the full bisect.

Activity

jseyfried

jseyfried commented on May 28, 2016

@jseyfried
Contributor

This was caused by #33712.

sophiajt

sophiajt commented on Jun 22, 2016

@sophiajt
ContributorAuthor

Noticing the same issue with src/test/compile-fail/bad-format-args.rs

estebank

estebank commented on Apr 20, 2017

@estebank
Contributor

Current output is back to what it was before:

error[E0308]: mismatched types
 --> <anon>:6:22
  |
6 |     stream.write_fmt(format!("message received"))
  |                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `std::fmt::Arguments`, found struct `std::string::String`
  |
  = note: expected type `std::fmt::Arguments<'_>`
             found type `std::string::String`
  = note: this error originates in a macro outside of the current crate
nikomatsakis

nikomatsakis commented on Apr 20, 2017

@nikomatsakis
Contributor

@estebank is there a regression test? if so, shall we close this issue?

added a commit that references this issue on Apr 21, 2017
903bdfc
added 4 commits that reference this issue on Apr 21, 2017
674f728
38439cc
7ac821d
df72158
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lints

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nikomatsakis@sophiajt@bstrie@estebank@jseyfried

        Issue actions

          Regression in macro error spans · Issue #33884 · rust-lang/rust