rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.93k stars 12.68k forks source link

rustc span format seems broken: file:line:line:column #79901

Open matthiaskrgr opened 3 years ago

matthiaskrgr commented 3 years ago

repro:

git clone https://github.com/matthiaskrgr/cargo-cache
cd cargo-cache
git checkout rustfmt_bug
cargo fmt
error[internal]: left behind trailing whitespace
   --> /home/matthias/vcs/github/cargo-cache/src/library.rs:147:147:0
    |
147 |
    | ^^^^
    |

warning: rustfmt has failed to format. See previous 1 errors.

This "147:147:0 seems super suspicious, why is printing the column twice in the span location?? rustfmt gets its span information from rustc afaik thus I opened this ticket against rustc.

rustfmt 1.4.29-nightly (70ce182 2020-12-04)

rustc 1.50.0-nightly (f0f68778f 2020-12-09)
binary: rustc
commit-hash: f0f68778f798d6d34649745b41770829b17ba5b8
commit-date: 2020-12-09
host: x86_64-unknown-linux-gnu
release: 1.50.0-nightly
camelid commented 3 years ago

@matthiaskrgr I tried looking at the branch on GitHub, but it doesn't seem to exist. https://github.com/matthiaskrgr/cargo-cache/tree/rustfmt_bug returns a 404.

matthiaskrgr commented 3 years ago

Oh sorry, I forgot to push it :sweat_smile: . It should be online now!

camelid commented 3 years ago

I was able to reproduce this on the playground.

camelid commented 3 years ago

A bug should probably be opened for rustfmt too, right? I don't think this code should make it crash.

matthiaskrgr commented 3 years ago

The error[internal]: left behind trailing whitespace is a rustfmt bug, I agree. This ticket is about the fact that it says /home/matthias/vcs/github/cargo-cache/src/library.rs:147:147:0 instead of /home/matthias/vcs/github/cargo-cache/src/library.rs:147:0 which I suspect to be a bug somewhere in a rustc_ap.* crate that rustfmt is using as dependency.

camelid commented 3 years ago

It's weird that it only seems to be happening in this one instance.

Cerber-Ursi commented 10 months ago

Bumping the topic due to the similar error popping on URLO; minimized example:

fn next() {
    let _ = // This comment causes rustfmt inernal error  
    {
      if true { // whitespace symbol at the end of next line is significant
      } 
    };
}
humb1t commented 10 months ago

Similar problem:

use async_graphql::{Context, EmptyMutation, EmptySubscription, Object, Schema, SimpleObject, ID};
use async_graphql_axum::GraphQL;
use axum::{routing::post_service, Router, Server};

#[derive(SimpleObject, Clone)]
struct Collectible {
    id: ID,
    name: String,
    collection: Collection,
}

#[derive(SimpleObject, Clone)]
#[graphql(unresolvable)]
struct Collection {
    id: String,
}

struct Query;

#[Object]
impl Query {
    #[graphql(entity)]
    async fn collectible_by_id<'a>(&self, ctx: &'a Context<'_>, id: ID) -> Collectible {
        ctx.data_unchecked::<Vec<Collectible>>()
            .iter()
            .find(|collectible| collectible.id == id)
            .unwrap()
            .clone()
    }
}

#[tokio::main]
async fn main() {
    Server::bind(&"0.0.0.0:4003".parse().unwrap())
        .serve(
            Router::new()
                .route("/", post_service(GraphQL::new(Schema::build(Query, EmptyMutation, EmptySubscription)
        .enable_federation()
        .data(vec![
        Collectible {
            id: "ethereum.0xAd2EB4808b817403005ae020B0662825eE021B0F.51".into(),
            name: "A highly effective form of birth control.".into(),
            collection: Collection {
                id: "ethereum.0xAd2EB4808b817403005ae020B0662825eE021B0F".to_string(),
            },
        },
        Collectible {
            id: "ethereum.0x7d256d82b32d8003d1ca1a1526ed211e6e0da9e2.11417".into(),
            name: "Fedoras are one of the most fashionable hats around and can look great with a variety of outfits.".into(),
            collection: Collection {
                id: "ethereum.0x7d256d82b32d8003d1ca1a1526ed211e6e0da9e2".to_string(),
            },   
        },
        Collectible {
            id: "ethereum.0xa58b5224e2fd94020cb2837231b2b0e4247301a6.970".into(),
            name: "This is the last straw. Hat you will wear. 11/10".into(),
            collection:  Collection {
                id: "ethereum.0xa58b5224e2fd94020cb2837231b2b0e4247301a6".to_string(),
            },        
        },
    ])
        .finish().clone())))
                .into_make_service(),
        )
        .await
        .unwrap();
}
error[internal]: left behind trailing whitespace
  --> /Users/bshn/workspace/collections_federation/collectibles/src/main.rs:52:52:15
   |
52 |             },
   |               ^^^
   |

error[internal]: left behind trailing whitespace
  --> /Users/bshn/workspace/collections_federation/collectibles/src/main.rs:59:59:15
   |
59 |             },
   |               ^^^^^^^^
   |

warning: rustfmt has failed to format. See previous 2 errors.

cargo 1.77.0-nightly (363a2d113 2023-12-22)