Skip to content

Commit aa076d6

Browse files
authored
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>(); } ```
2 parents 3374a7d + 0e615ca commit aa076d6

File tree

6 files changed

+112
-10
lines changed

6 files changed

+112
-10
lines changed

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ use rustc_hir::lang_items::LangItem;
1111
use rustc_index::bit_set::GrowableBitSet;
1212
use rustc_infer::infer::InferOk;
1313
use rustc_infer::infer::LateBoundRegionConversionTime::HigherRankedType;
14-
use rustc_middle::ty::{self, GenericParamDefKind, Ty, TyCtxt};
15-
use rustc_middle::ty::{GenericArg, GenericArgKind, InternalSubsts, SubstsRef};
16-
use rustc_middle::ty::{ToPolyTraitRef, ToPredicate};
14+
use rustc_middle::ty::{
15+
self, GenericArg, GenericArgKind, GenericParamDefKind, InternalSubsts, SubstsRef,
16+
ToPolyTraitRef, ToPredicate, Ty, TyCtxt,
17+
};
1718
use rustc_span::def_id::DefId;
1819

1920
use crate::traits::project::{normalize_with_depth, normalize_with_depth_to};
@@ -289,8 +290,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
289290

290291
let scope = type_at(2).skip_binder();
291292

292-
let assume =
293-
rustc_transmute::Assume::from_const(self.infcx.tcx, obligation.param_env, const_at(3));
293+
let Some(assume) =
294+
rustc_transmute::Assume::from_const(self.infcx.tcx, obligation.param_env, const_at(3)) else {
295+
return Err(Unimplemented);
296+
};
294297

295298
let cause = obligation.cause.clone();
296299

compiler/rustc_transmute/src/lib.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -115,18 +115,23 @@ mod rustc {
115115
tcx: TyCtxt<'tcx>,
116116
param_env: ParamEnv<'tcx>,
117117
c: Const<'tcx>,
118-
) -> Self {
118+
) -> Option<Self> {
119119
use rustc_middle::ty::ScalarInt;
120120
use rustc_middle::ty::TypeVisitable;
121121
use rustc_span::symbol::sym;
122122

123123
let c = c.eval(tcx, param_env);
124124

125125
if let Some(err) = c.error_reported() {
126-
return Self { alignment: true, lifetimes: true, safety: true, validity: true };
126+
return Some(Self {
127+
alignment: true,
128+
lifetimes: true,
129+
safety: true,
130+
validity: true,
131+
});
127132
}
128133

129-
let adt_def = c.ty().ty_adt_def().expect("The given `Const` must be an ADT.");
134+
let adt_def = c.ty().ty_adt_def()?;
130135

131136
assert_eq!(
132137
tcx.require_lang_item(LangItem::TransmuteOpts, None),
@@ -148,12 +153,12 @@ mod rustc {
148153
fields[field_idx].unwrap_leaf() == ScalarInt::TRUE
149154
};
150155

151-
Self {
156+
Some(Self {
152157
alignment: get_field(sym::alignment),
153158
lifetimes: get_field(sym::lifetimes),
154159
safety: get_field(sym::safety),
155160
validity: get_field(sym::validity),
156-
}
161+
})
157162
}
158163
}
159164
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![feature(transmutability)]
2+
3+
mod assert {
4+
use std::mem::BikeshedIntrinsicFrom;
5+
6+
pub fn is_transmutable<Src, Context, const ASSUME_ALIGNMENT: bool>()
7+
where
8+
Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME_ALIGNMENT>, //~ ERROR cannot find type `Dst` in this scope
9+
//~^ ERROR mismatched types
10+
{
11+
}
12+
}
13+
14+
fn via_const() {
15+
struct Context;
16+
struct Src;
17+
18+
assert::is_transmutable::<Src, Context, false>();
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0412]: cannot find type `Dst` in this scope
2+
--> $DIR/issue-101739-1.rs:8:9
3+
|
4+
LL | Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME_ALIGNMENT>,
5+
| ^^^ not found in this scope
6+
7+
error[E0308]: mismatched types
8+
--> $DIR/issue-101739-1.rs:8:50
9+
|
10+
LL | Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME_ALIGNMENT>,
11+
| ^^^^^^^^^^^^^^^^ expected struct `Assume`, found `bool`
12+
13+
error: aborting due to 2 previous errors
14+
15+
Some errors have detailed explanations: E0308, E0412.
16+
For more information about an error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#![crate_type = "lib"]
2+
#![feature(transmutability)]
3+
#![allow(dead_code, incomplete_features, non_camel_case_types)]
4+
5+
mod assert {
6+
use std::mem::BikeshedIntrinsicFrom;
7+
8+
pub fn is_transmutable<
9+
Src,
10+
Dst,
11+
Context,
12+
const ASSUME_ALIGNMENT: bool,
13+
const ASSUME_LIFETIMES: bool,
14+
const ASSUME_VALIDITY: bool,
15+
const ASSUME_VISIBILITY: bool,
16+
>()
17+
where
18+
Dst: BikeshedIntrinsicFrom< //~ ERROR this trait takes at most 3 generic arguments but 6 generic arguments were supplied
19+
Src,
20+
Context,
21+
ASSUME_ALIGNMENT,
22+
ASSUME_LIFETIMES,
23+
ASSUME_VALIDITY,
24+
ASSUME_VISIBILITY,
25+
>,
26+
{}
27+
}
28+
29+
fn via_const() {
30+
struct Context;
31+
#[repr(C)] struct Src;
32+
#[repr(C)] struct Dst;
33+
34+
const FALSE: bool = false;
35+
36+
assert::is_transmutable::<Src, Dst, Context, FALSE, FALSE, FALSE, FALSE>();
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error[E0107]: this trait takes at most 3 generic arguments but 6 generic arguments were supplied
2+
--> $DIR/issue-101739-2.rs:18:14
3+
|
4+
LL | Dst: BikeshedIntrinsicFrom<
5+
| ^^^^^^^^^^^^^^^^^^^^^ expected at most 3 generic arguments
6+
...
7+
LL | / ASSUME_LIFETIMES,
8+
LL | | ASSUME_VALIDITY,
9+
LL | | ASSUME_VISIBILITY,
10+
| |_____________________________- help: remove these generic arguments
11+
|
12+
note: trait defined here, with at most 3 generic parameters: `Src`, `Context`, `ASSUME`
13+
--> $SRC_DIR/core/src/mem/transmutability.rs:LL:COL
14+
|
15+
LL | pub unsafe trait BikeshedIntrinsicFrom<Src, Context, const ASSUME: Assume = { Assume::NOTHING }>
16+
| ^^^^^^^^^^^^^^^^^^^^^ --- ------- ------------------------------------------
17+
18+
error: aborting due to previous error
19+
20+
For more information about this error, try `rustc --explain E0107`.

0 commit comments

Comments
 (0)