Skip to content

(One representation of) the new gpio::Pin/spi::Spi types appears to kill rust-analyzer #461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ryankurte opened this issue Mar 12, 2022 · 5 comments

Comments

@ryankurte
Copy link
Contributor

ryankurte commented Mar 12, 2022

running rustc 1.61.0, if you happen to try to alias a Pin into an SPI device, rust-analyzer explodes...

type Spi1 = Spi<
        SPI1, 
        (
            Pin<'A', 5, Alternate<5> >,
            Pin<'A', 6, Alternate<5> >,
            Pin<'A', 7, Alternate<5> >,
        ),
        TransferModeNormal,
    >;

tested with rust-analyzer prerelease via vscode and nighly from rustup. this appears to be a reproduction of rust-lang/rust-analyzer#10390, with a suggestion this can be avoided by altering the ordering constraint to types before consts, eg. Pin<MODE = Input<Floating>, const P: char, const N: u8> instead of Pin<const P: char, const N: u8, MODE = Input<Floating>>.

i am not sure whether where is an alternate representation that would not trigger this, or if it is worth changing here or waiting for a fix, but, figured i'd leave some footprints for anyone else that runs into the following errors:


thread '<unnamed>' panicked at 'index out of bounds: the len is 1 but the index is 2', /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/chalk-ir-0.76.0/src/fold/subst.rs:60:19
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:116:14
   2: core::panicking::panic_bounds_check
             at /rustc/9d1b2106e23b1abd32fce1f17267604a5102f57a/library/core/src/panicking.rs:84:5
   3: <chalk_ir::fold::subst::Subst<I> as chalk_ir::fold::Folder<I>>::fold_free_var_ty
   4: <chalk_ir::Ty<I> as chalk_ir::fold::SuperFold<I>>::super_fold_with
   5: chalk_ir::fold::boring_impls::<impl chalk_ir::fold::Fold<I> for chalk_ir::GenericArg<I>>::fold_with
   6: <smallvec::SmallVec<A> as core::iter::traits::collect::Extend<<A as smallvec::Array>::Item>>::extend
...
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
WARN [12/03/2022, 9:42:00 pm]: LSP request failed {
  method: 'rust-analyzer/inlayHints',
  param: {
    textDocument: { uri: 'file:///home/ryan/projects/dsf-sensor/src/pub2.rs' }
  },
  error: [fo [Error]: server panicked: index out of bounds: the len is 1 but the index is 2
  	at Yn (/home/ryan/.vscode/extensions/matklad.rust-analyzer-0.3.963/out/main.js:7:223)
  	at Ln (/home/ryan/.vscode/extensions/matklad.rust-analyzer-0.3.963/out/main.js:6:6732)
  	at Immediate.<anonymous> (/home/ryan/.vscode/extensions/matklad.rust-analyzer-0.3.963/out/main.js:6:6579)
  	at processImmediate (internal/timers.js:461:21)] {
    code: -32603,
    data: undefined
  }
}
@burrbull
Copy link
Member

Sadly.
You could use released version of f4xx-hal until RA fixed.

@burrbull
Copy link
Member

burrbull commented Mar 12, 2022

@ryankurte
Is there error if use just:

use hal::gpio::{PA5, PA6, PA7};

type Spi1 =
    Spi<SPI1, (PA5<Alternate<5>>, PA5<Alternate<5>>, PA7<Alternate<5>>), TransferModeNormal>;

@ryankurte
Copy link
Contributor Author

You could use released version of f4xx-hal until RA fixed.

unfortunately i'm too far along the bleeding edge to back down at this point 🤣

Is there error if use just:

brilliant, that resolves it, thanks! also these changes are -super cool-, having a great experience with the updated HAL, hugely appreciate all your effort stm32-rs folks ^_^

@ryankurte ryankurte changed the title New gpio::Pin/spi::Spi types appear to kill rust-analyzer (One representation of) the new gpio::Pin/spi::Spi types appears to kill rust-analyzer Mar 12, 2022
@burrbull
Copy link
Member

burrbull commented Mar 30, 2022

@ryankurte Is there error if use just:

use hal::gpio::{PA5, PA6, PA7};

type Spi1 =
    Spi<SPI1, (PA5<Alternate<5>>, PA5<Alternate<5>>, PA7<Alternate<5>>), TransferModeNormal>;

Now it's possible also

use hal::gpio::{PA5, PA6, PA7, AF5};

type Spi1 = hal::spi::Spi1<(PA5<AF5>, PA6<AF5>, PA7<AF5>)>;

@ryankurte
Copy link
Contributor Author

ooh nice! looks like y'all are having some real fun with const types ^_^

thanks for all the help, seems like there's lots of good workarounds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants