Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions compiler/rustc_hir_typeck/src/upvar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1553,10 +1553,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) -> bool {
// FIXME(#132279): Using `non_body_analysis` here feels wrong.
let needs_drop = |ty: Ty<'tcx>| {
ty.has_significant_drop(
self.tcx,
ty::TypingEnv::non_body_analysis(self.tcx, closure_def_id),
)
let typing_env = ty::TypingEnv::non_body_analysis(self.tcx, closure_def_id);

// FIX for ICE #149746:
// We try to normalize the type first.
// If normalization fails, we assume it doesn't have a significant drop (false)
// to avoid crashing, allowing the compiler to emit the underlying type error later.
self.tcx
.try_normalize_erasing_regions(typing_env, ty)
.map(|normalized_ty| normalized_ty.has_significant_drop(self.tcx, typing_env))
.unwrap_or(false)
};

let is_drop_defined_for_ty = |ty: Ty<'tcx>| {
Expand Down
16 changes: 16 additions & 0 deletions tests/ui/associated-types/normalization-ice-issue-149746.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//@ edition: 2015..2021
#![warn(rust_2021_incompatible_closure_captures)]
trait Owner { type Ty<T: FnMut()>; }
impl Owner for () { type Ty<T: FnMut()> = T; }
pub struct Warns<T> {
_significant_drop: <() as Owner>::Ty<T>,
//~^ ERROR expected a `FnMut()` closure, found `T`
field: String,
}
pub fn test<T>(w: Warns<T>) {
//~^ ERROR expected a `FnMut()` closure, found `T`
_ = || w.field
//~^ ERROR expected a `FnMut()` closure, found `T`
//~| ERROR expected a `FnMut()` closure, found `T`
}
fn main() {}
60 changes: 60 additions & 0 deletions tests/ui/associated-types/normalization-ice-issue-149746.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
error[E0277]: expected a `FnMut()` closure, found `T`
--> $DIR/normalization-ice-issue-149746.rs:6:24
|
LL | _significant_drop: <() as Owner>::Ty<T>,
| ^^^^^^^^^^^^^^^^^^^^ expected an `FnMut()` closure, found `T`
|
= note: wrap the `T` in a closure with no arguments: `|| { /* code */ }`
note: required by a bound in `Owner::Ty`
--> $DIR/normalization-ice-issue-149746.rs:3:26
|
LL | trait Owner { type Ty<T: FnMut()>; }
| ^^^^^^^ required by this bound in `Owner::Ty`
help: consider restricting type parameter `T` with trait `FnMut`
|
LL | pub struct Warns<T: FnMut()> {
| +++++++++

error[E0277]: expected a `FnMut()` closure, found `T`
--> $DIR/normalization-ice-issue-149746.rs:12:9
|
LL | _ = || w.field
| ^^^^^^^^^^ expected an `FnMut()` closure, found `T`
|
= note: wrap the `T` in a closure with no arguments: `|| { /* code */ }`
note: required by a bound in `Owner::Ty`
--> $DIR/normalization-ice-issue-149746.rs:3:26
|
LL | trait Owner { type Ty<T: FnMut()>; }
| ^^^^^^^ required by this bound in `Owner::Ty`

error[E0277]: expected a `FnMut()` closure, found `T`
--> $DIR/normalization-ice-issue-149746.rs:10:16
|
LL | pub fn test<T>(w: Warns<T>) {
| ^ expected an `FnMut()` closure, found `T`
|
= note: wrap the `T` in a closure with no arguments: `|| { /* code */ }`
note: required by a bound in `Owner::Ty`
--> $DIR/normalization-ice-issue-149746.rs:3:26
|
LL | trait Owner { type Ty<T: FnMut()>; }
| ^^^^^^^ required by this bound in `Owner::Ty`

error[E0277]: expected a `FnMut()` closure, found `T`
--> $DIR/normalization-ice-issue-149746.rs:12:9
|
LL | _ = || w.field
| ^^^^^^^^^^ expected an `FnMut()` closure, found `T`
|
= note: wrap the `T` in a closure with no arguments: `|| { /* code */ }`
note: required by a bound in `Owner::Ty`
--> $DIR/normalization-ice-issue-149746.rs:3:26
|
LL | trait Owner { type Ty<T: FnMut()>; }
| ^^^^^^^ required by this bound in `Owner::Ty`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0277`.
Loading