Rustfmt: cannot find type `MmapSerializationSink` in crate `measureme`

Created on 20 Apr 2020  路  8Comments  路  Source: rust-lang/rustfmt

I updated dependencies without the Cargo.lock committed and how I can't build with rustc stable or nightly with any of these versions:

# rustfmt-nightly = "*"
# rustfmt-nightly = "=1.4.11"
# rustfmt_lib = "=2.0.0-rc.1"
rustfmt_lib = { git = "https://github.com/rust-lang/rustfmt" }

I keep getting this error:

error[E0412]: cannot find type `MmapSerializationSink` in crate `measureme`
   --> /Users/cameron/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-ap-rustc_data_structures-654.0.0/profiling.rs:103:37
    |
103 | type SerializationSink = measureme::MmapSerializationSink;
    |                                     ^^^^^^^^^^^^^^^^^^^^^ help: a trait with a similar name exists: `SerializationSink`
    | 
   ::: /Users/cameron/.cargo/registry/src/github.com-1ecc6299db9ec823/measureme-0.7.1/src/serialization.rs:14:1
    |
14  | pub trait SerializationSink: Sized + Send + Sync + 'static {
    | ---------------------------------------------------------- similarly named trait `SerializationSink` defined here

error[E0425]: cannot find function `get_resident` in this scope
   --> /Users/cameron/.cargo/registry/src/github.com-1ecc6299db9ec823/rustc-ap-rustc_data_structures-654.0.0/profiling.rs:585:28
    |
585 |     let mem_string = match get_resident() {
    |                            ^^^^^^^^^^^^ not found in this scope

error: aborting due to 2 previous errors
blocked

All 8 comments

Hi @ctaggart - Could you provide more context?

Are you trying to build something that is using rustfmt as a lib? What's the version of rust you're using?

rustfmt has the rustc-ap-* crates in its dependency tree, both on the master branch in this repo as well as the most recent 1.4.14 release. However, all the dependencies within the rustfmt tree, including rustc-ap-rustc_data_structures, are compiling successfully on the latest nightly (as well as the previous several nightlies that I have locally)

$ rustc -Vv
rustc 1.44.0-nightly (dbf8b6bf1 2020-04-19)
binary: rustc
commit-hash: dbf8b6bf116c7bece2987ff4bd2792f008a6ee77
commit-date: 2020-04-19
host: x86_64-unknown-linux-gnu
release: 1.44.0-nightly
LLVM version: 9.0

Hi @calebcartwright, thanks for the quick reply. I reproduced the issue here:
https://github.com/ctaggart/rustfmt_4132

It gets that error only when I target wasm:
cargo build --target wasm32-unknown-unknown

I'm wanting to embed formatting in a wasm app. The code I had from months ago was based on how RLS was using rustfmt.

https://github.com/ctaggart/rustfmt_4132/blob/master/src/lib.rs

use rustfmt_nightly::{Config, Edition, EmitMode, Input, Session, Verbosity};

fn format(source: String) -> String {
    // https://github.com/rust-lang/rls/blob/master/rls/src/actions/format.rs
    let mut config = Config::default();
    config.set().edition(Edition::Edition2018);
    config.set().emit_mode(EmitMode::Stdout);
    config.set().skip_children(true);
    config.set().verbose(Verbosity::Quiet);
    let mut buf = Vec::<u8>::new();
    {
        let mut session = Session::new(config, Some(&mut buf));
        session.format(Input::Text(source)).unwrap();
    }
    String::from_utf8(buf).unwrap()
}

If there is a better way to do this with the new rustfmt_lib with less dependencies, I'd love to know.

I opened up https://github.com/rust-lang/rust/pull/71369 with a possible fix. I'd still really like to know how to do the above with the new rustfmt_lib.

Out of curiosity, could you tell us a little more about your case and what you're planning on using the rustfmt lib for/what kind of formatting capabilities your app will provide? There's not many consumers of the rustfmt lib (RLS is the only one I know of that uses it to provide formatting in editors/IDEs) so it'd be helpful to know another use case anyways.

If there is a better way to do this with the new rustfmt_lib with less dependencies, I'd love to know.

rustfmt is always (or at least for the very extended forseeable future) going to require nightly to compile and have dependencies on the rustc internals because it needs parsing support for all the latest and greatest syntax as quickly as possible.

These internal APIs are inherently dynamic, and honestly not really intended for outside consumers. They regularly contain breaking changes which starts an upgrade dance involving rustfmt, racer, and rls (all of which have to be updated in coordination when new versions of those rustc internals are needed in any one of those projects).

Adding the rustfmt lib into your project's dependency tree will likely subject your project to some of these same challenges. I'm not saying you shouldn't do so, just wanted you to be aware :smile:

@ctaggart Thank you for the report! We can test whether the PR fixes this issue by updating rustc-ap-* crates to the version which includes the fix. These crates get published automatically every week, so we may need to wait an additional week or so after the PR gets merged.

My use case is to generate and format code from a wasm. The code generation is working, but I need it formatted and that is where rustfmt comes in. I'm okay with nightly. Thanks for the update on the timeline. Hopefully this is the only blocker and not just the first one.

Looks like the upstream PR was merged so those changes will be available in the next rustc-ap-* release (Tuesday)

This particular issue was fixed by updating to rustc 646 in #4157. I got rustfmt_lib working from wasm with a couple more fixes that will probably be rustc 658. See https://github.com/rust-lang/rust/pull/72017 .

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fulara picture fulara  路  4Comments

thomaseizinger picture thomaseizinger  路  3Comments

ratmice picture ratmice  路  3Comments

MoSal picture MoSal  路  5Comments

jonhoo picture jonhoo  路  4Comments