rust-lang / rust-lang/rustfmt

thread 'main' panicked at 'bad span: `.`: ``', src/tools/rustfmt/src/source_map.rs:52:13

Open
#5,716 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug E-needs-test
Dominant language
Rust
Stars
7k
Forks
1.1k
Avg merge
2d 13h
Merged PRs (30d)
24

Description

#[derive(Debug)]
struct S(String);

#[derive(Debug)]
struct T(S);


fn no_ref_nested() {
    let mut t = T(S());
    let c = || {
        println!("{:?}", t.0);
        let mut c = move || {
            t.0.10i32 = "new S".into();
            println!("{:?}", t.0.0);
        };
        c();
    };
    c();
}


fn main() {
    no_ref_nested();
}
warning: suffixes on a tuple index are invalid
  --> /tmp/im/2F2289E79BEA4CD52EB15181FD6F33470C0267578597C72C401DEA25348F0F1B.rs:13:15
   |
13 |             t.0.10i32 = "new S".into();
   |               ^^^^^^^ invalid suffix `i32`
   |
   = help: `i32` is *temporarily* accepted on tuple index fields as it was incorrectly accepted on stable for a few releases
   = help: on proc macros, you'll want to use `syn::Index::from` or `proc_macro::Literal::*_unsuffixed` for code that will desugar to tuple field access
   = help: see issue #60210 <https://github.com/rust-lang/rust/issues/60210> for more information

thread 'main' panicked at 'bad span: `.`: ``', src/tools/rustfmt/src/source_map.rs:52:13
stack backtrace:
   0: rust_begin_unwind
             at /rustc/ab654863c3d50482f260cf862647f1fe0ff5e010/library/std/src/panicking.rs:579:5
   1: core::panicking::panic_fmt
             at /rustc/ab654863c3d50482f260cf862647f1fe0ff5e010/library/core/src/panicking.rs:64:14
   2: <rustfmt_nightly::visitor::SnippetProvider as rustfmt_nightly::source_map::SpanUtils>::span_before
   3: rustfmt_nightly::chains::rewrite_chain
   4: rustfmt_nightly::expr::format_expr
   5: rustfmt_nightly::expr::rewrite_assignment
   6: rustfmt_nightly::expr::format_expr
   7: rustfmt_nightly::stmt::format_stmt
   8: <rustfmt_nightly::visitor::FmtVisitor>::walk_stmts
   9: <rustfmt_nightly::visitor::FmtVisitor>::visit_block
  10: rustfmt_nightly::expr::rewrite_block_with_visitor
  11: rustfmt_nightly::expr::rewrite_block
  12: rustfmt_nightly::expr::format_expr
  13: rustfmt_nightly::closures::rewrite_closure_expr
  14: rustfmt_nightly::closures::rewrite_closure
  15: rustfmt_nightly::expr::format_expr
  16: rustfmt_nightly::expr::rewrite_assign_rhs_expr::<rustc_ast::ast::Expr>
  17: rustfmt_nightly::expr::rewrite_assign_rhs_with::<alloc::string::String, rustc_ast::ast::Expr>
  18: <rustc_ast::ast::Local as rustfmt_nightly::rewrite::Rewrite>::rewrite
  19: rustfmt_nightly::stmt::format_stmt
  20: <rustfmt_nightly::visitor::FmtVisitor>::walk_stmts
  21: <rustfmt_nightly::visitor::FmtVisitor>::walk_stmts
  22: <rustfmt_nightly::visitor::FmtVisitor>::visit_block
  23: rustfmt_nightly::expr::rewrite_block_with_visitor
  24: rustfmt_nightly::expr::rewrite_block
  25: rustfmt_nightly::expr::format_expr
  26: rustfmt_nightly::closures::rewrite_closure_expr
  27: rustfmt_nightly::closures::rewrite_closure
  28: rustfmt_nightly::expr::format_expr
  29: rustfmt_nightly::expr::rewrite_assign_rhs_expr::<rustc_ast::ast::Expr>
  30: rustfmt_nightly::expr::rewrite_assign_rhs_with::<alloc::string::String, rustc_ast::ast::Expr>
  31: <rustc_ast::ast::Local as rustfmt_nightly::rewrite::Rewrite>::rewrite
  32: rustfmt_nightly::stmt::format_stmt
  33: <rustfmt_nightly::visitor::FmtVisitor>::walk_stmts
  34: <rustfmt_nightly::visitor::FmtVisitor>::walk_stmts
  35: <rustfmt_nightly::visitor::FmtVisitor>::visit_block
  36: <rustfmt_nightly::visitor::FmtVisitor>::visit_fn
  37: <rustfmt_nightly::visitor::FmtVisitor>::visit_item
  38: <rustfmt_nightly::visitor::FmtVisitor>::visit_items_with_reordering
  39: <rustfmt_nightly::visitor::FmtVisitor>::walk_mod_items
  40: <rustfmt_nightly::visitor::FmtVisitor>::format_separate_mod
  41: rustfmt_nightly::formatting::format_project::<rustfmt_nightly::Session<std::io::stdio::Stdout>>
  42: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::with::<<rustfmt_nightly::Session<std::io::stdio::Stdout>>::format_input_inner::{closure#0}, core::result::Result<rustfmt_nightly::FormatReport, rustfmt_nightly::ErrorKind>>
  43: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_span::create_session_if_not_set_then<core::result::Result<rustfmt_nightly::FormatReport, rustfmt_nightly::ErrorKind>, <rustfmt_nightly::Session<std::io::stdio::Stdout>>::format_input_inner::{closure#0}>::{closure#0}, core::result::Result<rustfmt_nightly::FormatReport, rustfmt_nightly::ErrorKind>>
  44: <rustfmt_nightly::Session<std::io::stdio::Stdout>>::format
  45: rustfmt::format_and_emit_report::<std::io::stdio::Stdout>
  46: <rustfmt_nightly::Session<std::io::stdio::Stdout>>::override_config::<rustfmt::format::{closure#0}, ()>
  47: rustfmt::execute
  48: rustfmt::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

rustfmt 1.5.2-nightly (ab65486 2023-03-15)
bad_span.zip

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the panic with the Rust snippet or bad_span.zip, then start at src/tools/rustfmt/src/source_map.rs:52 and follow the stack into chains::rewrite_chain. Done means rustfmt no longer panics on this input and completes formatting.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.