Dioxius macros confuse rustfmt
Rustfmt formats:
fn Layout() -> Element {
fn Links() -> Element {
rsx! {
nav {
ul {
id: "main-nav",
class: "nav nav-pills",
for item in RouteDiscriminants::iter() {
MenuItem { item }
}
}
}
}
}
rsx! {
header {
class: "text-bg-dark d-flex justify-content-center py-3",
Links {}
}
main {
class: "col-lg-8 mx-auto p-4 py-md-5",
Outlet::<Route> { }
}
}
}
into:
fn Layout() -> Element {
fn Links() -> Element {
rsx! {
nav {
ul {
id: "main-nav",
class: "nav nav-pills",
for item in RouteDiscriminants::iter() {
MenuItem { item }
}
}
}
}
}
rsx! {
header {
class: "text-bg-dark d-flex justify-content-center py-3",
Links {}
}
main {
class: "col-lg-8 mx-auto p-4 py-md-5",
Outlet::<Route> { }
}
}
}
@uzytkownik what version of rustfmt are you using? I'm unable to reproduce the issue locally building rustfmt from source.
@ytmimi Hmm. It looks something very strange goes on with tabs. It looks like rustfmt does not convert them into spaces which seems to be strange. I would expect based on documentation to have them converted into spaces by default- hard_tabs.
Outside of that it seems to be mismatch of tab_spaces between rustfmt and editor. I disabled tabs in editor fixing the problem but it seems to me that behaviour should be clarified in documentation or (even better) hard_tabs would convert them into spaces.
Also, which configuration options are you using?
@ytmimi None. I just run cargo fmt. No configuration.
Got it, so this was just a mismatch between rustfmt and your editors settings?
@ytmimi Sorry. As proximate cause (which was confusing for me) yes. Though I assumed by default cargo fmt converts to spaces based on hard_tabs documentation.
I'm not sure if the issue is with rustfmt. I ran a little test, and it seems that when hard_tabs=false is set leading tab characters are replaced with spaces based on the value of tab_spaces.
Given the following input that uses tabs:
fn Layout() -> Element {
fn Links() -> Element {
rsx! {
nav {
ul {
id: "main-nav",
class: "nav nav-pills",
for item in RouteDiscriminants::iter() {
MenuItem { item }
}
}
}
}
}
rsx! {
header {
class: "text-bg-dark d-flex justify-content-center py-3",
Links {}
}
main {
class: "col-lg-8 mx-auto p-4 py-md-5",
Outlet::<Route> { }
}
}
}
Running rustfmt with hard_tabs=false (the default, but I explicitly configured it) outputs:
fn Layout() -> Element {
fn Links() -> Element {
rsx! {
nav {
ul {
id: "main-nav",
class: "nav nav-pills",
for item in RouteDiscriminants::iter() {
MenuItem { item }
}
}
}
}
}
rsx! {
header {
class: "text-bg-dark d-flex justify-content-center py-3",
Links {}
}
main {
class: "col-lg-8 mx-auto p-4 py-md-5",
Outlet::<Route> { }
}
}
}
Let me know if you're able to recreate the scenario (and provide sample input) that lead to the odd indentation you noted in your original comment
@uzytkownik it's been a while since I've heard from you on this, and I'm still unable to reproduce the error so I'm going to close this.