Auto merge of #53316 - tristanburgess:52895_existential_type_ICE, r=oli-obk
52985: cause cycle err on inf trait normalization Issue: #52985 - If an existential type is defined, but no user code infers the concrete type behind the existential type, normalization would infinitely recurse on this existential type which is only defined in terms of itself. - Instead of raising an inf recurse error, we cause a cycle error to help highlight that the issue is that the type is only defined in terms of itself. - Three known potential improvements: - If type folding itself was exposed as a query, used by normalization and other mechanisms, cases that would cause infinite recursion would automatically cause a cycle error. - The span for the cycle error should be improved to point to user code that fails to allow inference of the concrete type of the existential type, assuming that this error occurs because no user code can allow inference the concrete type. - A mechanism to extend the cycle error with a helpful note would be nice. Currently, the error is built and maintained by src/librustc/ty/query/plumbing, with no known way to extend the information that the error gets built with. r? @oli-obk
This commit is contained in:
commit
f28f648a96
3 changed files with 70 additions and 9 deletions
23
src/test/ui/existential_types/no_inferrable_concrete_type.rs
Normal file
23
src/test/ui/existential_types/no_inferrable_concrete_type.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Issue 52985: Cause cycle error if user code provides no use case that allows an existential type
|
||||
// to be inferred to a concrete type. This results in an infinite cycle during type normalization.
|
||||
|
||||
#![feature(existential_type)]
|
||||
|
||||
existential type Foo: Copy; //~ cycle detected
|
||||
|
||||
// make compiler happy about using 'Foo'
|
||||
fn bar(x: Foo) -> Foo { x }
|
||||
|
||||
fn main() {
|
||||
let _: Foo = std::mem::transmute(0u8);
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
error[E0391]: cycle detected when normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All }, value: Foo }`
|
||||
--> $DIR/no_inferrable_concrete_type.rs:16:1
|
||||
|
|
||||
LL | existential type Foo: Copy; //~ cycle detected
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: ...which again requires normalizing `ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: All }, value: Foo }`, completing the cycle
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0391`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue