Closed ajewellamz closed 3 weeks ago
Hey @ajewellamz what exact version of cargo fmt / rustfmt are you using. You can run cargo fmt --version
to get that info.
Also, any chance you can get this down to a reproducible code snippet that you can add inline? That would be best. rustfmt can run just fine on code that doesn't compile (as long as it parses) so my suggestion would be to slowly remove function, struct, enum, macro, and trait definitions / impls from the file until you're able to narrow down what's causing the issue. It would be a great help 🙏🏼
rustfmt 1.7.1-stable (eeb90cda 2024-09-04)
I won't be able to do any work on this until next week at the earliest. I was assuming you could just run it in the debugger or something, if you had a fail case.
Ok, here's a minimal fail case. I've tried deleting various parts, and it seems to always succeed.
pub use ::dafny_runtime::Sequence;
pub use ::std::rc::Rc;
pub use crate::r#_StructuredEncryptionUtil_Compile::CanonCryptoItem;
pub use ::dafny_runtime::itertools::Itertools;
pub use crate::software::amazon::cryptography::dbencryptionsdk::structuredencryption::internaldafny::types::CryptoAction;
pub use crate::software::amazon::cryptography::materialproviders::internaldafny::types::EncryptedDataKey;
pub use ::dafny_runtime::Object;
pub use crate::software::amazon::cryptography::primitives::internaldafny::types::IAwsCryptographicPrimitivesClient;
pub use crate::software::amazon::cryptography::materialproviders::internaldafny::types::AlgorithmSuiteInfo;
pub use ::dafny_runtime::DafnyCharUTF16;
pub use crate::r#_StructuredEncryptionUtil_Compile::MessageID;
pub use crate::software::amazon::cryptography::materialproviders::internaldafny::types::EncryptionMaterials;
pub use crate::r#_Wrappers_Compile::Outcome;
pub use ::dafny_runtime::string_utf16_of;
pub use ::dafny_runtime::int;
pub use ::dafny_runtime::MapBuilder;
pub use ::dafny_runtime::_System::nat;
pub use crate::software::amazon::cryptography::primitives::internaldafny::types::HMacInput;
pub use ::dafny_runtime::rd;
pub use ::dafny_runtime::truncate;
pub use ::dafny_runtime::DafnyTypeEq;
pub use ::dafny_runtime::DafnyType;
Thanks! confirming that with rustfmt +1.81
(rustfmt 1.7.1-stable (eeb90cda 2024-09-04)
) I'm able to reproduce the panic with the above example:
I just ran into this trying to rustfmt some pretty terrifying expanded macro code. I found the reduced example above more useful to debug than the mess I had. I was not particularly successful in finding the issue but the issue appears to be in Ord
for UseSegment
somewhere. I'm guessing the issue might be that the different kind pairs are not given a total order?
Still broken in Rust 1.82, not surprising since rustfmt is still 1.7.1-stable
I was trying to fix this myself, but I'm having trouble building it.
I assumed that all I had to do was
git clone git@github.com:rust-lang/rust.git
cd rust/src/tools/rustfmt
git checkout 1.82.0 # same failure with or without this step
cargo build
but that fails to build, with 40 compile time errors in various file within src/tools/rustfmt/src
Am I missing something?
You want to clone the rustfmt repo, not the rust-lang/rust
repo.
git clone https://github.com/rust-lang/rustfmt.git
cd rustfmt
cargo build # should automatically install the relevant toolchain / components
Thanks, that works.
I've found the problem, but I'm not sure of the proper fix
Ord for UseSegment
is not transitive.
In imports.rs
there exists impl Ord for UseSegment {
within that function is
match (&self.kind, &other.kind) {
...
(Ident(ref pia, ref aa), Ident(ref pib, ref ab)) => {
...
1) if ia.starts_with(char::is_uppercase) && ib.starts_with(char::is_lowercase) {
return Ordering::Greater;
}
2) if ia.starts_with(char::is_lowercase) && ib.starts_with(char::is_uppercase) {
return Ordering::Less;
}
3) if is_upper_snake_case(ia) && !is_upper_snake_case(ib) {
return Ordering::Greater;
}
4) if !is_upper_snake_case(ia) && is_upper_snake_case(ib) {
return Ordering::Less;
}
5) ia.cmp(ib)
let A = DafnyType let B = _System let C = truncate
A < B by 5) B < C by 5) A > C by 1)
hence user-provided comparison function does not correctly implement a total order
lib.rs.gz
Un-gzip the attached lib.rs make it the only file in a crate run
cargo fmt
SeeAs an aside - with previous versions of Rust, cargo fmt also failed on this file. It didn't crash, but it left trailing spaces on some lines, and then reported failure.