Skip to content
Draft
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
18 changes: 17 additions & 1 deletion compiler/rustc_hir_analysis/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,22 @@ fn check_static_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) {
}
}

fn check_function_clauses(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGuaranteed> {

@lcnr lcnr Sep 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

didn't realize, we should move this to check::wfcheck which already has a function to check functions. feel free to wait until after the crater run is done

View changes since the review

let clauses = tcx.clauses_of(def_id);
let param_env = tcx.param_env(def_id);
enter_wf_checking_ctxt(tcx, def_id, |wfcx| {
for (clause, span) in clauses.clauses {
wfcx.register_obligation(Obligation::new(
tcx,
ObligationCause::new(*span, def_id, ObligationCauseCode::WellFormed(None)),
param_env,
*clause,
));
}
Ok(())
})
}

pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(), ErrorGuaranteed> {
let mut res = Ok(());
let generics = tcx.generics_of(def_id);
Expand Down Expand Up @@ -815,9 +831,9 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<(),
DefKind::Fn => {
tcx.ensure_ok().generics_of(def_id);
tcx.ensure_ok().type_of(def_id);
tcx.ensure_ok().clauses_of(def_id);
tcx.ensure_ok().fn_sig(def_id);
tcx.ensure_ok().codegen_fn_attrs(def_id);
res = res.and(check_function_clauses(tcx, def_id));
if let Some(i) = tcx.intrinsic(def_id) {
intrinsic::check_intrinsic_type(
tcx,
Expand Down
1 change: 1 addition & 0 deletions tests/ui/associated-inherent-types/issue-109789.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ impl Other for u32 {}
fn bar(_: Foo<for<'a> fn(&'a ())>::Assoc) {}
//~^ ERROR mismatched types
//~| ERROR mismatched types
//~| ERROR mismatched types
//~| ERROR higher-ranked subtype error
//~| ERROR higher-ranked subtype error
//~| ERROR higher-ranked subtype error
Expand Down
12 changes: 11 additions & 1 deletion tests/ui/associated-inherent-types/issue-109789.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ LL | fn bar(_: Foo<for<'a> fn(&'a ())>::Assoc) {}
found struct `Foo<for<'a> fn(&'a ())>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0308]: mismatched types
--> $DIR/issue-109789.rs:18:11
|
LL | fn bar(_: Foo<for<'a> fn(&'a ())>::Assoc) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected struct `Foo<fn(&'static ())>`
found struct `Foo<for<'a> fn(&'a ())>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: higher-ranked subtype error
--> $DIR/issue-109789.rs:18:1
|
Expand All @@ -39,6 +49,6 @@ LL | fn bar(_: Foo<for<'a> fn(&'a ())>::Assoc) {}
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: aborting due to 5 previous errors
error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0308`.
1 change: 1 addition & 0 deletions tests/ui/associated-inherent-types/issue-111404-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ impl<'a> Foo<fn(&'a ())> {
fn bar(_: fn(Foo<for<'b> fn(Foo<fn(&'b ())>::Assoc)>::Assoc)) {}
//~^ ERROR mismatched types [E0308]
//~| ERROR mismatched types [E0308]
//~| ERROR mismatched types [E0308]
//~| ERROR higher-ranked subtype error
//~| ERROR higher-ranked subtype error
//~| ERROR higher-ranked subtype error
Expand Down
12 changes: 11 additions & 1 deletion tests/ui/associated-inherent-types/issue-111404-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ LL | fn bar(_: fn(Foo<for<'b> fn(Foo<fn(&'b ())>::Assoc)>::Assoc)) {}
found struct `Foo<for<'b> fn(&'b ())>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error[E0308]: mismatched types
--> $DIR/issue-111404-1.rs:10:11
|
LL | fn bar(_: fn(Foo<for<'b> fn(Foo<fn(&'b ())>::Assoc)>::Assoc)) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ one type is more general than the other
|
= note: expected struct `Foo<fn(&())>`
found struct `Foo<for<'b> fn(&'b ())>`
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: higher-ranked subtype error
--> $DIR/issue-111404-1.rs:10:1
|
Expand All @@ -37,6 +47,6 @@ error: higher-ranked subtype error
LL | fn bar(_: fn(Foo<for<'b> fn(Foo<fn(&'b ())>::Assoc)>::Assoc)) {}
| ^

error: aborting due to 5 previous errors
error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0308`.
6 changes: 4 additions & 2 deletions tests/ui/associated-inherent-types/regionck-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ impl Lexer<'static> {
type Cursor = ();
}

fn test(_: Lexer::Cursor) {} //~ ERROR mismatched types
//~^ ERROR: lifetime may not live long enough
fn test(_: Lexer::Cursor) {}
//~^ ERROR: mismatched types
//~| ERROR: mismatched types
//~| ERROR: lifetime may not live long enough

fn main() {}
18 changes: 17 additions & 1 deletion tests/ui/associated-inherent-types/regionck-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@ LL | fn test(_: Lexer::Cursor) {}
| ^^^^^
= note: ...does not necessarily outlive the static lifetime

error[E0308]: mismatched types
--> $DIR/regionck-2.rs:12:12
|
LL | fn test(_: Lexer::Cursor) {}
| ^^^^^^^^^^^^^ lifetime mismatch
|
= note: expected struct `Lexer<'static>`
found struct `Lexer<'_>`
note: the anonymous lifetime defined here...
--> $DIR/regionck-2.rs:12:12
|
LL | fn test(_: Lexer::Cursor) {}
| ^^^^^
= note: ...does not necessarily outlive the static lifetime
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: lifetime may not live long enough
--> $DIR/regionck-2.rs:12:1
|
Expand All @@ -22,6 +38,6 @@ LL | fn test(_: Lexer::Cursor) {}
| | has type `Lexer<'1>::Cursor`
| requires that `'1` must outlive `'static`

error: aborting due to 2 previous errors
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0308`.
13 changes: 5 additions & 8 deletions tests/ui/associated-type-bounds/duplicate-bound-err.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
//@ edition: 2024

#![feature(
min_generic_const_args,
type_alias_impl_trait,
return_type_notation
)]
#![feature(min_generic_const_args, type_alias_impl_trait, return_type_notation)]
#![expect(incomplete_features)]
#![allow(refining_impl_trait_internal)]

Expand Down Expand Up @@ -74,12 +70,13 @@ impl Trait for u32 {
}

fn uncallable(_: impl Iterator<Item = i32, Item = u32>) {}
//~^ ERROR type annotations needed

fn uncallable_const(_: impl Trait<ASSOC = 3, ASSOC = 4>) {}
//~^ ERROR type annotations needed

fn uncallable_rtn(
_: impl Trait<foo(..): Trait<ASSOC = 3>, foo(..): Trait<ASSOC = 4>>
) {}
fn uncallable_rtn(_: impl Trait<foo(..): Trait<ASSOC = 3>, foo(..): Trait<ASSOC = 4>>) {}
//~^ ERROR type annotations needed

type MustFail = dyn Iterator<Item = i32, Item = u32>;
//~^ ERROR [E0719]
Expand Down
Loading
Loading