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

resolve: Always update globs importing from a module when bindings in that module change #113242

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions compiler/rustc_resolve/src/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,17 +391,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
// during which the resolution might end up getting re-defined via a glob cycle.
let (binding, t) = {
let resolution = &mut *self.resolution(module, key).borrow_mut();
let old_binding = resolution.binding();
let old_binding = resolution.binding;

let t = f(self, resolution);

match resolution.binding() {
_ if old_binding.is_some() => return t,
None => return t,
Some(binding) => match old_binding {
Some(old_binding) if ptr::eq(old_binding, binding) => return t,
_ => (binding, t),
},
match resolution.binding {
Some(binding)
if !old_binding.is_some_and(|old_binding| ptr::eq(binding, old_binding)) =>
{
(binding, t)
}
_ => return t,
}
};

Expand Down
3 changes: 1 addition & 2 deletions tests/ui/resolve/issue-112831.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// check-pass
// aux-build:issue-112831-aux.rs

mod zeroable {
Expand All @@ -9,7 +8,7 @@ use zeroable::*;

mod pod {
use super::*;
pub trait Pod: Zeroable {}
pub trait Pod: Zeroable {} //~ ERROR expected trait, found derive macro `Zeroable`
Copy link
Contributor

@bvanjoi bvanjoi Jul 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like a correct fix. Do we need to add a lint for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to fix #113099 (comment) first, then run crater again, then think about the lint.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fix is not correct because we need to locate (Mod(root::pod), Key(Zeroable, TypeNS)) instead of (Mod(root::pod), Key(Zeroable, Macro)). Therefore, this case should pass the check.

}

use pod::*;
Expand Down
14 changes: 14 additions & 0 deletions tests/ui/resolve/issue-112831.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error[E0404]: expected trait, found derive macro `Zeroable`
--> $DIR/issue-112831.rs:11:20
|
LL | pub trait Pod: Zeroable {}
| ^^^^^^^^ not a trait
|
help: consider importing this trait through its public re-export instead
|
LL + use Zeroable;
|

error: aborting due to previous error

For more information about this error, try `rustc --explain E0404`.