From 4e7e62aa8e79a10166e1ad0c6108d4f3e7f3f6f4 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 1 Jul 2023 20:26:35 +0300 Subject: [PATCH] resolve: Always update globs importing from a module when bindings in that module change --- compiler/rustc_resolve/src/imports.rs | 16 ++++++++-------- tests/ui/resolve/issue-112831.rs | 3 +-- tests/ui/resolve/issue-112831.stderr | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 10 deletions(-) create mode 100644 tests/ui/resolve/issue-112831.stderr diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs index 074f761c53baa..69b0e1cc2c582 100644 --- a/compiler/rustc_resolve/src/imports.rs +++ b/compiler/rustc_resolve/src/imports.rs @@ -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, } }; diff --git a/tests/ui/resolve/issue-112831.rs b/tests/ui/resolve/issue-112831.rs index ffd83ea8bc104..f7e3ccd19e33b 100644 --- a/tests/ui/resolve/issue-112831.rs +++ b/tests/ui/resolve/issue-112831.rs @@ -1,4 +1,3 @@ -// check-pass // aux-build:issue-112831-aux.rs mod zeroable { @@ -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` } use pod::*; diff --git a/tests/ui/resolve/issue-112831.stderr b/tests/ui/resolve/issue-112831.stderr new file mode 100644 index 0000000000000..fdfcc2a9e8a43 --- /dev/null +++ b/tests/ui/resolve/issue-112831.stderr @@ -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`.