From 30cdb688481f8d21698d0601c2cdb2ff5afdae78 Mon Sep 17 00:00:00 2001 From: Yosh Date: Thu, 6 Nov 2025 17:27:12 +0100 Subject: [PATCH 01/10] `DropGuard::into_inner` -> `DropGuard::dismiss` Also changes it from a static method to an instance method. --- library/core/src/mem/drop_guard.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/library/core/src/mem/drop_guard.rs b/library/core/src/mem/drop_guard.rs index fecc94b815e97..314277bcd95fe 100644 --- a/library/core/src/mem/drop_guard.rs +++ b/library/core/src/mem/drop_guard.rs @@ -63,13 +63,10 @@ where /// Consumes the `DropGuard`, returning the wrapped value. /// - /// This will not execute the closure. This is implemented as an associated - /// function to prevent any potential conflicts with any other methods called - /// `into_inner` from the `Deref` and `DerefMut` impls. - /// - /// It is typically preferred to call this function instead of `mem::forget` - /// because it will return the stored value and drop variables captured - /// by the closure instead of leaking their owned resources. + /// This will not execute the closure. It is typically preferred to call + /// this function instead of `mem::forget` because it will return the stored + /// value and drop variables captured by the closure instead of leaking their + /// owned resources. /// /// # Example /// @@ -81,11 +78,11 @@ where /// /// let value = String::from("Nori likes chicken"); /// let guard = DropGuard::new(value, |s| println!("{s}")); - /// assert_eq!(DropGuard::into_inner(guard), "Nori likes chicken"); + /// assert_eq!(guard.dismiss(), "Nori likes chicken"); /// ``` #[unstable(feature = "drop_guard", issue = "144426")] #[inline] - pub fn into_inner(guard: Self) -> T { + pub fn dismiss(self) -> T { // First we ensure that dropping the guard will not trigger // its destructor let mut guard = ManuallyDrop::new(guard); From 6f8a1a6082d574bf9bbaeb413fd5f1b0fa55b29a Mon Sep 17 00:00:00 2001 From: Yosh Date: Thu, 6 Nov 2025 17:51:59 +0100 Subject: [PATCH 02/10] Fix tests --- library/coretests/tests/mem.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/coretests/tests/mem.rs b/library/coretests/tests/mem.rs index e896c61ef4881..00582109aa2c5 100644 --- a/library/coretests/tests/mem.rs +++ b/library/coretests/tests/mem.rs @@ -815,7 +815,7 @@ fn drop_guard_into_inner() { let dropped = Cell::new(false); let value = DropGuard::new(42, |_| dropped.set(true)); let guard = DropGuard::new(value, |_| dropped.set(true)); - let inner = DropGuard::into_inner(guard); + let inner = guard.dismiss(); assert_eq!(dropped.get(), false); assert_eq!(*inner, 42); } @@ -837,7 +837,7 @@ fn drop_guard_always_drops_value_if_closure_drop_unwinds() { // run the destructor of the value we passed, which we validate. let _ = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { let guard = DropGuard::new(value_with_tracked_destruction, closure_that_panics_on_drop); - DropGuard::into_inner(guard); + guard.dismiss(); })); assert!(value_was_dropped); } From a15c21ecdbb4fa083a0116130864e93a904fd7ab Mon Sep 17 00:00:00 2001 From: Yosh Date: Thu, 6 Nov 2025 18:44:49 +0100 Subject: [PATCH 03/10] Update drop_guard.rs --- library/core/src/mem/drop_guard.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/core/src/mem/drop_guard.rs b/library/core/src/mem/drop_guard.rs index 314277bcd95fe..1301dedf1241a 100644 --- a/library/core/src/mem/drop_guard.rs +++ b/library/core/src/mem/drop_guard.rs @@ -85,19 +85,19 @@ where pub fn dismiss(self) -> T { // First we ensure that dropping the guard will not trigger // its destructor - let mut guard = ManuallyDrop::new(guard); + let mut this = ManuallyDrop::new(self); // Next we manually read the stored value from the guard. // // SAFETY: this is safe because we've taken ownership of the guard. - let value = unsafe { ManuallyDrop::take(&mut guard.inner) }; + let value = unsafe { ManuallyDrop::take(&mut this.inner) }; // Finally we drop the stored closure. We do this *after* having read // the value, so that even if the closure's `drop` function panics, // unwinding still tries to drop the value. // // SAFETY: this is safe because we've taken ownership of the guard. - unsafe { ManuallyDrop::drop(&mut guard.f) }; + unsafe { ManuallyDrop::drop(&mut this.f) }; value } } From feb13036efec5d2bb2362b500de63192f3b6b38f Mon Sep 17 00:00:00 2001 From: lcnr Date: Tue, 25 Nov 2025 10:19:28 +0100 Subject: [PATCH 04/10] remove support for type-of --- compiler/rustc_ast/src/ast.rs | 2 - compiler/rustc_ast/src/util/classify.rs | 1 - compiler/rustc_ast_lowering/src/lib.rs | 1 - compiler/rustc_ast_pretty/src/pprust/state.rs | 5 --- .../src/error_codes/E0516.md | 2 + compiler/rustc_hir/src/hir.rs | 2 - compiler/rustc_hir/src/intravisit.rs | 1 - compiler/rustc_hir_analysis/messages.ftl | 5 --- .../src/coherence/inherent_impls.rs | 9 +++-- .../src/coherence/orphan.rs | 14 +++---- .../rustc_hir_analysis/src/collect/type_of.rs | 20 +--------- compiler/rustc_hir_analysis/src/errors.rs | 11 ----- .../src/hir_ty_lowering/mod.rs | 1 - compiler/rustc_hir_pretty/src/lib.rs | 5 --- compiler/rustc_hir_typeck/src/lib.rs | 5 --- compiler/rustc_lint/src/unused.rs | 12 ------ .../rustc_next_trait_solver/src/coherence.rs | 33 ++++----------- compiler/rustc_parse/src/parser/ty.rs | 21 ++++++---- compiler/rustc_passes/src/input_stats.rs | 2 - compiler/rustc_resolve/src/late.rs | 3 -- src/tools/tidy/src/issues.txt | 3 -- tests/ui/closures/impl-closure-147146.rs | 7 ---- tests/ui/closures/impl-closure-147146.stderr | 15 ------- tests/ui/error-codes/E0516.rs | 1 - tests/ui/error-codes/E0516.stderr | 10 ++--- tests/ui/typeof/issue-100183.rs | 6 --- tests/ui/typeof/issue-100183.stderr | 15 ------- tests/ui/typeof/issue-29184.rs | 3 -- tests/ui/typeof/issue-29184.stderr | 15 ------- tests/ui/typeof/issue-42060.rs | 11 ----- tests/ui/typeof/issue-42060.stderr | 40 ------------------- tests/ui/typeof/type_mismatch.rs | 12 ------ tests/ui/typeof/type_mismatch.stderr | 30 -------------- 33 files changed, 38 insertions(+), 285 deletions(-) delete mode 100644 tests/ui/closures/impl-closure-147146.rs delete mode 100644 tests/ui/closures/impl-closure-147146.stderr delete mode 100644 tests/ui/typeof/issue-100183.rs delete mode 100644 tests/ui/typeof/issue-100183.stderr delete mode 100644 tests/ui/typeof/issue-29184.rs delete mode 100644 tests/ui/typeof/issue-29184.stderr delete mode 100644 tests/ui/typeof/issue-42060.rs delete mode 100644 tests/ui/typeof/issue-42060.stderr delete mode 100644 tests/ui/typeof/type_mismatch.rs delete mode 100644 tests/ui/typeof/type_mismatch.stderr diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index f2061f3088a25..e40d86dbb7b2d 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2513,8 +2513,6 @@ pub enum TyKind { ImplTrait(NodeId, #[visitable(extra = BoundKind::Impl)] GenericBounds), /// No-op; kept solely so that we can pretty-print faithfully. Paren(Box), - /// Unused for now. - Typeof(AnonConst), /// This means the type should be inferred instead of it having been /// specified. This can appear anywhere in a type. Infer, diff --git a/compiler/rustc_ast/src/util/classify.rs b/compiler/rustc_ast/src/util/classify.rs index f7daec4b0648c..2e494b968b6bd 100644 --- a/compiler/rustc_ast/src/util/classify.rs +++ b/compiler/rustc_ast/src/util/classify.rs @@ -294,7 +294,6 @@ fn type_trailing_braced_mac_call(mut ty: &ast::Ty) -> Option<&ast::MacCall> { | ast::TyKind::Never | ast::TyKind::Tup(..) | ast::TyKind::Paren(..) - | ast::TyKind::Typeof(..) | ast::TyKind::Infer | ast::TyKind::ImplicitSelf | ast::TyKind::CVarArgs diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 1f36454ec861a..dff46ece65430 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1367,7 +1367,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { self.lower_ty(ty, itctx), self.lower_array_length_to_const_arg(length), ), - TyKind::Typeof(expr) => hir::TyKind::Typeof(self.lower_anon_const_to_anon_const(expr)), TyKind::TraitObject(bounds, kind) => { let mut lifetime_bound = None; let (bounds, lifetime_bound) = self.with_dyn_type_scope(true, |this| { diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 21b14f1610779..3dce0498efbf9 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1325,11 +1325,6 @@ impl<'a> State<'a> { self.print_expr(&length.value, FixupContext::default()); self.word("]"); } - ast::TyKind::Typeof(e) => { - self.word("typeof("); - self.print_expr(&e.value, FixupContext::default()); - self.word(")"); - } ast::TyKind::Infer => { self.word("_"); } diff --git a/compiler/rustc_error_codes/src/error_codes/E0516.md b/compiler/rustc_error_codes/src/error_codes/E0516.md index 935c31bbab98a..baaa4903a3576 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0516.md +++ b/compiler/rustc_error_codes/src/error_codes/E0516.md @@ -1,3 +1,5 @@ +#### Note: this error code is no longer emitted by the compiler. + The `typeof` keyword is currently reserved but unimplemented. Erroneous code example: diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index db88de828aafd..5ea5bf406cf67 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -3680,8 +3680,6 @@ pub enum TyKind<'hir, Unambig = ()> { /// We use pointer tagging to represent a `&'hir Lifetime` and `TraitObjectSyntax` pair /// as otherwise this type being `repr(C)` would result in `TyKind` increasing in size. TraitObject(&'hir [PolyTraitRef<'hir>], TaggedRef<'hir, Lifetime, TraitObjectSyntax>), - /// Unused for now. - Typeof(&'hir AnonConst), /// Placeholder for a type that has failed to be defined. Err(rustc_span::ErrorGuaranteed), /// Pattern types (`pattern_type!(u32 is 1..)`) diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index 0b83e7239a992..625766f8bd3da 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -1029,7 +1029,6 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v, AmbigArg>) - } try_visit!(visitor.visit_lifetime(lifetime)); } - TyKind::Typeof(ref expression) => try_visit!(visitor.visit_anon_const(expression)), TyKind::InferDelegation(..) | TyKind::Err(_) => {} TyKind::Pat(ty, pat) => { try_visit!(visitor.visit_ty_unambig(ty)); diff --git a/compiler/rustc_hir_analysis/messages.ftl b/compiler/rustc_hir_analysis/messages.ftl index a313b91ef9bda..bcf4d7f59e34a 100644 --- a/compiler/rustc_hir_analysis/messages.ftl +++ b/compiler/rustc_hir_analysis/messages.ftl @@ -552,11 +552,6 @@ hir_analysis_ty_param_some = type parameter `{$param}` must be used as the type hir_analysis_type_of = {$ty} -hir_analysis_typeof_reserved_keyword_used = - `typeof` is a reserved keyword but unimplemented - .suggestion = consider replacing `typeof(...)` with an actual type - .label = reserved keyword - hir_analysis_unconstrained_generic_parameter = the {$param_def_kind} `{$param_name}` is not constrained by the impl trait, self type, or predicates .label = unconstrained {$param_def_kind} .const_param_note = expressions using a const parameter must map each value to a distinct output value diff --git a/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs b/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs index b069a74bf5adc..38ae7852ca99f 100644 --- a/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs +++ b/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs @@ -195,10 +195,11 @@ impl<'tcx> InherentCollect<'tcx> { | ty::Closure(..) | ty::CoroutineClosure(..) | ty::Coroutine(..) - | ty::CoroutineWitness(..) => { - Err(self.tcx.dcx().delayed_bug("cannot define inherent `impl` for closure types")) - } - ty::Alias(ty::Free, _) | ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) => { + | ty::CoroutineWitness(..) + | ty::Alias(ty::Free, _) + | ty::Bound(..) + | ty::Placeholder(_) + | ty::Infer(_) => { bug!("unexpected impl self type of impl: {:?} {:?}", id, self_ty); } // We could bail out here, but that will silence other useful errors. diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index 69921893fce40..f1e138dbcb97a 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -217,21 +217,19 @@ pub(crate) fn orphan_check_impl( | ty::Slice(..) | ty::RawPtr(..) | ty::Ref(..) - | ty::FnDef(..) | ty::FnPtr(..) | ty::Never | ty::Tuple(..) | ty::UnsafeBinder(_) => (LocalImpl::Allow, NonlocalImpl::DisallowOther), - ty::Closure(..) + ty::FnDef(..) + | ty::Closure(..) | ty::CoroutineClosure(..) | ty::Coroutine(..) - | ty::CoroutineWitness(..) => { - return Err(tcx - .dcx() - .delayed_bug("cannot define inherent `impl` for closure types")); - } - ty::Bound(..) | ty::Placeholder(..) | ty::Infer(..) => { + | ty::CoroutineWitness(..) + | ty::Bound(..) + | ty::Placeholder(..) + | ty::Infer(..) => { let sp = tcx.def_span(impl_def_id); span_bug!(sp, "weird self type for autotrait impl") } diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 9f87381887b30..180589340b4cb 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -7,15 +7,12 @@ use rustc_hir::{self as hir, AmbigArg, HirId}; use rustc_middle::query::plumbing::CyclePlaceholder; use rustc_middle::ty::print::with_forced_trimmed_paths; use rustc_middle::ty::util::IntTypeExt; -use rustc_middle::ty::{ - self, DefiningScopeKind, IsSuggestable, Ty, TyCtxt, TypeVisitableExt, fold_regions, -}; +use rustc_middle::ty::{self, DefiningScopeKind, IsSuggestable, Ty, TyCtxt, TypeVisitableExt}; use rustc_middle::{bug, span_bug}; use rustc_span::{DUMMY_SP, Ident, Span}; use super::{HirPlaceholderCollector, ItemCtxt, bad_placeholder}; use crate::check::wfcheck::check_static_item; -use crate::errors::TypeofReservedKeywordUsed; use crate::hir_ty_lowering::HirTyLowerer; mod opaque; @@ -48,21 +45,6 @@ fn anon_const_type_of<'tcx>(icx: &ItemCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx Node::Variant(Variant { disr_expr: Some(e), .. }) if e.hir_id == hir_id => { tcx.adt_def(tcx.hir_get_parent_item(hir_id)).repr().discr_type().to_ty(tcx) } - // Sort of affects the type system, but only for the purpose of diagnostics - // so no need for ConstArg. - Node::Ty(&hir::Ty { kind: TyKind::Typeof(ref e), span, .. }) if e.hir_id == hir_id => { - let ty = tcx.typeck(def_id).node_type(tcx.local_def_id_to_hir_id(def_id)); - let ty = fold_regions(tcx, ty, |r, _| { - if r.is_erased() { ty::Region::new_error_misc(tcx) } else { r } - }); - let (ty, opt_sugg) = if let Some(ty) = ty.make_suggestable(tcx, false, None) { - (ty, Some((span, Applicability::MachineApplicable))) - } else { - (ty, None) - }; - tcx.dcx().emit_err(TypeofReservedKeywordUsed { span, ty, opt_sugg }); - return ty; - } Node::Field(&hir::FieldDef { default: Some(c), def_id: field_def_id, .. }) if c.hir_id == hir_id => diff --git a/compiler/rustc_hir_analysis/src/errors.rs b/compiler/rustc_hir_analysis/src/errors.rs index 209b0156de323..f8809e051b600 100644 --- a/compiler/rustc_hir_analysis/src/errors.rs +++ b/compiler/rustc_hir_analysis/src/errors.rs @@ -378,17 +378,6 @@ pub(crate) struct ParenthesizedFnTraitExpansion { pub expanded_type: String, } -#[derive(Diagnostic)] -#[diag(hir_analysis_typeof_reserved_keyword_used, code = E0516)] -pub(crate) struct TypeofReservedKeywordUsed<'tcx> { - pub ty: Ty<'tcx>, - #[primary_span] - #[label] - pub span: Span, - #[suggestion(style = "verbose", code = "{ty}")] - pub opt_sugg: Option<(Span, Applicability)>, -} - #[derive(Diagnostic)] #[diag(hir_analysis_value_of_associated_struct_already_specified, code = E0719)] pub(crate) struct ValueOfAssociatedStructAlreadySpecified { diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index c881c77f38f15..4db9a4c2bcdd8 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -2582,7 +2582,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { let length = self.lower_const_arg(length, FeedConstTy::No); Ty::new_array_with_const_len(tcx, self.lower_ty(ty), length) } - hir::TyKind::Typeof(e) => tcx.type_of(e.def_id).instantiate_identity(), hir::TyKind::Infer(()) => { // Infer also appears as the type of arguments or return // values in an ExprKind::Closure, or as diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index b818a697960ac..b3b416955230f 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -445,11 +445,6 @@ impl<'a> State<'a> { self.print_const_arg(length); self.word("]"); } - hir::TyKind::Typeof(ref e) => { - self.word("typeof("); - self.print_anon_const(e); - self.word(")"); - } hir::TyKind::Err(_) => { self.popen(); self.word("/*ERROR*/"); diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index d090eb6338284..734d8963d6fda 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -296,11 +296,6 @@ fn infer_type_if_missing<'tcx>(fcx: &FnCtxt<'_, 'tcx>, node: Node<'tcx>) -> Opti } else if let Node::AnonConst(_) = node { let id = tcx.local_def_id_to_hir_id(def_id); match tcx.parent_hir_node(id) { - Node::Ty(&hir::Ty { kind: hir::TyKind::Typeof(anon_const), span, .. }) - if anon_const.hir_id == id => - { - Some(fcx.next_ty_var(span)) - } Node::Expr(&hir::Expr { kind: hir::ExprKind::InlineAsm(asm), span, .. }) | Node::Item(&hir::Item { kind: hir::ItemKind::GlobalAsm { asm, .. }, span, .. }) => { asm.operands.iter().find_map(|(op, _op_sp)| match op { diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 79c8d61461005..0ba54e3829f51 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -1660,18 +1660,6 @@ impl EarlyLintPass for UnusedBraces { ); } - ast::TyKind::Typeof(ref anon_const) => { - self.check_unused_delims_expr( - cx, - &anon_const.value, - UnusedDelimsCtx::AnonConst, - false, - None, - None, - false, - ); - } - _ => {} } } diff --git a/compiler/rustc_next_trait_solver/src/coherence.rs b/compiler/rustc_next_trait_solver/src/coherence.rs index b949deb119269..c370fd24a1bb3 100644 --- a/compiler/rustc_next_trait_solver/src/coherence.rs +++ b/compiler/rustc_next_trait_solver/src/coherence.rs @@ -336,7 +336,6 @@ where | ty::Uint(..) | ty::Float(..) | ty::Str - | ty::FnDef(..) | ty::Pat(..) | ty::FnPtr(..) | ty::Array(..) @@ -403,7 +402,6 @@ where // implement, so we don't use this behavior. // Addendum: Moreover, revealing the underlying type is likely to cause cycle // errors as we rely on coherence / the specialization graph during typeck. - self.found_non_local_ty(ty) } } @@ -435,31 +433,14 @@ where } } ty::Error(_) => ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)), - ty::Closure(did, ..) => { - if self.def_id_is_local(did) { - ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)) - } else { - self.found_non_local_ty(ty) - } - } - ty::CoroutineClosure(did, ..) => { - if self.def_id_is_local(did) { - ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)) - } else { - self.found_non_local_ty(ty) - } - } - ty::Coroutine(did, ..) => { - if self.def_id_is_local(did) { - ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)) - } else { - self.found_non_local_ty(ty) - } + + ty::FnDef(..) + | ty::Closure(..) + | ty::CoroutineClosure(..) + | ty::Coroutine(..) + | ty::CoroutineWitness(..) => { + unreachable!("unnameable type in coherence: {ty:?}"); } - // This should only be created when checking whether we have to check whether some - // auto trait impl applies. There will never be multiple impls, so we can just - // act as if it were a local type here. - ty::CoroutineWitness(..) => ControlFlow::Break(OrphanCheckEarlyExit::LocalTy(ty)), }; // A bit of a hack, the `OrphanChecker` is only used to visit a `TraitRef`, so // the first type we visit is always the self type. diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index df69adce142b8..c79b99a80e87a 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -7,7 +7,7 @@ use rustc_ast::{ TyKind, UnsafeBinderTy, }; use rustc_data_structures::stack::ensure_sufficient_stack; -use rustc_errors::{Applicability, Diag, PResult}; +use rustc_errors::{Applicability, Diag, E0516, PResult}; use rustc_span::{ErrorGuaranteed, Ident, Span, kw, sym}; use thin_vec::{ThinVec, thin_vec}; @@ -328,7 +328,7 @@ impl<'a> Parser<'a> { self.expect_and()?; self.parse_borrowed_pointee()? } else if self.eat_keyword_noexpect(kw::Typeof) { - self.parse_typeof_ty()? + self.parse_typeof_ty(lo)? } else if self.eat_keyword(exp!(Underscore)) { // A type to be inferred `_` TyKind::Infer @@ -784,13 +784,20 @@ impl<'a> Parser<'a> { } } - // Parses the `typeof(EXPR)`. - // To avoid ambiguity, the type is surrounded by parentheses. - fn parse_typeof_ty(&mut self) -> PResult<'a, TyKind> { + /// Parses the `typeof(EXPR)` for better diagnostics before returning + /// an error type. + fn parse_typeof_ty(&mut self, lo: Span) -> PResult<'a, TyKind> { self.expect(exp!(OpenParen))?; - let expr = self.parse_expr_anon_const()?; + let _expr = self.parse_expr_anon_const()?; self.expect(exp!(CloseParen))?; - Ok(TyKind::Typeof(expr)) + let span = lo.to(self.prev_token.span); + let guar = self + .dcx() + .struct_span_err(span, "`typeof` is a reserved keyword but unimplemented") + .with_note("consider replacing `typeof(...)` with an actual type") + .with_code(E0516) + .emit(); + Ok(TyKind::Err(guar)) } /// Parses a function pointer type (`TyKind::FnPtr`). diff --git a/compiler/rustc_passes/src/input_stats.rs b/compiler/rustc_passes/src/input_stats.rs index fe50b730256b7..35101624bd68e 100644 --- a/compiler/rustc_passes/src/input_stats.rs +++ b/compiler/rustc_passes/src/input_stats.rs @@ -408,7 +408,6 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { OpaqueDef, TraitAscription, TraitObject, - Typeof, Infer, Pat, Err @@ -683,7 +682,6 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { TraitObject, ImplTrait, Paren, - Typeof, Infer, ImplicitSelf, MacCall, diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index a92bc77b5b508..df620ddb66529 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -954,9 +954,6 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc self.visit_ty(element_ty); self.resolve_anon_const(length, AnonConstKind::ConstArg(IsRepeatExpr::No)); } - TyKind::Typeof(ct) => { - self.resolve_anon_const(ct, AnonConstKind::ConstArg(IsRepeatExpr::No)) - } _ => visit::walk_ty(self, ty), } self.diag_metadata.current_trait_object = prev; diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index 849dcb9e88fb1..68d472791fe77 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -2983,9 +2983,6 @@ ui/typeck/issue-96530.rs ui/typeck/issue-96738.rs ui/typeck/issue-98260.rs ui/typeck/issue-98982.rs -ui/typeof/issue-100183.rs -ui/typeof/issue-29184.rs -ui/typeof/issue-42060.rs ui/unboxed-closures/issue-18652.rs ui/unboxed-closures/issue-18661.rs ui/unboxed-closures/issue-30906.rs diff --git a/tests/ui/closures/impl-closure-147146.rs b/tests/ui/closures/impl-closure-147146.rs deleted file mode 100644 index b709e577354e5..0000000000000 --- a/tests/ui/closures/impl-closure-147146.rs +++ /dev/null @@ -1,7 +0,0 @@ -impl typeof(|| {}) {} -//~^ ERROR `typeof` is a reserved keyword but unimplemented - -unsafe impl Send for typeof(|| {}) {} -//~^ ERROR `typeof` is a reserved keyword but unimplemented - -fn main() {} diff --git a/tests/ui/closures/impl-closure-147146.stderr b/tests/ui/closures/impl-closure-147146.stderr deleted file mode 100644 index 6da16b5d450fd..0000000000000 --- a/tests/ui/closures/impl-closure-147146.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0516]: `typeof` is a reserved keyword but unimplemented - --> $DIR/impl-closure-147146.rs:1:6 - | -LL | impl typeof(|| {}) {} - | ^^^^^^^^^^^^^ reserved keyword - -error[E0516]: `typeof` is a reserved keyword but unimplemented - --> $DIR/impl-closure-147146.rs:4:22 - | -LL | unsafe impl Send for typeof(|| {}) {} - | ^^^^^^^^^^^^^ reserved keyword - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0516`. diff --git a/tests/ui/error-codes/E0516.rs b/tests/ui/error-codes/E0516.rs index f81b98cdadc8e..52b7ba441c14f 100644 --- a/tests/ui/error-codes/E0516.rs +++ b/tests/ui/error-codes/E0516.rs @@ -1,4 +1,3 @@ fn main() { let x: typeof(92) = 92; //~ ERROR E0516 - //~| NOTE reserved keyword } diff --git a/tests/ui/error-codes/E0516.stderr b/tests/ui/error-codes/E0516.stderr index f4127678d5b99..4a34198d73344 100644 --- a/tests/ui/error-codes/E0516.stderr +++ b/tests/ui/error-codes/E0516.stderr @@ -1,14 +1,10 @@ error[E0516]: `typeof` is a reserved keyword but unimplemented - --> $DIR/E0516.rs:2:12 + --> $DIR/E0516.rs:2:19 | LL | let x: typeof(92) = 92; - | ^^^^^^^^^^ reserved keyword - | -help: consider replacing `typeof(...)` with an actual type - | -LL - let x: typeof(92) = 92; -LL + let x: i32 = 92; + | ^^ | + = note: consider replacing `typeof(...)` with an actual type error: aborting due to 1 previous error diff --git a/tests/ui/typeof/issue-100183.rs b/tests/ui/typeof/issue-100183.rs deleted file mode 100644 index 13e9493eaa59b..0000000000000 --- a/tests/ui/typeof/issue-100183.rs +++ /dev/null @@ -1,6 +0,0 @@ -struct Struct { - y: (typeof("hey"),), - //~^ ERROR `typeof` is a reserved keyword but unimplemented -} - -fn main() {} diff --git a/tests/ui/typeof/issue-100183.stderr b/tests/ui/typeof/issue-100183.stderr deleted file mode 100644 index 765a5c54428f8..0000000000000 --- a/tests/ui/typeof/issue-100183.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0516]: `typeof` is a reserved keyword but unimplemented - --> $DIR/issue-100183.rs:2:9 - | -LL | y: (typeof("hey"),), - | ^^^^^^^^^^^^^ reserved keyword - | -help: consider replacing `typeof(...)` with an actual type - | -LL - y: (typeof("hey"),), -LL + y: (&str,), - | - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0516`. diff --git a/tests/ui/typeof/issue-29184.rs b/tests/ui/typeof/issue-29184.rs deleted file mode 100644 index c77e364c3b83c..0000000000000 --- a/tests/ui/typeof/issue-29184.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - let x: typeof(92) = 92; //~ ERROR `typeof` is a reserved keyword -} diff --git a/tests/ui/typeof/issue-29184.stderr b/tests/ui/typeof/issue-29184.stderr deleted file mode 100644 index d8d43504d7224..0000000000000 --- a/tests/ui/typeof/issue-29184.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0516]: `typeof` is a reserved keyword but unimplemented - --> $DIR/issue-29184.rs:2:12 - | -LL | let x: typeof(92) = 92; - | ^^^^^^^^^^ reserved keyword - | -help: consider replacing `typeof(...)` with an actual type - | -LL - let x: typeof(92) = 92; -LL + let x: i32 = 92; - | - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0516`. diff --git a/tests/ui/typeof/issue-42060.rs b/tests/ui/typeof/issue-42060.rs deleted file mode 100644 index 1740b238343c8..0000000000000 --- a/tests/ui/typeof/issue-42060.rs +++ /dev/null @@ -1,11 +0,0 @@ -fn main() { - let thing = (); - let other: typeof(thing) = thing; //~ ERROR attempt to use a non-constant value in a constant - //~^ ERROR `typeof` is a reserved keyword but unimplemented [E0516] -} - -fn f(){ - let q = 1; - ::N //~ ERROR attempt to use a non-constant value in a constant - //~^ ERROR `typeof` is a reserved keyword but unimplemented [E0516] -} diff --git a/tests/ui/typeof/issue-42060.stderr b/tests/ui/typeof/issue-42060.stderr deleted file mode 100644 index 733ad37693bec..0000000000000 --- a/tests/ui/typeof/issue-42060.stderr +++ /dev/null @@ -1,40 +0,0 @@ -error[E0435]: attempt to use a non-constant value in a constant - --> $DIR/issue-42060.rs:3:23 - | -LL | let other: typeof(thing) = thing; - | ^^^^^ non-constant value - | -help: consider using `const` instead of `let` - | -LL - let thing = (); -LL + const thing: /* Type */ = (); - | - -error[E0435]: attempt to use a non-constant value in a constant - --> $DIR/issue-42060.rs:9:13 - | -LL | ::N - | ^ non-constant value - | -help: consider using `const` instead of `let` - | -LL - let q = 1; -LL + const q: /* Type */ = 1; - | - -error[E0516]: `typeof` is a reserved keyword but unimplemented - --> $DIR/issue-42060.rs:3:16 - | -LL | let other: typeof(thing) = thing; - | ^^^^^^^^^^^^^ reserved keyword - -error[E0516]: `typeof` is a reserved keyword but unimplemented - --> $DIR/issue-42060.rs:9:6 - | -LL | ::N - | ^^^^^^^^^ reserved keyword - -error: aborting due to 4 previous errors - -Some errors have detailed explanations: E0435, E0516. -For more information about an error, try `rustc --explain E0435`. diff --git a/tests/ui/typeof/type_mismatch.rs b/tests/ui/typeof/type_mismatch.rs deleted file mode 100644 index a3444d6c2078c..0000000000000 --- a/tests/ui/typeof/type_mismatch.rs +++ /dev/null @@ -1,12 +0,0 @@ -// Test that using typeof results in the correct type mismatch errors instead of always assuming -// `usize`, in addition to the pre-existing "typeof is reserved and unimplemented" error - -//@ dont-require-annotations: NOTE - -fn main() { - const a: u8 = 1; - let b: typeof(a) = 1i8; - //~^ ERROR `typeof` is a reserved keyword but unimplemented - //~| ERROR mismatched types - //~| NOTE expected `u8`, found `i8` -} diff --git a/tests/ui/typeof/type_mismatch.stderr b/tests/ui/typeof/type_mismatch.stderr deleted file mode 100644 index 6a414c11f384c..0000000000000 --- a/tests/ui/typeof/type_mismatch.stderr +++ /dev/null @@ -1,30 +0,0 @@ -error[E0516]: `typeof` is a reserved keyword but unimplemented - --> $DIR/type_mismatch.rs:8:12 - | -LL | let b: typeof(a) = 1i8; - | ^^^^^^^^^ reserved keyword - | -help: consider replacing `typeof(...)` with an actual type - | -LL - let b: typeof(a) = 1i8; -LL + let b: u8 = 1i8; - | - -error[E0308]: mismatched types - --> $DIR/type_mismatch.rs:8:24 - | -LL | let b: typeof(a) = 1i8; - | --------- ^^^ expected `u8`, found `i8` - | | - | expected due to this - | -help: change the type of the numeric literal from `i8` to `u8` - | -LL - let b: typeof(a) = 1i8; -LL + let b: typeof(a) = 1u8; - | - -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0308, E0516. -For more information about an error, try `rustc --explain E0308`. From c58e52ebebcbe73090da13f5d1e1fe8e32ae0c57 Mon Sep 17 00:00:00 2001 From: Asuka Minato Date: Wed, 26 Nov 2025 07:21:57 +0900 Subject: [PATCH 05/10] fix --- src/librustdoc/clean/mod.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 38b12405ea821..020829df7b6a0 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -561,12 +561,7 @@ fn clean_generic_param_def( def.name, GenericParamDefKind::Const { ty: Box::new(clean_middle_ty( - ty::Binder::dummy( - cx.tcx - .type_of(def.def_id) - .no_bound_vars() - .expect("const parameter types cannot be generic"), - ), + ty::Binder::dummy(cx.tcx.type_of(def.def_id).instantiate_identity()), cx, Some(def.def_id), None, From 171c77e3870984d0290d41c3e39f5582067d1e3a Mon Sep 17 00:00:00 2001 From: Asuka Minato Date: Wed, 26 Nov 2025 16:33:13 +0900 Subject: [PATCH 06/10] add test --- .../const-param-type-references-generics.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/rustdoc/const-generics/const-param-type-references-generics.rs diff --git a/tests/rustdoc/const-generics/const-param-type-references-generics.rs b/tests/rustdoc/const-generics/const-param-type-references-generics.rs new file mode 100644 index 0000000000000..47bf3e253e69d --- /dev/null +++ b/tests/rustdoc/const-generics/const-param-type-references-generics.rs @@ -0,0 +1,16 @@ +//! rustdoc regression test for #149288: const generic parameter types may depend on +//! other generics when `generic_const_parameter_types` is enabled. +#![allow(incomplete_features)] +#![feature(adt_const_params, generic_const_parameter_types)] +#![crate_name = "foo"] + +pub struct Bar; + +pub fn takes(_: Bar) {} + +pub fn instantiate() { + takes(Bar::<2, { [1; 2] }>); +} + +//@ has foo/struct.Bar.html '//pre[@class="rust item-decl"]' 'pub struct Bar' +//@ has foo/fn.takes.html '//pre[@class="rust item-decl"]' 'pub fn takes(_: Bar)' From 8e08af176979005ffabeadbd5585f14db2663874 Mon Sep 17 00:00:00 2001 From: lcnr Date: Tue, 25 Nov 2025 11:34:27 +0100 Subject: [PATCH 07/10] fix tooling --- src/librustdoc/clean/mod.rs | 1 - src/tools/clippy/clippy_lints/src/dereference.rs | 3 +-- .../clippy/clippy_utils/src/ast_utils/mod.rs | 1 - .../clippy/clippy_utils/src/check_proc_macro.rs | 3 +-- src/tools/clippy/clippy_utils/src/hir_utils.rs | 3 --- src/tools/rustfmt/src/types.rs | 10 +--------- src/tools/rustfmt/tests/source/type.rs | 6 ------ src/tools/rustfmt/tests/target/type.rs | 4 ---- tests/rustdoc-ui/issues/ice-typeof-102986.rs | 5 ----- tests/rustdoc-ui/issues/ice-typeof-102986.stderr | 15 --------------- tests/ui/error-codes/E0516.stderr | 4 ++-- 11 files changed, 5 insertions(+), 50 deletions(-) delete mode 100644 tests/rustdoc-ui/issues/ice-typeof-102986.rs delete mode 100644 tests/rustdoc-ui/issues/ice-typeof-102986.stderr diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 38b12405ea821..1642293138369 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1841,7 +1841,6 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T // Rustdoc handles `TyKind::Err`s by turning them into `Type::Infer`s. TyKind::Infer(()) | TyKind::Err(_) - | TyKind::Typeof(..) | TyKind::InferDelegation(..) | TyKind::TraitAscription(_) => Infer, } diff --git a/src/tools/clippy/clippy_lints/src/dereference.rs b/src/tools/clippy/clippy_lints/src/dereference.rs index de1362081323a..548f03c9f2059 100644 --- a/src/tools/clippy/clippy_lints/src/dereference.rs +++ b/src/tools/clippy/clippy_lints/src/dereference.rs @@ -830,7 +830,6 @@ impl TyCoercionStability { TyKind::OpaqueDef(..) | TyKind::TraitAscription(..) | TyKind::Infer(()) - | TyKind::Typeof(..) | TyKind::TraitObject(..) | TyKind::InferDelegation(..) | TyKind::Err(_) => Self::Reborrow, @@ -911,7 +910,7 @@ fn ty_contains_infer(ty: &hir::Ty<'_>) -> bool { } fn visit_ty(&mut self, ty: &hir::Ty<'_, AmbigArg>) { - if self.0 || matches!(ty.kind, TyKind::OpaqueDef(..) | TyKind::Typeof(_) | TyKind::Err(_)) { + if self.0 || matches!(ty.kind, TyKind::OpaqueDef(..) | TyKind::Err(_)) { self.0 = true; } else { walk_ty(self, ty); diff --git a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs index 04a64e0fe9485..4bdbfc8853662 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs @@ -875,7 +875,6 @@ pub fn eq_ty(l: &Ty, r: &Ty) -> bool { (Path(lq, lp), Path(rq, rp)) => both(lq.as_deref(), rq.as_deref(), eq_qself) && eq_path(lp, rp), (TraitObject(lg, ls), TraitObject(rg, rs)) => ls == rs && over(lg, rg, eq_generic_bound), (ImplTrait(_, lg), ImplTrait(_, rg)) => over(lg, rg, eq_generic_bound), - (Typeof(l), Typeof(r)) => eq_expr(&l.value, &r.value), (MacCall(l), MacCall(r)) => eq_mac_call(l, r), _ => false, } diff --git a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs index 544218e09930a..50d9136b8b4dc 100644 --- a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs +++ b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs @@ -524,11 +524,10 @@ fn ast_ty_search_pat(ty: &ast::Ty) -> (Pat, Pat) { TyKind::ImplicitSelf // experimental - |TyKind::Pat(..) + | TyKind::Pat(..) // unused | TyKind::CVarArgs - | TyKind::Typeof(_) // placeholder | TyKind::Dummy diff --git a/src/tools/clippy/clippy_utils/src/hir_utils.rs b/src/tools/clippy/clippy_utils/src/hir_utils.rs index b286701fbed11..c6d82c0e63fa6 100644 --- a/src/tools/clippy/clippy_utils/src/hir_utils.rs +++ b/src/tools/clippy/clippy_utils/src/hir_utils.rs @@ -1309,9 +1309,6 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { TyKind::TraitObject(_, lifetime) => { self.hash_lifetime(lifetime); }, - TyKind::Typeof(anon_const) => { - self.hash_body(anon_const.body); - }, TyKind::UnsafeBinder(binder) => { self.hash_ty(binder.inner_ty); }, diff --git a/src/tools/rustfmt/src/types.rs b/src/tools/rustfmt/src/types.rs index 242d8c23113c3..2d7bc59c62788 100644 --- a/src/tools/rustfmt/src/types.rs +++ b/src/tools/rustfmt/src/types.rs @@ -8,8 +8,7 @@ use crate::comment::{combine_strs_with_missing_comments, contains_comment}; use crate::config::lists::*; use crate::config::{IndentStyle, StyleEdition, TypeDensity}; use crate::expr::{ - ExprType, RhsAssignKind, format_expr, rewrite_assign_rhs, rewrite_call, rewrite_tuple, - rewrite_unary_prefix, + ExprType, RhsAssignKind, format_expr, rewrite_assign_rhs, rewrite_tuple, rewrite_unary_prefix, }; use crate::lists::{ ListFormatting, ListItem, Separator, definitive_tactic, itemize_list, write_list, @@ -1031,13 +1030,6 @@ impl Rewrite for ast::Ty { } ast::TyKind::CVarArgs => Ok("...".to_owned()), ast::TyKind::Dummy | ast::TyKind::Err(_) => Ok(context.snippet(self.span).to_owned()), - ast::TyKind::Typeof(ref anon_const) => rewrite_call( - context, - "typeof", - &[anon_const.value.clone()], - self.span, - shape, - ), ast::TyKind::Pat(ref ty, ref pat) => { let ty = ty.rewrite_result(context, shape)?; let pat = pat.rewrite_result(context, shape)?; diff --git a/src/tools/rustfmt/tests/source/type.rs b/src/tools/rustfmt/tests/source/type.rs index 213fad7cb16b7..09ec22cf8d14c 100644 --- a/src/tools/rustfmt/tests/source/type.rs +++ b/src/tools/rustfmt/tests/source/type.rs @@ -158,9 +158,3 @@ impl Foo { Self(t) } } - -// #4357 -type T = typeof( -1); -impl T for .. { -} diff --git a/src/tools/rustfmt/tests/target/type.rs b/src/tools/rustfmt/tests/target/type.rs index 93479f8b484cb..623192b72b8b7 100644 --- a/src/tools/rustfmt/tests/target/type.rs +++ b/src/tools/rustfmt/tests/target/type.rs @@ -167,7 +167,3 @@ impl Foo { Self(t) } } - -// #4357 -type T = typeof(1); -impl T for .. {} diff --git a/tests/rustdoc-ui/issues/ice-typeof-102986.rs b/tests/rustdoc-ui/issues/ice-typeof-102986.rs deleted file mode 100644 index b1ad19cb9ff47..0000000000000 --- a/tests/rustdoc-ui/issues/ice-typeof-102986.rs +++ /dev/null @@ -1,5 +0,0 @@ -// https://github.com/rust-lang/rust/issues/102986 -struct Struct { - y: (typeof("hey"),), - //~^ ERROR `typeof` is a reserved keyword but unimplemented -} diff --git a/tests/rustdoc-ui/issues/ice-typeof-102986.stderr b/tests/rustdoc-ui/issues/ice-typeof-102986.stderr deleted file mode 100644 index 02e257a9163c1..0000000000000 --- a/tests/rustdoc-ui/issues/ice-typeof-102986.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0516]: `typeof` is a reserved keyword but unimplemented - --> $DIR/ice-typeof-102986.rs:3:9 - | -LL | y: (typeof("hey"),), - | ^^^^^^^^^^^^^ reserved keyword - | -help: consider replacing `typeof(...)` with an actual type - | -LL - y: (typeof("hey"),), -LL + y: (&str,), - | - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0516`. diff --git a/tests/ui/error-codes/E0516.stderr b/tests/ui/error-codes/E0516.stderr index 4a34198d73344..b1a9faedf1e77 100644 --- a/tests/ui/error-codes/E0516.stderr +++ b/tests/ui/error-codes/E0516.stderr @@ -1,8 +1,8 @@ error[E0516]: `typeof` is a reserved keyword but unimplemented - --> $DIR/E0516.rs:2:19 + --> $DIR/E0516.rs:2:12 | LL | let x: typeof(92) = 92; - | ^^ + | ^^^^^^^^^^ | = note: consider replacing `typeof(...)` with an actual type From b25336b0105b3f1fece5d0991dfae89be9d64aa6 Mon Sep 17 00:00:00 2001 From: Romain Perier Date: Sat, 15 Nov 2025 18:34:02 +0100 Subject: [PATCH 08/10] Untruthful multiple different versions of a crate in the dependency graph Currently, If `expected_def_id` and `another_trait_def_id` have their crate imported as ExternCrateSource::Path the method get_extern_crate_renamed_symbol() will return None for both, resulting in a false positive. This fixes the issue by using a slitly different approach, we use a predicate instead and do the comparison of the item names only when both crates are imported as ExternCrateSource::Extern and are direct dependencies of the LOCAL_CRATE, otherwise false is returned. --- .../src/error_reporting/traits/mod.rs | 49 +++++++++++++------ tests/ui/traits/auxiliary/crate1.rs | 7 +++ tests/ui/traits/auxiliary/crate2.rs | 1 + ...-multiple-different-versions-of-a-crate.rs | 12 +++++ ...tiple-different-versions-of-a-crate.stderr | 22 +++++++++ 5 files changed, 77 insertions(+), 14 deletions(-) create mode 100644 tests/ui/traits/auxiliary/crate1.rs create mode 100644 tests/ui/traits/auxiliary/crate2.rs create mode 100644 tests/ui/traits/wrong-multiple-different-versions-of-a-crate.rs create mode 100644 tests/ui/traits/wrong-multiple-different-versions-of-a-crate.stderr diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs index befc83a592c0f..3ba984b90a1d1 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs @@ -12,7 +12,7 @@ use std::{fmt, iter}; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::unord::UnordSet; use rustc_errors::{Applicability, Diag, E0038, E0276, MultiSpan, struct_span_code_err}; -use rustc_hir::def_id::{DefId, LocalDefId}; +use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId}; use rustc_hir::intravisit::Visitor; use rustc_hir::{self as hir, AmbigArg}; use rustc_infer::traits::solve::Goal; @@ -22,7 +22,8 @@ use rustc_infer::traits::{ }; use rustc_middle::ty::print::{PrintTraitRefExt as _, with_no_trimmed_paths}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt as _}; -use rustc_span::{DesugaringKind, ErrorGuaranteed, ExpnKind, Span, Symbol}; +use rustc_session::cstore::{ExternCrate, ExternCrateSource}; +use rustc_span::{DesugaringKind, ErrorGuaranteed, ExpnKind, Span}; use tracing::{info, instrument}; pub use self::overflow::*; @@ -353,14 +354,37 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { } } - fn get_extern_crate_renamed_symbol(&self, trait_def_id: DefId) -> Option { - if !trait_def_id.is_local() - && let Some(data) = self.tcx.extern_crate(trait_def_id.krate) - && let rustc_session::cstore::ExternCrateSource::Extern(def_id) = data.src - { - self.tcx.opt_item_name(def_id) - } else { - None + /// If the crates of `expected_def_id` and `trait_def_id` are imported as extern crate + /// under the same name (`extern crate foo as a` and `extern crate bar as a`) returns true, + /// otherwise returns false. + fn extern_crates_with_the_same_name( + &self, + expected_def_id: DefId, + trait_def_id: DefId, + ) -> bool { + if expected_def_id.is_local() || trait_def_id.is_local() { + return false; + } + // We only compare direct dependencies of the current crate, so it avoids unnecessary + // processing and excludes indirect dependencies, like `std` or `core`. In such a case + // both would be imported under the same name `std`. + match ( + self.tcx.extern_crate(expected_def_id.krate), + self.tcx.extern_crate(trait_def_id.krate), + ) { + ( + Some(ExternCrate { + src: ExternCrateSource::Extern(expected_def_id), + dependency_of: LOCAL_CRATE, + .. + }), + Some(ExternCrate { + src: ExternCrateSource::Extern(trait_def_id), + dependency_of: LOCAL_CRATE, + .. + }), + ) => self.tcx.item_name(expected_def_id) == self.tcx.item_name(trait_def_id), + _ => false, } } @@ -377,13 +401,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { { let krate = self.tcx.crate_name(expected_did.krate); let name = self.tcx.item_name(expected_did); - let locally_renamed_krate = self - .get_extern_crate_renamed_symbol(expected_did) - .map_or(None, |s| if s != krate { Some(s) } else { None }); let definitions_with_same_path: UnordSet<_> = found_dids .filter(|def_id| { def_id.krate != expected_did.krate - && (locally_renamed_krate == self.get_extern_crate_renamed_symbol(*def_id) + && (self.extern_crates_with_the_same_name(expected_did, *def_id) || self.tcx.crate_name(def_id.krate) == krate) && self.tcx.item_name(def_id) == name }) diff --git a/tests/ui/traits/auxiliary/crate1.rs b/tests/ui/traits/auxiliary/crate1.rs new file mode 100644 index 0000000000000..8512d89bd93a3 --- /dev/null +++ b/tests/ui/traits/auxiliary/crate1.rs @@ -0,0 +1,7 @@ +//@ aux-crate:crate2=crate2.rs + +pub trait Trait {} + +pub fn foo(_arg: impl Trait) {} + +pub fn bar(_arg: impl crate2::Trait) {} diff --git a/tests/ui/traits/auxiliary/crate2.rs b/tests/ui/traits/auxiliary/crate2.rs new file mode 100644 index 0000000000000..0a47fdc74d721 --- /dev/null +++ b/tests/ui/traits/auxiliary/crate2.rs @@ -0,0 +1 @@ +pub trait Trait {} diff --git a/tests/ui/traits/wrong-multiple-different-versions-of-a-crate.rs b/tests/ui/traits/wrong-multiple-different-versions-of-a-crate.rs new file mode 100644 index 0000000000000..ec6bb7bbcc594 --- /dev/null +++ b/tests/ui/traits/wrong-multiple-different-versions-of-a-crate.rs @@ -0,0 +1,12 @@ +// Test that we do not report false positives of a crate as being found multiple times in the +// dependency graph with different versions, when this crate is only present once. In this test, +// this was happening for `crate1` when two different crates in the dependencies were imported +// as ExternCrateSource::Path. +// Issue #148892. +//@ aux-crate:crate1=crate1.rs + +struct MyStruct; //~ HELP the trait `Trait` is not implemented for `MyStruct` + +fn main() { + crate1::foo(MyStruct); //~ ERROR the trait bound `MyStruct: Trait` is not satisfied +} diff --git a/tests/ui/traits/wrong-multiple-different-versions-of-a-crate.stderr b/tests/ui/traits/wrong-multiple-different-versions-of-a-crate.stderr new file mode 100644 index 0000000000000..7fec237f54d43 --- /dev/null +++ b/tests/ui/traits/wrong-multiple-different-versions-of-a-crate.stderr @@ -0,0 +1,22 @@ +error[E0277]: the trait bound `MyStruct: Trait` is not satisfied + --> $DIR/wrong-multiple-different-versions-of-a-crate.rs:11:17 + | +LL | crate1::foo(MyStruct); + | ----------- ^^^^^^^^ unsatisfied trait bound + | | + | required by a bound introduced by this call + | +help: the trait `Trait` is not implemented for `MyStruct` + --> $DIR/wrong-multiple-different-versions-of-a-crate.rs:8:1 + | +LL | struct MyStruct; + | ^^^^^^^^^^^^^^^ +note: required by a bound in `foo` + --> $DIR/auxiliary/crate1.rs:5:23 + | +LL | pub fn foo(_arg: impl Trait) {} + | ^^^^^ required by this bound in `foo` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0277`. From 133d520aaa0538522e4cab3041593454a5530264 Mon Sep 17 00:00:00 2001 From: Adwin White Date: Tue, 25 Nov 2025 11:08:58 +0800 Subject: [PATCH 09/10] deeply normalize param env in compare_impl_item --- .../src/check/compare_impl_item.rs | 21 ++++++- .../rustc_trait_selection/src/traits/mod.rs | 63 +++++++++++++++++++ .../trait-bounds/issue-100689.rs | 2 + .../trait-bounds/issue-102899.rs | 2 + ...eply-normalize-env-in-compare-impl-item.rs | 38 +++++++++++ .../normalize/normalize-param-env-2.stderr | 10 ++- 6 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 tests/ui/traits/next-solver/normalize/deeply-normalize-env-in-compare-impl-item.rs diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index 6a07d2988fdfc..fa497cc21e40d 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -236,7 +236,26 @@ fn compare_method_predicate_entailment<'tcx>( let normalize_cause = traits::ObligationCause::misc(impl_m_span, impl_m_def_id); let param_env = ty::ParamEnv::new(tcx.mk_clauses(&hybrid_preds)); - let param_env = traits::normalize_param_env_or_error(tcx, param_env, normalize_cause); + // FIXME(-Zhigher-ranked-assumptions): The `hybrid_preds` + // should be well-formed. However, using them may result in + // region errors as we currently don't track placeholder + // assumptions. + // + // To avoid being backwards incompatible with the old solver, + // we also eagerly normalize the where-bounds in the new solver + // here while ignoring region constraints. This means we can then + // use where-bounds whose normalization results in placeholder + // errors further down without getting any errors. + // + // It should be sound to do so as the only region errors here + // should be due to missing implied bounds. + // + // cc trait-system-refactor-initiative/issues/166. + let param_env = if tcx.next_trait_solver_globally() { + traits::deeply_normalize_param_env_ignoring_regions(tcx, param_env, normalize_cause) + } else { + traits::normalize_param_env_or_error(tcx, param_env, normalize_cause) + }; debug!(caller_bounds=?param_env.caller_bounds()); let infcx = &tcx.infer_ctxt().build(TypingMode::non_body_analysis()); diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 6032bcacec6a4..c9f7237b123fb 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -477,6 +477,69 @@ pub fn normalize_param_env_or_error<'tcx>( ty::ParamEnv::new(tcx.mk_clauses(&predicates)) } +/// Deeply normalize the param env using the next solver ignoring +/// region errors. +/// +/// FIXME(-Zhigher-ranked-assumptions): this is a hack to work around +/// the fact that we don't support placeholder assumptions right now +/// and is necessary for `compare_method_predicate_entailment`, see the +/// use of this function for more info. We should remove this once we +/// have proper support for implied bounds on binders. +#[instrument(level = "debug", skip(tcx))] +pub fn deeply_normalize_param_env_ignoring_regions<'tcx>( + tcx: TyCtxt<'tcx>, + unnormalized_env: ty::ParamEnv<'tcx>, + cause: ObligationCause<'tcx>, +) -> ty::ParamEnv<'tcx> { + let predicates: Vec<_> = + util::elaborate(tcx, unnormalized_env.caller_bounds().into_iter()).collect(); + + debug!("normalize_param_env_or_error: elaborated-predicates={:?}", predicates); + + let elaborated_env = ty::ParamEnv::new(tcx.mk_clauses(&predicates)); + if !elaborated_env.has_aliases() { + return elaborated_env; + } + + let span = cause.span; + let infcx = tcx + .infer_ctxt() + .with_next_trait_solver(true) + .ignoring_regions() + .build(TypingMode::non_body_analysis()); + let predicates = match crate::solve::deeply_normalize::<_, FulfillmentError<'tcx>>( + infcx.at(&cause, elaborated_env), + predicates, + ) { + Ok(predicates) => predicates, + Err(errors) => { + infcx.err_ctxt().report_fulfillment_errors(errors); + // An unnormalized env is better than nothing. + debug!("normalize_param_env_or_error: errored resolving predicates"); + return elaborated_env; + } + }; + + debug!("do_normalize_predicates: normalized predicates = {:?}", predicates); + // FIXME(-Zhigher-ranked-assumptions): We're ignoring region errors for now. + // There're placeholder constraints `leaking` out. + // See the fixme in the enclosing function's docs for more. + let _errors = infcx.resolve_regions(cause.body_id, elaborated_env, []); + + let predicates = match infcx.fully_resolve(predicates) { + Ok(predicates) => predicates, + Err(fixup_err) => { + span_bug!( + span, + "inference variables in normalized parameter environment: {}", + fixup_err + ) + } + }; + debug!("normalize_param_env_or_error: final predicates={:?}", predicates); + ty::ParamEnv::new(tcx.mk_clauses(&predicates)) +} + #[derive(Debug)] pub enum EvaluateConstErr { /// The constant being evaluated was either a generic parameter or inference variable, *or*, diff --git a/tests/ui/higher-ranked/trait-bounds/issue-100689.rs b/tests/ui/higher-ranked/trait-bounds/issue-100689.rs index f405abfb2a2ef..6bfad56b93d29 100644 --- a/tests/ui/higher-ranked/trait-bounds/issue-100689.rs +++ b/tests/ui/higher-ranked/trait-bounds/issue-100689.rs @@ -1,4 +1,6 @@ //@ check-pass +//@ revisions: old next +//@[next] compile-flags: -Znext-solver struct Foo<'a> { foo: &'a mut usize, diff --git a/tests/ui/higher-ranked/trait-bounds/issue-102899.rs b/tests/ui/higher-ranked/trait-bounds/issue-102899.rs index b4ef75319e5c1..77d4d0179b1ba 100644 --- a/tests/ui/higher-ranked/trait-bounds/issue-102899.rs +++ b/tests/ui/higher-ranked/trait-bounds/issue-102899.rs @@ -1,4 +1,6 @@ //@ check-pass +//@ revisions: old next +//@[next] compile-flags: -Znext-solver pub trait BufferTrait<'buffer> { type Subset<'channel> diff --git a/tests/ui/traits/next-solver/normalize/deeply-normalize-env-in-compare-impl-item.rs b/tests/ui/traits/next-solver/normalize/deeply-normalize-env-in-compare-impl-item.rs new file mode 100644 index 0000000000000..e68f82da88af8 --- /dev/null +++ b/tests/ui/traits/next-solver/normalize/deeply-normalize-env-in-compare-impl-item.rs @@ -0,0 +1,38 @@ +//@ check-pass +//@ compile-flags: -Znext-solver + +// See trait-system-refactor-initiative/issues/166. +// The old solver doesn't check normalization constraints in `compare_impl_item`. +// The new solver performs lazy normalization so those region constraints may get postponed to +// an infcx that considers regions. +trait Trait { + type Assoc<'a> + where + Self: 'a; +} +impl<'b> Trait for &'b u32 { + type Assoc<'a> = &'a u32 + where + Self: 'a; +} + +trait Bound {} +trait Entailment { + fn method() + where + Self: for<'a> Bound<::Assoc<'a>>; +} + +impl<'b, T> Entailment<&'b u32> for T { + // Instantiates trait where-clauses with `&'b u32` and then normalizes + // `T: for<'a> Bound<<&'b u32 as Trait>::Assoc<'a>>` in a separate infcx + // without checking region constraints. + // + // It normalizes to `T: Bound<&'a u32>`, dropping the `&'b u32: 'a` constraint. + fn method() + where + Self: for<'a> Bound<&'a u32> + {} +} + +fn main() {} diff --git a/tests/ui/traits/next-solver/normalize/normalize-param-env-2.stderr b/tests/ui/traits/next-solver/normalize/normalize-param-env-2.stderr index d179c80596238..82a5f33628e61 100644 --- a/tests/ui/traits/next-solver/normalize/normalize-param-env-2.stderr +++ b/tests/ui/traits/next-solver/normalize/normalize-param-env-2.stderr @@ -1,3 +1,11 @@ +error[E0275]: overflow evaluating the requirement `<() as A>::Assoc == _` + --> $DIR/normalize-param-env-2.rs:22:5 + | +LL | / fn f() +LL | | where +LL | | Self::Assoc: A, + | |__________________________^ + error[E0275]: overflow evaluating the requirement `<() as A>::Assoc: A` --> $DIR/normalize-param-env-2.rs:24:22 | @@ -46,6 +54,6 @@ LL | where LL | Self::Assoc: A, | ^^^^ required by this bound in `A::f` -error: aborting due to 5 previous errors +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0275`. From a5dc701e7479705fa50ceb777a022e130bc8e164 Mon Sep 17 00:00:00 2001 From: reddevilmidzy Date: Thu, 27 Nov 2025 01:10:26 +0900 Subject: [PATCH 10/10] Relocate some tests and remove fn-main directory Relocate issues/issue-51022.rs to entry-point/main-with-lifetime-param.rs Relocate issue-50714.rs to entry-point/main-where-fn-bound.rs Rename issue-118772.rs to main-with-invalid-signature.rs and delete duplicate test remove ui/entry-point/issue-118772.rs in issues.txt Relocate fn-main/wrong-location.rs to entry-point/main-in-submodule.rs Remove fn-main directory Relocate issue-50688.rs to mismatched_types/array-len-is-closure.rs --- src/tools/tidy/src/issues.txt | 1 - tests/ui/README.md | 4 ---- .../main-in-submodule.rs} | 0 .../main-in-submodule.stderr} | 8 ++++---- .../main-where-fn-bound.rs} | 0 .../main-where-fn-bound.stderr} | 2 +- ...ssue-118772.rs => main-with-invalid-signature.rs} | 2 ++ ...772.stderr => main-with-invalid-signature.stderr} | 2 +- tests/ui/entry-point/main-with-lifetime-param.rs | 4 ++++ .../main-with-lifetime-param.stderr} | 4 ++-- tests/ui/fn-main/wrong-type.rs | 8 -------- tests/ui/fn-main/wrong-type.stderr | 12 ------------ tests/ui/issues/issue-50688.rs | 3 --- tests/ui/issues/issue-51022.rs | 2 -- tests/ui/mismatched_types/array-len-is-closure.rs | 5 +++++ .../array-len-is-closure.stderr} | 4 ++-- 16 files changed, 21 insertions(+), 40 deletions(-) rename tests/ui/{fn-main/wrong-location.rs => entry-point/main-in-submodule.rs} (100%) rename tests/ui/{fn-main/wrong-location.stderr => entry-point/main-in-submodule.stderr} (71%) rename tests/ui/{issues/issue-50714.rs => entry-point/main-where-fn-bound.rs} (100%) rename tests/ui/{issues/issue-50714.stderr => entry-point/main-where-fn-bound.stderr} (88%) rename tests/ui/entry-point/{issue-118772.rs => main-with-invalid-signature.rs} (55%) rename tests/ui/entry-point/{issue-118772.stderr => main-with-invalid-signature.stderr} (88%) create mode 100644 tests/ui/entry-point/main-with-lifetime-param.rs rename tests/ui/{issues/issue-51022.stderr => entry-point/main-with-lifetime-param.stderr} (78%) delete mode 100644 tests/ui/fn-main/wrong-type.rs delete mode 100644 tests/ui/fn-main/wrong-type.stderr delete mode 100644 tests/ui/issues/issue-50688.rs delete mode 100644 tests/ui/issues/issue-51022.rs create mode 100644 tests/ui/mismatched_types/array-len-is-closure.rs rename tests/ui/{issues/issue-50688.stderr => mismatched_types/array-len-is-closure.stderr} (69%) diff --git a/src/tools/tidy/src/issues.txt b/src/tools/tidy/src/issues.txt index 849dcb9e88fb1..acabfe96f2ea7 100644 --- a/src/tools/tidy/src/issues.txt +++ b/src/tools/tidy/src/issues.txt @@ -930,7 +930,6 @@ ui/dst/issue-90528-unsizing-suggestion-4.rs ui/dyn-keyword/issue-5153.rs ui/dyn-keyword/issue-56327-dyn-trait-in-macro-is-okay.rs ui/empty/issue-37026.rs -ui/entry-point/issue-118772.rs ui/enum-discriminant/auxiliary/issue-41394.rs ui/enum-discriminant/issue-104519.rs ui/enum-discriminant/issue-41394-rpass.rs diff --git a/tests/ui/README.md b/tests/ui/README.md index 3b28ef694dd30..6cec5a27d21ce 100644 --- a/tests/ui/README.md +++ b/tests/ui/README.md @@ -585,10 +585,6 @@ Exercises the `format!` macro. A broad category of tests on functions. -## `tests/ui/fn-main/` - -**FIXME**: Serves a duplicate purpose with `ui/entry-point`, should be combined. - ## `tests/ui/for/`: `for` keyword Tests on the `for` keyword and some of its associated errors, such as attempting to write the faulty pattern `for _ in 0..1 {} else {}`. diff --git a/tests/ui/fn-main/wrong-location.rs b/tests/ui/entry-point/main-in-submodule.rs similarity index 100% rename from tests/ui/fn-main/wrong-location.rs rename to tests/ui/entry-point/main-in-submodule.rs diff --git a/tests/ui/fn-main/wrong-location.stderr b/tests/ui/entry-point/main-in-submodule.stderr similarity index 71% rename from tests/ui/fn-main/wrong-location.stderr rename to tests/ui/entry-point/main-in-submodule.stderr index c47092bc47e92..60265909c7aec 100644 --- a/tests/ui/fn-main/wrong-location.stderr +++ b/tests/ui/entry-point/main-in-submodule.stderr @@ -1,11 +1,11 @@ -error[E0601]: `main` function not found in crate `wrong_location` - --> $DIR/wrong-location.rs:5:2 +error[E0601]: `main` function not found in crate `main_in_submodule` + --> $DIR/main-in-submodule.rs:5:2 | LL | } - | ^ the main function must be defined at the crate level (in `$DIR/wrong-location.rs`) + | ^ the main function must be defined at the crate level (in `$DIR/main-in-submodule.rs`) | note: here is a function named `main` - --> $DIR/wrong-location.rs:4:5 + --> $DIR/main-in-submodule.rs:4:5 | LL | fn main() { } | ^^^^^^^^^ diff --git a/tests/ui/issues/issue-50714.rs b/tests/ui/entry-point/main-where-fn-bound.rs similarity index 100% rename from tests/ui/issues/issue-50714.rs rename to tests/ui/entry-point/main-where-fn-bound.rs diff --git a/tests/ui/issues/issue-50714.stderr b/tests/ui/entry-point/main-where-fn-bound.stderr similarity index 88% rename from tests/ui/issues/issue-50714.stderr rename to tests/ui/entry-point/main-where-fn-bound.stderr index 57f9769d1dd56..ba814876e6281 100644 --- a/tests/ui/issues/issue-50714.stderr +++ b/tests/ui/entry-point/main-where-fn-bound.stderr @@ -1,5 +1,5 @@ error[E0646]: `main` function is not allowed to have a `where` clause - --> $DIR/issue-50714.rs:3:11 + --> $DIR/main-where-fn-bound.rs:3:11 | LL | fn main() where fn(&()): Eq {} | ^^^^^^^^^^^^^^^^^ `main` cannot have a `where` clause diff --git a/tests/ui/entry-point/issue-118772.rs b/tests/ui/entry-point/main-with-invalid-signature.rs similarity index 55% rename from tests/ui/entry-point/issue-118772.rs rename to tests/ui/entry-point/main-with-invalid-signature.rs index 1a4173e1252d7..782da32756cc8 100644 --- a/tests/ui/entry-point/issue-118772.rs +++ b/tests/ui/entry-point/main-with-invalid-signature.rs @@ -1,3 +1,5 @@ +//! Regression test for + fn main(_: &i32) { //~ ERROR `main` function has wrong type println!("Hello, world!"); } diff --git a/tests/ui/entry-point/issue-118772.stderr b/tests/ui/entry-point/main-with-invalid-signature.stderr similarity index 88% rename from tests/ui/entry-point/issue-118772.stderr rename to tests/ui/entry-point/main-with-invalid-signature.stderr index cc33427f59d04..95b6bff179a94 100644 --- a/tests/ui/entry-point/issue-118772.stderr +++ b/tests/ui/entry-point/main-with-invalid-signature.stderr @@ -1,5 +1,5 @@ error[E0580]: `main` function has wrong type - --> $DIR/issue-118772.rs:1:1 + --> $DIR/main-with-invalid-signature.rs:3:1 | LL | fn main(_: &i32) { | ^^^^^^^^^^^^^^^^ incorrect number of function parameters diff --git a/tests/ui/entry-point/main-with-lifetime-param.rs b/tests/ui/entry-point/main-with-lifetime-param.rs new file mode 100644 index 0000000000000..cb8cba12a58f2 --- /dev/null +++ b/tests/ui/entry-point/main-with-lifetime-param.rs @@ -0,0 +1,4 @@ +//! Regression test for + +fn main<'a>() {} +//~^ ERROR `main` function is not allowed to have generic parameters [E0131] diff --git a/tests/ui/issues/issue-51022.stderr b/tests/ui/entry-point/main-with-lifetime-param.stderr similarity index 78% rename from tests/ui/issues/issue-51022.stderr rename to tests/ui/entry-point/main-with-lifetime-param.stderr index c02c0ac93fa07..fc1dff0b22b49 100644 --- a/tests/ui/issues/issue-51022.stderr +++ b/tests/ui/entry-point/main-with-lifetime-param.stderr @@ -1,7 +1,7 @@ error[E0131]: `main` function is not allowed to have generic parameters - --> $DIR/issue-51022.rs:1:8 + --> $DIR/main-with-lifetime-param.rs:3:8 | -LL | fn main<'a>() { } +LL | fn main<'a>() {} | ^^^^ `main` cannot have generic parameters error: aborting due to 1 previous error diff --git a/tests/ui/fn-main/wrong-type.rs b/tests/ui/fn-main/wrong-type.rs deleted file mode 100644 index 31deba72af4b3..0000000000000 --- a/tests/ui/fn-main/wrong-type.rs +++ /dev/null @@ -1,8 +0,0 @@ -struct S { - x: isize, - y: isize, -} - -fn main(foo: S) { -//~^ ERROR: `main` function has wrong type [E0580] -} diff --git a/tests/ui/fn-main/wrong-type.stderr b/tests/ui/fn-main/wrong-type.stderr deleted file mode 100644 index 2b0096431dbac..0000000000000 --- a/tests/ui/fn-main/wrong-type.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0580]: `main` function has wrong type - --> $DIR/wrong-type.rs:6:1 - | -LL | fn main(foo: S) { - | ^^^^^^^^^^^^^^^ incorrect number of function parameters - | - = note: expected signature `fn()` - found signature `fn(S)` - -error: aborting due to 1 previous error - -For more information about this error, try `rustc --explain E0580`. diff --git a/tests/ui/issues/issue-50688.rs b/tests/ui/issues/issue-50688.rs deleted file mode 100644 index 88f898b86f914..0000000000000 --- a/tests/ui/issues/issue-50688.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - [1; || {}]; //~ ERROR mismatched types -} diff --git a/tests/ui/issues/issue-51022.rs b/tests/ui/issues/issue-51022.rs deleted file mode 100644 index cebdfe00c1b9d..0000000000000 --- a/tests/ui/issues/issue-51022.rs +++ /dev/null @@ -1,2 +0,0 @@ -fn main<'a>() { } - //~^ ERROR `main` function is not allowed to have generic parameters [E0131] diff --git a/tests/ui/mismatched_types/array-len-is-closure.rs b/tests/ui/mismatched_types/array-len-is-closure.rs new file mode 100644 index 0000000000000..824b604ced10e --- /dev/null +++ b/tests/ui/mismatched_types/array-len-is-closure.rs @@ -0,0 +1,5 @@ +//! Regression test for + +fn main() { + [1; || {}]; //~ ERROR mismatched types +} diff --git a/tests/ui/issues/issue-50688.stderr b/tests/ui/mismatched_types/array-len-is-closure.stderr similarity index 69% rename from tests/ui/issues/issue-50688.stderr rename to tests/ui/mismatched_types/array-len-is-closure.stderr index 873f179f56d94..db5d801871bc5 100644 --- a/tests/ui/issues/issue-50688.stderr +++ b/tests/ui/mismatched_types/array-len-is-closure.stderr @@ -1,11 +1,11 @@ error[E0308]: mismatched types - --> $DIR/issue-50688.rs:2:9 + --> $DIR/array-len-is-closure.rs:4:9 | LL | [1; || {}]; | ^^^^^ expected `usize`, found closure | = note: expected type `usize` - found closure `{closure@$DIR/issue-50688.rs:2:9: 2:11}` + found closure `{closure@$DIR/array-len-is-closure.rs:4:9: 4:11}` error: aborting due to 1 previous error