Skip to content

Commit f91fa51

Browse files
authored
Rollup merge of #105201 - cjgillot:issue-105040, r=compiler-errors
Do not call fn_sig on non-functions. Fixes #105040 Fixes #89271
2 parents b1e6806 + e973240 commit f91fa51

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1918,6 +1918,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19181918
receiver: Option<&'tcx hir::Expr<'tcx>>,
19191919
args: &'tcx [hir::Expr<'tcx>],
19201920
) -> bool {
1921+
// Do not call `fn_sig` on non-functions.
1922+
if !matches!(
1923+
self.tcx.def_kind(def_id),
1924+
DefKind::Fn | DefKind::AssocFn | DefKind::Variant | DefKind::Ctor(..)
1925+
) {
1926+
return false;
1927+
}
1928+
19211929
let sig = self.tcx.fn_sig(def_id).skip_binder();
19221930
let args_referencing_param: Vec<_> = sig
19231931
.inputs()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
unsafe fn pointer(v: usize, w: u32) {}
2+
3+
pub trait UniformScalar {}
4+
impl UniformScalar for u32 {}
5+
6+
pub trait GlUniformScalar: UniformScalar {
7+
const FACTORY: unsafe fn(usize, Self) -> ();
8+
}
9+
impl GlUniformScalar for u32 {
10+
const FACTORY: unsafe fn(usize, Self) -> () = pointer;
11+
}
12+
13+
pub fn foo<T: UniformScalar>(value: T) {
14+
<T as GlUniformScalar>::FACTORY(1, value);
15+
//~^ ERROR the trait bound `T: GlUniformScalar` is not satisfied
16+
}
17+
18+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error[E0277]: the trait bound `T: GlUniformScalar` is not satisfied
2+
--> $DIR/assoc-const-as-fn.rs:14:5
3+
|
4+
LL | <T as GlUniformScalar>::FACTORY(1, value);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `GlUniformScalar` is not implemented for `T`
6+
|
7+
help: consider further restricting this bound
8+
|
9+
LL | pub fn foo<T: UniformScalar + GlUniformScalar>(value: T) {
10+
| +++++++++++++++++
11+
12+
error: aborting due to previous error
13+
14+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)