Comments (3)
My thought after some debug:
There are some ways to trigger panic in compiler/rustc_pattern_analysis
, because we trust that the type analysed here are all correct but they may not.
Consider two programs below:
// program A
enum NestedEnum {
First,
Second,
}
enum Enum {
Variant(*const ()),
// Variant(*const &'a ()),
}
fn foo(x: Enum) {
match x {
Enum::Variant(NestedEnum::Second) => {}
}
}
// program B
enum NestedEnum {
First,
Second,
}
enum Enum {
// Variant(*const ()),
Variant(*const &'a ()),
}
fn foo(x: Enum) {
match x {
Enum::Variant(NestedEnum::Second) => {}
}
}
program B will panic at compile while program A not. The difference occurs here:
rust/compiler/rustc_mir_build/src/thir/pattern/check_match.rs
Lines 29 to 32 in 6a207f4
program A will early return at
tcx.thir_body(def_id)?
, but program B will not and cause the panic.I have checked the
typeck_results
of two programs, and there is a key different between them: in program A typeck_results.tainted_by_errors
is Some(ErrorGuaranteed(()))
, and in program B that is None
.
A:
TypeckResults { hir_owner: DefId(0:12 ~ tmp[d0fa]::foo), type_dependent_defs: UnordMap { inner: {} }, field_indices: UnordMap { inner: {} }, nested_fields: UnordMap { inner: {} }, node_types: UnordMap { inner: {16: (), 13: (), 10: NestedEnum, 4: Enum, 1: Enum, 14: (), 11: Enum, 2: Enum, 15: (), 3: ()} }, node_args: UnordMap { inner: {} }, user_provided_types: UnordMap { inner: {} }, user_provided_sigs: UnordMap { inner: {} }, adjustments: UnordMap { inner: {} }, pat_binding_modes: UnordMap { inner: {2: BindingMode(No, Not)} }, rust_2024_migration_desugared_pats: UnordSet { inner: {} }, pat_adjustments: UnordMap { inner: {} }, skipped_ref_pats: UnordSet { inner: {} }, closure_kind_origins: UnordMap { inner: {} }, liberated_fn_sigs: UnordMap { inner: {0: fn(Enum)} }, fru_field_types: UnordMap { inner: {} }, coercion_casts: UnordSet { inner: {} }, used_trait_imports: UnordSet { inner: {} }, tainted_by_errors: Some(ErrorGuaranteed(())), concrete_opaque_types: {}, closure_min_captures: UnordMap { inner: {} }, closure_fake_reads: UnordMap { inner: {} }, rvalue_scopes: RvalueScopes { map: UnordMap { inner: {} } }, coroutine_stalled_predicates: {}, treat_byte_string_as_slice: UnordSet { inner: {} }, closure_size_eval: UnordMap { inner: {} }, offset_of_data: UnordMap { inner: {} }, inline_consts: {} }
B:
TypeckResults { hir_owner: DefId(0:12 ~ tmp2[62c9]::foo), type_dependent_defs: UnordMap { inner: {} }, field_indices: UnordMap { inner: {} }, nested_fields: UnordMap { inner: {} }, node_types: UnordMap { inner: {16: (), 13: (), 10: NestedEnum, 4: Enum, 1: Enum, 14: (), 11: Enum, 2: Enum, 15: (), 3: ()} }, node_args: UnordMap { inner: {} }, user_provided_types: UnordMap { inner: {} }, user_provided_sigs: UnordMap { inner: {} }, adjustments: UnordMap { inner: {} }, pat_binding_modes: UnordMap { inner: {2: BindingMode(No, Not)} }, rust_2024_migration_desugared_pats: UnordSet { inner: {} }, pat_adjustments: UnordMap { inner: {} }, skipped_ref_pats: UnordSet { inner: {} }, closure_kind_origins: UnordMap { inner: {} }, liberated_fn_sigs: UnordMap { inner: {0: fn(Enum)} }, fru_field_types: UnordMap { inner: {} }, coercion_casts: UnordSet { inner: {} }, used_trait_imports: UnordSet { inner: {} }, tainted_by_errors: None, concrete_opaque_types: {}, closure_min_captures: UnordMap { inner: {} }, closure_fake_reads: UnordMap { inner: {} }, rvalue_scopes: RvalueScopes { map: UnordMap { inner: {} } }, coroutine_stalled_predicates: {}, treat_byte_string_as_slice: UnordSet { inner: {} }, closure_size_eval: UnordMap { inner: {} }, offset_of_data: UnordMap { inner: {} }, inline_consts: {} }
In TyCtxt::thir_body
's comment, it says: If typeck for that body failed, returns an empty Thir.
, but seems that it return ErrorGuaranteed
rather than empty Thir
if typeck failed. Is the description wrong here?
from rust.
Because this hack, I think.
rust/compiler/rustc_hir_typeck/src/writeback.rs
Lines 125 to 130 in 76c7382
from rust.
program A set tainted_by_errors
to Some(ErrorGuaranteed(()))
here, but program B not.
rust/compiler/rustc_hir_typeck/src/pat.rs
Line 1165 in 921645c
from rust.
Related Issues (20)
- Tracking Issue for async drop codegen HOT 1
- Error tainting in parallel compiler HOT 2
- Cargo check internal error (using UOM library) HOT 5
- document for E0502 insufficiently general
- "deny" lints are ignored in macro expansion HOT 1
- Trait bound order-dependent type errors using non_lifetime_binders HOT 1
- ICE: incr: `no entry found for key` HOT 4
- Compiler hangs on recursive HRTB HOT 2
- Regression between nightlies with `-Zpolonius` HOT 5
- ICE: `assertion failed: matches!(diagnostic.level, Error | Warning | Allow)` HOT 2
- "rustc-LLVM ERROR: underestimated function size" on thumbv6m-none-eabi HOT 7
- `invalid_value` does not warn when transmuting from a unit struct to an uninhabited type
- Words in `<code></code>` in docs make machine translation even weirder than usual HOT 3
- ICE: `assert_eq!(alloc.mutability, mutability)` failed in `validity.rs` HOT 4
- Confusing "the caller chooses a type which can be different" [E308] HOT 4
- Async code causes error "one type is more general than the other" (expected `async` block, found that same `async` block) when demanding an `impl Send` HOT 1
- Extremely un-informative error when a future that capture the environment is used as Send HOT 1
- Async code causes error "implementation of `FnOnce` is not general enough" when demanding an `impl Send` HOT 1
- `tidy` requires `src/tools/rustc-perf`? HOT 2
- 1.79 regression in `const` temporary lifetime extension HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust.