Rollup merge of #82112 - BoxyUwU:tumbleweed, r=varkor
const_generics: Dont evaluate array length const when handling yet another error Same ICE as #82009 except triggered by a different error. cc ``@lcnr`` r? ``@varkor``
This commit is contained in:
commit
928819a9f7
4 changed files with 49 additions and 23 deletions
|
@ -72,17 +72,16 @@ pub fn is_const_evaluatable<'cx, 'tcx>(
|
||||||
// We were unable to unify the abstract constant with
|
// We were unable to unify the abstract constant with
|
||||||
// a constant found in the caller bounds, there are
|
// a constant found in the caller bounds, there are
|
||||||
// now three possible cases here.
|
// now three possible cases here.
|
||||||
//
|
|
||||||
// - The substs are concrete enough that we can simply
|
|
||||||
// try and evaluate the given constant.
|
|
||||||
// - The abstract const still references an inference
|
|
||||||
// variable, in this case we return `TooGeneric`.
|
|
||||||
// - The abstract const references a generic parameter,
|
|
||||||
// this means that we emit an error here.
|
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
enum FailureKind {
|
enum FailureKind {
|
||||||
|
/// The abstract const still references an inference
|
||||||
|
/// variable, in this case we return `TooGeneric`.
|
||||||
MentionsInfer,
|
MentionsInfer,
|
||||||
|
/// The abstract const references a generic parameter,
|
||||||
|
/// this means that we emit an error here.
|
||||||
MentionsParam,
|
MentionsParam,
|
||||||
|
/// The substs are concrete enough that we can simply
|
||||||
|
/// try and evaluate the given constant.
|
||||||
Concrete,
|
Concrete,
|
||||||
}
|
}
|
||||||
let mut failure_kind = FailureKind::Concrete;
|
let mut failure_kind = FailureKind::Concrete;
|
||||||
|
|
|
@ -200,22 +200,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
|
||||||
if let Some(def) = aty.ty_adt_def() {
|
if let Some(def) = aty.ty_adt_def() {
|
||||||
// We also want to be able to select the array's type's original
|
// We also want to be able to select the array's type's original
|
||||||
// signature with no type arguments resolved
|
// signature with no type arguments resolved
|
||||||
flags.push((
|
let type_string = self.tcx.type_of(def.did).to_string();
|
||||||
sym::_Self,
|
flags.push((sym::_Self, Some(format!("[{}]", type_string))));
|
||||||
Some(format!("[{}]", self.tcx.type_of(def.did).to_string())),
|
|
||||||
));
|
let len = len.val.try_to_value().and_then(|v| v.try_to_machine_usize(self.tcx));
|
||||||
let tcx = self.tcx;
|
let string = match len {
|
||||||
if let Some(len) = len.try_eval_usize(tcx, ty::ParamEnv::empty()) {
|
Some(n) => format!("[{}; {}]", type_string, n),
|
||||||
flags.push((
|
None => format!("[{}; _]", type_string),
|
||||||
sym::_Self,
|
};
|
||||||
Some(format!("[{}; {}]", self.tcx.type_of(def.did).to_string(), len)),
|
flags.push((sym::_Self, Some(string)));
|
||||||
));
|
|
||||||
} else {
|
|
||||||
flags.push((
|
|
||||||
sym::_Self,
|
|
||||||
Some(format!("[{}; _]", self.tcx.type_of(def.did).to_string())),
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let ty::Dynamic(traits, _) = self_ty.kind() {
|
if let ty::Dynamic(traits, _) = self_ty.kind() {
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
#![feature(const_generics, const_evaluatable_checked)]
|
||||||
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
|
// This tests that during error handling for the "trait not implemented" error
|
||||||
|
// we dont try to evaluate std::mem::size_of::<Self::Assoc> causing an ICE
|
||||||
|
|
||||||
|
struct Adt;
|
||||||
|
|
||||||
|
trait Foo {
|
||||||
|
type Assoc;
|
||||||
|
fn foo()
|
||||||
|
where
|
||||||
|
[Adt; std::mem::size_of::<Self::Assoc>()]: ,
|
||||||
|
{
|
||||||
|
<[Adt; std::mem::size_of::<Self::Assoc>()] as Foo>::bar()
|
||||||
|
//~^ Error: the trait bound
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bar() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,12 @@
|
||||||
|
error[E0277]: the trait bound `[Adt; _]: Foo` is not satisfied
|
||||||
|
--> $DIR/dont-evaluate-array-len-on-err-1.rs:15:9
|
||||||
|
|
|
||||||
|
LL | <[Adt; std::mem::size_of::<Self::Assoc>()] as Foo>::bar()
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Foo` is not implemented for `[Adt; _]`
|
||||||
|
...
|
||||||
|
LL | fn bar() {}
|
||||||
|
| -------- required by `Foo::bar`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0277`.
|
Loading…
Add table
Add a link
Reference in a new issue