-
Notifications
You must be signed in to change notification settings - Fork 13.7k
fresh binding should shadow the def in expand #143141
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
base: master
Are you sure you want to change the base?
Conversation
tests/ui/resolve/fresh-should-shallow-definitation-after-macro-expand.rs
Outdated
Show resolved
Hide resolved
tests/ui/resolve/fresh-should-shallow-definitation-after-macro-expand.rs
Outdated
Show resolved
Hide resolved
tests/ui/resolve/fresh-should-shallow-definitation-after-macro-expand.rs
Outdated
Show resolved
Hide resolved
I don't understand why this works and how it fixes the issue. |
Also "shallow" -> "shadow" in the PR/commit messages and file names. |
There may be a bug if
rust/compiler/rustc_resolve/src/ident.rs Lines 320 to 328 in 86e05cd
|
@rustbot ready |
@bvanjoi |
Are you sure this cannot successfully resolve some names that should not be resolved? I need to test this with additional cases across different rib contexts. @rustbot author |
Reminder, once the PR becomes ready for a review, use |
tests/ui/resolve/fresh-should-shadow-definitation-in-decl-macro-expand.rs
Outdated
Show resolved
Hide resolved
tests/ui/resolve/fresh-should-shadow-definitation-in-decl-macro-expand.rs
Outdated
Show resolved
Hide resolved
tests/ui/resolve/fresh-should-shadow-definitation-in-macro-expand.rs
Outdated
Show resolved
Hide resolved
tests/ui/resolve/fresh-should-shadow-definitation-in-macro-expand-in-block.rs
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
resolve: Introduce `RibKind::Block` to avoid confusing module items, blocks with items, and blocks without items. Addresses rust-lang#143141 (comment) and rust-lang#143141 (comment). A couple of related cleanups are also added on top.
resolve: Introduce `RibKind::Block` to avoid confusing module items, blocks with items, and blocks without items. Addresses rust-lang#143141 (comment) and rust-lang#143141 (comment). A couple of related cleanups are also added on top.
resolve: Introduce `RibKind::Block` to avoid confusing module items, blocks with items, and blocks without items. Addresses rust-lang#143141 (comment) and rust-lang#143141 (comment). A couple of related cleanups are also added on top.
resolve: Introduce `RibKind::Block` to avoid confusing module items, blocks with items, and blocks without items. Addresses rust-lang#143141 (comment) and rust-lang#143141 (comment). A couple of related cleanups are also added on top.
Rollup merge of #145065 - petrochenkov:riblock, r=davidtwco resolve: Introduce `RibKind::Block` to avoid confusing module items, blocks with items, and blocks without items. Addresses #143141 (comment) and #143141 (comment). A couple of related cleanups are also added on top.
This refers to the |
Additionally, what would be the expected behavior for this particular case? fn f_with_macro_export() {
let d = 10;
{
#[macro_export]
macro_rules! m {
() => {
d
};
}
use crate::m;
m!(); // compile success
}
use crate::m;
m!(); // Should this case compile successfully? Note that it currently throws a 'not found' error in the master branch
} |
Yes, some error like that. |
I'd expect it to be ok, |
This PR was rebased onto a different master commit! Check out the changes with our |
This PR was rebased onto a different master commit! Check out the changes with our |
This comment has been minimized.
This comment has been minimized.
resolve: Introduce `RibKind::Block` to avoid confusing module items, blocks with items, and blocks without items. Addresses rust-lang/rust#143141 (comment) and rust-lang/rust#143141 (comment). A couple of related cleanups are also added on top.
This comment was marked as resolved.
This comment was marked as resolved.
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
These changes have wide-ranging implications. Could you please review whether the modifications in |
The job Click to see the possible cause of the failure (guessed by this bot)
|
Reduce for #143141 (comment) macro_rules! m2 {
() => {{
static B: i32 = S;
42
}};
}
macro_rules! m {
() => {
static S: i32 = m2!();
};
}
fn main() {
m!();
} |
Using lexical scope at macro definition sites presents problematic outcomes:
What do you think? Should we introduce this change as a lint instead? @petrochenkov |
@@ -20,9 +19,9 @@ extern crate legacy_interaction; | |||
mod def_site { | |||
// Unless this macro opts out of hygiene, it should resolve the same wherever it is invoked. | |||
pub macro m2() { | |||
::legacy_interaction::m!(); | |||
::legacy_interaction::m!(); //~ ERROR cannot find function `g` in this scope |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't look correct.
g
is an item, so it should be found at call site, not at def site, because m!
is not a macro 2.0.
macro_rules
use https://doc.rust-lang.org/stable/proc_macro/struct.Span.html#method.mixed_site so only local variables and labels are looked up at definition site (and $crate
, but we are not talking about it here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same with wrap_unhygienic_example.rs
.
We'll definitely need a crater run and possibly a lint in the end. But at this point we probably rather need some more or less formal model of the rules that we want to achieve. #![allow(unused)]
fn f() {
let a = 0;
{
fn a() {}
{
let a = 0;
{
fn a() {}
#[macro_export]
macro_rules! mac {
() => {
let a = 0;
{
fn a() {}
{
let a = 0;
{
a; // use
}
}
}
};
}
}
}
}
}
fn main() {
let a = 0;
{
fn a() {}
{
let a = 0;
{
mac!();
}
}
}
} |
Fixes #95237
r? @petrochenkov or @cjgillot