Skip to content

Commit 8df154b

Browse files
committed
Auto merge of #145773 - jhpratt:rollup-kocqnzv, r=jhpratt
Rollup of 28 pull requests Successful merges: - #132087 (Fix overly restrictive lifetime in `core::panic::Location::file` return type) - #137396 (Recover `param: Ty = EXPR`) - #137457 (Fix host code appearing in Wasm binaries) - #142185 (Convert moves of references to copies in ReferencePropagation) - #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`) - #145633 (Fix some typos in LocalKey documentation) - #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.) - #145742 (rustdoc js: Even more typechecking improvments ) - #145743 (doc: fix some typos in comment) - #145745 (tests: Ignore basic-stepping.rs on LoongArch) - #145747 (Refactor lint buffering to avoid requiring a giant enum) - #145751 (fix(lexer): Allow '-' in the frontmatter infostring continue set) - #145761 (Add aarch64_be-unknown-hermit target) - #145762 (convert strings to symbols in attr diagnostics) - #145763 (Ship LLVM tools for the correct target when cross-compiling) - #145765 (Revert suggestions for missing methods in tuples) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 78b89eb + 418bbb2 commit 8df154b

File tree

315 files changed

+6170
-2092
lines changed

Some content is hidden

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

315 files changed

+6170
-2092
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3797,6 +3797,7 @@ dependencies = [
37973797
"annotate-snippets 0.11.5",
37983798
"derive_setters",
37993799
"rustc_abi",
3800+
"rustc_ast",
38003801
"rustc_data_structures",
38013802
"rustc_error_codes",
38023803
"rustc_error_messages",
@@ -4134,7 +4135,6 @@ dependencies = [
41344135
name = "rustc_lint_defs"
41354136
version = "0.0.0"
41364137
dependencies = [
4137-
"rustc_abi",
41384138
"rustc_ast",
41394139
"rustc_data_structures",
41404140
"rustc_error_messages",

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_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_passes/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ ast_passes_extern_without_abi = `extern` declarations without an explicit ABI ar
113113
.suggestion = specify an ABI
114114
.help = prior to Rust 2024, a default ABI was inferred
115115
116+
ast_passes_extern_without_abi_sugg = `extern` declarations without an explicit ABI are deprecated
117+
.label = ABI should be specified here
118+
.suggestion = explicitly specify the {$default_abi} ABI
119+
116120
ast_passes_feature_on_non_nightly = `#![feature]` may not be used on the {$channel} release channel
117121
.suggestion = remove the attribute
118122
.stable_since = the feature `{$name}` has been stable since `{$since}` and no longer requires an attribute to enable

compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ use rustc_ast::*;
2727
use rustc_ast_pretty::pprust::{self, State};
2828
use rustc_attr_parsing::validate_attr;
2929
use rustc_data_structures::fx::FxIndexMap;
30-
use rustc_errors::DiagCtxtHandle;
30+
use rustc_errors::{DiagCtxtHandle, LintBuffer};
3131
use rustc_feature::Features;
3232
use rustc_session::Session;
33+
use rustc_session::lint::BuiltinLintDiag;
3334
use rustc_session::lint::builtin::{
3435
DEPRECATED_WHERE_CLAUSE_LOCATION, MISSING_ABI, MISSING_UNSAFE_ON_EXTERN,
3536
PATTERNS_IN_FNS_WITHOUT_BODY,
3637
};
37-
use rustc_session::lint::{BuiltinLintDiag, LintBuffer};
3838
use rustc_span::{Ident, Span, kw, sym};
3939
use rustc_target::spec::{AbiMap, AbiMapping};
4040
use thin_vec::thin_vec;
@@ -876,7 +876,7 @@ impl<'a> AstValidator<'a> {
876876
MISSING_ABI,
877877
id,
878878
span,
879-
BuiltinLintDiag::MissingAbi(span, ExternAbi::FALLBACK),
879+
errors::MissingAbiSugg { span, default_abi: ExternAbi::FALLBACK },
880880
)
881881
}
882882
}

compiler/rustc_ast_passes/src/errors.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_abi::ExternAbi;
44
use rustc_ast::ParamKindOrd;
55
use rustc_errors::codes::*;
66
use rustc_errors::{Applicability, Diag, EmissionGuarantee, Subdiagnostic};
7-
use rustc_macros::{Diagnostic, Subdiagnostic};
7+
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
88
use rustc_span::{Ident, Span, Symbol};
99

1010
use crate::fluent_generated as fluent;
@@ -815,6 +815,14 @@ pub(crate) struct MissingAbi {
815815
pub span: Span,
816816
}
817817

818+
#[derive(LintDiagnostic)]
819+
#[diag(ast_passes_extern_without_abi_sugg)]
820+
pub(crate) struct MissingAbiSugg {
821+
#[suggestion(code = "extern {default_abi}", applicability = "machine-applicable")]
822+
pub span: Span,
823+
pub default_abi: ExternAbi,
824+
}
825+
818826
#[derive(Diagnostic)]
819827
#[diag(ast_passes_abi_custom_safe_foreign_function)]
820828
pub(crate) struct AbiCustomSafeForeignFunction {

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: 83 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl<S: Stage> SingleAttributeParser<S> for OptimizeParser {
3535
Some(sym::speed) => OptimizeAttr::Speed,
3636
Some(sym::none) => OptimizeAttr::DoNotOptimize,
3737
_ => {
38-
cx.expected_specific_argument(single.span(), vec!["size", "speed", "none"]);
38+
cx.expected_specific_argument(single.span(), &[sym::size, sym::speed, sym::none]);
3939
OptimizeAttr::Default
4040
}
4141
};
@@ -82,7 +82,7 @@ impl<S: Stage> SingleAttributeParser<S> for CoverageParser {
8282

8383
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
8484
let Some(args) = args.list() else {
85-
cx.expected_specific_argument_and_list(cx.attr_span, vec!["on", "off"]);
85+
cx.expected_specific_argument_and_list(cx.attr_span, &[sym::on, sym::off]);
8686
return None;
8787
};
8888

@@ -91,7 +91,8 @@ impl<S: Stage> SingleAttributeParser<S> for CoverageParser {
9191
return None;
9292
};
9393

94-
let fail_incorrect_argument = |span| cx.expected_specific_argument(span, vec!["on", "off"]);
94+
let fail_incorrect_argument =
95+
|span| cx.expected_specific_argument(span, &[sym::on, sym::off]);
9596

9697
let Some(arg) = arg.meta_item() else {
9798
fail_incorrect_argument(args.span);
@@ -343,7 +344,7 @@ impl<S: Stage> AttributeParser<S> for UsedParser {
343344
UsedBy::Linker
344345
}
345346
_ => {
346-
cx.expected_specific_argument(l.span(), vec!["compiler", "linker"]);
347+
cx.expected_specific_argument(l.span(), &[sym::compiler, sym::linker]);
347348
return;
348349
}
349350
}
@@ -376,57 +377,68 @@ impl<S: Stage> AttributeParser<S> for UsedParser {
376377
}
377378
}
378379

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

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

387437
fn extend<'c>(
388438
cx: &'c mut AcceptContext<'_, '_, S>,
389439
args: &'c ArgParser<'_>,
390440
) -> 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
441+
parse_tf_attribute(cx, args)
430442
}
431443

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

compiler/rustc_attr_parsing/src/attributes/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<S: Stage> SingleAttributeParser<S> for InlineParser {
4949
Some(AttributeKind::Inline(InlineAttr::Never, cx.attr_span))
5050
}
5151
_ => {
52-
cx.expected_specific_argument(l.span(), vec!["always", "never"]);
52+
cx.expected_specific_argument(l.span(), &[sym::always, sym::never]);
5353
return None;
5454
}
5555
}

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,16 @@ impl<S: Stage> SingleAttributeParser<S> for LinkageParser {
206206
_ => {
207207
cx.expected_specific_argument(
208208
name_value.value_span,
209-
vec![
210-
"available_externally",
211-
"common",
212-
"extern_weak",
213-
"external",
214-
"internal",
215-
"linkonce",
216-
"linkonce_odr",
217-
"weak",
218-
"weak_odr",
209+
&[
210+
sym::available_externally,
211+
sym::common,
212+
sym::extern_weak,
213+
sym::external,
214+
sym::internal,
215+
sym::linkonce,
216+
sym::linkonce_odr,
217+
sym::weak,
218+
sym::weak_odr,
219219
],
220220
);
221221
return None;

0 commit comments

Comments
 (0)