diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs index f5a64ede398ea..8f9c8821b998a 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs @@ -609,13 +609,10 @@ pub(crate) fn prohibit_explicit_late_bound_lifetimes( position: GenericArgPosition, ) -> ExplicitLateBound { let param_counts = def.own_counts(); - let infer_lifetimes = position != GenericArgPosition::Type && !args.has_lifetime_params(); - if infer_lifetimes { - return ExplicitLateBound::No; - } - - if let Some(span_late) = def.has_late_bound_regions { + if let Some(span_late) = def.has_late_bound_regions + && args.has_lifetime_params() + { let msg = "cannot specify lifetime arguments explicitly \ if late bound lifetime parameters are present"; let note = "the late bound lifetime parameter is introduced here"; diff --git a/tests/crashes/137084.rs b/tests/crashes/137084.rs deleted file mode 100644 index 0f248c2120628..0000000000000 --- a/tests/crashes/137084.rs +++ /dev/null @@ -1,6 +0,0 @@ -//@ known-bug: #137084 -#![feature(min_generic_const_args)] -fn a() {} -fn d(e: &String) { - a:: -} diff --git a/tests/ui/const-generics/fn-item-as-const-arg-137084.rs b/tests/ui/const-generics/fn-item-as-const-arg-137084.rs new file mode 100644 index 0000000000000..8b75a3c8c96d1 --- /dev/null +++ b/tests/ui/const-generics/fn-item-as-const-arg-137084.rs @@ -0,0 +1,14 @@ +// Regression test for https://github.com/rust-lang/rust/issues/137084 +// Previously caused ICE when using function item as const generic argument + +#![feature(min_generic_const_args)] +#![allow(incomplete_features)] + +fn a() {} +fn d(e: &String) { + a:: + //~^ ERROR mismatched types + //~| ERROR the constant `d` is not of type `i32` +} + +fn main() {} diff --git a/tests/ui/const-generics/fn-item-as-const-arg-137084.stderr b/tests/ui/const-generics/fn-item-as-const-arg-137084.stderr new file mode 100644 index 0000000000000..58b74c655cd23 --- /dev/null +++ b/tests/ui/const-generics/fn-item-as-const-arg-137084.stderr @@ -0,0 +1,35 @@ +error[E0308]: mismatched types + --> $DIR/fn-item-as-const-arg-137084.rs:9:5 + | +LL | fn a() {} + | -------------------- function `a` defined here +LL | fn d(e: &String) { +LL | a:: + | ^^^^^^ expected `()`, found fn item + | + = note: expected unit type `()` + found fn item `fn() {a::}` +help: try adding a return type + | +LL | fn d(e: &String) -> fn() { + | +++++++ +help: use parentheses to call this function + | +LL | a::() + | ++ + +error: the constant `d` is not of type `i32` + --> $DIR/fn-item-as-const-arg-137084.rs:9:9 + | +LL | a:: + | ^ expected `i32`, found fn item + | +note: required by a const generic parameter in `a` + --> $DIR/fn-item-as-const-arg-137084.rs:7:6 + | +LL | fn a() {} + | ^^^^^^^^^^^^ required by this const generic parameter in `a` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/const-generics/ice-151186-fn-ptr-in-where-clause.rs b/tests/ui/const-generics/ice-151186-fn-ptr-in-where-clause.rs new file mode 100644 index 0000000000000..7710fc68d7957 --- /dev/null +++ b/tests/ui/const-generics/ice-151186-fn-ptr-in-where-clause.rs @@ -0,0 +1,16 @@ +// Regression test for https://github.com/rust-lang/rust/issues/151186 + +#![feature(min_generic_const_args)] +#![allow(incomplete_features)] + +trait Maybe {} + +trait MyTrait ()> {} +//~^ ERROR using function pointers as const generic parameters is forbidden + +fn foo<'a>(x: &'a ()) -> &'a () { x } + +impl Maybe for T where T: MyTrait<{ foo }> {} +//~^ ERROR the constant `foo` is not of type `fn()` + +fn main() {} diff --git a/tests/ui/const-generics/ice-151186-fn-ptr-in-where-clause.stderr b/tests/ui/const-generics/ice-151186-fn-ptr-in-where-clause.stderr new file mode 100644 index 0000000000000..7c9d7ee7dde59 --- /dev/null +++ b/tests/ui/const-generics/ice-151186-fn-ptr-in-where-clause.stderr @@ -0,0 +1,22 @@ +error: using function pointers as const generic parameters is forbidden + --> $DIR/ice-151186-fn-ptr-in-where-clause.rs:8:24 + | +LL | trait MyTrait ()> {} + | ^^^^^^^^^^ + | + = note: the only supported types are integers, `bool`, and `char` + +error: the constant `foo` is not of type `fn()` + --> $DIR/ice-151186-fn-ptr-in-where-clause.rs:13:33 + | +LL | impl Maybe for T where T: MyTrait<{ foo }> {} + | ^^^^^^^^^^^^^^^^ expected fn pointer, found fn item + | +note: required by a const generic parameter in `MyTrait` + --> $DIR/ice-151186-fn-ptr-in-where-clause.rs:8:15 + | +LL | trait MyTrait ()> {} + | ^^^^^^^^^^^^^^^^^^^ required by this const generic parameter in `MyTrait` + +error: aborting due to 2 previous errors +