Auto merge of #157787 - cuviper:beta-next, r=cuviper

[beta] backports

- Revert "Build shared LLVM lib for windows-gnullvm" rust-lang/rust#156962
- Allow building the source tarballs while offline rust-lang/rust#157014
- resolve: Partially revert "Remove a special case for dummy imports" rust-lang/rust#157719
- resolve: Remove exported imports from `maybe_unused_trait_imports` rust-lang/rust#157713
- [beta-1.97] Update cargo submodule rust-lang/rust#157792

r? cuviper
diff --git a/compiler/rustc_resolve/src/check_unused.rs b/compiler/rustc_resolve/src/check_unused.rs
index 84221cb..30d4458 100644
--- a/compiler/rustc_resolve/src/check_unused.rs
+++ b/compiler/rustc_resolve/src/check_unused.rs
@@ -105,6 +105,7 @@ fn check_use_tree(&mut self, use_tree: &'a ast::UseTree, id: ast::NodeId) {
         let def_id = self.r.owner_def_id(id);
         if self.r.effective_visibilities.is_exported(def_id) {
             self.check_import_as_underscore(use_tree, id);
+            self.r.maybe_unused_trait_imports.swap_remove(&def_id);
             return;
         }
 
diff --git a/compiler/rustc_resolve/src/imports.rs b/compiler/rustc_resolve/src/imports.rs
index c49e0fc..2f734e6 100644
--- a/compiler/rustc_resolve/src/imports.rs
+++ b/compiler/rustc_resolve/src/imports.rs
@@ -568,6 +568,15 @@ pub(crate) fn try_plant_decl_into_local_module(
             orig_ident_span,
             warn_ambiguity,
             |this, resolution| {
+                if res == Res::Err
+                    && let Some(old_decl) = resolution.best_decl()
+                    && old_decl.res() != Res::Err
+                {
+                    // Do not override real declarations with `Res::Err`s from error recovery.
+                    // FIXME: this special case shouldn't be necessary, but removing it triggers an ICE
+                    // due to some other issues (#157406, tests/ui/imports/dummy-import-ice.rs).
+                    return Ok(());
+                }
                 if decl.is_glob_import() {
                     resolution.glob_decl = Some(match resolution.glob_decl {
                         Some(old_decl) => this.select_glob_decl(
diff --git a/src/bootstrap/src/core/build_steps/vendor.rs b/src/bootstrap/src/core/build_steps/vendor.rs
index 2465985..17bee20 100644
--- a/src/bootstrap/src/core/build_steps/vendor.rs
+++ b/src/bootstrap/src/core/build_steps/vendor.rs
@@ -114,6 +114,13 @@ fn run(self, builder: &Builder<'_>) -> Self::Output {
                 cmd.arg("--sync").arg(sync_arg);
             }
 
+            // Reuse vendored dependencies when building source tarball for offline support.
+            if builder.config.vendor {
+                cmd.arg("--respect-source-config")
+                    .arg("--config")
+                    .arg(builder.src.join(".cargo").join("config.toml"));
+            }
+
             // Will read the libstd Cargo.toml
             // which uses the unstable `public-dependency` feature.
             cmd.env("RUSTC_BOOTSTRAP", "1");
@@ -135,6 +142,13 @@ fn run(self, builder: &Builder<'_>) -> Self::Output {
             cmd.arg("--versioned-dirs");
         }
 
+        // Reuse vendored dependencies when building source tarball for offline support.
+        if builder.config.vendor {
+            cmd.arg("--respect-source-config")
+                .arg("--config")
+                .arg(builder.src.join("library").join(".cargo").join("config.toml"));
+        }
+
         // Will read the libstd Cargo.toml
         // which uses the unstable `public-dependency` feature.
         cmd.env("RUSTC_BOOTSTRAP", "1");
diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml
index 448a2c9..45eeff9 100644
--- a/src/ci/github-actions/jobs.yml
+++ b/src/ci/github-actions/jobs.yml
@@ -722,7 +722,6 @@
         --target=aarch64-pc-windows-gnullvm,i686-pc-windows-gnullvm
         --enable-full-tools
         --enable-profiler
-        --enable-llvm-link-shared
       DIST_REQUIRE_ALL_TOOLS: 1
       CODEGEN_BACKENDS: llvm,cranelift
       CC_i686_pc_windows_gnullvm: i686-w64-mingw32-clang
@@ -735,7 +734,6 @@
         --build=x86_64-pc-windows-gnullvm
         --enable-full-tools
         --enable-profiler
-        --enable-llvm-link-shared
       DIST_REQUIRE_ALL_TOOLS: 1
       CODEGEN_BACKENDS: llvm,cranelift
     <<: *job-windows
diff --git a/src/tools/cargo b/src/tools/cargo
index 31bcf52..910306f 160000
--- a/src/tools/cargo
+++ b/src/tools/cargo
@@ -1 +1 @@
-Subproject commit 31bcf52c870d00e7b993ec65fdb888ea12bc2052
+Subproject commit 910306f2a7b889a7ff58fd4a451d3daf356a4cbb
diff --git a/tests/ui/imports/auxiliary/dummy-import-ice-macro.rs b/tests/ui/imports/auxiliary/dummy-import-ice-macro.rs
new file mode 100644
index 0000000..b5bc9c7
--- /dev/null
+++ b/tests/ui/imports/auxiliary/dummy-import-ice-macro.rs
@@ -0,0 +1,15 @@
+extern crate proc_macro;
+use proc_macro::TokenStream;
+
+#[proc_macro]
+pub fn my_macro(_: proc_macro::TokenStream) -> proc_macro::TokenStream {
+    r"
+        use own::*;
+        mod own {
+            pub use super::submodule::*;
+            pub use super::ambiguous;
+        }
+    "
+    .parse()
+    .unwrap()
+}
diff --git a/tests/ui/imports/dummy-import-ice.rs b/tests/ui/imports/dummy-import-ice.rs
new file mode 100644
index 0000000..e1e82db
--- /dev/null
+++ b/tests/ui/imports/dummy-import-ice.rs
@@ -0,0 +1,20 @@
+// Regression test for issue #157406.
+
+//@ check-pass
+//@ proc-macro: dummy-import-ice-macro.rs
+
+extern crate dummy_import_ice_macro;
+
+pub fn foo() {
+    ambiguous();
+}
+
+mod submodule {
+    pub fn ambiguous() {}
+}
+
+pub mod ambiguous {}
+
+dummy_import_ice_macro::my_macro!();
+
+fn main() {}
diff --git a/tests/ui/imports/issue-56125.rs b/tests/ui/imports/issue-56125.rs
index a30ac36..4e7e7ac 100644
--- a/tests/ui/imports/issue-56125.rs
+++ b/tests/ui/imports/issue-56125.rs
@@ -15,7 +15,7 @@ mod m2 {
 mod m3 {
     mod empty {}
     use empty::issue_56125; //~ ERROR unresolved import `empty::issue_56125`
-    use issue_56125::*;
+    use issue_56125::*; //~ ERROR `issue_56125` is ambiguous
 }
 
 fn main() {}
diff --git a/tests/ui/imports/issue-56125.stderr b/tests/ui/imports/issue-56125.stderr
index f9a169b..371130f 100644
--- a/tests/ui/imports/issue-56125.stderr
+++ b/tests/ui/imports/issue-56125.stderr
@@ -54,7 +54,24 @@
    = help: consider adding an explicit import of `issue_56125` to disambiguate
    = help: or use `self::issue_56125` to refer to this module unambiguously
 
-error: aborting due to 3 previous errors
+error[E0659]: `issue_56125` is ambiguous
+  --> $DIR/issue-56125.rs:18:9
+   |
+LL |     use issue_56125::*;
+   |         ^^^^^^^^^^^ ambiguous name
+   |
+   = note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
+   = note: `issue_56125` could refer to a crate passed with `--extern`
+   = help: use `::issue_56125` to refer to this crate unambiguously
+note: `issue_56125` could also refer to the module imported here
+  --> $DIR/issue-56125.rs:18:9
+   |
+LL |     use issue_56125::*;
+   |         ^^^^^^^^^^^^^^
+   = help: consider adding an explicit import of `issue_56125` to disambiguate
+   = help: or use `self::issue_56125` to refer to this module unambiguously
+
+error: aborting due to 4 previous errors
 
 Some errors have detailed explanations: E0432, E0659.
 For more information about an error, try `rustc --explain E0432`.
diff --git a/tests/ui/imports/shadow-glob-module-resolution-2.rs b/tests/ui/imports/shadow-glob-module-resolution-2.rs
index ac2901e..c3abd1f 100644
--- a/tests/ui/imports/shadow-glob-module-resolution-2.rs
+++ b/tests/ui/imports/shadow-glob-module-resolution-2.rs
@@ -14,5 +14,7 @@ pub trait D {}
 use e as b;
 //~^ ERROR: unresolved import `e`
 use b::c::D as e;
+//~^ ERROR: cannot determine resolution for the import
+//~| ERROR: cannot determine resolution for the import
 
 fn main() { }
diff --git a/tests/ui/imports/shadow-glob-module-resolution-2.stderr b/tests/ui/imports/shadow-glob-module-resolution-2.stderr
index ba8a2ce..2674538 100644
--- a/tests/ui/imports/shadow-glob-module-resolution-2.stderr
+++ b/tests/ui/imports/shadow-glob-module-resolution-2.stderr
@@ -1,3 +1,17 @@
+error: cannot determine resolution for the import
+  --> $DIR/shadow-glob-module-resolution-2.rs:16:5
+   |
+LL | use b::c::D as e;
+   |     ^^^^^^^^^^^^
+
+error: cannot determine resolution for the import
+  --> $DIR/shadow-glob-module-resolution-2.rs:16:5
+   |
+LL | use b::c::D as e;
+   |     ^^^^^^^^^^^^
+   |
+   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+
 error[E0432]: unresolved import `e`
   --> $DIR/shadow-glob-module-resolution-2.rs:14:5
    |
@@ -10,6 +24,6 @@
 LL + use a as b;
    |
 
-error: aborting due to 1 previous error
+error: aborting due to 3 previous errors
 
 For more information about this error, try `rustc --explain E0432`.
diff --git a/tests/ui/imports/shadow-glob-module-resolution-4.rs b/tests/ui/imports/shadow-glob-module-resolution-4.rs
index 38fe7d1..581cdc1 100644
--- a/tests/ui/imports/shadow-glob-module-resolution-4.rs
+++ b/tests/ui/imports/shadow-glob-module-resolution-4.rs
@@ -12,6 +12,8 @@ pub trait C {}
 
 use b::C as e;
 //~^ ERROR: unresolved import `b::C`
+//~| ERROR: cannot determine resolution for the import
+//~| ERROR: cannot determine resolution for the import
 
 fn e() {}
 
diff --git a/tests/ui/imports/shadow-glob-module-resolution-4.stderr b/tests/ui/imports/shadow-glob-module-resolution-4.stderr
index d94a593..063beb6 100644
--- a/tests/ui/imports/shadow-glob-module-resolution-4.stderr
+++ b/tests/ui/imports/shadow-glob-module-resolution-4.stderr
@@ -1,9 +1,23 @@
+error: cannot determine resolution for the import
+  --> $DIR/shadow-glob-module-resolution-4.rs:13:5
+   |
+LL | use b::C as e;
+   |     ^^^^^^^^^
+
+error: cannot determine resolution for the import
+  --> $DIR/shadow-glob-module-resolution-4.rs:13:5
+   |
+LL | use b::C as e;
+   |     ^^^^^^^^^
+   |
+   = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
+
 error[E0432]: unresolved import `b::C`
   --> $DIR/shadow-glob-module-resolution-4.rs:13:5
    |
 LL | use b::C as e;
    |     ^^^^^^^^^
 
-error: aborting due to 1 previous error
+error: aborting due to 3 previous errors
 
 For more information about this error, try `rustc --explain E0432`.
diff --git a/tests/ui/imports/unused-import-issue-157420.rs b/tests/ui/imports/unused-import-issue-157420.rs
new file mode 100644
index 0000000..550c455
--- /dev/null
+++ b/tests/ui/imports/unused-import-issue-157420.rs
@@ -0,0 +1,19 @@
+//@ check-pass
+//@ edition: 2018..
+
+#![crate_type = "lib"] // needed to enable doc link collection
+#![warn(unused_imports)]
+
+pub use inner::*;
+use crate::outer::*;
+
+mod outer {
+    pub mod inner {
+        pub trait Trait {} // must be a trait
+    }
+
+    pub use inner::*;
+}
+
+/// [A::assoc] // needed to force collection of traits in scope, without filter on assoc item name
+pub struct A;