Skip to content

Commit 3e0a442

Browse files
committed
Auto merge of #155398 - JonathanBrouwer:rollup-rrqTa9g, r=<try>
Rollup of 15 pull requests try-job: dist-various-1 try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple try-job: x86_64-mingw-1 try-job: i686-msvc-2
2 parents 18b439f + 85ca316 commit 3e0a442

116 files changed

Lines changed: 343646 additions & 39298 deletions

File tree

Some content is hidden

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

compiler/rustc_ast_pretty/src/helpers.rs

Lines changed: 0 additions & 49 deletions
This file was deleted.

compiler/rustc_ast_pretty/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@
33
#![feature(negative_impls)]
44
// tidy-alphabetical-end
55

6-
mod helpers;
76
pub mod pp;
87
pub mod pprust;

compiler/rustc_ast_pretty/src/pp.rs

Lines changed: 134 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@
132132
//! methods called `Printer::scan_*`, and the 'PRINT' process is the
133133
//! method called `Printer::print`.
134134
135-
mod convenience;
136135
mod ring;
137136

138137
use std::borrow::Cow;
@@ -188,6 +187,12 @@ pub(crate) enum Token {
188187
End,
189188
}
190189

190+
impl Token {
191+
pub(crate) fn is_hardbreak_tok(&self) -> bool {
192+
*self == Printer::hardbreak_tok_offset(0)
193+
}
194+
}
195+
191196
#[derive(Copy, Clone)]
192197
enum PrintFrame {
193198
Fits,
@@ -479,4 +484,132 @@ impl Printer {
479484
self.out.push_str(string);
480485
self.space -= string.len() as isize;
481486
}
487+
488+
/// Synthesizes a comment that was not textually present in the original
489+
/// source file.
490+
pub fn synth_comment(&mut self, text: impl Into<Cow<'static, str>>) {
491+
self.word("/*");
492+
self.space();
493+
self.word(text);
494+
self.space();
495+
self.word("*/")
496+
}
497+
498+
/// "raw box"
499+
pub fn rbox(&mut self, indent: isize, breaks: Breaks) -> BoxMarker {
500+
self.scan_begin(BeginToken { indent: IndentStyle::Block { offset: indent }, breaks })
501+
}
502+
503+
/// Inconsistent breaking box
504+
pub fn ibox(&mut self, indent: isize) -> BoxMarker {
505+
self.rbox(indent, Breaks::Inconsistent)
506+
}
507+
508+
/// Consistent breaking box
509+
pub fn cbox(&mut self, indent: isize) -> BoxMarker {
510+
self.rbox(indent, Breaks::Consistent)
511+
}
512+
513+
pub fn visual_align(&mut self) -> BoxMarker {
514+
self.scan_begin(BeginToken { indent: IndentStyle::Visual, breaks: Breaks::Consistent })
515+
}
516+
517+
pub fn break_offset(&mut self, n: usize, off: isize) {
518+
self.scan_break(BreakToken {
519+
offset: off,
520+
blank_space: n as isize,
521+
..BreakToken::default()
522+
});
523+
}
524+
525+
pub fn end(&mut self, b: BoxMarker) {
526+
self.scan_end(b)
527+
}
528+
529+
pub fn eof(mut self) -> String {
530+
self.scan_eof();
531+
self.out
532+
}
533+
534+
pub fn word<S: Into<Cow<'static, str>>>(&mut self, wrd: S) {
535+
let string = wrd.into();
536+
self.scan_string(string)
537+
}
538+
539+
pub fn word_space<W: Into<Cow<'static, str>>>(&mut self, w: W) {
540+
self.word(w);
541+
self.space();
542+
}
543+
544+
pub fn nbsp(&mut self) {
545+
self.word(" ")
546+
}
547+
548+
pub fn word_nbsp<S: Into<Cow<'static, str>>>(&mut self, w: S) {
549+
self.word(w);
550+
self.nbsp()
551+
}
552+
553+
fn spaces(&mut self, n: usize) {
554+
self.break_offset(n, 0)
555+
}
556+
557+
pub fn zerobreak(&mut self) {
558+
self.spaces(0)
559+
}
560+
561+
pub fn space(&mut self) {
562+
self.spaces(1)
563+
}
564+
565+
pub fn popen(&mut self) {
566+
self.word("(");
567+
}
568+
569+
pub fn pclose(&mut self) {
570+
self.word(")");
571+
}
572+
573+
pub fn hardbreak(&mut self) {
574+
self.spaces(SIZE_INFINITY as usize)
575+
}
576+
577+
pub fn is_beginning_of_line(&self) -> bool {
578+
match self.last_token() {
579+
Some(last_token) => last_token.is_hardbreak_tok(),
580+
None => true,
581+
}
582+
}
583+
584+
pub fn hardbreak_if_not_bol(&mut self) {
585+
if !self.is_beginning_of_line() {
586+
self.hardbreak()
587+
}
588+
}
589+
590+
pub fn space_if_not_bol(&mut self) {
591+
if !self.is_beginning_of_line() {
592+
self.space();
593+
}
594+
}
595+
596+
pub(crate) fn hardbreak_tok_offset(off: isize) -> Token {
597+
Token::Break(BreakToken {
598+
offset: off,
599+
blank_space: SIZE_INFINITY,
600+
..BreakToken::default()
601+
})
602+
}
603+
604+
pub fn trailing_comma(&mut self) {
605+
self.scan_break(BreakToken { pre_break: Some(','), ..BreakToken::default() });
606+
}
607+
608+
pub fn trailing_comma_or_space(&mut self) {
609+
self.scan_break(BreakToken {
610+
blank_space: 1,
611+
pre_break: Some(','),
612+
..BreakToken::default()
613+
});
614+
}
482615
}

compiler/rustc_ast_pretty/src/pp/convenience.rs

Lines changed: 0 additions & 97 deletions
This file was deleted.

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_session::parse::{ParseSess, feature_err};
1919
use rustc_span::{ErrorGuaranteed, Span, Symbol, sym};
2020
use thin_vec::ThinVec;
2121

22+
use crate::attributes::AttributeSafety;
2223
use crate::context::{AcceptContext, ShouldEmit, Stage};
2324
use crate::parser::{
2425
AllowExprMetavar, ArgParser, MetaItemListParser, MetaItemOrLitParser, NameValueParser,
@@ -410,6 +411,7 @@ fn parse_cfg_attr_internal<'a>(
410411
attribute.style,
411412
AttrPath { segments: attribute.path().into_boxed_slice(), span: attribute.span },
412413
Some(attribute.get_normal_item().unsafety),
414+
AttributeSafety::Normal,
413415
ParsedDescription::Attribute,
414416
pred_span,
415417
lint_node_id,

compiler/rustc_attr_parsing/src/attributes/cfg_select.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_session::Session;
1212
use rustc_session::lint::builtin::UNREACHABLE_CFG_SELECT_PREDICATES;
1313
use rustc_span::{ErrorGuaranteed, Span, Symbol, sym};
1414

15+
use crate::attributes::AttributeSafety;
1516
use crate::parser::{AllowExprMetavar, MetaItemOrLitParser};
1617
use crate::{AttributeParser, ParsedDescription, ShouldEmit, errors, parse_cfg_entry};
1718

@@ -105,6 +106,7 @@ pub fn parse_cfg_select(
105106
AttrStyle::Inner,
106107
AttrPath { segments: vec![sym::cfg_select].into_boxed_slice(), span: cfg_span },
107108
None,
109+
AttributeSafety::Normal,
108110
ParsedDescription::Macro,
109111
cfg_span,
110112
lint_node_id,

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use rustc_hir::attrs::{CoverageAttrKind, OptimizeAttr, RtsanSetting, SanitizerSet, UsedBy};
22
use rustc_session::parse::feature_err;
3+
use rustc_span::edition::Edition::Edition2024;
34

45
use super::prelude::*;
6+
use crate::attributes::AttributeSafety;
57
use crate::session_diagnostics::{
68
NakedFunctionIncompatibleAttribute, NullOnExport, NullOnObjcClass, NullOnObjcSelector,
79
ObjcClassExpectedStringLiteral, ObjcSelectorExpectedStringLiteral,
@@ -103,6 +105,7 @@ pub(crate) struct ExportNameParser;
103105
impl<S: Stage> SingleAttributeParser<S> for ExportNameParser {
104106
const PATH: &[rustc_span::Symbol] = &[sym::export_name];
105107
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
108+
const SAFETY: AttributeSafety = AttributeSafety::Unsafe { unsafe_since: Some(Edition2024) };
106109
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
107110
Allow(Target::Static),
108111
Allow(Target::Fn),
@@ -220,6 +223,7 @@ impl<S: Stage> AttributeParser<S> for NakedParser {
220223
this.span = Some(cx.attr_span);
221224
}
222225
})];
226+
const SAFETY: AttributeSafety = AttributeSafety::Unsafe { unsafe_since: None };
223227
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
224228
Allow(Target::Fn),
225229
Allow(Target::Method(MethodKind::Inherent)),
@@ -340,6 +344,7 @@ pub(crate) struct NoMangleParser;
340344
impl<S: Stage> NoArgsAttributeParser<S> for NoMangleParser {
341345
const PATH: &[Symbol] = &[sym::no_mangle];
342346
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
347+
const SAFETY: AttributeSafety = AttributeSafety::Unsafe { unsafe_since: Some(Edition2024) };
343348
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
344349
Allow(Target::Fn),
345350
Allow(Target::Static),
@@ -542,6 +547,7 @@ pub(crate) struct ForceTargetFeatureParser;
542547
impl<S: Stage> CombineAttributeParser<S> for ForceTargetFeatureParser {
543548
type Item = (Symbol, Span);
544549
const PATH: &[Symbol] = &[sym::force_target_feature];
550+
const SAFETY: AttributeSafety = AttributeSafety::Unsafe { unsafe_since: None };
545551
const CONVERT: ConvertFn<Self::Item> = |items, span| AttributeKind::TargetFeature {
546552
features: items,
547553
attr_span: span,

0 commit comments

Comments
 (0)