Skip to content

Getting "error: mismatched types: expected std::result::Result<(BUG[0u],uint),~str>..." #10031

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
utkarshkukreti opened this issue Oct 23, 2013 · 4 comments · Fixed by #11851
Closed

Comments

@utkarshkukreti
Copy link
Contributor

I'm getting the following error when trying to compile a library I wrote - https://github.com/utkarshkukreti/parley.rs

➜ r1 git:(master) make
test/parser_test.rs:5:41: 16:3 error: mismatched types: expected `std::result::Result<(BUG[0u],uint),~str>` but found `std::result::Result<(~str,<VI2>),~str>` (expected type parameter but found ~str)
test/parser_test.rs:5 let zero: Parser<~str> = do Parser |s| {
test/parser_test.rs:6 match s.len() {
test/parser_test.rs:7 0 => Err(~"Expected `0` but found EOF"),
test/parser_test.rs:8 _ => {
test/parser_test.rs:9 match s[0] as char {
test/parser_test.rs:10 '0' => Ok((~"Yes!", 1)),
...
test/parser_test.rs:5:27: 16:3 error: mismatched types: expected `parley::parser::Parser<~str>` but found `parley::parser::Parser<BUG[0u]>` (expected ~str but found type parameter)
test/parser_test.rs:5 let zero: Parser<~str> = do Parser |s| {
test/parser_test.rs:6 match s.len() {
test/parser_test.rs:7 0 => Err(~"Expected `0` but found EOF"),
test/parser_test.rs:8 _ => {
test/parser_test.rs:9 match s[0] as char {
test/parser_test.rs:10 '0' => Ok((~"Yes!", 1)),
...
error: aborting due to 2 previous errors
task '<unnamed>' failed at 'explicit failure', /Users/utkarsh/dev/git/rust/src/libsyntax/diagnostic.rs:98
task '<unnamed>' failed at 'explicit failure', /Users/utkarsh/dev/git/rust/src/librustc/rustc.rs:395
make: *** [test] Error 101

utkarshkukreti/parley.rs@9b8ac76 is the commit which caused this; just a re-arrangement of the code, making the core part of the library a crate.

I grepped the error message in the Rust's codebase, and found only one result - https://github.com/mozilla/rust/blob/8c97c5ebfd64de87b3868fc8dbfd79a74c4be3cb/src/librustc/util/ppaux.rs#L449 which says

                  // This should not happen...
                  format!("BUG[{:?}]", id)
@utkarshkukreti
Copy link
Contributor Author

I've made a reduced test case here - https://gist.github.com/37693cca7676c3033d22

➜ cat mod.rs
#[link(name = "min", vers = "0.1")];

pub struct Wrap<A>(A);
➜ cat test.rs
extern mod min;

#[test]
fn min_test() {
  let x: min::Wrap<int> = min::Wrap(10);
}
➜ rustc --lib mod.rs
warning: no debug symbols in executable (-arch x86_64)
➜ rustc --test -L . test.rs
test.rs:5:36: 5:38 error: mismatched types: expected `BUG[0u]` but found `<VI0>` (expected type parameter but found integral variable)
test.rs:5   let x: min::Wrap<int> = min::Wrap(10);
                                              ^~
test.rs:5:26: 5:40 error: mismatched types: expected `min::Wrap<int>` but found `min::Wrap<BUG[0u]>` (expected int but found type parameter)
test.rs:5   let x: min::Wrap<int> = min::Wrap(10);
                                    ^~~~~~~~~~~~~~
error: aborting due to 2 previous errors
task '<unnamed>' failed at 'explicit failure', /Users/utkarsh/dev/git/rust/src/libsyntax/diagnostic.rs:98
task '<unnamed>' failed at 'explicit failure', /Users/utkarsh/dev/git/rust/src/librustc/rustc.rs:395

@eholk
Copy link
Contributor

eholk commented Nov 4, 2013

I just saw a bug that looks similar to this.

@pnkfelix
Copy link
Member

i just encountered this at well. Will take a stab at resolving it.

pnkfelix added a commit to pnkfelix/rust that referenced this issue Jan 21, 2014
…strumentation.

modmin.rs:
    #[crate_id = "min#0.1"];

    #[cfg(not(nontuple))]
    pub struct Wrap<A>(A);

    #[cfg(nontuple)]
    pub struct Wrap<A>{ a: A }

    #[cfg(nontuple)]
    pub fn Wrap<A>(a: A) -> Wrap<A> { Wrap{ a: a } }

test.rs:
    extern mod min;

    fn main() {
        let _x: min::Wrap<()> = min::Wrap(());
    }

Makefile:
    default: test

    RUSTC=rustc

    TEMP_FILE=$(mktmp -t deps)
    TEMP_FILE=/tmp/foo

    define DEPS_ON_RUSTC
    # $(1) rustc args
    # $(2) output variable
      $(2) = $(shell TMP=$(TEMP_FILE) $(RUSTC) --dep-info $TMP --no-analysis $(1) ; sed -e s'/^[^:]*://' $TMP )
    endef

    define FILENAME_ON_RUSTC
    # $(1) rustc args
    # $(2) output variable
       $(2) := $(shell $(RUSTC) --crate-file-name $(1))
    endef

    LIBMOD_FLAGS=--lib modmin.rs
    $(eval $(call FILENAME_ON_RUSTC, $(LIBMOD_FLAGS), LIBMOD))
    $(eval $(call DEPS_ON_RUSTC, $(LIBMOD_FLAGS), LIBMOD_DEPS))
    $(LIBMOD): $(LIBMOD_DEPS)
    	$(RUSTC) $(LIBMOD_FLAGS)

    TEST_FLAGS=--test test.rs
    $(eval $(call FILENAME_ON_RUSTC, $(TEST_FLAGS), TEST))
    $(eval $(call DEPS_ON_RUSTC, $(TEST_FLAGS), TEST_DEPS))
    $(TEST): $(TEST_DEPS) $(LIBMOD)
    	$(RUSTC) -L. $(TEST_FLAGS)

    clean:
    	rm -f $(LIBMOD) $(TEST)
@pnkfelix
Copy link
Member

okay I think I found the problem. In rustc::metadata::encoder, the encode_info_for_struct_ctor, which, AFAICT, emits the same metadata that you would for a function that also does the construction, seems to be missing a call to encode_bounds_and_type. (Not quite sure how we have gotten away with that info missing from the crate...)

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

Successfully merging a pull request may close this issue.

3 participants