forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#120972 - lukas-code:autoderef-type-error, r…
…=compiler-errors fix ICE for deref coercions with type errors Follow-up to rust-lang#120895, where I made types with errors go through the full coercion code, which is necessary if we want to build MIR for bodies with errors (rust-lang#120550). The code for coercing `&T` to `&U` currently assumes that autoderef for `&T` will succeed for at least two steps (`&T` and `T`): https://github.com/rust-lang/rust/blob/b17491c8f6d555386104dfd82004c01bfef09c95/compiler/rustc_hir_typeck/src/coercion.rs#L339-L464 But for types with errors, we previously only returned the no-op autoderef step (`&{type error}` -> `&{type error}`) and then stopped early. This PR changes autoderef for types with errors to still go through the built-in derefs (e.g. `&&{type error}` -> `&{type error}` -> `{type error}`) and only stop early when it would have to go looking for `Deref` trait impls. fixes rust-lang#120945 r? ``@compiler-errors`` or compiler
- Loading branch information
Showing
4 changed files
with
39 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
// Regression test for an ICE: https://github.com/rust-lang/rust/issues/120884 | ||
// Test that we don't ICE for coercions with type errors. | ||
// We still need to properly go through coercions between types with errors instead of | ||
// shortcutting and returning success, because we need the adjustments for building the MIR. | ||
|
||
pub fn has_error() -> TypeError {} | ||
//~^ ERROR cannot find type `TypeError` in this scope | ||
|
||
// https://github.com/rust-lang/rust/issues/120884 | ||
// Casting a function item to a data pointer in valid in HIR, but invalid in MIR. | ||
// We need an adjustment (ReifyFnPointer) to insert a cast from the function item | ||
// to a function pointer as a separate MIR statement. | ||
pub fn cast() -> *const u8 { | ||
// Casting a function item to a data pointer in valid in HIR, but invalid in MIR. | ||
// We need an adjustment (ReifyFnPointer) to insert a cast from the function item | ||
// to a function pointer as a separate MIR statement. | ||
has_error as *const u8 | ||
} | ||
|
||
// https://github.com/rust-lang/rust/issues/120945 | ||
// This one ICEd, because we skipped the builtin deref from `&TypeError` to `TypeError`. | ||
pub fn autoderef_source(e: &TypeError) { | ||
//~^ ERROR cannot find type `TypeError` in this scope | ||
autoderef_target(e) | ||
} | ||
|
||
pub fn autoderef_target(_: &TypeError) {} | ||
//~^ ERROR cannot find type `TypeError` in this scope | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters