Skip to content

Confusing error message when same-named field and method both in scope #2327

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
brson opened this issue May 2, 2012 · 8 comments
Closed
Assignees
Milestone

Comments

@brson
Copy link
Contributor

brson commented May 2, 2012

/home/brian/dev/rust/src/test/run-pass/act.rs:178:18: 178:29 error: mismatched types: expected function or native function but found @mut bool
/home/brian/dev/rust/src/test/run-pass/act.rs:178               _ { msg.defer() }

I had both a field and a method called defer. rustc should say that both are defined and show me where.

@nikomatsakis
Copy link
Contributor

Just as a side comment, this ambiguity would be addressed by using -> as the method operator.

@ghost ghost assigned catamorphism and andreasgal May 3, 2012
@catamorphism
Copy link
Contributor

Do we want to allow a class that has a field and a method with the same name? Or should the typechecker reject such a thing? (I re-read the spec and there's nothing about it.)

I would also be very cranky about using -> as the method operator (no good reason, I just think it's ugly), but I guess if we have to, we have to. Well, one dubious reason (it's also used for function return types, which doesn't really have anything to do with method calls).

@ghost ghost assigned catamorphism May 3, 2012
@bstrie
Copy link
Contributor

bstrie commented May 4, 2012

I naively figured that it would be illegal to have a field and a method with the same name. It seems like it would become a source of confusion. Niko mentioned on the mailing list that sometimes this is necessary to fulfill an iface, but I don't understand why that would be so.

@nikomatsakis
Copy link
Contributor

Imagine an iface defined in some library X:

iface nameable {
    fn name() -> str;
}

and now a type defined in library Y:

type my_thing = {name: str};

and now I would like to define an impl so I can use my_thing as a nameable. I can't change the source of either one, as they come from different libraries I do not have control over.

@bstrie
Copy link
Contributor

bstrie commented May 5, 2012

A link to the thread with Niko's proposal:

https://mail.mozilla.org/pipermail/rust-dev/2012-May/001819.html

I'm still a bit wary of using the same accessor notation for two distinct and potentially-colliding concepts. Perhaps \ could be used for method access? I don't think it's entirely unprecedented, but I can't recall where I've seen it before.

@graydon
Copy link
Contributor

graydon commented Aug 31, 2012

Possibly will get fixed by disambiguation between record field-selection and method-call. Niko will check back on this.

@catamorphism
Copy link
Contributor

Blocked on @nikomatsakis landing AST changes.

@catamorphism
Copy link
Contributor

Dup of #3446

@ghost ghost assigned nikomatsakis Sep 12, 2012
bors added a commit to rust-lang-ci/rust that referenced this issue Sep 22, 2022
call_function: make the unit-return-type case more convenient
celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Add benchcomp parser for kani perf tests

This commit adds a parser that emits CBMC-generated metrics to
benchcomp. It is intended to be run in a kani checkout after running
`kani-perf.sh`. A minimal working example would be to run `benchcomp` in
a directory containing the following benchcomp.yaml:

    variants:
      kani_0.17:
        config:
          directory: ~/src/kani
          command_line: git checkout .; git checkout kani-0.17.0 && rm -rf target && cargo build-dev && ./scripts/kani-perf.sh ; true
      kani_0.24:
        config:
          directory: ~/src/kani
          command_line: git checkout .; git checkout main; rm -rf target && cargo build-dev && ./scripts/kani-perf.sh ; true
    run:
      suites:
        kani_perf:
          parser:
            module: kani_perf
          variants:
            - kani_0.17
            - kani_0.24

This commit also contains minor fixes to ensure that the test suite runs
to completion even if it exited with a non-zero return code.
tshepang pushed a commit to tshepang/rust that referenced this issue Apr 19, 2025
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

6 participants