-
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.
compiler/rustc_resolve/src/late.rs
Outdated
} | ||
LookaheadItemInBlock::MacroDef { bindings: macro_bindings, .. } => { | ||
let bindings = | ||
bindings.last().unwrap().1.iter().filter_map(|(name, res)| { |
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.
bindings.last().unwrap().1.iter().filter_map(|(name, res)| { | |
bindings.last().unwrap().1.iter().copied().filter(|(name, _)| !need_removed.contains(name)) |
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.
We cannot use copied().filter
here because bindings.last().unwrap().1.iter()
yields elements of type (&_, &_)
rather than the required &_
.
compiler/rustc_resolve/src/late.rs
Outdated
|
||
if let Some(last_pat_id) = last_pat_id | ||
&& let RibKind::Block { id: block, .. } = self.ribs[ValueNS].last_mut().unwrap().kind | ||
&& let Some(items) = self.r.lookahead_items_in_block.get_mut(&block) |
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.
So, in
let a = 0;
{
let b = 1;
macro_rules! m { ... }
}
only b
will be added to LookaheadItemInBlock::MacroDef
bindings for m
, but not a
.
Is this ok?
If yes, why is this ok?
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.
Please see the latest patch: I've made the binding store into the macro definitions site for each child block.
let a0: BindingF = m!(); //~ NOTE in this expansion of m! | ||
let f = || -> BindingF { 42 }; | ||
let a1: BindingF = m!(); | ||
macro m() { f() } //~ ERROR cannot find function `f` 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.
f
can be found at m
's definition site, we should report a different error in this case, like "f
is not yet alive at point of use" or something.
Could you also add a test case demonstrating what happens with this example? fn f() {
let a = 10;
#[macro_export]
macro_rules! m { () => { a } }
}
fn main() {
fn a() {}
crate::m!();
} |
☔ The latest upstream changes (presumably #145077) made this pull request unmergeable. Please resolve the merge conflicts. |
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.
☔ The latest upstream changes (presumably #145773) made this pull request unmergeable. Please resolve the merge conflicts. |
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!();
} |
Fixes #95237
r? @petrochenkov or @cjgillot