You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rustfmt can't parse nested structs nested numerical accessors for structs
File will not parse when it contains a line like let turnirs_instances = Turnirs::get(&mut conn, info.0.0).unwrap();. Note the variable info which contains a single element, which in turn, also contains a single element. Both accessed via the index notation. The sample code, where I actually encountered the error is using Actix web framework but that is not what we should focus on.
To Reproduce
#[get("/{turnirsid}")]pubasyncfnturnirs_single_handler(info: web::Path<(u32,)>,tmpl: web::Data<tera::Tera>,) -> Result<HttpResponse,Error>{letmut conn = DB_WRAPPER.get_conn();// this is where the error happenslet turnirs_instances = Turnirs::get(&mut conn, info.0.0).unwrap();let turnirs_results = Turnirs::count_turnirs_summary(&mut conn, info.0.0).unwrap();letmut context = Context::new();
context.insert("turnirs",&turnirs_instances);// Note the incorrecto formatting below
context.insert("turnirs_result",&turnirs_results);let s = tmpl
.render("turnirs/turnirs_single.html",&context).map_err(|_| error::ErrorInternalServerError("Template error"))?;Ok(HttpResponse::Ok().content_type("text/html").body(s))}
If (for testing purposes) the variable accessor is changed to from info.0.0 to info.0 then the code snippet formats properly
Expected behaviour
#[get("/{turnirsid}")]pubasyncfnturnirs_single_handler(info: web::Path<(u32,)>,tmpl: web::Data<tera::Tera>,) -> Result<HttpResponse,Error>{letmut conn = DB_WRAPPER.get_conn();let turnirs_instances = Turnirs::get(&mut conn, info.0.0).unwrap();let turnirs_results = Turnirs::count_turnirs_summary(&mut conn, info.0.0).unwrap();letmut context = Context::new();// Note the code is formatted correctly here
context.insert("turnirs",&turnirs_instances);
context.insert("turnirs_result",&turnirs_results);let s = tmpl
.render("turnirs/turnirs_single.html",&context).map_err(|_| error::ErrorInternalServerError("Template error"))?;Ok(HttpResponse::Ok().content_type("text/html").body(s))}
Meta
Note the edition only exists because of the async next to the function.
$ rustfmt src/views/same.rs --edition 2018
thread 'main' panicked at 'bad span: `.`: ``', src/tools/rustfmt/src/source_map.rs:52:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Rustfmt can't parse nested structs nested numerical accessors for structs
File will not parse when it contains a line like
let turnirs_instances = Turnirs::get(&mut conn, info.0.0).unwrap();
. Note the variableinfo
which contains a single element, which in turn, also contains a single element. Both accessed via the index notation. The sample code, where I actually encountered the error is using Actix web framework but that is not what we should focus on.To Reproduce
If (for testing purposes) the variable accessor is changed to from
info.0.0
toinfo.0
then the code snippet formats properlyExpected behaviour
Meta
Note the
edition
only exists because of theasync
next to the function.rustfmt
,cargo-fmt
, via VSCode. all of them fail to parse the file with selectors like this.A workaround is to use accessors like
(info.0).0
, but if it wasn't enforced by the compiler then I would not write this bug report.The text was updated successfully, but these errors were encountered: