Skip to content

Nested functions are called by name, so the wrong function is called #8587

Closed
@bluss

Description

@bluss

The following example shows that in method h(), it returns the result of the function nested inside the method f().

pub struct X;

impl X {
    fn f(&self) -> int {
        #[inline(never)]
        fn inner() -> int {
            0
        }
        inner()
    }

    fn g(&self) -> int {
        #[inline(never)]
        fn inner_2() -> int {
            1
        }
        inner_2()
    }

    fn h(&self) -> int {
        #[inline(never)]
        fn inner() -> int {
            2
        }
        inner()
    }
}

mod tests {
    use super::*;

    #[test]
    fn test_function() {
        let n = X;
        assert_eq!(n.f(), 0);
        assert_eq!(n.g(), 1);
        assert_eq!(n.h(), 2);       // This test fails!
    }
}

Output:

running 1 test
task <unnamed> failed at 'assertion failed: `(left == right) && (right == left)` (left: `0`, right: `2`)', nestf.rs:38
test tests::test_function ... FAILED

failures:
    tests::test_function

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions