Skip to content

Commit e909668

Browse files
authored
Merge pull request #20318 from Veykril/push-vpqsrylmkqqm
fix: Ignore `Destruct` bounds again
2 parents 098fdb4 + afee071 commit e909668

File tree

5 files changed

+58
-20
lines changed

5 files changed

+58
-20
lines changed

crates/hir-ty/src/lower.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,9 +590,14 @@ impl<'a> TyLoweringContext<'a> {
590590
.resolve_trait(ctx.ty_ctx().db, ctx.ty_ctx().resolver.krate());
591591
let pointee_sized = LangItem::PointeeSized
592592
.resolve_trait(ctx.ty_ctx().db, ctx.ty_ctx().resolver.krate());
593-
if meta_sized.is_some_and(|it| it == trait_ref.hir_trait_id()) {
593+
let destruct = LangItem::Destruct
594+
.resolve_trait(ctx.ty_ctx().db, ctx.ty_ctx().resolver.krate());
595+
let hir_trait_id = trait_ref.hir_trait_id();
596+
if meta_sized.is_some_and(|it| it == hir_trait_id)
597+
|| destruct.is_some_and(|it| it == hir_trait_id)
598+
{
594599
// Ignore this bound
595-
} else if pointee_sized.is_some_and(|it| it == trait_ref.hir_trait_id()) {
600+
} else if pointee_sized.is_some_and(|it| it == hir_trait_id) {
596601
// Regard this as `?Sized` bound
597602
ctx.ty_ctx().unsized_types.insert(self_ty);
598603
} else {

crates/hir-ty/src/tests/regression.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,3 +2349,37 @@ fn test() {
23492349
"#]],
23502350
);
23512351
}
2352+
2353+
#[test]
2354+
fn rust_destruct_option_clone() {
2355+
check_types(
2356+
r#"
2357+
//- minicore: option, drop
2358+
fn test(o: &Option<i32>) {
2359+
o.my_clone();
2360+
//^^^^^^^^^^^^ Option<i32>
2361+
}
2362+
pub trait MyClone: Sized {
2363+
fn my_clone(&self) -> Self;
2364+
}
2365+
impl<T> const MyClone for Option<T>
2366+
where
2367+
T: ~const MyClone + ~const Destruct,
2368+
{
2369+
fn my_clone(&self) -> Self {
2370+
match self {
2371+
Some(x) => Some(x.my_clone()),
2372+
None => None,
2373+
}
2374+
}
2375+
}
2376+
impl const MyClone for i32 {
2377+
fn my_clone(&self) -> Self {
2378+
*self
2379+
}
2380+
}
2381+
#[lang = "destruct"]
2382+
pub trait Destruct {}
2383+
"#,
2384+
);
2385+
}

crates/project-model/src/build_dependencies.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ impl BuildScriptOutput {
6262
self.cfgs.is_empty()
6363
&& self.envs.is_empty()
6464
&& self.out_dir.is_none()
65-
&& self.proc_macro_dylib_path == ProcMacroDylibPath::NotBuilt
65+
&& matches!(
66+
self.proc_macro_dylib_path,
67+
ProcMacroDylibPath::NotBuilt | ProcMacroDylibPath::NotProcMacro
68+
)
6669
}
6770
}
6871

@@ -462,10 +465,10 @@ impl WorkspaceBuildScripts {
462465
let lockfile_path =
463466
<_ as AsRef<Utf8Path>>::as_ref(manifest_path).with_extension("lock");
464467
if let Some((temp_dir, target_lockfile)) = make_lockfile_copy(&lockfile_path) {
468+
requires_unstable_options = true;
465469
temp_dir_guard = Some(temp_dir);
466470
cmd.arg("--lockfile-path");
467471
cmd.arg(target_lockfile.as_str());
468-
requires_unstable_options = true;
469472
}
470473
}
471474
match &config.features {

crates/project-model/src/cargo_workspace.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,6 @@ impl FetchMetadata {
601601
}
602602
command.current_dir(current_dir);
603603

604-
let mut needs_nightly = false;
605604
let mut other_options = vec![];
606605
// cargo metadata only supports a subset of flags of what cargo usually accepts, and usually
607606
// the only relevant flags for metadata here are unstable ones, so we pass those along
@@ -611,15 +610,13 @@ impl FetchMetadata {
611610
if arg == "-Z"
612611
&& let Some(arg) = extra_args.next()
613612
{
614-
needs_nightly = true;
615613
other_options.push("-Z".to_owned());
616614
other_options.push(arg.to_owned());
617615
}
618616
}
619617

620618
let mut lockfile_path = None;
621619
if cargo_toml.is_rust_manifest() {
622-
needs_nightly = true;
623620
other_options.push("-Zscript".to_owned());
624621
} else if config
625622
.toolchain_version
@@ -637,10 +634,6 @@ impl FetchMetadata {
637634

638635
command.other_options(other_options.clone());
639636

640-
if needs_nightly {
641-
command.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly");
642-
}
643-
644637
// Pre-fetch basic metadata using `--no-deps`, which:
645638
// - avoids fetching registries like crates.io,
646639
// - skips dependency resolution and does not modify lockfiles,
@@ -710,7 +703,7 @@ impl FetchMetadata {
710703
other_options.push(target_lockfile.to_string());
711704
using_lockfile_copy = true;
712705
}
713-
if using_lockfile_copy {
706+
if using_lockfile_copy || other_options.iter().any(|it| it.starts_with("-Z")) {
714707
command.env("__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS", "nightly");
715708
other_options.push("-Zunstable-options".to_owned());
716709
}

crates/project-model/src/workspace.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,14 +1316,17 @@ fn cargo_to_crate_graph(
13161316
public_deps.add_to_crate_graph(crate_graph, from);
13171317

13181318
// Add dep edge of all targets to the package's lib target
1319-
if let Some((to, name)) = lib_tgt.clone() {
1320-
match to != from && kind != TargetKind::BuildScript {
1321-
true => {
1322-
let name = CrateName::normalize_dashes(&name);
1323-
add_dep(crate_graph, from, name, to);
1324-
}
1325-
false => (),
1326-
}
1319+
if let Some((to, name)) = lib_tgt.clone()
1320+
&& to != from
1321+
&& kind != TargetKind::BuildScript
1322+
{
1323+
// (build script can not depend on its library target)
1324+
1325+
// For root projects with dashes in their name,
1326+
// cargo metadata does not do any normalization,
1327+
// so we do it ourselves currently
1328+
let name = CrateName::normalize_dashes(&name);
1329+
add_dep(crate_graph, from, name, to);
13271330
}
13281331
}
13291332
}

0 commit comments

Comments
 (0)