Skip to content

Commit e7978bd

Browse files
committed
Auto merge of #145764 - jhpratt:rollup-uzej5kg, r=jhpratt
Rollup of 20 pull requests Successful merges: - #132087 (Fix overly restrictive lifetime in `core::panic::Location::file` return type) - #137396 (Recover `param: Ty = EXPR`) - #142185 (Convert moves of references to copies in ReferencePropagation) - #144443 (Make target pointer width in target json an integer) - #144648 (Implementation: `#[feature(nonpoison_rwlock)]`) - #144897 (print raw lifetime idents with r#) - #145218 ([Debuginfo] improve enum value formatting in LLDB for better readability) - #145380 (Add codegen-llvm regression tests) - #145573 (Add an experimental unsafe(force_target_feature) attribute.) - #145597 (resolve: Remove `ScopeSet::Late`) - #145641 (On E0277, point at type that doesn't implement bound) - #145669 (rustdoc-search: GUI tests check for `//` in URL) - #145695 (Introduce ProjectionElem::try_map.) - #145710 (Fix the ABI parameter inconsistency issue in debug.rs for LoongArch64) - #145726 (Experiment: Reborrow trait) - #145731 (Make raw pointers work in type-based search) - #145736 (triagebot: Update style team reviewers) - #145738 (Uplift rustc_mir_transform::coverage::counters::union_find to rustc_data_structures.) - #145743 (doc: fix some typos in comment) - #145745 (tests: Ignore basic-stepping.rs on LoongArch) Failed merges: - #145670 (port `sanitize` attribute to the new parsing infrastructure) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 6545b05 + 555ef1c commit e7978bd

File tree

272 files changed

+5577
-1516
lines changed

Some content is hidden

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

272 files changed

+5577
-1516
lines changed

compiler/rustc_abi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ pub enum TargetDataLayoutErrors<'a> {
315315
MissingAlignment { cause: &'a str },
316316
InvalidAlignment { cause: &'a str, err: AlignFromBytesError },
317317
InconsistentTargetArchitecture { dl: &'a str, target: &'a str },
318-
InconsistentTargetPointerWidth { pointer_size: u64, target: u32 },
318+
InconsistentTargetPointerWidth { pointer_size: u64, target: u16 },
319319
InvalidBitsSize { err: String },
320320
UnknownPointerSpecification { err: String },
321321
}

compiler/rustc_ast/src/token.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub use NtPatKind::*;
77
pub use TokenKind::*;
88
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
99
use rustc_span::edition::Edition;
10+
use rustc_span::symbol::IdentPrintMode;
1011
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, kw, sym};
1112
#[allow(clippy::useless_attribute)] // FIXME: following use of `hidden_glob_reexports` incorrectly triggers `useless_attribute` lint.
1213
#[allow(hidden_glob_reexports)]
@@ -344,15 +345,24 @@ pub enum IdentIsRaw {
344345
Yes,
345346
}
346347

347-
impl From<bool> for IdentIsRaw {
348-
fn from(b: bool) -> Self {
349-
if b { Self::Yes } else { Self::No }
348+
impl IdentIsRaw {
349+
pub fn to_print_mode_ident(self) -> IdentPrintMode {
350+
match self {
351+
IdentIsRaw::No => IdentPrintMode::Normal,
352+
IdentIsRaw::Yes => IdentPrintMode::RawIdent,
353+
}
354+
}
355+
pub fn to_print_mode_lifetime(self) -> IdentPrintMode {
356+
match self {
357+
IdentIsRaw::No => IdentPrintMode::Normal,
358+
IdentIsRaw::Yes => IdentPrintMode::RawLifetime,
359+
}
350360
}
351361
}
352362

353-
impl From<IdentIsRaw> for bool {
354-
fn from(is_raw: IdentIsRaw) -> bool {
355-
matches!(is_raw, IdentIsRaw::Yes)
363+
impl From<bool> for IdentIsRaw {
364+
fn from(b: bool) -> Self {
365+
if b { Self::Yes } else { Self::No }
356366
}
357367
}
358368

compiler/rustc_ast_ir/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl IntTy {
6969
})
7070
}
7171

72-
pub fn normalize(&self, target_width: u32) -> Self {
72+
pub fn normalize(&self, target_width: u16) -> Self {
7373
match self {
7474
IntTy::Isize => match target_width {
7575
16 => IntTy::I16,
@@ -148,7 +148,7 @@ impl UintTy {
148148
})
149149
}
150150

151-
pub fn normalize(&self, target_width: u32) -> Self {
151+
pub fn normalize(&self, target_width: u16) -> Self {
152152
match self {
153153
UintTy::Usize => match target_width {
154154
16 => UintTy::U16,

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
15961596
let safety = self.lower_safety(h.safety, default_safety);
15971597

15981598
// Treat safe `#[target_feature]` functions as unsafe, but also remember that we did so.
1599-
let safety = if find_attr!(attrs, AttributeKind::TargetFeature { .. })
1599+
let safety = if find_attr!(attrs, AttributeKind::TargetFeature { was_forced: false, .. })
16001600
&& safety.is_safe()
16011601
&& !self.tcx.sess.target.is_like_wasm
16021602
{

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::borrow::Cow;
1010
use std::sync::Arc;
1111

1212
use rustc_ast::attr::AttrIdGenerator;
13-
use rustc_ast::token::{self, CommentKind, Delimiter, IdentIsRaw, Token, TokenKind};
13+
use rustc_ast::token::{self, CommentKind, Delimiter, Token, TokenKind};
1414
use rustc_ast::tokenstream::{Spacing, TokenStream, TokenTree};
1515
use rustc_ast::util::classify;
1616
use rustc_ast::util::comments::{Comment, CommentStyle};
@@ -441,7 +441,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
441441
fn print_generic_args(&mut self, args: &ast::GenericArgs, colons_before_params: bool);
442442

443443
fn print_ident(&mut self, ident: Ident) {
444-
self.word(IdentPrinter::for_ast_ident(ident, ident.is_raw_guess()).to_string());
444+
self.word(IdentPrinter::for_ast_ident(ident, ident.guess_print_mode()).to_string());
445445
self.ann_post(ident)
446446
}
447447

@@ -1015,17 +1015,16 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
10151015

10161016
/* Name components */
10171017
token::Ident(name, is_raw) => {
1018-
IdentPrinter::new(name, is_raw.into(), convert_dollar_crate).to_string().into()
1018+
IdentPrinter::new(name, is_raw.to_print_mode_ident(), convert_dollar_crate)
1019+
.to_string()
1020+
.into()
10191021
}
10201022
token::NtIdent(ident, is_raw) => {
1021-
IdentPrinter::for_ast_ident(ident, is_raw.into()).to_string().into()
1023+
IdentPrinter::for_ast_ident(ident, is_raw.to_print_mode_ident()).to_string().into()
10221024
}
10231025

1024-
token::Lifetime(name, IdentIsRaw::No)
1025-
| token::NtLifetime(Ident { name, .. }, IdentIsRaw::No) => name.to_string().into(),
1026-
token::Lifetime(name, IdentIsRaw::Yes)
1027-
| token::NtLifetime(Ident { name, .. }, IdentIsRaw::Yes) => {
1028-
format!("'r#{}", &name.as_str()[1..]).into()
1026+
token::Lifetime(name, is_raw) | token::NtLifetime(Ident { name, .. }, is_raw) => {
1027+
IdentPrinter::new(name, is_raw.to_print_mode_lifetime(), None).to_string().into()
10291028
}
10301029

10311030
/* Other */

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 78 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -376,57 +376,68 @@ impl<S: Stage> AttributeParser<S> for UsedParser {
376376
}
377377
}
378378

379+
fn parse_tf_attribute<'c, S: Stage>(
380+
cx: &'c mut AcceptContext<'_, '_, S>,
381+
args: &'c ArgParser<'_>,
382+
) -> impl IntoIterator<Item = (Symbol, Span)> + 'c {
383+
let mut features = Vec::new();
384+
let ArgParser::List(list) = args else {
385+
cx.expected_list(cx.attr_span);
386+
return features;
387+
};
388+
if list.is_empty() {
389+
cx.warn_empty_attribute(cx.attr_span);
390+
return features;
391+
}
392+
for item in list.mixed() {
393+
let Some(name_value) = item.meta_item() else {
394+
cx.expected_name_value(item.span(), Some(sym::enable));
395+
return features;
396+
};
397+
398+
// Validate name
399+
let Some(name) = name_value.path().word_sym() else {
400+
cx.expected_name_value(name_value.path().span(), Some(sym::enable));
401+
return features;
402+
};
403+
if name != sym::enable {
404+
cx.expected_name_value(name_value.path().span(), Some(sym::enable));
405+
return features;
406+
}
407+
408+
// Use value
409+
let Some(name_value) = name_value.args().name_value() else {
410+
cx.expected_name_value(item.span(), Some(sym::enable));
411+
return features;
412+
};
413+
let Some(value_str) = name_value.value_as_str() else {
414+
cx.expected_string_literal(name_value.value_span, Some(name_value.value_as_lit()));
415+
return features;
416+
};
417+
for feature in value_str.as_str().split(",") {
418+
features.push((Symbol::intern(feature), item.span()));
419+
}
420+
}
421+
features
422+
}
423+
379424
pub(crate) struct TargetFeatureParser;
380425

381426
impl<S: Stage> CombineAttributeParser<S> for TargetFeatureParser {
382427
type Item = (Symbol, Span);
383428
const PATH: &[Symbol] = &[sym::target_feature];
384-
const CONVERT: ConvertFn<Self::Item> = |items, span| AttributeKind::TargetFeature(items, span);
429+
const CONVERT: ConvertFn<Self::Item> = |items, span| AttributeKind::TargetFeature {
430+
features: items,
431+
attr_span: span,
432+
was_forced: false,
433+
};
385434
const TEMPLATE: AttributeTemplate = template!(List: &["enable = \"feat1, feat2\""]);
386435

387436
fn extend<'c>(
388437
cx: &'c mut AcceptContext<'_, '_, S>,
389438
args: &'c ArgParser<'_>,
390439
) -> impl IntoIterator<Item = Self::Item> + 'c {
391-
let mut features = Vec::new();
392-
let ArgParser::List(list) = args else {
393-
cx.expected_list(cx.attr_span);
394-
return features;
395-
};
396-
if list.is_empty() {
397-
cx.warn_empty_attribute(cx.attr_span);
398-
return features;
399-
}
400-
for item in list.mixed() {
401-
let Some(name_value) = item.meta_item() else {
402-
cx.expected_name_value(item.span(), Some(sym::enable));
403-
return features;
404-
};
405-
406-
// Validate name
407-
let Some(name) = name_value.path().word_sym() else {
408-
cx.expected_name_value(name_value.path().span(), Some(sym::enable));
409-
return features;
410-
};
411-
if name != sym::enable {
412-
cx.expected_name_value(name_value.path().span(), Some(sym::enable));
413-
return features;
414-
}
415-
416-
// Use value
417-
let Some(name_value) = name_value.args().name_value() else {
418-
cx.expected_name_value(item.span(), Some(sym::enable));
419-
return features;
420-
};
421-
let Some(value_str) = name_value.value_as_str() else {
422-
cx.expected_string_literal(name_value.value_span, Some(name_value.value_as_lit()));
423-
return features;
424-
};
425-
for feature in value_str.as_str().split(",") {
426-
features.push((Symbol::intern(feature), item.span()));
427-
}
428-
}
429-
features
440+
parse_tf_attribute(cx, args)
430441
}
431442

432443
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
@@ -440,3 +451,30 @@ impl<S: Stage> CombineAttributeParser<S> for TargetFeatureParser {
440451
Warn(Target::MacroDef),
441452
]);
442453
}
454+
455+
pub(crate) struct ForceTargetFeatureParser;
456+
457+
impl<S: Stage> CombineAttributeParser<S> for ForceTargetFeatureParser {
458+
type Item = (Symbol, Span);
459+
const PATH: &[Symbol] = &[sym::force_target_feature];
460+
const CONVERT: ConvertFn<Self::Item> = |items, span| AttributeKind::TargetFeature {
461+
features: items,
462+
attr_span: span,
463+
was_forced: true,
464+
};
465+
const TEMPLATE: AttributeTemplate = template!(List: &["enable = \"feat1, feat2\""]);
466+
467+
fn extend<'c>(
468+
cx: &'c mut AcceptContext<'_, '_, S>,
469+
args: &'c ArgParser<'_>,
470+
) -> impl IntoIterator<Item = Self::Item> + 'c {
471+
parse_tf_attribute(cx, args)
472+
}
473+
474+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
475+
Allow(Target::Fn),
476+
Allow(Target::Method(MethodKind::Inherent)),
477+
Allow(Target::Method(MethodKind::Trait { body: true })),
478+
Allow(Target::Method(MethodKind::TraitImpl)),
479+
]);
480+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ use crate::attributes::allow_unstable::{
1919
};
2020
use crate::attributes::body::CoroutineParser;
2121
use crate::attributes::codegen_attrs::{
22-
ColdParser, CoverageParser, ExportNameParser, NakedParser, NoMangleParser, OptimizeParser,
23-
TargetFeatureParser, TrackCallerParser, UsedParser,
22+
ColdParser, CoverageParser, ExportNameParser, ForceTargetFeatureParser, NakedParser,
23+
NoMangleParser, OptimizeParser, TargetFeatureParser, TrackCallerParser, UsedParser,
2424
};
2525
use crate::attributes::confusables::ConfusablesParser;
2626
use crate::attributes::deprecation::DeprecationParser;
@@ -157,6 +157,7 @@ attribute_parsers!(
157157
// tidy-alphabetical-start
158158
Combine<AllowConstFnUnstableParser>,
159159
Combine<AllowInternalUnstableParser>,
160+
Combine<ForceTargetFeatureParser>,
160161
Combine<ReprParser>,
161162
Combine<TargetFeatureParser>,
162163
Combine<UnstableFeatureBoundParser>,

compiler/rustc_codegen_gcc/target_specs/m68k-unknown-linux-gnu.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
"unix"
2323
],
2424
"target-mcount": "_mcount",
25-
"target-pointer-width": "32"
25+
"target-pointer-width": 32
2626
}

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,15 @@ fn process_builtin_attrs(
193193
}
194194
}
195195
AttributeKind::Optimize(optimize, _) => codegen_fn_attrs.optimize = *optimize,
196-
AttributeKind::TargetFeature(features, attr_span) => {
196+
AttributeKind::TargetFeature { features, attr_span, was_forced } => {
197197
let Some(sig) = tcx.hir_node_by_def_id(did).fn_sig() else {
198198
tcx.dcx().span_delayed_bug(*attr_span, "target_feature applied to non-fn");
199199
continue;
200200
};
201201
let safe_target_features =
202202
matches!(sig.header.safety, hir::HeaderSafety::SafeTargetFeatures);
203203
codegen_fn_attrs.safe_target_features = safe_target_features;
204-
if safe_target_features {
204+
if safe_target_features && !was_forced {
205205
if tcx.sess.target.is_like_wasm || tcx.sess.opts.actually_rustdoc {
206206
// The `#[target_feature]` attribute is allowed on
207207
// WebAssembly targets on all functions. Prior to stabilizing
@@ -232,6 +232,7 @@ fn process_builtin_attrs(
232232
tcx,
233233
did,
234234
features,
235+
*was_forced,
235236
rust_target_features,
236237
&mut codegen_fn_attrs.target_features,
237238
);
@@ -462,7 +463,7 @@ fn check_result(
462463
.collect(),
463464
) {
464465
let span =
465-
find_attr!(tcx.get_all_attrs(did), AttributeKind::TargetFeature(_, span) => *span)
466+
find_attr!(tcx.get_all_attrs(did), AttributeKind::TargetFeature{attr_span: span, ..} => *span)
466467
.unwrap_or_else(|| tcx.def_span(did));
467468

468469
tcx.dcx()

compiler/rustc_codegen_ssa/src/target_features.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_data_structures::unord::{UnordMap, UnordSet};
33
use rustc_hir::attrs::InstructionSetAttr;
44
use rustc_hir::def::DefKind;
55
use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId};
6-
use rustc_middle::middle::codegen_fn_attrs::TargetFeature;
6+
use rustc_middle::middle::codegen_fn_attrs::{TargetFeature, TargetFeatureKind};
77
use rustc_middle::query::Providers;
88
use rustc_middle::ty::TyCtxt;
99
use rustc_session::Session;
@@ -22,6 +22,7 @@ pub(crate) fn from_target_feature_attr(
2222
tcx: TyCtxt<'_>,
2323
did: LocalDefId,
2424
features: &[(Symbol, Span)],
25+
was_forced: bool,
2526
rust_target_features: &UnordMap<String, target_features::Stability>,
2627
target_features: &mut Vec<TargetFeature>,
2728
) {
@@ -88,7 +89,14 @@ pub(crate) fn from_target_feature_attr(
8889
}
8990
}
9091
}
91-
target_features.push(TargetFeature { name, implied: name != feature })
92+
let kind = if name != feature {
93+
TargetFeatureKind::Implied
94+
} else if was_forced {
95+
TargetFeatureKind::Forced
96+
} else {
97+
TargetFeatureKind::Enabled
98+
};
99+
target_features.push(TargetFeature { name, kind })
92100
}
93101
}
94102
}

0 commit comments

Comments
 (0)