Skip to content
Merged
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
11 changes: 10 additions & 1 deletion compiler/rustc_hir_analysis/src/check/compare_eii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ pub(crate) fn compare_eii_function_types<'tcx>(
eii_name: Symbol,
eii_attr_span: Span,
) -> Result<(), ErrorGuaranteed> {
// Already errored, returning to avoid icing.
if tcx.generics_of(foreign_item).own_requires_monomorphization() {
return Err(tcx.dcx().delayed_bug("compared an EII impl against a generic declaration"));
}
check_eii_target(tcx, external_impl, foreign_item, eii_name, eii_attr_span)?;
check_is_structurally_compatible(tcx, external_impl, foreign_item, eii_name, eii_attr_span)?;

Expand Down Expand Up @@ -289,10 +293,15 @@ fn check_is_structurally_compatible<'tcx>(
fn check_no_generics<'tcx>(
tcx: TyCtxt<'tcx>,
external_impl: LocalDefId,
_declaration: DefId,
declaration: DefId,
eii_name: Symbol,
eii_attr_span: Span,
) -> Result<(), ErrorGuaranteed> {
// Already errored, return to avoid icing
if tcx.generics_of(declaration).own_requires_monomorphization() {
return Err(tcx.dcx().delayed_bug("compared an EII impl against a generic declaration"));
}

let generics = tcx.generics_of(external_impl);
if generics.own_requires_monomorphization()
// When an EII implementation is automatically generated by the `#[eii]` macro,
Expand Down
18 changes: 18 additions & 0 deletions tests/ui/eii/type_checking/generic_declaration_and_impl.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//@ check-fail
// Check that comparing an EII implementation against a generic declaration
// (already rejected by E0044) does not ICE in error reporting.
// Regression test for the ICE when note_and_explain_type_err tries to look up
// declaration parameters in external_impl's empty generics.
#![feature(extern_item_impls)]

#[eii(foo)]
fn bar<T>(x: T) where T: FnOnce() -> u64 { x() }
//~^ ERROR externally implementable items may not have type parameters
//~| ERROR mismatched types

#[foo]
fn y(a: u64) -> u64 {
a
}

fn main() {}
27 changes: 27 additions & 0 deletions tests/ui/eii/type_checking/generic_declaration_and_impl.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
error[E0044]: externally implementable items may not have type parameters
--> $DIR/generic_declaration_and_impl.rs:9:1
|
LL | fn bar<T>(x: T) where T: FnOnce() -> u64 { x() }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't have type parameters
|
= help: replace the type parameters with concrete types like `u32`

error[E0308]: mismatched types
--> $DIR/generic_declaration_and_impl.rs:9:44
|
LL | fn bar<T>(x: T) where T: FnOnce() -> u64 { x() }
| ^^^ expected `()`, found `u64`
|
help: consider using a semicolon here
|
LL | fn bar<T>(x: T) where T: FnOnce() -> u64 { x(); }
| +
help: try adding a return type
|
LL | fn bar<T>(x: T) -> u64 where T: FnOnce() -> u64 { x() }
| ++++++

error: aborting due to 2 previous errors

Some errors have detailed explanations: E0044, E0308.
For more information about an error, try `rustc --explain E0044`.
Loading