Skip to content

Commit d12e1e1

Browse files
committed
Auto merge of #155542 - JonathanBrouwer:rollup-F7GZlGr, r=JonathanBrouwer
Rollup of 10 pull requests Successful merges: - #155054 (constify `Index(Mut)`, `Deref(Mut)` for `Vec`) - #155264 (Add autocast support for `x86amx`) - #155507 (suggest expect instead of unwrap when arg provided) - #154664 (core/num: Implement feature `integer_cast_extras`) - #155238 (compiletest: add a new diff for compare-out-by-lines tests.) - #155474 (Rename incremental `cfail`/`cpass` revisions to `bfail`/`bpass`) - #155493 (docs(num): fix stale link to `mem::Alignment`) - #155529 (Remove `AttributeLintKind` variants - part 3) - #155531 (Tweak `is_ascii_punctuation()` docs wording) - #155533 (Provide a const new for `GlobalCache`)
2 parents e22c616 + d00c047 commit d12e1e1

124 files changed

Lines changed: 3618 additions & 3265 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_attr_parsing/src/attributes/doc.rs

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use rustc_ast::ast::{AttrStyle, LitKind, MetaItemLit};
2-
use rustc_errors::{Diagnostic, msg};
2+
use rustc_errors::{Applicability, Diagnostic, msg};
33
use rustc_feature::template;
44
use rustc_hir::Target;
55
use rustc_hir::attrs::{
@@ -13,7 +13,10 @@ use thin_vec::ThinVec;
1313
use super::prelude::{ALL_TARGETS, AllowedTargets};
1414
use super::{AcceptMapping, AttributeParser};
1515
use crate::context::{AcceptContext, FinalizeContext, Stage};
16-
use crate::errors::{DocAliasDuplicated, DocAutoCfgExpectsHideOrShow, IllFormedAttributeInput};
16+
use crate::errors::{
17+
DocAliasDuplicated, DocAutoCfgExpectsHideOrShow, DocAutoCfgHideShowExpectsList,
18+
DocAutoCfgHideShowUnexpectedItem, DocUnknownInclude, IllFormedAttributeInput,
19+
};
1720
use crate::parser::{ArgParser, MetaItemOrLitParser, MetaItemParser, OwnedPathParser};
1821
use crate::session_diagnostics::{
1922
DocAliasBadChar, DocAliasEmpty, DocAliasMalformed, DocAliasStartEnd, DocAttrNotCrateLevel,
@@ -364,9 +367,11 @@ impl DocParser {
364367
}
365368
};
366369
let ArgParser::List(list) = item.args() else {
367-
cx.emit_lint(
370+
cx.emit_dyn_lint(
368371
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
369-
AttributeLintKind::DocAutoCfgHideShowExpectsList { attr_name },
372+
move |dcx, level| {
373+
DocAutoCfgHideShowExpectsList { attr_name }.into_diag(dcx, level)
374+
},
370375
item.span(),
371376
);
372377
continue;
@@ -376,9 +381,12 @@ impl DocParser {
376381

377382
for item in list.mixed() {
378383
let MetaItemOrLitParser::MetaItemParser(sub_item) = item else {
379-
cx.emit_lint(
384+
cx.emit_dyn_lint(
380385
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
381-
AttributeLintKind::DocAutoCfgHideShowUnexpectedItem { attr_name },
386+
move |dcx, level| {
387+
DocAutoCfgHideShowUnexpectedItem { attr_name }
388+
.into_diag(dcx, level)
389+
},
382390
item.span(),
383391
);
384392
continue;
@@ -416,10 +424,11 @@ impl DocParser {
416424
}
417425
}
418426
_ => {
419-
cx.emit_lint(
427+
cx.emit_dyn_lint(
420428
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
421-
AttributeLintKind::DocAutoCfgHideShowUnexpectedItem {
422-
attr_name,
429+
move |dcx, level| {
430+
DocAutoCfgHideShowUnexpectedItem { attr_name }
431+
.into_diag(dcx, level)
423432
},
424433
sub_item.span(),
425434
);
@@ -615,14 +624,19 @@ impl DocParser {
615624
AttrStyle::Outer => "",
616625
AttrStyle::Inner => "!",
617626
};
618-
cx.emit_lint(
627+
let value = nv.value_as_lit().symbol;
628+
let span = path.span();
629+
cx.emit_dyn_lint(
619630
rustc_session::lint::builtin::INVALID_DOC_ATTRIBUTES,
620-
AttributeLintKind::DocUnknownInclude {
621-
inner,
622-
value: nv.value_as_lit().symbol,
623-
span: path.span(),
631+
move |dcx, level| {
632+
DocUnknownInclude {
633+
inner,
634+
value,
635+
sugg: (span, Applicability::MaybeIncorrect),
636+
}
637+
.into_diag(dcx, level)
624638
},
625-
path.span(),
639+
span,
626640
);
627641
}
628642
Some(name @ (sym::passes | sym::no_default_passes)) => {

compiler/rustc_attr_parsing/src/attributes/proc_macro_attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_hir::lints::AttributeLintKind;
1+
use rustc_errors::Diagnostic;
22
use rustc_session::lint::builtin::AMBIGUOUS_DERIVE_HELPERS;
33

44
use super::prelude::*;
@@ -125,9 +125,9 @@ fn parse_derive_like<S: Stage>(
125125
return None;
126126
}
127127
if rustc_feature::is_builtin_attr_name(ident.name) {
128-
cx.emit_lint(
128+
cx.emit_dyn_lint(
129129
AMBIGUOUS_DERIVE_HELPERS,
130-
AttributeLintKind::AmbiguousDeriveHelpers,
130+
|dcx, level| crate::errors::AmbiguousDeriveHelpers.into_diag(dcx, level),
131131
ident.span,
132132
);
133133
}

compiler/rustc_attr_parsing/src/errors.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_errors::{DiagArgValue, MultiSpan};
1+
use rustc_errors::{Applicability, DiagArgValue, MultiSpan};
22
use rustc_macros::{Diagnostic, Subdiagnostic};
33
use rustc_span::{Span, Symbol};
44

@@ -177,3 +177,31 @@ pub(crate) struct DocAliasDuplicated {
177177
#[derive(Diagnostic)]
178178
#[diag("only `hide` or `show` are allowed in `#[doc(auto_cfg(...))]`")]
179179
pub(crate) struct DocAutoCfgExpectsHideOrShow;
180+
181+
#[derive(Diagnostic)]
182+
#[diag("there exists a built-in attribute with the same name")]
183+
pub(crate) struct AmbiguousDeriveHelpers;
184+
185+
#[derive(Diagnostic)]
186+
#[diag("`#![doc(auto_cfg({$attr_name}(...)))]` only accepts identifiers or key/value items")]
187+
pub(crate) struct DocAutoCfgHideShowUnexpectedItem {
188+
pub attr_name: Symbol,
189+
}
190+
191+
#[derive(Diagnostic)]
192+
#[diag("`#![doc(auto_cfg({$attr_name}(...)))]` expects a list of items")]
193+
pub(crate) struct DocAutoCfgHideShowExpectsList {
194+
pub attr_name: Symbol,
195+
}
196+
197+
#[derive(Diagnostic)]
198+
#[diag("unknown `doc` attribute `include`")]
199+
pub(crate) struct DocUnknownInclude {
200+
pub inner: &'static str,
201+
pub value: Symbol,
202+
#[suggestion(
203+
"use `doc = include_str!` instead",
204+
code = "#{inner}[doc = include_str!(\"{value}\")]"
205+
)]
206+
pub sugg: (Span, Applicability),
207+
}

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,24 @@ fn can_autocast<'ll>(cx: &CodegenCx<'ll, '_>, rust_ty: &'ll Type, llvm_ty: &'ll
10331033
}
10341034
}
10351035
TypeKind::BFloat => rust_ty == cx.type_i16(),
1036+
TypeKind::X86_AMX if cx.type_kind(rust_ty) == TypeKind::Vector => {
1037+
let element_ty = cx.element_type(rust_ty);
1038+
let element_count = cx.vector_length(rust_ty) as u64;
1039+
1040+
let element_size_bits = match cx.type_kind(element_ty) {
1041+
TypeKind::Half => 16,
1042+
TypeKind::Float => 32,
1043+
TypeKind::Double => 64,
1044+
TypeKind::FP128 => 128,
1045+
TypeKind::Integer => cx.int_width(element_ty),
1046+
TypeKind::Pointer => cx.int_width(cx.isize_ty),
1047+
_ => bug!(
1048+
"Vector element type `{element_ty:?}` not one of integer, float or pointer"
1049+
),
1050+
};
1051+
1052+
element_size_bits * element_count == 8192
1053+
}
10361054
_ => false,
10371055
}
10381056
}
@@ -1102,6 +1120,12 @@ fn autocast<'ll>(
11021120
)
11031121
}
11041122
}
1123+
(TypeKind::Vector, TypeKind::X86_AMX) => {
1124+
bx.call_intrinsic("llvm.x86.cast.vector.to.tile", &[src_ty], &[val])
1125+
}
1126+
(TypeKind::X86_AMX, TypeKind::Vector) => {
1127+
bx.call_intrinsic("llvm.x86.cast.tile.to.vector", &[dest_ty], &[val])
1128+
}
11051129
_ => bx.bitcast(val, dest_ty), // for `bf16(xN)` <-> `u16(xN)`
11061130
}
11071131
}

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,6 +2346,17 @@ impl<'a, 'b, 'tcx> FnCallDiagCtxt<'a, 'b, 'tcx> {
23462346
provided_span,
23472347
format!("unexpected argument{idx}{provided_ty_name}"),
23482348
));
2349+
if self.provided_arg_tys.len() == 1
2350+
&& let Some(span) = self.maybe_suggest_expect_for_unwrap(provided_ty)
2351+
{
2352+
err.span_suggestion_verbose(
2353+
span,
2354+
"did you mean to use `expect`?",
2355+
"expect",
2356+
Applicability::MaybeIncorrect,
2357+
);
2358+
continue;
2359+
}
23492360
let mut span = provided_span;
23502361
if span.can_be_used_for_suggestions()
23512362
&& self.call_metadata.error_span.can_be_used_for_suggestions()
@@ -2776,6 +2787,22 @@ impl<'a, 'b, 'tcx> FnCallDiagCtxt<'a, 'b, 'tcx> {
27762787

27772788
(suggestion_span, suggestion)
27782789
}
2790+
2791+
fn maybe_suggest_expect_for_unwrap(&self, provided_ty: Ty<'tcx>) -> Option<Span> {
2792+
let tcx = self.tcx();
2793+
if let Some(call_ident) = self.call_metadata.call_ident
2794+
&& call_ident.name == sym::unwrap
2795+
&& let Some(callee_ty) = self.callee_ty
2796+
&& let ty::Adt(adt, _) = callee_ty.peel_refs().kind()
2797+
&& (tcx.is_diagnostic_item(sym::Option, adt.did())
2798+
|| tcx.is_diagnostic_item(sym::Result, adt.did()))
2799+
&& self.may_coerce(provided_ty, Ty::new_static_str(tcx))
2800+
{
2801+
Some(call_ident.span)
2802+
} else {
2803+
None
2804+
}
2805+
}
27792806
}
27802807

27812808
struct ArgMatchingCtxt<'a, 'b, 'tcx> {

compiler/rustc_lint/src/early/diagnostics.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::any::Any;
22

33
use rustc_data_structures::sync::DynSend;
4-
use rustc_errors::{Applicability, Diag, DiagCtxtHandle, Diagnostic, Level};
4+
use rustc_errors::{Diag, DiagCtxtHandle, Diagnostic, Level};
55
use rustc_hir::lints::{AttributeLintKind, FormatWarning};
66
use rustc_middle::ty::TyCtxt;
77
use rustc_session::Session;
@@ -43,29 +43,6 @@ impl<'a> Diagnostic<'a, ()> for DecorateAttrLint<'_, '_, '_> {
4343
.into_diag(dcx, level)
4444
}
4545

46-
&AttributeLintKind::AmbiguousDeriveHelpers => {
47-
lints::AmbiguousDeriveHelpers.into_diag(dcx, level)
48-
}
49-
50-
&AttributeLintKind::DocAutoCfgHideShowUnexpectedItem { attr_name } => {
51-
lints::DocAutoCfgHideShowUnexpectedItem { attr_name }.into_diag(dcx, level)
52-
}
53-
54-
&AttributeLintKind::DocAutoCfgHideShowExpectsList { attr_name } => {
55-
lints::DocAutoCfgHideShowExpectsList { attr_name }.into_diag(dcx, level)
56-
}
57-
58-
&AttributeLintKind::DocInvalid => lints::DocInvalid.into_diag(dcx, level),
59-
60-
&AttributeLintKind::DocUnknownInclude { span, inner, value } => {
61-
lints::DocUnknownInclude {
62-
inner,
63-
value,
64-
sugg: (span, Applicability::MaybeIncorrect),
65-
}
66-
.into_diag(dcx, level)
67-
}
68-
6946
&AttributeLintKind::DocUnknownSpotlight { span } => {
7047
lints::DocUnknownSpotlight { sugg_span: span }.into_diag(dcx, level)
7148
}

compiler/rustc_lint/src/lints.rs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3303,38 +3303,6 @@ pub(crate) struct ExpectedNoArgs;
33033303
)]
33043304
pub(crate) struct ExpectedNameValue;
33053305

3306-
#[derive(Diagnostic)]
3307-
#[diag("there exists a built-in attribute with the same name")]
3308-
pub(crate) struct AmbiguousDeriveHelpers;
3309-
3310-
#[derive(Diagnostic)]
3311-
#[diag("`#![doc(auto_cfg({$attr_name}(...)))]` only accepts identifiers or key/value items")]
3312-
pub(crate) struct DocAutoCfgHideShowUnexpectedItem {
3313-
pub attr_name: Symbol,
3314-
}
3315-
3316-
#[derive(Diagnostic)]
3317-
#[diag("`#![doc(auto_cfg({$attr_name}(...)))]` expects a list of items")]
3318-
pub(crate) struct DocAutoCfgHideShowExpectsList {
3319-
pub attr_name: Symbol,
3320-
}
3321-
3322-
#[derive(Diagnostic)]
3323-
#[diag("invalid `doc` attribute")]
3324-
pub(crate) struct DocInvalid;
3325-
3326-
#[derive(Diagnostic)]
3327-
#[diag("unknown `doc` attribute `include`")]
3328-
pub(crate) struct DocUnknownInclude {
3329-
pub inner: &'static str,
3330-
pub value: Symbol,
3331-
#[suggestion(
3332-
"use `doc = include_str!` instead",
3333-
code = "#{inner}[doc = include_str!(\"{value}\")]"
3334-
)]
3335-
pub sugg: (Span, Applicability),
3336-
}
3337-
33383306
#[derive(Diagnostic)]
33393307
#[diag("unknown `doc` attribute `spotlight`")]
33403308
#[note("`doc(spotlight)` was renamed to `doc(notable_trait)`")]

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -656,11 +656,6 @@ pub enum DeprecatedSinceKind {
656656
pub enum AttributeLintKind {
657657
UnexpectedCfgName((Symbol, Span), Option<(Symbol, Span)>),
658658
UnexpectedCfgValue((Symbol, Span), Option<(Symbol, Span)>),
659-
DocAutoCfgHideShowUnexpectedItem { attr_name: Symbol },
660-
DocAutoCfgHideShowExpectsList { attr_name: Symbol },
661-
DocInvalid,
662-
AmbiguousDeriveHelpers,
663-
DocUnknownInclude { span: Span, inner: &'static str, value: Symbol },
664659
DocUnknownSpotlight { span: Span },
665660
DocUnknownPasses { name: Symbol, span: Span },
666661
DocUnknownPlugins { span: Span },

compiler/rustc_monomorphize/src/mono_checks/abi_check.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! This module ensures that if a function's ABI requires a particular target feature,
22
//! that target feature is enabled both on the callee and all callers.
3-
use rustc_abi::{BackendRepr, CanonAbi, RegKind, X86Call};
3+
use rustc_abi::{BackendRepr, CanonAbi, ExternAbi, RegKind, X86Call};
44
use rustc_hir::{CRATE_HIR_ID, HirId};
55
use rustc_middle::mir::{self, Location, traversal};
66
use rustc_middle::ty::{self, Instance, InstanceKind, Ty, TyCtxt};
@@ -160,6 +160,12 @@ fn do_check_unsized_params<'tcx>(
160160
/// - the signature requires target features that are not enabled
161161
fn check_instance_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
162162
let typing_env = ty::TypingEnv::fully_monomorphized();
163+
let ty = instance.ty(tcx, typing_env);
164+
if ty.is_fn() && ty.fn_sig(tcx).abi() == ExternAbi::Unadjusted {
165+
// We disable all checks for the unadjusted ABI to allow linking to arbitrary LLVM
166+
// intrinsics
167+
return;
168+
}
163169
let Ok(abi) = tcx.fn_abi_of_instance(typing_env.as_query_input((instance, ty::List::empty())))
164170
else {
165171
// An error will be reported during codegen if we cannot determine the ABI of this
@@ -194,9 +200,12 @@ fn check_call_site_abi<'tcx>(
194200
caller: InstanceKind<'tcx>,
195201
loc: impl Fn() -> (Span, HirId) + Copy,
196202
) {
197-
if callee.fn_sig(tcx).abi().is_rustic_abi() {
203+
let extern_abi = callee.fn_sig(tcx).abi();
204+
if extern_abi.is_rustic_abi() || extern_abi == ExternAbi::Unadjusted {
198205
// We directly handle the soundness of Rust ABIs -- so let's skip the majority of
199206
// call sites to avoid a perf regression.
207+
// We disable all checks for the unadjusted ABI to allow linking to arbitrary LLVM
208+
// intrinsics
200209
return;
201210
}
202211
let typing_env = ty::TypingEnv::fully_monomorphized();

compiler/rustc_type_ir/src/search_graph/global_cache.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ pub struct GlobalCache<X: Cx> {
3939
}
4040

4141
impl<X: Cx> GlobalCache<X> {
42+
#[inline]
43+
pub const fn new() -> Self {
44+
GlobalCache { map: HashMap::with_hasher(rustc_hash::FxBuildHasher) }
45+
}
46+
4247
/// Insert a final result into the global cache.
4348
pub(super) fn insert(
4449
&mut self,

0 commit comments

Comments
 (0)