Rollup merge of #102613 - TaKO8Ki:fix-part-of-101739, r=compiler-errors
Fix ICE #101739 Fixes a part of #101739 This cannot cover the following case. It causes `too many args provided` error and obligation does not have references error. I want your advice to solve the following cases as well in this pull request or a follow-up. ```rust #![crate_type = "lib"] #![feature(transmutability)] #![allow(dead_code, incomplete_features, non_camel_case_types)] mod assert { use std::mem::BikeshedIntrinsicFrom; pub fn is_transmutable< Src, Dst, Context, const ASSUME_ALIGNMENT: bool, const ASSUME_LIFETIMES: bool, const ASSUME_VALIDITY: bool, const ASSUME_VISIBILITY: bool, >() where Dst: BikeshedIntrinsicFrom< Src, Context, ASSUME_ALIGNMENT, ASSUME_LIFETIMES, ASSUME_VALIDITY, ASSUME_VISIBILITY, >, {} } fn via_const() { struct Context; #[repr(C)] struct Src; #[repr(C)] struct Dst; const FALSE: bool = false; assert::is_transmutable::<Src, Dst, Context, FALSE, FALSE, FALSE, FALSE>(); } ```
This commit is contained in:
commit
aa076d6144
@ -11,9 +11,10 @@
|
||||
use rustc_index::bit_set::GrowableBitSet;
|
||||
use rustc_infer::infer::InferOk;
|
||||
use rustc_infer::infer::LateBoundRegionConversionTime::HigherRankedType;
|
||||
use rustc_middle::ty::{self, GenericParamDefKind, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef};
|
||||
use rustc_middle::ty::{ToPolyTraitRef, ToPredicate};
|
||||
use rustc_middle::ty::{
|
||||
self, GenericArg, GenericArgKind, GenericParamDefKind, InternalSubsts, SubstsRef,
|
||||
ToPolyTraitRef, ToPredicate, Ty, TyCtxt,
|
||||
};
|
||||
use rustc_span::def_id::DefId;
|
||||
|
||||
use crate::traits::project::{normalize_with_depth, normalize_with_depth_to};
|
||||
@ -289,8 +290,10 @@ fn confirm_transmutability_candidate(
|
||||
|
||||
let scope = type_at(2).skip_binder();
|
||||
|
||||
let assume =
|
||||
rustc_transmute::Assume::from_const(self.infcx.tcx, obligation.param_env, const_at(3));
|
||||
let Some(assume) =
|
||||
rustc_transmute::Assume::from_const(self.infcx.tcx, obligation.param_env, const_at(3)) else {
|
||||
return Err(Unimplemented);
|
||||
};
|
||||
|
||||
let cause = obligation.cause.clone();
|
||||
|
||||
|
@ -115,7 +115,7 @@ pub fn from_const<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
param_env: ParamEnv<'tcx>,
|
||||
c: Const<'tcx>,
|
||||
) -> Self {
|
||||
) -> Option<Self> {
|
||||
use rustc_middle::ty::ScalarInt;
|
||||
use rustc_middle::ty::TypeVisitable;
|
||||
use rustc_span::symbol::sym;
|
||||
@ -123,10 +123,15 @@ pub fn from_const<'tcx>(
|
||||
let c = c.eval(tcx, param_env);
|
||||
|
||||
if let Some(err) = c.error_reported() {
|
||||
return Self { alignment: true, lifetimes: true, safety: true, validity: true };
|
||||
return Some(Self {
|
||||
alignment: true,
|
||||
lifetimes: true,
|
||||
safety: true,
|
||||
validity: true,
|
||||
});
|
||||
}
|
||||
|
||||
let adt_def = c.ty().ty_adt_def().expect("The given `Const` must be an ADT.");
|
||||
let adt_def = c.ty().ty_adt_def()?;
|
||||
|
||||
assert_eq!(
|
||||
tcx.require_lang_item(LangItem::TransmuteOpts, None),
|
||||
@ -148,12 +153,12 @@ pub fn from_const<'tcx>(
|
||||
fields[field_idx].unwrap_leaf() == ScalarInt::TRUE
|
||||
};
|
||||
|
||||
Self {
|
||||
Some(Self {
|
||||
alignment: get_field(sym::alignment),
|
||||
lifetimes: get_field(sym::lifetimes),
|
||||
safety: get_field(sym::safety),
|
||||
validity: get_field(sym::validity),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
21
src/test/ui/transmutability/issue-101739-1.rs
Normal file
21
src/test/ui/transmutability/issue-101739-1.rs
Normal file
@ -0,0 +1,21 @@
|
||||
#![feature(transmutability)]
|
||||
|
||||
mod assert {
|
||||
use std::mem::BikeshedIntrinsicFrom;
|
||||
|
||||
pub fn is_transmutable<Src, Context, const ASSUME_ALIGNMENT: bool>()
|
||||
where
|
||||
Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME_ALIGNMENT>, //~ ERROR cannot find type `Dst` in this scope
|
||||
//~^ ERROR mismatched types
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
fn via_const() {
|
||||
struct Context;
|
||||
struct Src;
|
||||
|
||||
assert::is_transmutable::<Src, Context, false>();
|
||||
}
|
||||
|
||||
fn main() {}
|
16
src/test/ui/transmutability/issue-101739-1.stderr
Normal file
16
src/test/ui/transmutability/issue-101739-1.stderr
Normal file
@ -0,0 +1,16 @@
|
||||
error[E0412]: cannot find type `Dst` in this scope
|
||||
--> $DIR/issue-101739-1.rs:8:9
|
||||
|
|
||||
LL | Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME_ALIGNMENT>,
|
||||
| ^^^ not found in this scope
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/issue-101739-1.rs:8:50
|
||||
|
|
||||
LL | Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME_ALIGNMENT>,
|
||||
| ^^^^^^^^^^^^^^^^ expected struct `Assume`, found `bool`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0308, E0412.
|
||||
For more information about an error, try `rustc --explain E0308`.
|
37
src/test/ui/transmutability/issue-101739-2.rs
Normal file
37
src/test/ui/transmutability/issue-101739-2.rs
Normal file
@ -0,0 +1,37 @@
|
||||
#![crate_type = "lib"]
|
||||
#![feature(transmutability)]
|
||||
#![allow(dead_code, incomplete_features, non_camel_case_types)]
|
||||
|
||||
mod assert {
|
||||
use std::mem::BikeshedIntrinsicFrom;
|
||||
|
||||
pub fn is_transmutable<
|
||||
Src,
|
||||
Dst,
|
||||
Context,
|
||||
const ASSUME_ALIGNMENT: bool,
|
||||
const ASSUME_LIFETIMES: bool,
|
||||
const ASSUME_VALIDITY: bool,
|
||||
const ASSUME_VISIBILITY: bool,
|
||||
>()
|
||||
where
|
||||
Dst: BikeshedIntrinsicFrom< //~ ERROR this trait takes at most 3 generic arguments but 6 generic arguments were supplied
|
||||
Src,
|
||||
Context,
|
||||
ASSUME_ALIGNMENT,
|
||||
ASSUME_LIFETIMES,
|
||||
ASSUME_VALIDITY,
|
||||
ASSUME_VISIBILITY,
|
||||
>,
|
||||
{}
|
||||
}
|
||||
|
||||
fn via_const() {
|
||||
struct Context;
|
||||
#[repr(C)] struct Src;
|
||||
#[repr(C)] struct Dst;
|
||||
|
||||
const FALSE: bool = false;
|
||||
|
||||
assert::is_transmutable::<Src, Dst, Context, FALSE, FALSE, FALSE, FALSE>();
|
||||
}
|
20
src/test/ui/transmutability/issue-101739-2.stderr
Normal file
20
src/test/ui/transmutability/issue-101739-2.stderr
Normal file
@ -0,0 +1,20 @@
|
||||
error[E0107]: this trait takes at most 3 generic arguments but 6 generic arguments were supplied
|
||||
--> $DIR/issue-101739-2.rs:18:14
|
||||
|
|
||||
LL | Dst: BikeshedIntrinsicFrom<
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ expected at most 3 generic arguments
|
||||
...
|
||||
LL | / ASSUME_LIFETIMES,
|
||||
LL | | ASSUME_VALIDITY,
|
||||
LL | | ASSUME_VISIBILITY,
|
||||
| |_____________________________- help: remove these generic arguments
|
||||
|
|
||||
note: trait defined here, with at most 3 generic parameters: `Src`, `Context`, `ASSUME`
|
||||
--> $SRC_DIR/core/src/mem/transmutability.rs:LL:COL
|
||||
|
|
||||
LL | pub unsafe trait BikeshedIntrinsicFrom<Src, Context, const ASSUME: Assume = { Assume::NOTHING }>
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ --- ------- ------------------------------------------
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0107`.
|
Loading…
Reference in New Issue
Block a user