Skip to content

Commit a413f77

Browse files
committed
Auto merge of #143363 - jdonszelmann:rollup-7cv1kql, r=jdonszelmann
Rollup of 6 pull requests Successful merges: - #134006 (setup typos check in CI) - #142876 (Port `#[target_feature]` to new attribute parsing infrastructure) - #143038 (avoid suggesting traits from private dependencies) - #143083 (Fix rustdoc not correctly showing attributes on re-exports) - #143283 (document optional jobs) - #143329 (minicore: use core's `diagnostic::on_unimplemented` messages) Failed merges: - #143237 (Port `#[no_implicit_prelude]` to the new attribute parsing infrastructure) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9e64506 + f85283b commit a413f77

File tree

170 files changed

+951
-518
lines changed

Some content is hidden

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

170 files changed

+951
-518
lines changed

.github/workflows/spellcheck.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This workflow runs spellcheck job
2+
3+
name: Spellcheck
4+
on:
5+
pull_request:
6+
branches:
7+
- "**"
8+
9+
jobs:
10+
spellcheck:
11+
name: run spellchecker
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout the source code
15+
uses: actions/checkout@v4
16+
17+
- name: check typos
18+
# sync version with src/tools/tidy/src/ext_tool_checks.rs in spellcheck_runner
19+
uses: crate-ci/[email protected]
20+
with:
21+
# sync target files with src/tools/tidy/src/ext_tool_checks.rs in check_impl
22+
files: ./compiler ./library ./src/bootstrap ./src/librustdoc
23+
config: ./typos.toml

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4629,6 +4629,7 @@ dependencies = [
46294629
"itertools",
46304630
"rustc_abi",
46314631
"rustc_ast",
4632+
"rustc_attr_data_structures",
46324633
"rustc_data_structures",
46334634
"rustc_errors",
46344635
"rustc_fluent_macro",

REUSE.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ path = [
3636
"rustfmt.toml",
3737
"rust-bors.toml",
3838
"triagebot.toml",
39+
"typos.toml",
3940
"x",
4041
"x.ps1",
4142
"x.py",

compiler/rustc_ast/src/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ impl Expr {
13441344
}
13451345
}
13461346

1347-
/// Returns an expression with (when possible) *one* outter brace removed
1347+
/// Returns an expression with (when possible) *one* outer brace removed
13481348
pub fn maybe_unwrap_block(&self) -> &Expr {
13491349
if let ExprKind::Block(block, None) = &self.kind
13501350
&& let [stmt] = block.stmts.as_slice()

compiler/rustc_ast/src/visit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ macro_rules! common_visitor_and_walkers {
142142
)?
143143

144144
// Methods in this trait have one of three forms, with the last two forms
145-
// only occuring on `MutVisitor`:
145+
// only occurring on `MutVisitor`:
146146
//
147147
// fn visit_t(&mut self, t: &mut T); // common
148148
// fn flat_map_t(&mut self, t: T) -> SmallVec<[T; 1]>; // rare

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use rustc_abi::ExternAbi;
22
use rustc_ast::ptr::P;
33
use rustc_ast::visit::AssocCtxt;
44
use rustc_ast::*;
5+
use rustc_attr_data_structures::{AttributeKind, find_attr};
56
use rustc_errors::{E0570, ErrorGuaranteed, struct_span_code_err};
67
use rustc_hir::def::{DefKind, PerNS, Res};
78
use rustc_hir::def_id::{CRATE_DEF_ID, LocalDefId};
@@ -1621,7 +1622,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
16211622
let safety = self.lower_safety(h.safety, default_safety);
16221623

16231624
// Treat safe `#[target_feature]` functions as unsafe, but also remember that we did so.
1624-
let safety = if attrs.iter().any(|attr| attr.has_name(sym::target_feature))
1625+
let safety = if find_attr!(attrs, AttributeKind::TargetFeature { .. })
16251626
&& safety.is_safe()
16261627
&& !self.tcx.sess.target.is_like_wasm
16271628
{

compiler/rustc_ast_passes/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ast_passes_abi_cannot_be_coroutine =
22
functions with the {$abi} ABI cannot be `{$coroutine_kind_str}`
3-
.suggestion = remove the `{$coroutine_kind_str}` keyword from this definiton
3+
.suggestion = remove the `{$coroutine_kind_str}` keyword from this definition
44
55
ast_passes_abi_custom_safe_foreign_function =
66
foreign functions with the "custom" ABI cannot be safe

compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,10 +198,10 @@ pub enum AttributeKind {
198198
Align { align: Align, span: Span },
199199

200200
/// Represents `#[rustc_allow_const_fn_unstable]`.
201-
AllowConstFnUnstable(ThinVec<Symbol>),
201+
AllowConstFnUnstable(ThinVec<Symbol>, Span),
202202

203203
/// Represents `#[allow_internal_unstable]`.
204-
AllowInternalUnstable(ThinVec<(Symbol, Span)>),
204+
AllowInternalUnstable(ThinVec<(Symbol, Span)>, Span),
205205

206206
/// Represents `#[rustc_as_ptr]` (used by the `dangling_pointers_from_temporaries` lint).
207207
AsPtr(Span),
@@ -309,6 +309,9 @@ pub enum AttributeKind {
309309
span: Span,
310310
},
311311

312+
/// Represents `#[target_feature(enable = "...")]`
313+
TargetFeature(ThinVec<(Symbol, Span)>, Span),
314+
312315
/// Represents `#[track_caller]`
313316
TrackCaller(Span),
314317

compiler/rustc_attr_data_structures/src/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ impl AttributeKind {
4242
RustcLayoutScalarValidRangeStart(..) => Yes,
4343
RustcObjectLifetimeDefault => No,
4444
SkipDuringMethodDispatch { .. } => No,
45+
TargetFeature(..) => No,
4546
TrackCaller(..) => Yes,
4647
Used { .. } => No,
4748
}

compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ pub(crate) struct AllowInternalUnstableParser;
1313
impl<S: Stage> CombineAttributeParser<S> for AllowInternalUnstableParser {
1414
const PATH: &[Symbol] = &[sym::allow_internal_unstable];
1515
type Item = (Symbol, Span);
16-
const CONVERT: ConvertFn<Self::Item> = AttributeKind::AllowInternalUnstable;
16+
const CONVERT: ConvertFn<Self::Item> =
17+
|items, span| AttributeKind::AllowInternalUnstable(items, span);
1718
const TEMPLATE: AttributeTemplate = template!(Word, List: "feat1, feat2, ...");
1819

1920
fn extend<'c>(
@@ -30,7 +31,8 @@ pub(crate) struct AllowConstFnUnstableParser;
3031
impl<S: Stage> CombineAttributeParser<S> for AllowConstFnUnstableParser {
3132
const PATH: &[Symbol] = &[sym::rustc_allow_const_fn_unstable];
3233
type Item = Symbol;
33-
const CONVERT: ConvertFn<Self::Item> = AttributeKind::AllowConstFnUnstable;
34+
const CONVERT: ConvertFn<Self::Item> =
35+
|items, first_span| AttributeKind::AllowConstFnUnstable(items, first_span);
3436
const TEMPLATE: AttributeTemplate = template!(Word, List: "feat1, feat2, ...");
3537

3638
fn extend<'c>(

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{fluent_generated, parse_version};
1414

1515
/// Emitter of a builtin lint from `cfg_matches`.
1616
///
17-
/// Used to support emiting a lint (currently on check-cfg), either:
17+
/// Used to support emitting a lint (currently on check-cfg), either:
1818
/// - as an early buffered lint (in `rustc`)
1919
/// - or has a "normal" lint from HIR (in `rustdoc`)
2020
pub trait CfgMatchesLintEmitter {

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use rustc_session::parse::feature_err;
44
use rustc_span::{Span, Symbol, sym};
55

66
use super::{
7-
AcceptMapping, AttributeOrder, AttributeParser, NoArgsAttributeParser, OnDuplicate,
8-
SingleAttributeParser,
7+
AcceptMapping, AttributeOrder, AttributeParser, CombineAttributeParser, ConvertFn,
8+
NoArgsAttributeParser, OnDuplicate, SingleAttributeParser,
99
};
1010
use crate::context::{AcceptContext, FinalizeContext, Stage};
1111
use crate::parser::ArgParser;
@@ -280,3 +280,53 @@ impl<S: Stage> AttributeParser<S> for UsedParser {
280280
})
281281
}
282282
}
283+
284+
pub(crate) struct TargetFeatureParser;
285+
286+
impl<S: Stage> CombineAttributeParser<S> for TargetFeatureParser {
287+
type Item = (Symbol, Span);
288+
const PATH: &[Symbol] = &[sym::target_feature];
289+
const CONVERT: ConvertFn<Self::Item> = |items, span| AttributeKind::TargetFeature(items, span);
290+
const TEMPLATE: AttributeTemplate = template!(List: "enable = \"feat1, feat2\"");
291+
292+
fn extend<'c>(
293+
cx: &'c mut AcceptContext<'_, '_, S>,
294+
args: &'c ArgParser<'_>,
295+
) -> impl IntoIterator<Item = Self::Item> + 'c {
296+
let mut features = Vec::new();
297+
let ArgParser::List(list) = args else {
298+
cx.expected_list(cx.attr_span);
299+
return features;
300+
};
301+
for item in list.mixed() {
302+
let Some(name_value) = item.meta_item() else {
303+
cx.expected_name_value(item.span(), Some(sym::enable));
304+
return features;
305+
};
306+
307+
// Validate name
308+
let Some(name) = name_value.path().word_sym() else {
309+
cx.expected_name_value(name_value.path().span(), Some(sym::enable));
310+
return features;
311+
};
312+
if name != sym::enable {
313+
cx.expected_name_value(name_value.path().span(), Some(sym::enable));
314+
return features;
315+
}
316+
317+
// Use value
318+
let Some(name_value) = name_value.args().name_value() else {
319+
cx.expected_name_value(item.span(), Some(sym::enable));
320+
return features;
321+
};
322+
let Some(value_str) = name_value.value_as_str() else {
323+
cx.expected_string_literal(name_value.value_span, Some(name_value.value_as_lit()));
324+
return features;
325+
};
326+
for feature in value_str.as_str().split(",") {
327+
features.push((Symbol::intern(feature), item.span()));
328+
}
329+
}
330+
features
331+
}
332+
}

compiler/rustc_attr_parsing/src/attributes/mod.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl<T: NoArgsAttributeParser<S>, S: Stage> SingleAttributeParser<S> for Without
264264
}
265265
}
266266

267-
type ConvertFn<E> = fn(ThinVec<E>) -> AttributeKind;
267+
type ConvertFn<E> = fn(ThinVec<E>, Span) -> AttributeKind;
268268

269269
/// Alternative to [`AttributeParser`] that automatically handles state management.
270270
/// If multiple attributes appear on an element, combines the values of each into a
@@ -295,25 +295,40 @@ pub(crate) trait CombineAttributeParser<S: Stage>: 'static {
295295

296296
/// Use in combination with [`CombineAttributeParser`].
297297
/// `Combine<T: CombineAttributeParser>` implements [`AttributeParser`].
298-
pub(crate) struct Combine<T: CombineAttributeParser<S>, S: Stage>(
299-
PhantomData<(S, T)>,
300-
ThinVec<<T as CombineAttributeParser<S>>::Item>,
301-
);
298+
pub(crate) struct Combine<T: CombineAttributeParser<S>, S: Stage> {
299+
phantom: PhantomData<(S, T)>,
300+
/// A list of all items produced by parsing attributes so far. One attribute can produce any amount of items.
301+
items: ThinVec<<T as CombineAttributeParser<S>>::Item>,
302+
/// The full span of the first attribute that was encountered.
303+
first_span: Option<Span>,
304+
}
302305

303306
impl<T: CombineAttributeParser<S>, S: Stage> Default for Combine<T, S> {
304307
fn default() -> Self {
305-
Self(Default::default(), Default::default())
308+
Self {
309+
phantom: Default::default(),
310+
items: Default::default(),
311+
first_span: Default::default(),
312+
}
306313
}
307314
}
308315

309316
impl<T: CombineAttributeParser<S>, S: Stage> AttributeParser<S> for Combine<T, S> {
310317
const ATTRIBUTES: AcceptMapping<Self, S> = &[(
311318
T::PATH,
312319
<T as CombineAttributeParser<S>>::TEMPLATE,
313-
|group: &mut Combine<T, S>, cx, args| group.1.extend(T::extend(cx, args)),
320+
|group: &mut Combine<T, S>, cx, args| {
321+
// Keep track of the span of the first attribute, for diagnostics
322+
group.first_span.get_or_insert(cx.attr_span);
323+
group.items.extend(T::extend(cx, args))
324+
},
314325
)];
315326

316327
fn finalize(self, _cx: &FinalizeContext<'_, '_, S>) -> Option<AttributeKind> {
317-
if self.1.is_empty() { None } else { Some(T::CONVERT(self.1)) }
328+
if let Some(first_span) = self.first_span {
329+
Some(T::CONVERT(self.items, first_span))
330+
} else {
331+
None
332+
}
318333
}
319334
}

compiler/rustc_attr_parsing/src/attributes/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(crate) struct ReprParser;
2323
impl<S: Stage> CombineAttributeParser<S> for ReprParser {
2424
type Item = (ReprAttr, Span);
2525
const PATH: &[Symbol] = &[sym::repr];
26-
const CONVERT: ConvertFn<Self::Item> = AttributeKind::Repr;
26+
const CONVERT: ConvertFn<Self::Item> = |items, _| AttributeKind::Repr(items);
2727
// FIXME(jdonszelmann): never used
2828
const TEMPLATE: AttributeTemplate =
2929
template!(List: "C | Rust | align(...) | packed(...) | <integer type> | transparent");

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
1616

1717
use crate::attributes::allow_unstable::{AllowConstFnUnstableParser, AllowInternalUnstableParser};
1818
use crate::attributes::codegen_attrs::{
19-
ColdParser, ExportNameParser, NakedParser, NoMangleParser, OptimizeParser, TrackCallerParser,
20-
UsedParser,
19+
ColdParser, ExportNameParser, NakedParser, NoMangleParser, OptimizeParser, TargetFeatureParser,
20+
TrackCallerParser, UsedParser,
2121
};
2222
use crate::attributes::confusables::ConfusablesParser;
2323
use crate::attributes::deprecation::DeprecationParser;
@@ -118,6 +118,7 @@ attribute_parsers!(
118118
Combine<AllowConstFnUnstableParser>,
119119
Combine<AllowInternalUnstableParser>,
120120
Combine<ReprParser>,
121+
Combine<TargetFeatureParser>,
121122
// tidy-alphabetical-end
122123

123124
// tidy-alphabetical-start
@@ -189,7 +190,7 @@ impl Stage for Late {
189190
}
190191
}
191192

192-
/// used when parsing attributes for miscelaneous things *before* ast lowering
193+
/// used when parsing attributes for miscellaneous things *before* ast lowering
193194
pub struct Early;
194195
/// used when parsing attributes during ast lowering
195196
pub struct Late;

compiler/rustc_builtin_macros/src/autodiff.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ mod llvm_enzyme {
562562
/// so instead we manually build something that should pass the type checker.
563563
/// We also add a inline_asm line, as one more barrier for rustc to prevent inlining
564564
/// or const propagation. inline_asm will also triggers an Enzyme crash if due to another
565-
/// bug would ever try to accidentially differentiate this placeholder function body.
565+
/// bug would ever try to accidentally differentiate this placeholder function body.
566566
/// Finally, we also add back_box usages of all input arguments, to prevent rustc
567567
/// from optimizing any arguments away.
568568
fn gen_enzyme_body(
@@ -606,7 +606,7 @@ mod llvm_enzyme {
606606
return body;
607607
}
608608

609-
// Everything from here onwards just tries to fullfil the return type. Fun!
609+
// Everything from here onwards just tries to fulfil the return type. Fun!
610610

611611
// having an active-only return means we'll drop the original return type.
612612
// So that can be treated identical to not having one in the first place.

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ fn call_simple_intrinsic<'ll, 'tcx>(
107107
sym::minimumf32 => ("llvm.minimum", &[bx.type_f32()]),
108108
sym::minimumf64 => ("llvm.minimum", &[bx.type_f64()]),
109109
// There are issues on x86_64 and aarch64 with the f128 variant,
110-
// let's instead use the instrinsic fallback body.
110+
// let's instead use the intrinsic fallback body.
111111
// sym::minimumf128 => ("llvm.minimum", &[cx.type_f128()]),
112112
sym::maxnumf16 => ("llvm.maxnum", &[bx.type_f16()]),
113113
sym::maxnumf32 => ("llvm.maxnum", &[bx.type_f32()]),
@@ -118,7 +118,7 @@ fn call_simple_intrinsic<'ll, 'tcx>(
118118
sym::maximumf32 => ("llvm.maximum", &[bx.type_f32()]),
119119
sym::maximumf64 => ("llvm.maximum", &[bx.type_f64()]),
120120
// There are issues on x86_64 and aarch64 with the f128 variant,
121-
// let's instead use the instrinsic fallback body.
121+
// let's instead use the intrinsic fallback body.
122122
// sym::maximumf128 => ("llvm.maximum", &[cx.type_f128()]),
123123
sym::copysignf16 => ("llvm.copysign", &[bx.type_f16()]),
124124
sym::copysignf32 => ("llvm.copysign", &[bx.type_f32()]),

compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ unsafe extern "C" {
4040
pub(crate) fn LLVMDumpValue(V: &Value);
4141
pub(crate) fn LLVMGetFunctionCallConv(F: &Value) -> c_uint;
4242
pub(crate) fn LLVMGetReturnType(T: &Type) -> &Type;
43-
pub(crate) fn LLVMGetParams(Fnc: &Value, parms: *mut &Value);
43+
pub(crate) fn LLVMGetParams(Fnc: &Value, params: *mut &Value);
4444
pub(crate) fn LLVMGetNamedFunction(M: &Module, Name: *const c_char) -> Option<&Value>;
4545
}
4646

compiler/rustc_codegen_llvm/src/va_arg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ fn emit_xtensa_va_arg<'ll, 'tcx>(
861861

862862
// On big-endian, for values smaller than the slot size we'd have to align the read to the end
863863
// of the slot rather than the start. While the ISA and GCC support big-endian, all the Xtensa
864-
// targets supported by rustc are litte-endian so don't worry about it.
864+
// targets supported by rustc are little-endian so don't worry about it.
865865

866866
// if from_regsave {
867867
// unsafe { *regsave_value_ptr }

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ codegen_ssa_failed_to_get_layout = failed to get layout for {$ty}: {$err}
6262
6363
codegen_ssa_failed_to_write = failed to write {$path}: {$error}
6464
65+
codegen_ssa_feature_not_valid = the feature named `{$feature}` is not valid for this target
66+
.label = `{$feature}` is not valid for this target
67+
.help = consider removing the leading `+` in the feature name
68+
6569
codegen_ssa_field_associated_value_expected = associated value expected for `{$name}`
6670
6771
codegen_ssa_forbidden_ctarget_feature =
@@ -289,7 +293,7 @@ codegen_ssa_thorin_missing_referenced_unit = unit {$unit} referenced by executab
289293
290294
codegen_ssa_thorin_missing_required_section = input object missing required section `{$section}`
291295
292-
codegen_ssa_thorin_mixed_input_encodings = input objects haved mixed encodings
296+
codegen_ssa_thorin_mixed_input_encodings = input objects have mixed encodings
293297
294298
codegen_ssa_thorin_multiple_debug_info_section = multiple `.debug_info.dwo` sections
295299

0 commit comments

Comments
 (0)