Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a30f178

Browse files
committed
Auto merge of #142864 - jhpratt:rollup-mf0yq8o, r=jhpratt
Rollup of 10 pull requests Successful merges: - #140254 (Pass -Cpanic=abort for the panic_abort crate) - #142600 (Port `#[rustc_pub_transparent]` to the new attribute system) - #142617 (improve search graph docs, reset `encountered_overflow` between reruns) - #142747 (rustdoc_json: conversion cleanups) - #142776 (All HIR attributes are outer) - #142800 (integer docs: remove extraneous text) - #142841 (Enable fmt-write-bloat for Windows) - #142845 (Enable textrel-on-minimal-lib for Windows) - #142850 (remove asm_goto feature annotation, for it is now stabilized) - #142860 (Notify me on tidy changes) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9972ebf + 34dd536 commit a30f178

File tree

36 files changed

+536
-913
lines changed

36 files changed

+536
-913
lines changed

‎compiler/rustc_ast/src/attr/mod.rs‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,24 @@ impl AttributeExt for Attribute {
206206
}
207207
}
208208

209-
fn style(&self) -> AttrStyle {
210-
self.style
209+
fn doc_resolution_scope(&self) -> Option<AttrStyle> {
210+
match &self.kind {
211+
AttrKind::DocComment(..) => Some(self.style),
212+
AttrKind::Normal(normal)
213+
if normal.item.path == sym::doc && normal.item.value_str().is_some() =>
214+
{
215+
Some(self.style)
216+
}
217+
_ => None,
218+
}
211219
}
212220
}
213221

214222
impl Attribute {
223+
pub fn style(&self) -> AttrStyle {
224+
self.style
225+
}
226+
215227
pub fn may_have_doc_links(&self) -> bool {
216228
self.doc_str().is_some_and(|s| comments::may_have_doc_links(s.as_str()))
217229
}
@@ -806,7 +818,14 @@ pub trait AttributeExt: Debug {
806818
/// * `#[doc(...)]` returns `None`.
807819
fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)>;
808820

809-
fn style(&self) -> AttrStyle;
821+
/// Returns outer or inner if this is a doc attribute or a sugared doc
822+
/// comment, otherwise None.
823+
///
824+
/// This is used in the case of doc comments on modules, to decide whether
825+
/// to resolve intra-doc links against the symbols in scope within the
826+
/// commented module (for inner doc) vs within its parent module (for outer
827+
/// doc).
828+
fn doc_resolution_scope(&self) -> Option<AttrStyle>;
810829
}
811830

812831
// FIXME(fn_delegation): use function delegation instead of manually forwarding
@@ -881,8 +900,4 @@ impl Attribute {
881900
pub fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)> {
882901
AttributeExt::doc_str_and_comment_kind(self)
883902
}
884-
885-
pub fn style(&self) -> AttrStyle {
886-
AttributeExt::style(self)
887-
}
888903
}

‎compiler/rustc_attr_data_structures/src/attributes.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ pub enum AttributeKind {
240240
/// Represents `#[optimize(size|speed)]`
241241
Optimize(OptimizeAttr, Span),
242242

243+
/// Represents `#[rustc_pub_transparent]` (used by the `repr_transparent_external_private_fields` lint).
244+
PubTransparent(Span),
245+
243246
/// Represents [`#[repr]`](https://doc.rust-lang.org/stable/reference/type-layout.html#representations).
244247
Repr(ThinVec<(ReprAttr, Span)>),
245248

‎compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,16 @@ impl<S: Stage> SingleAttributeParser<S> for AsPtrParser {
1919
Some(AttributeKind::AsPtr(cx.attr_span))
2020
}
2121
}
22+
23+
pub(crate) struct PubTransparentParser;
24+
impl<S: Stage> SingleAttributeParser<S> for PubTransparentParser {
25+
const PATH: &[Symbol] = &[sym::rustc_pub_transparent];
26+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepFirst;
27+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
28+
const TEMPLATE: AttributeTemplate = template!(Word);
29+
30+
fn convert(cx: &mut AcceptContext<'_, '_, S>, _args: &ArgParser<'_>) -> Option<AttributeKind> {
31+
// FIXME: check that there's no args (this is currently checked elsewhere)
32+
Some(AttributeKind::PubTransparent(cx.attr_span))
33+
}
34+
}

‎compiler/rustc_attr_parsing/src/context.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::attributes::codegen_attrs::{ColdParser, OptimizeParser};
1919
use crate::attributes::confusables::ConfusablesParser;
2020
use crate::attributes::deprecation::DeprecationParser;
2121
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
22-
use crate::attributes::lint_helpers::AsPtrParser;
22+
use crate::attributes::lint_helpers::{AsPtrParser,PubTransparentParser};
2323
use crate::attributes::repr::{AlignParser, ReprParser};
2424
use crate::attributes::semantics::MayDangleParser;
2525
use crate::attributes::stability::{
@@ -113,6 +113,7 @@ attribute_parsers!(
113113
Single<InlineParser>,
114114
Single<MayDangleParser>,
115115
Single<OptimizeParser>,
116+
Single<PubTransparentParser>,
116117
Single<RustcForceInlineParser>,
117118
Single<TransparencyParser>,
118119
// tidy-alphabetical-end

‎compiler/rustc_feature/src/builtin_attrs.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
710710
),
711711
rustc_attr!(
712712
rustc_pub_transparent, Normal, template!(Word),
713-
WarnFollowing, EncodeCrossCrate::Yes,
713+
ErrorFollowing, EncodeCrossCrate::Yes,
714714
"used internally to mark types with a `transparent` representation when it is guaranteed by the documentation",
715715
),
716716

‎compiler/rustc_hir/src/hir.rs‎

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,12 +1346,13 @@ impl AttributeExt for Attribute {
13461346
}
13471347
}
13481348

1349-
#[inline]
1350-
fn style(&self) -> AttrStyle {
1351-
match &self {
1352-
Attribute::Unparsed(u) => u.style,
1353-
Attribute::Parsed(AttributeKind::DocComment { style, .. }) => *style,
1354-
_ => panic!(),
1349+
fn doc_resolution_scope(&self) -> Option<AttrStyle> {
1350+
match self {
1351+
Attribute::Parsed(AttributeKind::DocComment { style, .. }) => Some(*style),
1352+
Attribute::Unparsed(attr) if self.has_name(sym::doc) && self.value_str().is_some() => {
1353+
Some(attr.style)
1354+
}
1355+
_ => None,
13551356
}
13561357
}
13571358
}
@@ -1442,11 +1443,6 @@ impl Attribute {
14421443
pub fn doc_str_and_comment_kind(&self) -> Option<(Symbol, CommentKind)> {
14431444
AttributeExt::doc_str_and_comment_kind(self)
14441445
}
1445-
1446-
#[inline]
1447-
pub fn style(&self) -> AttrStyle {
1448-
AttributeExt::style(self)
1449-
}
14501446
}
14511447

14521448
/// Attributes owned by a HIR owner.
@@ -2286,16 +2282,9 @@ pub struct Expr<'hir> {
22862282
}
22872283

22882284
impl Expr<'_> {
2289-
pub fn precedence(
2290-
&self,
2291-
for_each_attr: &dyn Fn(HirId, &mut dyn FnMut(&Attribute)),
2292-
) -> ExprPrecedence {
2285+
pub fn precedence(&self, has_attr: &dyn Fn(HirId) -> bool) -> ExprPrecedence {
22932286
let prefix_attrs_precedence = || -> ExprPrecedence {
2294-
let mut has_outer_attr = false;
2295-
for_each_attr(self.hir_id, &mut |attr: &Attribute| {
2296-
has_outer_attr |= matches!(attr.style(), AttrStyle::Outer)
2297-
});
2298-
if has_outer_attr { ExprPrecedence::Prefix } else { ExprPrecedence::Unambiguous }
2287+
if has_attr(self.hir_id) { ExprPrecedence::Prefix } else { ExprPrecedence::Unambiguous }
22992288
};
23002289

23012290
match &self.kind {
@@ -2351,7 +2340,7 @@ impl Expr<'_> {
23512340
| ExprKind::Use(..)
23522341
| ExprKind::Err(_) => prefix_attrs_precedence(),
23532342

2354-
ExprKind::DropTemps(expr, ..) => expr.precedence(for_each_attr),
2343+
ExprKind::DropTemps(expr, ..) => expr.precedence(has_attr),
23552344
}
23562345
}
23572346

‎compiler/rustc_hir_analysis/src/check/check.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::cell::LazyCell;
22
use std::ops::ControlFlow;
33

44
use rustc_abi::FieldIdx;
5+
use rustc_attr_data_structures::AttributeKind;
56
use rustc_attr_data_structures::ReprAttr::ReprPacked;
67
use rustc_data_structures::unord::{UnordMap, UnordSet};
78
use rustc_errors::codes::*;
@@ -1384,7 +1385,11 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
13841385
ty::Tuple(list) => list.iter().try_for_each(|t| check_non_exhaustive(tcx, t)),
13851386
ty::Array(ty, _) => check_non_exhaustive(tcx, *ty),
13861387
ty::Adt(def, args) => {
1387-
if !def.did().is_local() && !tcx.has_attr(def.did(), sym::rustc_pub_transparent)
1388+
if !def.did().is_local()
1389+
&& !attrs::find_attr!(
1390+
tcx.get_all_attrs(def.did()),
1391+
AttributeKind::PubTransparent(_)
1392+
)
13881393
{
13891394
let non_exhaustive = def.is_variant_list_non_exhaustive()
13901395
|| def

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /