From 3dd638fe6c0761aa0c124b7cf80a49ad7e04ed97 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 16 Feb 2023 20:32:59 +0000 Subject: [PATCH 1/3] Move call trait lang item malformed check to typeck --- .../rustc_hir_analysis/src/check/wfcheck.rs | 52 +------------------ compiler/rustc_hir_typeck/src/method/mod.rs | 6 +++ .../fn-fn_mut-call-ill-formed.bad_item.stderr | 18 +++++++ .../fn-fn_mut-call-ill-formed.bad_sig.stderr | 18 +++++++ ...-fn_mut-call-ill-formed.fn_bad_item.stderr | 18 +++++++ ...n-fn_mut-call-ill-formed.fn_bad_sig.stderr | 18 +++++++ ...mut-call-ill-formed.fn_mut_bad_item.stderr | 18 +++++++ ..._mut-call-ill-formed.fn_mut_bad_sig.stderr | 18 +++++++ ...ut-call-ill-formed.fn_once_bad_item.stderr | 18 +++++++ ...mut-call-ill-formed.fn_once_bad_sig.stderr | 9 ++++ .../lang-items/fn-fn_mut-call-ill-formed.rs | 34 +++++++++--- .../fn-fn_mut-call-ill-formed.stderr | 14 ----- 12 files changed, 170 insertions(+), 71 deletions(-) create mode 100644 tests/ui/lang-items/fn-fn_mut-call-ill-formed.bad_item.stderr create mode 100644 tests/ui/lang-items/fn-fn_mut-call-ill-formed.bad_sig.stderr create mode 100644 tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_bad_item.stderr create mode 100644 tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_bad_sig.stderr create mode 100644 tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_mut_bad_item.stderr create mode 100644 tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_mut_bad_sig.stderr create mode 100644 tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_once_bad_item.stderr create mode 100644 tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_once_bad_sig.stderr delete mode 100644 tests/ui/lang-items/fn-fn_mut-call-ill-formed.stderr diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 16e7dcd0060da..71eae7d63730a 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -16,7 +16,7 @@ use rustc_middle::mir::ConstraintCategory; use rustc_middle::ty::query::Providers; use rustc_middle::ty::trait_def::TraitSpecializationKind; use rustc_middle::ty::{ - self, ir::TypeVisitor, AdtKind, DefIdTree, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, + self, ir::TypeVisitor, AdtKind, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, }; use rustc_middle::ty::{GenericArgKind, InternalSubsts}; @@ -277,56 +277,6 @@ fn check_trait_item(tcx: TyCtxt<'_>, trait_item: &hir::TraitItem<'_>) { }; check_object_unsafe_self_trait_by_name(tcx, trait_item); check_associated_item(tcx, def_id, span, method_sig); - - let encl_trait_def_id = tcx.local_parent(def_id); - let encl_trait = tcx.hir().expect_item(encl_trait_def_id); - let encl_trait_def_id = encl_trait.owner_id.to_def_id(); - let fn_lang_item_name = if Some(encl_trait_def_id) == tcx.lang_items().fn_trait() { - Some("fn") - } else if Some(encl_trait_def_id) == tcx.lang_items().fn_mut_trait() { - Some("fn_mut") - } else { - None - }; - - if let (Some(fn_lang_item_name), "call") = - (fn_lang_item_name, trait_item.ident.name.to_ident_string().as_str()) - { - // We are looking at the `call` function of the `fn` or `fn_mut` lang item. - // Do some rudimentary sanity checking to avoid an ICE later (issue #83471). - if let Some(hir::FnSig { decl, span, .. }) = method_sig { - if let [self_ty, _] = decl.inputs { - if !matches!(self_ty.kind, hir::TyKind::Ref(_, _)) { - tcx.sess - .struct_span_err( - self_ty.span, - &format!( - "first argument of `call` in `{fn_lang_item_name}` lang item must be a reference", - ), - ) - .emit(); - } - } else { - tcx.sess - .struct_span_err( - *span, - &format!( - "`call` function in `{fn_lang_item_name}` lang item takes exactly two arguments", - ), - ) - .emit(); - } - } else { - tcx.sess - .struct_span_err( - trait_item.span, - &format!( - "`call` trait item in `{fn_lang_item_name}` lang item must be a function", - ), - ) - .emit(); - } - } } /// Require that the user writes where clauses on GATs for the implicit diff --git a/compiler/rustc_hir_typeck/src/method/mod.rs b/compiler/rustc_hir_typeck/src/method/mod.rs index d5d10cf272afa..c9ae82e8efbdf 100644 --- a/compiler/rustc_hir_typeck/src/method/mod.rs +++ b/compiler/rustc_hir_typeck/src/method/mod.rs @@ -380,6 +380,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ); return None; }; + + if method_item.kind != ty::AssocKind::Fn { + self.tcx.sess.delay_span_bug(tcx.def_span(method_item.def_id), "not a method"); + return None; + } + let def_id = method_item.def_id; let generics = tcx.generics_of(def_id); diff --git a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.bad_item.stderr b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.bad_item.stderr new file mode 100644 index 0000000000000..a45f629ff531a --- /dev/null +++ b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.bad_item.stderr @@ -0,0 +1,18 @@ +error: failed to find an overloaded call trait for closure call + --> $DIR/fn-fn_mut-call-ill-formed.rs:39:5 + | +LL | a(); + | ^^^ + | + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + +error: failed to find an overloaded call trait for closure call + --> $DIR/fn-fn_mut-call-ill-formed.rs:43:5 + | +LL | b(); + | ^^^ + | + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + +error: aborting due to 2 previous errors + diff --git a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.bad_sig.stderr b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.bad_sig.stderr new file mode 100644 index 0000000000000..a45f629ff531a --- /dev/null +++ b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.bad_sig.stderr @@ -0,0 +1,18 @@ +error: failed to find an overloaded call trait for closure call + --> $DIR/fn-fn_mut-call-ill-formed.rs:39:5 + | +LL | a(); + | ^^^ + | + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + +error: failed to find an overloaded call trait for closure call + --> $DIR/fn-fn_mut-call-ill-formed.rs:43:5 + | +LL | b(); + | ^^^ + | + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + +error: aborting due to 2 previous errors + diff --git a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_bad_item.stderr b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_bad_item.stderr new file mode 100644 index 0000000000000..a2600c85cfff4 --- /dev/null +++ b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_bad_item.stderr @@ -0,0 +1,18 @@ +error: failed to find an overloaded call trait for closure call + --> $DIR/fn-fn_mut-call-ill-formed.rs:42:5 + | +LL | a(); + | ^^^ + | + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + +error: failed to find an overloaded call trait for closure call + --> $DIR/fn-fn_mut-call-ill-formed.rs:47:5 + | +LL | b(); + | ^^^ + | + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + +error: aborting due to 2 previous errors + diff --git a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_bad_sig.stderr b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_bad_sig.stderr new file mode 100644 index 0000000000000..a2600c85cfff4 --- /dev/null +++ b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_bad_sig.stderr @@ -0,0 +1,18 @@ +error: failed to find an overloaded call trait for closure call + --> $DIR/fn-fn_mut-call-ill-formed.rs:42:5 + | +LL | a(); + | ^^^ + | + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + +error: failed to find an overloaded call trait for closure call + --> $DIR/fn-fn_mut-call-ill-formed.rs:47:5 + | +LL | b(); + | ^^^ + | + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + +error: aborting due to 2 previous errors + diff --git a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_mut_bad_item.stderr b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_mut_bad_item.stderr new file mode 100644 index 0000000000000..a2600c85cfff4 --- /dev/null +++ b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_mut_bad_item.stderr @@ -0,0 +1,18 @@ +error: failed to find an overloaded call trait for closure call + --> $DIR/fn-fn_mut-call-ill-formed.rs:42:5 + | +LL | a(); + | ^^^ + | + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + +error: failed to find an overloaded call trait for closure call + --> $DIR/fn-fn_mut-call-ill-formed.rs:47:5 + | +LL | b(); + | ^^^ + | + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + +error: aborting due to 2 previous errors + diff --git a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_mut_bad_sig.stderr b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_mut_bad_sig.stderr new file mode 100644 index 0000000000000..a2600c85cfff4 --- /dev/null +++ b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_mut_bad_sig.stderr @@ -0,0 +1,18 @@ +error: failed to find an overloaded call trait for closure call + --> $DIR/fn-fn_mut-call-ill-formed.rs:42:5 + | +LL | a(); + | ^^^ + | + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + +error: failed to find an overloaded call trait for closure call + --> $DIR/fn-fn_mut-call-ill-formed.rs:47:5 + | +LL | b(); + | ^^^ + | + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + +error: aborting due to 2 previous errors + diff --git a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_once_bad_item.stderr b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_once_bad_item.stderr new file mode 100644 index 0000000000000..a2600c85cfff4 --- /dev/null +++ b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_once_bad_item.stderr @@ -0,0 +1,18 @@ +error: failed to find an overloaded call trait for closure call + --> $DIR/fn-fn_mut-call-ill-formed.rs:42:5 + | +LL | a(); + | ^^^ + | + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + +error: failed to find an overloaded call trait for closure call + --> $DIR/fn-fn_mut-call-ill-formed.rs:47:5 + | +LL | b(); + | ^^^ + | + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + +error: aborting due to 2 previous errors + diff --git a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_once_bad_sig.stderr b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_once_bad_sig.stderr new file mode 100644 index 0000000000000..bb91eedebeaa5 --- /dev/null +++ b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_once_bad_sig.stderr @@ -0,0 +1,9 @@ +error[E0308]: mismatched types + --> $DIR/fn-fn_mut-call-ill-formed.rs:47:5 + | +LL | b(); + | ^^^ expected `i32`, found `()` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.rs b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.rs index 52bd8136d9c0c..757c6538d05b0 100644 --- a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.rs +++ b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.rs @@ -1,27 +1,49 @@ -// Make sure that an error is reported if the `call` function of the -// `fn`/`fn_mut` lang item is grossly ill-formed. +// revisions: fn_once_bad_item fn_once_bad_sig fn_mut_bad_item fn_mut_bad_sig fn_bad_item fn_bad_sig #![feature(lang_items)] #![feature(no_core)] #![no_core] +#[lang = "sized"] +trait Sized {} + +#[cfg(any(fn_bad_item, fn_bad_sig))] #[lang = "fn"] trait MyFn { + #[cfg(fn_bad_sig)] + fn call(i: i32) -> i32 { 0 } + + #[cfg(fn_bad_item)] const call: i32 = 42; - //~^ ERROR: `call` trait item in `fn` lang item must be a function } +#[cfg(any(fn_mut_bad_item, fn_mut_bad_sig))] #[lang = "fn_mut"] trait MyFnMut { - fn call(i: i32, j: i32) -> i32 { i + j } - //~^ ERROR: first argument of `call` in `fn_mut` lang item must be a reference + #[cfg(fn_mut_bad_sig)] + fn call_mut(i: i32) -> i32 { 0 } + + #[cfg(fn_mut_bad_item)] + const call_mut: i32 = 42; +} + +#[cfg(any(fn_once_bad_item, fn_once_bad_sig))] +#[lang = "fn_once"] +trait MyFnOnce { + #[cfg(fn_once_bad_sig)] + fn call_once(i: i32) -> i32 { 0 } + + #[cfg(fn_once_bad_item)] + const call_once: i32 = 42; } fn main() { let a = || 42; a(); + //~^ ERROR failed to find an overloaded call trait for closure call let mut i = 0; - let mut b = || { i += 1; }; + let mut b = || { }; b(); + //~^ ERROR failed to find an overloaded call trait for closure call } diff --git a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.stderr b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.stderr deleted file mode 100644 index 82bdae270c8bb..0000000000000 --- a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error: `call` trait item in `fn` lang item must be a function - --> $DIR/fn-fn_mut-call-ill-formed.rs:10:5 - | -LL | const call: i32 = 42; - | ^^^^^^^^^^^^^^^^^^^^^ - -error: first argument of `call` in `fn_mut` lang item must be a reference - --> $DIR/fn-fn_mut-call-ill-formed.rs:16:16 - | -LL | fn call(i: i32, j: i32) -> i32 { i + j } - | ^^^ - -error: aborting due to 2 previous errors - From ff9c5db03cc4fad005b9e3651b42a6945a0d9f36 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 16 Feb 2023 20:52:29 +0000 Subject: [PATCH 2/3] Tweak wording --- compiler/rustc_hir_typeck/src/callee.rs | 14 ++++++++++++-- .../fn-fn_mut-call-ill-formed.bad_item.stderr | 4 ++-- .../fn-fn_mut-call-ill-formed.bad_sig.stderr | 4 ++-- ...fn-fn_mut-call-ill-formed.fn_bad_item.stderr | 4 ++-- .../fn-fn_mut-call-ill-formed.fn_bad_sig.stderr | 4 ++-- ...n_mut-call-ill-formed.fn_mut_bad_item.stderr | 4 ++-- ...fn_mut-call-ill-formed.fn_mut_bad_sig.stderr | 4 ++-- ..._mut-call-ill-formed.fn_once_bad_item.stderr | 4 ++-- ...n_mut-call-ill-formed.fn_once_bad_sig.stderr | 17 +++++++++++++---- tests/ui/lang-items/issue-86238.stderr | 2 +- 10 files changed, 40 insertions(+), 21 deletions(-) diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index 089863a66e73b..06b2b2451f0fa 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -247,6 +247,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { adjusted_ty, opt_input_type.as_ref().map(slice::from_ref), ) { + // Check for `self` receiver on the method, otherwise we can't use this as a `Fn*` trait. + if !self.tcx.associated_item(ok.value.def_id).fn_has_self_parameter { + self.tcx.sess.delay_span_bug( + call_expr.span, + "input to overloaded call fn is not a self receiver", + ); + return None; + } + let method = self.register_infer_ok_obligations(ok); let mut autoref = None; if borrow { @@ -257,7 +266,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // caused an error elsewhere. self.tcx .sess - .delay_span_bug(call_expr.span, "input to call/call_mut is not a ref?"); + .delay_span_bug(call_expr.span, "input to call/call_mut is not a ref"); return None; }; @@ -271,6 +280,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { target: method.sig.inputs()[0], }); } + return Some((autoref, method)); } } @@ -823,7 +833,7 @@ impl<'a, 'tcx> DeferredCallResolution<'tcx> { ); err.help( "make sure the `fn`/`fn_mut`/`fn_once` lang items are defined \ - and have associated `call`/`call_mut`/`call_once` functions", + and have correctly defined `call`/`call_mut`/`call_once` methods", ); err.emit(); } diff --git a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.bad_item.stderr b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.bad_item.stderr index a45f629ff531a..ff603111e94c5 100644 --- a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.bad_item.stderr +++ b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.bad_item.stderr @@ -4,7 +4,7 @@ error: failed to find an overloaded call trait for closure call LL | a(); | ^^^ | - = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods error: failed to find an overloaded call trait for closure call --> $DIR/fn-fn_mut-call-ill-formed.rs:43:5 @@ -12,7 +12,7 @@ error: failed to find an overloaded call trait for closure call LL | b(); | ^^^ | - = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods error: aborting due to 2 previous errors diff --git a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.bad_sig.stderr b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.bad_sig.stderr index a45f629ff531a..ff603111e94c5 100644 --- a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.bad_sig.stderr +++ b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.bad_sig.stderr @@ -4,7 +4,7 @@ error: failed to find an overloaded call trait for closure call LL | a(); | ^^^ | - = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods error: failed to find an overloaded call trait for closure call --> $DIR/fn-fn_mut-call-ill-formed.rs:43:5 @@ -12,7 +12,7 @@ error: failed to find an overloaded call trait for closure call LL | b(); | ^^^ | - = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods error: aborting due to 2 previous errors diff --git a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_bad_item.stderr b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_bad_item.stderr index a2600c85cfff4..02e33c597fe87 100644 --- a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_bad_item.stderr +++ b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_bad_item.stderr @@ -4,7 +4,7 @@ error: failed to find an overloaded call trait for closure call LL | a(); | ^^^ | - = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods error: failed to find an overloaded call trait for closure call --> $DIR/fn-fn_mut-call-ill-formed.rs:47:5 @@ -12,7 +12,7 @@ error: failed to find an overloaded call trait for closure call LL | b(); | ^^^ | - = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods error: aborting due to 2 previous errors diff --git a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_bad_sig.stderr b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_bad_sig.stderr index a2600c85cfff4..02e33c597fe87 100644 --- a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_bad_sig.stderr +++ b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_bad_sig.stderr @@ -4,7 +4,7 @@ error: failed to find an overloaded call trait for closure call LL | a(); | ^^^ | - = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods error: failed to find an overloaded call trait for closure call --> $DIR/fn-fn_mut-call-ill-formed.rs:47:5 @@ -12,7 +12,7 @@ error: failed to find an overloaded call trait for closure call LL | b(); | ^^^ | - = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods error: aborting due to 2 previous errors diff --git a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_mut_bad_item.stderr b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_mut_bad_item.stderr index a2600c85cfff4..02e33c597fe87 100644 --- a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_mut_bad_item.stderr +++ b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_mut_bad_item.stderr @@ -4,7 +4,7 @@ error: failed to find an overloaded call trait for closure call LL | a(); | ^^^ | - = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods error: failed to find an overloaded call trait for closure call --> $DIR/fn-fn_mut-call-ill-formed.rs:47:5 @@ -12,7 +12,7 @@ error: failed to find an overloaded call trait for closure call LL | b(); | ^^^ | - = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods error: aborting due to 2 previous errors diff --git a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_mut_bad_sig.stderr b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_mut_bad_sig.stderr index a2600c85cfff4..02e33c597fe87 100644 --- a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_mut_bad_sig.stderr +++ b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_mut_bad_sig.stderr @@ -4,7 +4,7 @@ error: failed to find an overloaded call trait for closure call LL | a(); | ^^^ | - = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods error: failed to find an overloaded call trait for closure call --> $DIR/fn-fn_mut-call-ill-formed.rs:47:5 @@ -12,7 +12,7 @@ error: failed to find an overloaded call trait for closure call LL | b(); | ^^^ | - = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods error: aborting due to 2 previous errors diff --git a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_once_bad_item.stderr b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_once_bad_item.stderr index a2600c85cfff4..02e33c597fe87 100644 --- a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_once_bad_item.stderr +++ b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_once_bad_item.stderr @@ -4,7 +4,7 @@ error: failed to find an overloaded call trait for closure call LL | a(); | ^^^ | - = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods error: failed to find an overloaded call trait for closure call --> $DIR/fn-fn_mut-call-ill-formed.rs:47:5 @@ -12,7 +12,7 @@ error: failed to find an overloaded call trait for closure call LL | b(); | ^^^ | - = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods error: aborting due to 2 previous errors diff --git a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_once_bad_sig.stderr b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_once_bad_sig.stderr index bb91eedebeaa5..02e33c597fe87 100644 --- a/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_once_bad_sig.stderr +++ b/tests/ui/lang-items/fn-fn_mut-call-ill-formed.fn_once_bad_sig.stderr @@ -1,9 +1,18 @@ -error[E0308]: mismatched types +error: failed to find an overloaded call trait for closure call + --> $DIR/fn-fn_mut-call-ill-formed.rs:42:5 + | +LL | a(); + | ^^^ + | + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods + +error: failed to find an overloaded call trait for closure call --> $DIR/fn-fn_mut-call-ill-formed.rs:47:5 | LL | b(); - | ^^^ expected `i32`, found `()` + | ^^^ + | + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods -error: aborting due to previous error +error: aborting due to 2 previous errors -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/lang-items/issue-86238.stderr b/tests/ui/lang-items/issue-86238.stderr index 767e6de2263b9..c6e811a94fe20 100644 --- a/tests/ui/lang-items/issue-86238.stderr +++ b/tests/ui/lang-items/issue-86238.stderr @@ -4,7 +4,7 @@ error: failed to find an overloaded call trait for closure call LL | one() | ^^^^^ | - = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have associated `call`/`call_mut`/`call_once` functions + = help: make sure the `fn`/`fn_mut`/`fn_once` lang items are defined and have correctly defined `call`/`call_mut`/`call_once` methods error: aborting due to previous error From 2a700d47f592a52ebc32ae41b67cd5da756a17d9 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Thu, 16 Feb 2023 20:58:48 +0000 Subject: [PATCH 3/3] Add ICE test for bad Add::add impl item type --- tests/ui/lang-items/bad-add-impl.rs | 18 ++++++++++++++++++ tests/ui/lang-items/bad-add-impl.stderr | 11 +++++++++++ 2 files changed, 29 insertions(+) create mode 100644 tests/ui/lang-items/bad-add-impl.rs create mode 100644 tests/ui/lang-items/bad-add-impl.stderr diff --git a/tests/ui/lang-items/bad-add-impl.rs b/tests/ui/lang-items/bad-add-impl.rs new file mode 100644 index 0000000000000..0c44edbe51a0c --- /dev/null +++ b/tests/ui/lang-items/bad-add-impl.rs @@ -0,0 +1,18 @@ +#![feature(no_core)] +#![feature(lang_items)] +#![no_core] + +#[lang = "sized"] +trait Sized {} + +#[lang = "add"] +trait Add { + const add: u32 = 1u32; +} + +impl Add for u32 {} + +fn main() { + 1u32 + 1u32; + //~^ ERROR cannot add `u32` to `u32` +} diff --git a/tests/ui/lang-items/bad-add-impl.stderr b/tests/ui/lang-items/bad-add-impl.stderr new file mode 100644 index 0000000000000..3143729f99bb0 --- /dev/null +++ b/tests/ui/lang-items/bad-add-impl.stderr @@ -0,0 +1,11 @@ +error[E0369]: cannot add `u32` to `u32` + --> $DIR/bad-add-impl.rs:16:10 + | +LL | 1u32 + 1u32; + | ---- ^ ---- u32 + | | + | u32 + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0369`.