From 35693778e81a0e94e13a5a48809657c6b05f7f42 Mon Sep 17 00:00:00 2001 From: cijiugechu Date: Thu, 2 Apr 2026 23:15:28 +0800 Subject: [PATCH 1/2] Fix ICE in unsafe binder discriminant queries Forward discriminant-related queries through `ty::UnsafeBinder` to the erased inner type, matching the existing layout behavior. --- compiler/rustc_middle/src/ty/sty.rs | 10 +++++++++- .../discriminant-for-variant.rs | 11 +++++++++++ .../discriminant-for-variant.stderr | 19 +++++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 tests/ui/unsafe-binders/discriminant-for-variant.rs create mode 100644 tests/ui/unsafe-binders/discriminant-for-variant.stderr diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 0d047b348d9e1..b6d4f6ca0d82e 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1630,6 +1630,9 @@ impl<'tcx> Ty<'tcx> { TyKind::Coroutine(def_id, args) => { Some(args.as_coroutine().variant_range(*def_id, tcx)) } + TyKind::UnsafeBinder(bound_ty) => { + tcx.instantiate_bound_regions_with_erased((*bound_ty).into()).variant_range(tcx) + } _ => None, } } @@ -1651,6 +1654,9 @@ impl<'tcx> Ty<'tcx> { TyKind::Coroutine(def_id, args) => { Some(args.as_coroutine().discriminant_for_variant(*def_id, tcx, variant_index)) } + TyKind::UnsafeBinder(bound_ty) => tcx + .instantiate_bound_regions_with_erased((*bound_ty).into()) + .discriminant_for_variant(tcx, variant_index), _ => None, } } @@ -1669,6 +1675,9 @@ impl<'tcx> Ty<'tcx> { } ty::Pat(ty, _) => ty.discriminant_ty(tcx), + ty::UnsafeBinder(bound_ty) => { + tcx.instantiate_bound_regions_with_erased((*bound_ty).into()).discriminant_ty(tcx) + } ty::Bool | ty::Char @@ -1690,7 +1699,6 @@ impl<'tcx> Ty<'tcx> { | ty::CoroutineWitness(..) | ty::Never | ty::Tuple(_) - | ty::UnsafeBinder(_) | ty::Error(_) | ty::Infer(IntVar(_) | FloatVar(_)) => tcx.types.u8, diff --git a/tests/ui/unsafe-binders/discriminant-for-variant.rs b/tests/ui/unsafe-binders/discriminant-for-variant.rs new file mode 100644 index 0000000000000..6a2ef22e92628 --- /dev/null +++ b/tests/ui/unsafe-binders/discriminant-for-variant.rs @@ -0,0 +1,11 @@ +#![feature(unsafe_binders)] + +const None: Option Option>> = None; +//~^ ERROR the trait bound `Box<(dyn Send + 'static)>: Copy` is not satisfied +//~| ERROR the trait bound `Box<(dyn Send + 'static)>: Copy` is not satisfied + +fn main() { + match None { + _ => {} + } +} diff --git a/tests/ui/unsafe-binders/discriminant-for-variant.stderr b/tests/ui/unsafe-binders/discriminant-for-variant.stderr new file mode 100644 index 0000000000000..ed1a38ae14e40 --- /dev/null +++ b/tests/ui/unsafe-binders/discriminant-for-variant.stderr @@ -0,0 +1,19 @@ +error[E0277]: the trait bound `Box<(dyn Send + 'static)>: Copy` is not satisfied + --> $DIR/discriminant-for-variant.rs:3:13 + | +LL | const None: Option Option>> = None; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `Box<(dyn Send + 'static)>` + | + = note: required for `Option>` to implement `Copy` + +error[E0277]: the trait bound `Box<(dyn Send + 'static)>: Copy` is not satisfied + --> $DIR/discriminant-for-variant.rs:3:54 + | +LL | const None: Option Option>> = None; + | ^^^^ the trait `Copy` is not implemented for `Box<(dyn Send + 'static)>` + | + = note: required for `Option>` to implement `Copy` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0277`. From c3709eee095c22f873cec3fd5d893da035ba5d69 Mon Sep 17 00:00:00 2001 From: David Wood Date: Fri, 3 Apr 2026 09:14:07 +0000 Subject: [PATCH 2/2] ast_validation: scalable vectors okay for rustdoc Scalable vector types in `core_arch` are cfg'd for aarch64 and for rustdoc, which can successfully document these types given any `--target` (`core_arch` CI uses `i686-unknown-linux-gnu`) - this shouldn't trigger the "scalable vectors not supported on arch" error. --- compiler/rustc_ast_passes/src/ast_validation.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index ee46bdcf7d8bb..dc2a8be5b3cf1 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -1379,7 +1379,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> { this.dcx() .emit_err(errors::ScalableVectorNotTupleStruct { span: item.span }); } - if !self.sess.target.arch.supports_scalable_vectors() { + if !self.sess.target.arch.supports_scalable_vectors() + && !self.sess.opts.actually_rustdoc + { this.dcx().emit_err(errors::ScalableVectorBadArch { span: attr.span }); } }