Skip to content

Commit 5ca574e

Browse files
committed
Auto merge of rust-lang#143173 - matthiaskrgr:rollup-ieu5k05, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - rust-lang#142021 (Doc: clarify priority of lint level sources) - rust-lang#142367 (Add regression test for rust-lang#137857 to ensure that we generate intra doc links for extern crate items.) - rust-lang#142641 (Generate symbols.o for proc-macros too) - rust-lang#142889 (Clarify doc comment on unix OpenOptions) - rust-lang#143063 (explain `ImportData::imported_module`) - rust-lang#143088 (Improve documentation of `TagEncoding`) - rust-lang#143135 (fix typos on some doc comments) - rust-lang#143138 (Port `#[link_name]` to the new attribute parsing infrastructure) - rust-lang#143155 (`librustdoc` house-keeping 🧹) - rust-lang#143169 (Remove unused feature gates) - rust-lang#143171 (Fix the span of trait bound modifier `[const]`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents dddd7ab + a262c00 commit 5ca574e

File tree

65 files changed

+580
-400
lines changed

Some content is hidden

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

65 files changed

+580
-400
lines changed

compiler/rustc_abi/src/lib.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1592,24 +1592,33 @@ pub enum TagEncoding<VariantIdx: Idx> {
15921592
/// (so converting the tag to the discriminant can require sign extension).
15931593
Direct,
15941594

1595-
/// Niche (values invalid for a type) encoding the discriminant:
1596-
/// Discriminant and variant index coincide.
1595+
/// Niche (values invalid for a type) encoding the discriminant.
1596+
/// Note that for this encoding, the discriminant and variant index of each variant coincide!
1597+
/// This invariant is codified as part of [`layout_sanity_check`](../rustc_ty_utils/layout/invariant/fn.layout_sanity_check.html).
1598+
///
15971599
/// The variant `untagged_variant` contains a niche at an arbitrary
1598-
/// offset (field `tag_field` of the enum), which for a variant with
1599-
/// discriminant `d` is set to
1600-
/// `(d - niche_variants.start).wrapping_add(niche_start)`
1601-
/// (this is wrapping arithmetic using the type of the niche field).
1600+
/// offset (field [`Variants::Multiple::tag_field`] of the enum).
1601+
/// For a variant with variant index `i`, such that `i != untagged_variant`,
1602+
/// the tag is set to `(i - niche_variants.start).wrapping_add(niche_start)`
1603+
/// (this is wrapping arithmetic using the type of the niche field, cf. the
1604+
/// [`tag_for_variant`](../rustc_const_eval/interpret/struct.InterpCx.html#method.tag_for_variant)
1605+
/// query implementation).
1606+
/// To recover the variant index `i` from a `tag`, the above formula has to be reversed,
1607+
/// i.e. `i = tag.wrapping_sub(niche_start) + niche_variants.start`. If `i` ends up outside
1608+
/// `niche_variants`, the tag must have encoded the `untagged_variant`.
16021609
///
1603-
/// For example, `Option<(usize, &T)>` is represented such that
1604-
/// `None` has a null pointer for the second tuple field, and
1605-
/// `Some` is the identity function (with a non-null reference).
1610+
/// For example, `Option<(usize, &T)>` is represented such that the tag for
1611+
/// `None` is the null pointer in the second tuple field, and
1612+
/// `Some` is the identity function (with a non-null reference)
1613+
/// and has no additional tag, i.e. the reference being non-null uniquely identifies this variant.
16061614
///
16071615
/// Other variants that are not `untagged_variant` and that are outside the `niche_variants`
16081616
/// range cannot be represented; they must be uninhabited.
1617+
/// Nonetheless, uninhabited variants can also fall into the range of `niche_variants`.
16091618
Niche {
16101619
untagged_variant: VariantIdx,
1611-
/// This range *may* contain `untagged_variant`; that is then just a "dead value" and
1612-
/// not used to encode anything.
1620+
/// This range *may* contain `untagged_variant` or uninhabited variants;
1621+
/// these are then just "dead values" and not used to encode anything.
16131622
niche_variants: RangeInclusive<VariantIdx>,
16141623
/// This is inbounds of the type of the niche field
16151624
/// (not sign-extended, i.e., all bits beyond the niche field size are 0).

compiler/rustc_ast/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
#![feature(box_patterns)]
1717
#![feature(if_let_guard)]
1818
#![feature(macro_metavar_expr)]
19-
#![feature(negative_impls)]
20-
#![feature(never_type)]
2119
#![feature(rustdoc_internals)]
22-
#![feature(stmt_expr_attributes)]
2320
#![recursion_limit = "256"]
2421
// tidy-alphabetical-end
2522

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ pub enum AttributeKind {
253253
/// Represents `#[inline]` and `#[rustc_force_inline]`.
254254
Inline(InlineAttr, Span),
255255

256+
/// Represents `#[link_name]`.
257+
LinkName { name: Symbol, span: Span },
258+
256259
/// Represents `#[loop_match]`.
257260
LoopMatch(Span),
258261

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ impl AttributeKind {
2929
Stability { .. } => Yes,
3030
Cold(..) => No,
3131
ConstContinue(..) => No,
32+
LinkName { .. } => Yes,
3233
LoopMatch(..) => No,
3334
MayDangle(..) => No,
3435
MustUse { .. } => Yes,
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use rustc_attr_data_structures::AttributeKind;
2+
use rustc_attr_data_structures::AttributeKind::LinkName;
3+
use rustc_feature::{AttributeTemplate, template};
4+
use rustc_span::{Symbol, sym};
5+
6+
use crate::attributes::{AttributeOrder, OnDuplicate, SingleAttributeParser};
7+
use crate::context::{AcceptContext, Stage};
8+
use crate::parser::ArgParser;
9+
10+
pub(crate) struct LinkNameParser;
11+
12+
impl<S: Stage> SingleAttributeParser<S> for LinkNameParser {
13+
const PATH: &[Symbol] = &[sym::link_name];
14+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst;
15+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
16+
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
17+
18+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
19+
let Some(nv) = args.name_value() else {
20+
cx.expected_name_value(cx.attr_span, None);
21+
return None;
22+
};
23+
let Some(name) = nv.value_as_str() else {
24+
cx.expected_string_literal(nv.value_span, Some(nv.value_as_lit()));
25+
return None;
26+
};
27+
28+
Some(LinkName { name, span: cx.attr_span })
29+
}
30+
}

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub(crate) mod codegen_attrs;
3131
pub(crate) mod confusables;
3232
pub(crate) mod deprecation;
3333
pub(crate) mod inline;
34+
pub(crate) mod link_attrs;
3435
pub(crate) mod lint_helpers;
3536
pub(crate) mod loop_match;
3637
pub(crate) mod must_use;

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use crate::attributes::codegen_attrs::{
2222
use crate::attributes::confusables::ConfusablesParser;
2323
use crate::attributes::deprecation::DeprecationParser;
2424
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
25+
use crate::attributes::link_attrs::LinkNameParser;
2526
use crate::attributes::lint_helpers::{AsPtrParser, PubTransparentParser};
2627
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
2728
use crate::attributes::must_use::MustUseParser;
@@ -121,6 +122,7 @@ attribute_parsers!(
121122
Single<DeprecationParser>,
122123
Single<ExportNameParser>,
123124
Single<InlineParser>,
125+
Single<LinkNameParser>,
124126
Single<LoopMatchParser>,
125127
Single<MayDangleParser>,
126128
Single<MustUseParser>,

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,8 +1870,13 @@ pub(crate) fn linked_symbols(
18701870
crate_type: CrateType,
18711871
) -> Vec<(String, SymbolExportKind)> {
18721872
match crate_type {
1873-
CrateType::Executable | CrateType::Cdylib | CrateType::Dylib | CrateType::Sdylib => (),
1874-
CrateType::Staticlib | CrateType::ProcMacro | CrateType::Rlib => {
1873+
CrateType::Executable
1874+
| CrateType::ProcMacro
1875+
| CrateType::Cdylib
1876+
| CrateType::Dylib
1877+
| CrateType::Sdylib => (),
1878+
CrateType::Staticlib | CrateType::Rlib => {
1879+
// These are not linked, so no need to generate symbols.o for them.
18751880
return Vec::new();
18761881
}
18771882
}

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
123123
}
124124
AttributeKind::Naked(_) => codegen_fn_attrs.flags |= CodegenFnAttrFlags::NAKED,
125125
AttributeKind::Align { align, .. } => codegen_fn_attrs.alignment = Some(*align),
126+
AttributeKind::LinkName { name, .. } => codegen_fn_attrs.link_name = Some(*name),
126127
AttributeKind::NoMangle(attr_span) => {
127128
if tcx.opt_item_name(did.to_def_id()).is_some() {
128129
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE;
@@ -262,7 +263,6 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
262263
}
263264
}
264265
}
265-
sym::link_name => codegen_fn_attrs.link_name = attr.value_str(),
266266
sym::link_ordinal => {
267267
link_ordinal_span = Some(attr.span());
268268
if let ordinal @ Some(_) = check_link_ordinal(tcx, attr) {

compiler/rustc_codegen_ssa/src/mir/operand.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -479,17 +479,8 @@ impl<'a, 'tcx, V: CodegenObject> OperandRef<'tcx, V> {
479479
_ => (tag_imm, bx.cx().immediate_backend_type(tag_op.layout)),
480480
};
481481

482-
// Layout ensures that we only get here for cases where the discriminant
482+
// `layout_sanity_check` ensures that we only get here for cases where the discriminant
483483
// value and the variant index match, since that's all `Niche` can encode.
484-
// But for emphasis and debugging, let's double-check one anyway.
485-
debug_assert_eq!(
486-
self.layout
487-
.ty
488-
.discriminant_for_variant(bx.tcx(), untagged_variant)
489-
.unwrap()
490-
.val,
491-
u128::from(untagged_variant.as_u32()),
492-
);
493484

494485
let relative_max = niche_variants.end().as_u32() - niche_variants.start().as_u32();
495486

0 commit comments

Comments
 (0)