Skip to content
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

test type_override fails even when correct solution is made in macros lesson #1846

Closed
donottellmetonottellyou opened this issue Jan 1, 2024 · 1 comment

Comments

@donottellmetonottellyou
Copy link

This code in tests/macros.rs:

#[test]
#[ignore]
fn type_override() {
    // The macro should always use std::collections::HashMap and ignore crate::std::collections::HashMap
    mod std {
        pub mod collections {
            pub struct HashMap;

            impl HashMap {
                #[allow(dead_code)]
                pub fn new() -> Self {
                    panic!(
                        "Do not allow users to override which HashMap is used"
                    );
                }

                #[allow(dead_code)]
                pub fn insert<K, V>(&mut self, _key: K, _val: V) {
                    panic!(
                        "Do not allow users to override which HashMap is used"
                    );
                }
            }
        }
    }

    let _empty: ::std::collections::HashMap<(), ()> = hashmap!();
    let _without_comma = hashmap!(1 => 2, 3 => 4);
    let _with_trailing = hashmap!(1 => 2, 3 => 4,);
}

incorrectly produces a compiler error when the correct std::collections::HashMap is used. I believe the intended purpose was to panic if the incorrect version was used, but it also breaks compiling the whole crate since rust throws a compiler error. Instead, we should use simple_trybuild::compile_fail to detect if the build succeeds. If it does, the hashmap macro was built incorrectly and we will fail the build. If it fails to compile, the usage is correctly using the std struct (presumably no one is going to build their own implementation of HashMap, though it would be technically permissible).

Copy link
Contributor

github-actions bot commented Jan 1, 2024

Hello. Thanks for opening an issue on Exercism 🙂

At Exercism we use our Community Forum, not GitHub issues, as the primary place for discussion. That allows maintainers and contributors from across Exercism's ecosystem to discuss your problems/ideas/suggestions without them having to subscribe to hundreds of repositories.

This issue will be automatically closed. Please use this link to copy your GitHub Issue into a new topic on the forum, where we look forward to chatting with you!

If you're interested in learning more about this auto-responder, please read this blog post.

@github-actions github-actions bot closed this as completed Jan 1, 2024
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

1 participant