about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <me@lukaswirth.dev>2025-07-27 20:50:23 +0000
committerGitHub <noreply@github.com>2025-07-27 20:50:23 +0000
commitea927c03e24162642124eb7952ecdf0dd4d134cc (patch)
treee2f75cb77648da1de001e29507ae8a12c5b5e75c
parent7f19af89b64dd02ee3b7fcdcd0832df5cad88dc6 (diff)
parentd846d615aaed6bf923fff012507b8b2f95c52d8c (diff)
downloadrust-ea927c03e24162642124eb7952ecdf0dd4d134cc.tar.gz
rust-ea927c03e24162642124eb7952ecdf0dd4d134cc.zip
Merge pull request #20318 from Veykril/push-vpqsrylmkqqm
fix: Ignore `Destruct` bounds again
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/lower.rs9
-rw-r--r--src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs34
-rw-r--r--src/tools/rust-analyzer/crates/project-model/src/build_dependencies.rs7
-rw-r--r--src/tools/rust-analyzer/crates/project-model/src/cargo_workspace.rs9
-rw-r--r--src/tools/rust-analyzer/crates/project-model/src/workspace.rs19
5 files changed, 58 insertions, 20 deletions
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs b/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs
index f32b6af4d85..d61e7de6672 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/lower.rs
@@ -590,9 +590,14 @@ impl<'a> TyLoweringContext<'a> {
                         .resolve_trait(ctx.ty_ctx().db, ctx.ty_ctx().resolver.krate());
                     let pointee_sized = LangItem::PointeeSized
                         .resolve_trait(ctx.ty_ctx().db, ctx.ty_ctx().resolver.krate());
-                    if meta_sized.is_some_and(|it| it == trait_ref.hir_trait_id()) {
+                    let destruct = LangItem::Destruct
+                        .resolve_trait(ctx.ty_ctx().db, ctx.ty_ctx().resolver.krate());
+                    let hir_trait_id = trait_ref.hir_trait_id();
+                    if meta_sized.is_some_and(|it| it == hir_trait_id)
+                        || destruct.is_some_and(|it| it == hir_trait_id)
+                    {
                         // Ignore this bound
-                    } else if pointee_sized.is_some_and(|it| it == trait_ref.hir_trait_id()) {
+                    } else if pointee_sized.is_some_and(|it| it == hir_trait_id) {
                         // Regard this as `?Sized` bound
                         ctx.ty_ctx().unsized_types.insert(self_ty);
                     } else {
diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs b/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs
index 238753e12e4..c4c17a93c9c 100644
--- a/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs
+++ b/src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs
@@ -2349,3 +2349,37 @@ fn test() {
         "#]],
     );
 }
+
+#[test]
+fn rust_destruct_option_clone() {
+    check_types(
+        r#"
+//- minicore: option, drop
+fn test(o: &Option<i32>) {
+    o.my_clone();
+  //^^^^^^^^^^^^ Option<i32>
+}
+pub trait MyClone: Sized {
+    fn my_clone(&self) -> Self;
+}
+impl<T> const MyClone for Option<T>
+where
+    T: ~const MyClone + ~const Destruct,
+{
+    fn my_clone(&self) -> Self {
+        match self {
+            Some(x) => Some(x.my_clone()),
+            None => None,
+        }
+    }
+}
+impl const MyClone for i32 {
+    fn my_clone(&self) -> Self {
+        *self
+    }
+}
+#[lang = "destruct"]
+pub trait Destruct {}
+"#,
+    );
+}
diff --git a/src/tools/rust-analyzer/crates/project-model/src/build_dependencies.rs b/src/tools/rust-analyzer/crates/project-model/src/build_dependencies.rs
index 289b033a6ad..9888984934f 100644
--- a/src/tools/rust-analyzer/crates/project-model/src/build_dependencies.rs
+++ b/src/tools/rust-analyzer/crates/project-model/src/build_dependencies.rs
@@ -62,7 +62,10 @@ impl BuildScriptOutput {
         self.cfgs.is_empty()
             && self.envs.is_empty()
             && self.out_dir.is_none()
-            && self.proc_macro_dylib_path == ProcMacroDylibPath::NotBuilt
+            && matches!(
+                self.proc_macro_dylib_path,
+                ProcMacroDylibPath::NotBuilt | ProcMacroDylibPath::NotProcMacro
+            )
     }
 }
 
@@ -462,10 +465,10 @@ impl WorkspaceBuildScripts {
                     let lockfile_path =
                         <_ as AsRef<Utf8Path>>::as_ref(manifest_path).with_extension("lock");
                     if let Some((temp_dir, target_lockfile)) = make_lockfile_copy(&lockfile_path) {
+                        requires_unstable_options = true;
                         temp_dir_guard = Some(temp_dir);
                         cmd.arg("--lockfile-path");
                         cmd.arg(target_lockfile.as_str());
-                        requires_unstable_options = true;
                     }
                 }
                 match &config.features {
diff --git a/src/tools/rust-analyzer/crates/project-model/src/cargo_workspace.rs b/src/tools/rust-analyzer/crates/project-model/src/cargo_workspace.rs
index b5f68b2435d..e613fd590c7 100644
--- a/src/tools/rust-analyzer/crates/project-model/src/cargo_workspace.rs
+++ b/src/tools/rust-analyzer/crates/project-model/src/cargo_workspace.rs
@@ -601,7 +601,6 @@ impl FetchMetadata {
         }
         command.current_dir(current_dir);
 
-        let mut needs_nightly = false;
         let mut other_options = vec![];
         // cargo metadata only supports a subset of flags of what cargo usually accepts, and usually
         // the only relevant flags for metadata here are unstable ones, so we pass those along
@@ -611,7 +610,6 @@ impl FetchMetadata {
             if arg == "-Z"
                 && let Some(arg) = extra_args.next()
             {
-                needs_nightly = true;
                 other_options.push("-Z".to_owned());
                 other_options.push(arg.to_owned());
             }
@@ -619,7 +617,6 @@ impl FetchMetadata {
 
         let mut lockfile_path = None;
         if cargo_toml.is_rust_manifest() {
-            needs_nightly = true;
             other_options.push("-Zscript".to_owned());
         } else if config
             .toolchain_version
@@ -637,10 +634,6 @@ impl FetchMetadata {
 
         command.other_options(other_options.clone());
 
-        if needs_nightly {
-            command.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly");
-        }
-
         // Pre-fetch basic metadata using `--no-deps`, which:
         // - avoids fetching registries like crates.io,
         // - skips dependency resolution and does not modify lockfiles,
@@ -710,7 +703,7 @@ impl FetchMetadata {
             other_options.push(target_lockfile.to_string());
             using_lockfile_copy = true;
         }
-        if using_lockfile_copy {
+        if using_lockfile_copy || other_options.iter().any(|it| it.starts_with("-Z")) {
             command.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly");
             other_options.push("-Zunstable-options".to_owned());
         }
diff --git a/src/tools/rust-analyzer/crates/project-model/src/workspace.rs b/src/tools/rust-analyzer/crates/project-model/src/workspace.rs
index f031fef165e..f53c0ae7dc2 100644
--- a/src/tools/rust-analyzer/crates/project-model/src/workspace.rs
+++ b/src/tools/rust-analyzer/crates/project-model/src/workspace.rs
@@ -1316,14 +1316,17 @@ fn cargo_to_crate_graph(
             public_deps.add_to_crate_graph(crate_graph, from);
 
             // Add dep edge of all targets to the package's lib target
-            if let Some((to, name)) = lib_tgt.clone() {
-                match to != from && kind != TargetKind::BuildScript {
-                    true => {
-                        let name = CrateName::normalize_dashes(&name);
-                        add_dep(crate_graph, from, name, to);
-                    }
-                    false => (),
-                }
+            if let Some((to, name)) = lib_tgt.clone()
+                && to != from
+                && kind != TargetKind::BuildScript
+            {
+                // (build script can not depend on its library target)
+
+                // For root projects with dashes in their name,
+                // cargo metadata does not do any normalization,
+                // so we do it ourselves currently
+                let name = CrateName::normalize_dashes(&name);
+                add_dep(crate_graph, from, name, to);
             }
         }
     }