Skip to content

Commit c39f318

Browse files
committed
Auto merge of rust-lang#131237 - GuillaumeGomez:rollup-il2i7z7, r=GuillaumeGomez
Rollup of 4 pull requests Successful merges: - rust-lang#131034 (Implement RFC3695 Allow boolean literals as cfg predicates) - rust-lang#131202 (Use wide pointers consistenly across the compiler) - rust-lang#131230 (Enable `--no-sandbox` option by default for rustdoc GUI tests) - rust-lang#131232 (Week off of reviews to focus on docs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 267cf8d + 6d69af7 commit c39f318

File tree

71 files changed

+407
-211
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+407
-211
lines changed

compiler/rustc_ast/src/attr/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,16 @@ impl NestedMetaItem {
527527
}
528528
}
529529

530+
/// Returns the `MetaItem` if `self` is a `NestedMetaItem::MetaItem` or if it's
531+
/// `NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Bool(_), .. })`.
532+
pub fn meta_item_or_bool(&self) -> Option<&NestedMetaItem> {
533+
match self {
534+
NestedMetaItem::MetaItem(_item) => Some(self),
535+
NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Bool(_), .. }) => Some(self),
536+
_ => None,
537+
}
538+
}
539+
530540
/// Returns the `MetaItem` if `self` is a `NestedMetaItem::MetaItem`.
531541
pub fn meta_item(&self) -> Option<&MetaItem> {
532542
match self {

compiler/rustc_attr/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ attr_unknown_version_literal =
107107
attr_unstable_cfg_target_compact =
108108
compact `cfg(target(..))` is experimental and subject to change
109109
110+
attr_unsupported_literal_cfg_boolean =
111+
literal in `cfg` predicate value must be a boolean
110112
attr_unsupported_literal_cfg_string =
111113
literal in `cfg` predicate value must be a string
112114
attr_unsupported_literal_deprecated_kv_pair =

compiler/rustc_attr/src/builtin.rs

+45-12
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_session::parse::feature_err;
1818
use rustc_session::{RustcVersion, Session};
1919
use rustc_span::Span;
2020
use rustc_span::hygiene::Transparency;
21-
use rustc_span::symbol::{Symbol, sym};
21+
use rustc_span::symbol::{Symbol, kw, sym};
2222

2323
use crate::fluent_generated;
2424
use crate::session_diagnostics::{self, IncorrectReprFormatGenericCause};
@@ -36,6 +36,7 @@ pub fn is_builtin_attr(attr: &Attribute) -> bool {
3636
pub(crate) enum UnsupportedLiteralReason {
3737
Generic,
3838
CfgString,
39+
CfgBoolean,
3940
DeprecatedString,
4041
DeprecatedKvPair,
4142
}
@@ -533,7 +534,7 @@ pub struct Condition {
533534

534535
/// Tests if a cfg-pattern matches the cfg set
535536
pub fn cfg_matches(
536-
cfg: &ast::MetaItem,
537+
cfg: &ast::NestedMetaItem,
537538
sess: &Session,
538539
lint_node_id: NodeId,
539540
features: Option<&Features>,
@@ -604,12 +605,43 @@ pub fn parse_version(s: Symbol) -> Option<RustcVersion> {
604605
/// Evaluate a cfg-like condition (with `any` and `all`), using `eval` to
605606
/// evaluate individual items.
606607
pub fn eval_condition(
607-
cfg: &ast::MetaItem,
608+
cfg: &ast::NestedMetaItem,
608609
sess: &Session,
609610
features: Option<&Features>,
610611
eval: &mut impl FnMut(Condition) -> bool,
611612
) -> bool {
612613
let dcx = sess.dcx();
614+
615+
let cfg = match cfg {
616+
ast::NestedMetaItem::MetaItem(meta_item) => meta_item,
617+
ast::NestedMetaItem::Lit(MetaItemLit { kind: LitKind::Bool(b), .. }) => {
618+
if let Some(features) = features {
619+
// we can't use `try_gate_cfg` as symbols don't differentiate between `r#true`
620+
// and `true`, and we want to keep the former working without feature gate
621+
gate_cfg(
622+
&((
623+
if *b { kw::True } else { kw::False },
624+
sym::cfg_boolean_literals,
625+
|features: &Features| features.cfg_boolean_literals,
626+
)),
627+
cfg.span(),
628+
sess,
629+
features,
630+
);
631+
}
632+
return *b;
633+
}
634+
_ => {
635+
dcx.emit_err(session_diagnostics::UnsupportedLiteral {
636+
span: cfg.span(),
637+
reason: UnsupportedLiteralReason::CfgBoolean,
638+
is_bytestr: false,
639+
start_point_span: sess.source_map().start_point(cfg.span()),
640+
});
641+
return false;
642+
}
643+
};
644+
613645
match &cfg.kind {
614646
ast::MetaItemKind::List(mis) if cfg.name_or_empty() == sym::version => {
615647
try_gate_cfg(sym::version, cfg.span, sess, features);
@@ -645,7 +677,7 @@ pub fn eval_condition(
645677
}
646678
ast::MetaItemKind::List(mis) => {
647679
for mi in mis.iter() {
648-
if !mi.is_meta_item() {
680+
if mi.meta_item_or_bool().is_none() {
649681
dcx.emit_err(session_diagnostics::UnsupportedLiteral {
650682
span: mi.span(),
651683
reason: UnsupportedLiteralReason::Generic,
@@ -663,23 +695,19 @@ pub fn eval_condition(
663695
.iter()
664696
// We don't use any() here, because we want to evaluate all cfg condition
665697
// as eval_condition can (and does) extra checks
666-
.fold(false, |res, mi| {
667-
res | eval_condition(mi.meta_item().unwrap(), sess, features, eval)
668-
}),
698+
.fold(false, |res, mi| res | eval_condition(mi, sess, features, eval)),
669699
sym::all => mis
670700
.iter()
671701
// We don't use all() here, because we want to evaluate all cfg condition
672702
// as eval_condition can (and does) extra checks
673-
.fold(true, |res, mi| {
674-
res & eval_condition(mi.meta_item().unwrap(), sess, features, eval)
675-
}),
703+
.fold(true, |res, mi| res & eval_condition(mi, sess, features, eval)),
676704
sym::not => {
677705
let [mi] = mis.as_slice() else {
678706
dcx.emit_err(session_diagnostics::ExpectedOneCfgPattern { span: cfg.span });
679707
return false;
680708
};
681709

682-
!eval_condition(mi.meta_item().unwrap(), sess, features, eval)
710+
!eval_condition(mi, sess, features, eval)
683711
}
684712
sym::target => {
685713
if let Some(features) = features
@@ -700,7 +728,12 @@ pub fn eval_condition(
700728
seg.ident.name = Symbol::intern(&format!("target_{}", seg.ident.name));
701729
}
702730

703-
res & eval_condition(&mi, sess, features, eval)
731+
res & eval_condition(
732+
&ast::NestedMetaItem::MetaItem(mi),
733+
sess,
734+
features,
735+
eval,
736+
)
704737
})
705738
}
706739
_ => {

compiler/rustc_attr/src/session_diagnostics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for UnsupportedLiteral {
206206
let mut diag = Diag::new(dcx, level, match self.reason {
207207
UnsupportedLiteralReason::Generic => fluent::attr_unsupported_literal_generic,
208208
UnsupportedLiteralReason::CfgString => fluent::attr_unsupported_literal_cfg_string,
209+
UnsupportedLiteralReason::CfgBoolean => fluent::attr_unsupported_literal_cfg_boolean,
209210
UnsupportedLiteralReason::DeprecatedString => {
210211
fluent::attr_unsupported_literal_deprecated_string
211212
}

compiler/rustc_builtin_macros/src/cfg.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_ast::token;
66
use rustc_ast::tokenstream::TokenStream;
77
use rustc_errors::PResult;
88
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
9-
use rustc_parse::parser::attr::AllowLeadingUnsafe;
109
use rustc_span::Span;
1110
use {rustc_ast as ast, rustc_attr as attr};
1211

@@ -36,14 +35,18 @@ pub(crate) fn expand_cfg(
3635
})
3736
}
3837

39-
fn parse_cfg<'a>(cx: &ExtCtxt<'a>, span: Span, tts: TokenStream) -> PResult<'a, ast::MetaItem> {
38+
fn parse_cfg<'a>(
39+
cx: &ExtCtxt<'a>,
40+
span: Span,
41+
tts: TokenStream,
42+
) -> PResult<'a, ast::NestedMetaItem> {
4043
let mut p = cx.new_parser_from_tts(tts);
4144

4245
if p.token == token::Eof {
4346
return Err(cx.dcx().create_err(errors::RequiresCfgPattern { span }));
4447
}
4548

46-
let cfg = p.parse_meta_item(AllowLeadingUnsafe::No)?;
49+
let cfg = p.parse_meta_item_inner()?;
4750

4851
let _ = p.eat(&token::Comma);
4952

compiler/rustc_codegen_cranelift/example/std_example.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ fn main() {
168168

169169
foo(I64X2([0, 0]));
170170

171-
transmute_fat_pointer();
171+
transmute_wide_pointer();
172172

173173
rust_call_abi();
174174

@@ -192,7 +192,7 @@ type TwoPtrs = i64;
192192
#[cfg(target_pointer_width = "64")]
193193
type TwoPtrs = i128;
194194

195-
fn transmute_fat_pointer() -> TwoPtrs {
195+
fn transmute_wide_pointer() -> TwoPtrs {
196196
unsafe { transmute::<_, TwoPtrs>("true !") }
197197
}
198198

compiler/rustc_codegen_cranelift/src/base.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -713,17 +713,17 @@ fn codegen_stmt<'tcx>(
713713
let from_ty = operand.layout().ty;
714714
let to_ty = fx.monomorphize(to_ty);
715715

716-
fn is_fat_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
716+
fn is_wide_ptr<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> bool {
717717
ty.builtin_deref(true)
718718
.is_some_and(|pointee_ty| has_ptr_meta(fx.tcx, pointee_ty))
719719
}
720720

721-
if is_fat_ptr(fx, from_ty) {
722-
if is_fat_ptr(fx, to_ty) {
723-
// fat-ptr -> fat-ptr
721+
if is_wide_ptr(fx, from_ty) {
722+
if is_wide_ptr(fx, to_ty) {
723+
// wide-ptr -> wide-ptr
724724
lval.write_cvalue(fx, operand.cast_pointer_to(dest_layout));
725725
} else {
726-
// fat-ptr -> thin-ptr
726+
// wide-ptr -> thin-ptr
727727
let (ptr, _extra) = operand.load_scalar_pair(fx);
728728
lval.write_cvalue(fx, CValue::by_val(ptr, dest_layout))
729729
}

compiler/rustc_codegen_cranelift/src/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn clif_pair_type_from_ty<'tcx>(
101101
})
102102
}
103103

104-
/// Is a pointer to this type a fat ptr?
104+
/// Is a pointer to this type a wide ptr?
105105
pub(crate) fn has_ptr_meta<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
106106
if ty.is_sized(tcx, ParamEnv::reveal_all()) {
107107
return false;

compiler/rustc_codegen_cranelift/src/debuginfo/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl DebugContext {
139139

140140
pointer_type_id
141141
} else {
142-
// FIXME implement debuginfo for fat pointers
142+
// FIXME implement debuginfo for wide pointers
143143
self.placeholder_for_type(tcx, type_dbg, ptr_type)
144144
}
145145
}

compiler/rustc_codegen_gcc/src/intrinsic/simd.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
478478
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
479479
bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
480480
});
481-
require!(metadata.is_unit(), InvalidMonomorphization::CastFatPointer {
481+
require!(metadata.is_unit(), InvalidMonomorphization::CastWidePointer {
482482
span,
483483
name,
484484
ty: in_elem
@@ -493,7 +493,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
493493
let metadata = p_ty.ptr_metadata_ty(bx.tcx, |ty| {
494494
bx.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), ty)
495495
});
496-
require!(metadata.is_unit(), InvalidMonomorphization::CastFatPointer {
496+
require!(metadata.is_unit(), InvalidMonomorphization::CastWidePointer {
497497
span,
498498
name,
499499
ty: out_elem

compiler/rustc_codegen_gcc/src/type_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
207207
// layout.
208208
if let Abi::Scalar(ref scalar) = self.abi {
209209
// Use a different cache for scalars because pointers to DSTs
210-
// can be either fat or thin (data pointers of fat pointers).
210+
// can be either wide or thin (data pointers of wide pointers).
211211
if let Some(&ty) = cx.scalar_types.borrow().get(&self.ty) {
212212
return ty;
213213
}

compiler/rustc_codegen_llvm/src/abi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_codegen_ssa::mir::place::{PlaceRef, PlaceValue};
77
use rustc_codegen_ssa::traits::*;
88
use rustc_middle::ty::Ty;
99
use rustc_middle::ty::layout::LayoutOf;
10-
pub(crate) use rustc_middle::ty::layout::{FAT_PTR_ADDR, FAT_PTR_EXTRA};
10+
pub(crate) use rustc_middle::ty::layout::{WIDE_PTR_ADDR, WIDE_PTR_EXTRA};
1111
use rustc_middle::{bug, ty};
1212
use rustc_session::config;
1313
pub(crate) use rustc_target::abi::call::*;

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use super::utils::{
3434
};
3535
use crate::common::CodegenCx;
3636
use crate::debuginfo::metadata::type_map::build_type_with_children;
37-
use crate::debuginfo::utils::{FatPtrKind, fat_pointer_kind};
37+
use crate::debuginfo::utils::{WidePtrKind, wide_pointer_kind};
3838
use crate::llvm::debuginfo::{
3939
DIDescriptor, DIFile, DIFlags, DILexicalBlock, DIScope, DIType, DebugEmissionKind,
4040
DebugNameTableKind,
@@ -161,7 +161,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
161161
unique_type_id: UniqueTypeId<'tcx>,
162162
) -> DINodeCreationResult<'ll> {
163163
// The debuginfo generated by this function is only valid if `ptr_type` is really just
164-
// a (fat) pointer. Make sure it is not called for e.g. `Box<T, NonZSTAllocator>`.
164+
// a (wide) pointer. Make sure it is not called for e.g. `Box<T, NonZSTAllocator>`.
165165
assert_eq!(
166166
cx.size_and_align_of(ptr_type),
167167
cx.size_and_align_of(Ty::new_mut_ptr(cx.tcx, pointee_type))
@@ -174,7 +174,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
174174
let data_layout = &cx.tcx.data_layout;
175175
let ptr_type_debuginfo_name = compute_debuginfo_type_name(cx.tcx, ptr_type, true);
176176

177-
match fat_pointer_kind(cx, pointee_type) {
177+
match wide_pointer_kind(cx, pointee_type) {
178178
None => {
179179
// This is a thin pointer. Create a regular pointer type and give it the correct name.
180180
assert_eq!(
@@ -197,7 +197,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
197197

198198
DINodeCreationResult { di_node, already_stored_in_typemap: false }
199199
}
200-
Some(fat_pointer_kind) => {
200+
Some(wide_pointer_kind) => {
201201
type_map::build_type_with_children(
202202
cx,
203203
type_map::stub(
@@ -210,7 +210,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
210210
DIFlags::FlagZero,
211211
),
212212
|cx, owner| {
213-
// FIXME: If this fat pointer is a `Box` then we don't want to use its
213+
// FIXME: If this wide pointer is a `Box` then we don't want to use its
214214
// type layout and instead use the layout of the raw pointer inside
215215
// of it.
216216
// The proper way to handle this is to not treat Box as a pointer
@@ -227,16 +227,16 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
227227
};
228228

229229
let layout = cx.layout_of(layout_type);
230-
let addr_field = layout.field(cx, abi::FAT_PTR_ADDR);
231-
let extra_field = layout.field(cx, abi::FAT_PTR_EXTRA);
230+
let addr_field = layout.field(cx, abi::WIDE_PTR_ADDR);
231+
let extra_field = layout.field(cx, abi::WIDE_PTR_EXTRA);
232232

233-
let (addr_field_name, extra_field_name) = match fat_pointer_kind {
234-
FatPtrKind::Dyn => ("pointer", "vtable"),
235-
FatPtrKind::Slice => ("data_ptr", "length"),
233+
let (addr_field_name, extra_field_name) = match wide_pointer_kind {
234+
WidePtrKind::Dyn => ("pointer", "vtable"),
235+
WidePtrKind::Slice => ("data_ptr", "length"),
236236
};
237237

238-
assert_eq!(abi::FAT_PTR_ADDR, 0);
239-
assert_eq!(abi::FAT_PTR_EXTRA, 1);
238+
assert_eq!(abi::WIDE_PTR_ADDR, 0);
239+
assert_eq!(abi::WIDE_PTR_EXTRA, 1);
240240

241241
// The data pointer type is a regular, thin pointer, regardless of whether this
242242
// is a slice or a trait object.
@@ -258,7 +258,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
258258
owner,
259259
addr_field_name,
260260
(addr_field.size, addr_field.align.abi),
261-
layout.fields.offset(abi::FAT_PTR_ADDR),
261+
layout.fields.offset(abi::WIDE_PTR_ADDR),
262262
DIFlags::FlagZero,
263263
data_ptr_type_di_node,
264264
),
@@ -267,7 +267,7 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
267267
owner,
268268
extra_field_name,
269269
(extra_field.size, extra_field.align.abi),
270-
layout.fields.offset(abi::FAT_PTR_EXTRA),
270+
layout.fields.offset(abi::WIDE_PTR_EXTRA),
271271
DIFlags::FlagZero,
272272
type_di_node(cx, extra_field.ty),
273273
),
@@ -391,7 +391,7 @@ fn build_dyn_type_di_node<'ll, 'tcx>(
391391
///
392392
/// NOTE: We currently emit just emit the debuginfo for the element type here
393393
/// (i.e. `T` for slices and `u8` for `str`), so that we end up with
394-
/// `*const T` for the `data_ptr` field of the corresponding fat-pointer
394+
/// `*const T` for the `data_ptr` field of the corresponding wide-pointer
395395
/// debuginfo of `&[T]`.
396396
///
397397
/// It would be preferable and more accurate if we emitted a DIArray of T

0 commit comments

Comments
 (0)