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
9 changes: 3 additions & 6 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is somewhat confusing to me 🤔

Can you try doing two things for me:

  1. remove the infer_lifetimes case above, it seems unnecessary if we only emit an error/fcw if there's explicit arguments given
  2. use args.has_lifetime_params() instead of !args.args.is_empty(), I think this is closer to the logic we want, especially for cases like this where there are arguments but they're not lifetimes

I think both of these together would make it a lot easier to read this fn 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi again! thanks for the review! implemented all of your suggestions, now waiting for CI check, tests passed, fn now looking better and more consistent :3

&& 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";
Expand Down
6 changes: 0 additions & 6 deletions tests/crashes/137084.rs

This file was deleted.

14 changes: 14 additions & 0 deletions tests/ui/const-generics/fn-item-as-const-arg-137084.rs
Original file line number Diff line number Diff line change
@@ -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<const b: i32>() {}
fn d(e: &String) {
a::<d>
//~^ ERROR mismatched types
//~| ERROR the constant `d` is not of type `i32`
}

fn main() {}
35 changes: 35 additions & 0 deletions tests/ui/const-generics/fn-item-as-const-arg-137084.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
error[E0308]: mismatched types
--> $DIR/fn-item-as-const-arg-137084.rs:9:5
|
LL | fn a<const b: i32>() {}
| -------------------- function `a` defined here
LL | fn d(e: &String) {
LL | a::<d>
| ^^^^^^ expected `()`, found fn item
|
= note: expected unit type `()`
found fn item `fn() {a::<d>}`
help: try adding a return type
|
LL | fn d(e: &String) -> fn() {
| +++++++
help: use parentheses to call this function
|
LL | a::<d>()
| ++

error: the constant `d` is not of type `i32`
--> $DIR/fn-item-as-const-arg-137084.rs:9:9
|
LL | a::<d>
| ^ 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<const b: i32>() {}
| ^^^^^^^^^^^^ 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`.
16 changes: 16 additions & 0 deletions tests/ui/const-generics/ice-151186-fn-ptr-in-where-clause.rs
Original file line number Diff line number Diff line change
@@ -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<T> {}

trait MyTrait<const F: fn() -> ()> {}
//~^ ERROR using function pointers as const generic parameters is forbidden

fn foo<'a>(x: &'a ()) -> &'a () { x }

impl<T> Maybe<T> for T where T: MyTrait<{ foo }> {}
//~^ ERROR the constant `foo` is not of type `fn()`

fn main() {}
22 changes: 22 additions & 0 deletions tests/ui/const-generics/ice-151186-fn-ptr-in-where-clause.stderr
Original file line number Diff line number Diff line change
@@ -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<const F: fn() -> ()> {}
| ^^^^^^^^^^
|
= 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<T> Maybe<T> 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<const F: fn() -> ()> {}
| ^^^^^^^^^^^^^^^^^^^ required by this const generic parameter in `MyTrait`

error: aborting due to 2 previous errors

Loading