Auto merge of #146919 - lcnr:yeet-fast-path, r=fee1-dead

remove incorrect fast path

Using `tcx.is_copy_modulo_regions` drops information from the current `typing_env`. Writing a regression test for this is really hard. We need to prove `Copy` of something that doesn't directly reference a coroutine or an opaque, but does so indirectly.

cc rust-lang/rust#146813.
This commit is contained in:
bors 2025-09-25 23:50:40 +00:00
commit b733736ea2
4 changed files with 41 additions and 40 deletions

View file

@ -9,7 +9,7 @@ use rustc_middle::infer::canonical::{
Canonical, CanonicalQueryInput, CanonicalQueryResponse, QueryResponse,
};
use rustc_middle::traits::query::NoSolution;
use rustc_middle::ty::{self, GenericArg, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, Upcast};
use rustc_middle::ty::{self, GenericArg, Ty, TyCtxt, TypeFoldable, Upcast};
use rustc_span::DUMMY_SP;
use tracing::instrument;
@ -31,19 +31,7 @@ impl<'tcx> InferCtxt<'tcx> {
fn type_is_copy_modulo_regions(&self, param_env: ty::ParamEnv<'tcx>, ty: Ty<'tcx>) -> bool {
let ty = self.resolve_vars_if_possible(ty);
// FIXME(#132279): This should be removed as it causes us to incorrectly
// handle opaques in their defining scope, and stalled coroutines.
if !self.next_trait_solver() && !(param_env, ty).has_infer() && !ty.has_coroutines() {
return self.tcx.type_is_copy_modulo_regions(self.typing_env(param_env), ty);
}
let copy_def_id = self.tcx.require_lang_item(LangItem::Copy, DUMMY_SP);
// This can get called from typeck (by euv), and `moves_by_default`
// rightly refuses to work with inference variables, but
// moves_by_default has a cache, which we want to use in other
// cases.
traits::type_known_to_meet_bound_modulo_regions(self, param_env, ty, copy_def_id)
}

View file

@ -0,0 +1,40 @@
//@ edition: 2024
//@ revisions: current next
//@[next] compile-flags: -Znext-solver
//@ check-pass
// Regression test for #146813. We previously used a pseudo-canonical
// query during HIR typeck which caused a query cycle when looking at the
// witness of a coroutine.
use std::future::Future;
trait ConnectMiddleware {}
trait ConnectHandler: Sized {
fn with<M>(self, _: M) -> impl ConnectHandler
where
M: ConnectMiddleware,
{
LayeredConnectHandler
}
}
struct LayeredConnectHandler;
impl ConnectHandler for LayeredConnectHandler {}
impl<F> ConnectHandler for F where F: FnOnce() {}
impl<F, Fut> ConnectMiddleware for F
where
F: FnOnce() -> Fut,
Fut: Future<Output = ()> + Send,
{
}
pub async fn fails() {
{ || {} }
.with(async || ())
.with(async || ())
.with(async || ());
}
fn main() {}

View file

@ -1,19 +0,0 @@
#![feature(lang_items, no_core)]
#![no_core]
#![no_main]
#[lang = "pointee_sized"]
pub trait PointeeSized {}
#[lang = "meta_sized"]
pub trait MetaSized: PointeeSized {}
#[lang = "sized"]
trait Sized: MetaSized { }
struct S;
#[no_mangle]
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
argc //~ ERROR requires `copy` lang_item
}

View file

@ -1,8 +0,0 @@
error: requires `copy` lang_item
--> $DIR/missing-copy-lang-item-issue-19660.rs:18:5
|
LL | argc
| ^^^^
error: aborting due to 1 previous error