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

regression: assert_eq cannot find panic with no_implicit_prelude #61567

Closed
Mark-Simulacrum opened this issue Jun 5, 2019 · 5 comments · Fixed by #61629
Closed

regression: assert_eq cannot find panic with no_implicit_prelude #61567

Mark-Simulacrum opened this issue Jun 5, 2019 · 5 comments · Fixed by #61629
Labels
regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Mark-Simulacrum
Copy link
Member

This only works on 2015 edition. This code sample will fail to compile on beta but succeed on stable.

#![no_implicit_prelude]

fn _foo() {
    assert_eq!(10, 20);
}

cc @petrochenkov

@Mark-Simulacrum Mark-Simulacrum added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels Jun 5, 2019
@petrochenkov
Copy link
Contributor

For all macros beside panic the underlying issue is fixed in #61629.
panic is special, #61629 describes the situation in more detail.

Centril added a commit to Centril/rust that referenced this issue Jun 12, 2019
Hygienize macros in the standard library

Same as rust-lang#55597, but for all macros in the standard library.
Nested macro calls will now call what they are intended to call rather than whatever is in the closest scope at call site.
Technically this is a breaking change, so crater run would probably be useful.

---

One exception that is not hygienized is calls to `panic!(...)`.
Macros defined in libcore do not want to call `core::panic`.
What they really want to call is either `std::panic` or `core::panic` depending on `no_std` settings.
EDIT: After some thought, recursive calls to `panic` from `panic` itself probably do want to use `$crate` (UPDATE: done).

Calling `std::panic` from macros defined in std and "whatever `panic` is in scope" from macros defined in libcore is probably even worse than always calling "whatever `panic` is in scope", so I kept the existing code.

The only way to do the std/core switch correctly that I'm aware of is to define a built-in panic macro that would dispatch to `std::panic` or `core::panic` using compiler magic.
Then standard library macros could delegate to this built-in macro.
The macro could be named `panic` too, that would fix rust-lang#61567.
(This PR doesn't do that.)

---
cc rust-lang#56389
cc rust-lang#61567
Fixes rust-lang#61699
r? @alexcrichton
Centril added a commit to Centril/rust that referenced this issue Jun 12, 2019
Hygienize macros in the standard library

Same as rust-lang#55597, but for all macros in the standard library.
Nested macro calls will now call what they are intended to call rather than whatever is in the closest scope at call site.
Technically this is a breaking change, so crater run would probably be useful.

---

One exception that is not hygienized is calls to `panic!(...)`.
Macros defined in libcore do not want to call `core::panic`.
What they really want to call is either `std::panic` or `core::panic` depending on `no_std` settings.
EDIT: After some thought, recursive calls to `panic` from `panic` itself probably do want to use `$crate` (UPDATE: done).

Calling `std::panic` from macros defined in std and "whatever `panic` is in scope" from macros defined in libcore is probably even worse than always calling "whatever `panic` is in scope", so I kept the existing code.

The only way to do the std/core switch correctly that I'm aware of is to define a built-in panic macro that would dispatch to `std::panic` or `core::panic` using compiler magic.
Then standard library macros could delegate to this built-in macro.
The macro could be named `panic` too, that would fix rust-lang#61567.
(This PR doesn't do that.)

---
cc rust-lang#56389
cc rust-lang#61567
Fixes rust-lang#61699
r? @alexcrichton
@petrochenkov petrochenkov reopened this Jun 13, 2019
@petrochenkov petrochenkov self-assigned this Jun 19, 2019
@petrochenkov petrochenkov removed their assignment Jun 19, 2019
@petrochenkov
Copy link
Contributor

#61971 implements a temporary solution, but I'd rather leave this as wontfix.

@pnkfelix
Copy link
Member

Discussed at T-compiler meeting. Closing as wont-fix.

@petrochenkov
Copy link
Contributor

#62002 provides a proper solution.

@m-ou-se
Copy link
Member

m-ou-se commented Oct 25, 2020

#78343 would fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
4 participants