Skip to content

Commit d35cb8a

Browse files
committed
Auto merge of #142861 - jhpratt:rollup-h7c4fx9, r=jhpratt
Rollup of 10 pull requests Successful merges: - #140254 (Pass -Cpanic=abort for the panic_abort crate) - #142594 (Add DesugaringKind::FormatLiteral) - #142600 (Port `#[rustc_pub_transparent]` to the new attribute system) - #142617 (improve search graph docs, reset `encountered_overflow` between reruns) - #142641 (Generate symbols.o for proc-macros too) - #142747 (rustdoc_json: conversion cleanups) - #142776 (All HIR attributes are outer) - #142800 (integer docs: remove extraneous text) - #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 fa2f355 + adf3aad commit d35cb8a

File tree

100 files changed

+852
-1069
lines changed

Some content is hidden

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

100 files changed

+852
-1069
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_ast/src/format.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,14 @@ pub struct FormatArgs {
5050
///
5151
/// Generally only useful for lints that care about the raw bytes the user wrote.
5252
pub uncooked_fmt_str: (LitKind, Symbol),
53+
/// Was the format literal written in the source?
54+
/// - `format!("boo")` => true,
55+
/// - `format!(concat!("b", "o", "o"))` => false,
56+
/// - `format!(include_str!("boo.txt"))` => false,
57+
///
58+
/// If it wasn't written in the source then we have to be careful with spans pointing into it
59+
/// and suggestions about rewriting it.
60+
pub is_source_literal: bool,
5361
}
5462

5563
/// A piece of a format template string.

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,7 +1389,7 @@ macro_rules! common_visitor_and_walkers {
13891389

13901390
// FIXME: visit the template exhaustively.
13911391
pub fn walk_format_args<$($lt,)? V: $Visitor$(<$lt>)?>(vis: &mut V, fmt: &$($lt)? $($mut)? FormatArgs) -> V::Result {
1392-
let FormatArgs { span, template: _, arguments, uncooked_fmt_str: _ } = fmt;
1392+
let FormatArgs { span, template: _, arguments, uncooked_fmt_str: _, is_source_literal: _ } = fmt;
13931393
let args = $(${ignore($mut)} arguments.all_args_mut())? $(${ignore($lt)} arguments.all_args())? ;
13941394
for FormatArgument { kind, expr } in args {
13951395
match kind {

compiler/rustc_ast_lowering/src/format.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_ast::*;
44
use rustc_data_structures::fx::FxIndexMap;
55
use rustc_hir as hir;
66
use rustc_session::config::FmtDebug;
7-
use rustc_span::{Ident, Span, Symbol, sym};
7+
use rustc_span::{DesugaringKind, Ident, Span, Symbol, sym};
88

99
use super::LoweringContext;
1010

@@ -14,6 +14,13 @@ impl<'hir> LoweringContext<'_, 'hir> {
1414
// format_args!() had any arguments _before_ flattening/inlining.
1515
let allow_const = fmt.arguments.all_args().is_empty();
1616
let mut fmt = Cow::Borrowed(fmt);
17+
18+
let sp = self.mark_span_with_reason(
19+
DesugaringKind::FormatLiteral { source: fmt.is_source_literal },
20+
sp,
21+
sp.ctxt().outer_expn_data().allow_internal_unstable,
22+
);
23+
1724
if self.tcx.sess.opts.unstable_opts.flatten_format_args {
1825
fmt = flatten_format_args(fmt);
1926
fmt = self.inline_literals(fmt);

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_builtin_macros/src/format.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,7 @@ fn make_format_args(
606606
template,
607607
arguments: args,
608608
uncooked_fmt_str,
609+
is_source_literal,
609610
}))
610611
}
611612

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,8 +1817,13 @@ pub(crate) fn linked_symbols(
18171817
crate_type: CrateType,
18181818
) -> Vec<(String, SymbolExportKind)> {
18191819
match crate_type {
1820-
CrateType::Executable | CrateType::Cdylib | CrateType::Dylib | CrateType::Sdylib => (),
1821-
CrateType::Staticlib | CrateType::ProcMacro | CrateType::Rlib => {
1820+
CrateType::Executable
1821+
| CrateType::ProcMacro
1822+
| CrateType::Cdylib
1823+
| CrateType::Dylib
1824+
| CrateType::Sdylib => (),
1825+
CrateType::Staticlib | CrateType::Rlib => {
1826+
// These are not linked, so no need to generate symbols.o for them.
18221827
return Vec::new();
18231828
}
18241829
}

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)