Skip to content

Commit b6100cc

Browse files
committed
Auto merge of #155099 - JonathanBrouwer:rollup-nKbnTlV, r=JonathanBrouwer
Rollup of 8 pull requests Successful merges: - #155047 (Always exhaustively match on typing mode) - #155080 (Simplify `try_load_from_disk_fn`.) - #152384 (Restrict EII declarations to functions at lowering time) - #153796 (Fix ICE when combining #[eii] with #[core::contracts::ensures]) - #154369 (Fix `pattern_from_macro_note` for bit-or expr) - #155027 ( Rename some more of our internal `#[rustc_*]` TEST attributes) - #155031 (delegation: fix unelided lifetime ICE, refactoring of GenericArgPosition) - #155040 (Fix code block whitespace handling in Markdown)
2 parents 8317fef + eec05ee commit b6100cc

File tree

144 files changed

+2128
-1610
lines changed

Some content is hidden

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

144 files changed

+2128
-1610
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4692,7 +4692,6 @@ dependencies = [
46924692
"rustc-demangle",
46934693
"rustc_abi",
46944694
"rustc_data_structures",
4695-
"rustc_errors",
46964695
"rustc_hashes",
46974696
"rustc_hir",
46984697
"rustc_middle",

compiler/rustc_ast_lowering/src/pat.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,11 @@ impl<'hir, R: ResolverAstLoweringExt<'hir>> LoweringContext<'_, 'hir, R> {
421421
}
422422
_ => {
423423
let is_const_block = matches!(expr.kind, ExprKind::ConstBlock(_));
424-
let pattern_from_macro = expr.is_approximately_pattern();
424+
let pattern_from_macro = expr.is_approximately_pattern()
425+
|| matches!(
426+
expr.peel_parens().kind,
427+
ExprKind::Binary(Spanned { node: BinOpKind::BitOr, .. }, ..)
428+
);
425429
let guar = self.dcx().emit_err(ArbitraryExpressionInPattern {
426430
span,
427431
pattern_from_macro_note: pattern_from_macro,

compiler/rustc_attr_parsing/src/attributes/rustc_dump.rs

Lines changed: 123 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
use rustc_hir::attrs::AttributeKind;
1+
use rustc_hir::attrs::{AttributeKind, RustcDumpLayoutKind};
22
use rustc_hir::{MethodKind, Target};
33
use rustc_span::{Span, Symbol, sym};
44

5-
use crate::attributes::prelude::Allow;
6-
use crate::attributes::{NoArgsAttributeParser, OnDuplicate};
5+
use super::prelude::*;
76
use crate::context::Stage;
87
use crate::target_checking::AllowedTargets;
98

@@ -25,6 +24,39 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpDefParentsParser {
2524
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpDefParents;
2625
}
2726

27+
pub(crate) struct RustcDumpDefPathParser;
28+
29+
impl<S: Stage> SingleAttributeParser<S> for RustcDumpDefPathParser {
30+
const PATH: &[Symbol] = &[sym::rustc_dump_def_path];
31+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
32+
Allow(Target::Fn),
33+
Allow(Target::Method(MethodKind::TraitImpl)),
34+
Allow(Target::Method(MethodKind::Inherent)),
35+
Allow(Target::Method(MethodKind::Trait { body: true })),
36+
Allow(Target::ForeignFn),
37+
Allow(Target::ForeignStatic),
38+
Allow(Target::Impl { of_trait: false }),
39+
]);
40+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
41+
const TEMPLATE: AttributeTemplate = template!(Word);
42+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
43+
if let Err(span) = args.no_args() {
44+
cx.adcx().expected_no_args(span);
45+
return None;
46+
}
47+
Some(AttributeKind::RustcDumpDefPath(cx.attr_span))
48+
}
49+
}
50+
51+
pub(crate) struct RustcDumpHiddenTypeOfOpaquesParser;
52+
53+
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpHiddenTypeOfOpaquesParser {
54+
const PATH: &[Symbol] = &[sym::rustc_dump_hidden_type_of_opaques];
55+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
56+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
57+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpHiddenTypeOfOpaques;
58+
}
59+
2860
pub(crate) struct RustcDumpInferredOutlivesParser;
2961

3062
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpInferredOutlivesParser {
@@ -48,6 +80,70 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpItemBoundsParser {
4880
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpItemBounds;
4981
}
5082

83+
pub(crate) struct RustcDumpLayoutParser;
84+
85+
impl<S: Stage> CombineAttributeParser<S> for RustcDumpLayoutParser {
86+
const PATH: &[Symbol] = &[sym::rustc_dump_layout];
87+
88+
type Item = RustcDumpLayoutKind;
89+
90+
const CONVERT: ConvertFn<Self::Item> = |items, _| AttributeKind::RustcDumpLayout(items);
91+
92+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
93+
Allow(Target::Struct),
94+
Allow(Target::Enum),
95+
Allow(Target::Union),
96+
Allow(Target::TyAlias),
97+
]);
98+
99+
const TEMPLATE: AttributeTemplate =
100+
template!(List: &["abi", "align", "size", "homogenous_aggregate", "debug"]);
101+
fn extend(
102+
cx: &mut AcceptContext<'_, '_, S>,
103+
args: &ArgParser,
104+
) -> impl IntoIterator<Item = Self::Item> {
105+
let ArgParser::List(items) = args else {
106+
let attr_span = cx.attr_span;
107+
cx.adcx().expected_list(attr_span, args);
108+
return vec![];
109+
};
110+
111+
let mut result = Vec::new();
112+
for item in items.mixed() {
113+
let Some(arg) = item.meta_item() else {
114+
cx.adcx().expected_not_literal(item.span());
115+
continue;
116+
};
117+
let Some(ident) = arg.ident() else {
118+
cx.adcx().expected_identifier(arg.span());
119+
return vec![];
120+
};
121+
let kind = match ident.name {
122+
sym::align => RustcDumpLayoutKind::Align,
123+
sym::backend_repr => RustcDumpLayoutKind::BackendRepr,
124+
sym::debug => RustcDumpLayoutKind::Debug,
125+
sym::homogeneous_aggregate => RustcDumpLayoutKind::HomogenousAggregate,
126+
sym::size => RustcDumpLayoutKind::Size,
127+
_ => {
128+
cx.adcx().expected_specific_argument(
129+
ident.span,
130+
&[
131+
sym::align,
132+
sym::backend_repr,
133+
sym::debug,
134+
sym::homogeneous_aggregate,
135+
sym::size,
136+
],
137+
);
138+
continue;
139+
}
140+
};
141+
result.push(kind);
142+
}
143+
result
144+
}
145+
}
146+
51147
pub(crate) struct RustcDumpObjectLifetimeDefaultsParser;
52148

53149
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpObjectLifetimeDefaultsParser {
@@ -103,6 +199,30 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpPredicatesParser {
103199
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpPredicates;
104200
}
105201

202+
pub(crate) struct RustcDumpSymbolNameParser;
203+
204+
impl<S: Stage> SingleAttributeParser<S> for RustcDumpSymbolNameParser {
205+
const PATH: &[Symbol] = &[sym::rustc_dump_symbol_name];
206+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
207+
Allow(Target::Fn),
208+
Allow(Target::Method(MethodKind::TraitImpl)),
209+
Allow(Target::Method(MethodKind::Inherent)),
210+
Allow(Target::Method(MethodKind::Trait { body: true })),
211+
Allow(Target::ForeignFn),
212+
Allow(Target::ForeignStatic),
213+
Allow(Target::Impl { of_trait: false }),
214+
]);
215+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
216+
const TEMPLATE: AttributeTemplate = template!(Word);
217+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
218+
if let Err(span) = args.no_args() {
219+
cx.adcx().expected_no_args(span);
220+
return None;
221+
}
222+
Some(AttributeKind::RustcDumpSymbolName(cx.attr_span))
223+
}
224+
}
225+
106226
pub(crate) struct RustcDumpVariancesParser;
107227

108228
impl<S: Stage> NoArgsAttributeParser<S> for RustcDumpVariancesParser {

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 10 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use rustc_ast::{LitIntType, LitKind, MetaItemLit};
44
use rustc_hir::LangItem;
55
use rustc_hir::attrs::{
66
BorrowckGraphvizFormatKind, CguFields, CguKind, DivergingBlockBehavior,
7-
DivergingFallbackBehavior, RustcCleanAttribute, RustcCleanQueries, RustcLayoutType,
8-
RustcMirKind,
7+
DivergingFallbackBehavior, RustcCleanAttribute, RustcCleanQueries, RustcMirKind,
98
};
109
use rustc_session::errors;
1110
use rustc_span::Symbol;
@@ -681,14 +680,6 @@ impl<S: Stage> NoArgsAttributeParser<S> for PanicHandlerParser {
681680
const CREATE: fn(Span) -> AttributeKind = |span| AttributeKind::Lang(LangItem::PanicImpl, span);
682681
}
683682

684-
pub(crate) struct RustcHiddenTypeOfOpaquesParser;
685-
686-
impl<S: Stage> NoArgsAttributeParser<S> for RustcHiddenTypeOfOpaquesParser {
687-
const PATH: &[Symbol] = &[sym::rustc_hidden_type_of_opaques];
688-
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
689-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
690-
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcHiddenTypeOfOpaques;
691-
}
692683
pub(crate) struct RustcNounwindParser;
693684

694685
impl<S: Stage> NoArgsAttributeParser<S> for RustcNounwindParser {
@@ -713,64 +704,6 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcOffloadKernelParser {
713704
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcOffloadKernel;
714705
}
715706

716-
pub(crate) struct RustcLayoutParser;
717-
718-
impl<S: Stage> CombineAttributeParser<S> for RustcLayoutParser {
719-
const PATH: &[Symbol] = &[sym::rustc_layout];
720-
721-
type Item = RustcLayoutType;
722-
723-
const CONVERT: ConvertFn<Self::Item> = |items, _| AttributeKind::RustcLayout(items);
724-
725-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
726-
Allow(Target::Struct),
727-
Allow(Target::Enum),
728-
Allow(Target::Union),
729-
Allow(Target::TyAlias),
730-
]);
731-
732-
const TEMPLATE: AttributeTemplate =
733-
template!(List: &["abi", "align", "size", "homogenous_aggregate", "debug"]);
734-
fn extend(
735-
cx: &mut AcceptContext<'_, '_, S>,
736-
args: &ArgParser,
737-
) -> impl IntoIterator<Item = Self::Item> {
738-
let ArgParser::List(items) = args else {
739-
let attr_span = cx.attr_span;
740-
cx.adcx().expected_list(attr_span, args);
741-
return vec![];
742-
};
743-
744-
let mut result = Vec::new();
745-
for item in items.mixed() {
746-
let Some(arg) = item.meta_item() else {
747-
cx.adcx().expected_not_literal(item.span());
748-
continue;
749-
};
750-
let Some(ident) = arg.ident() else {
751-
cx.adcx().expected_identifier(arg.span());
752-
return vec![];
753-
};
754-
let ty = match ident.name {
755-
sym::abi => RustcLayoutType::Abi,
756-
sym::align => RustcLayoutType::Align,
757-
sym::size => RustcLayoutType::Size,
758-
sym::homogeneous_aggregate => RustcLayoutType::HomogenousAggregate,
759-
sym::debug => RustcLayoutType::Debug,
760-
_ => {
761-
cx.adcx().expected_specific_argument(
762-
ident.span,
763-
&[sym::abi, sym::align, sym::size, sym::homogeneous_aggregate, sym::debug],
764-
);
765-
continue;
766-
}
767-
};
768-
result.push(ty);
769-
}
770-
result
771-
}
772-
}
773-
774707
pub(crate) struct RustcMirParser;
775708

776709
impl<S: Stage> CombineAttributeParser<S> for RustcMirParser {
@@ -1210,54 +1143,6 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcNonnullOptimizationGuaranteedPa
12101143
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcNonnullOptimizationGuaranteed;
12111144
}
12121145

1213-
pub(crate) struct RustcSymbolNameParser;
1214-
1215-
impl<S: Stage> SingleAttributeParser<S> for RustcSymbolNameParser {
1216-
const PATH: &[Symbol] = &[sym::rustc_symbol_name];
1217-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
1218-
Allow(Target::Fn),
1219-
Allow(Target::Method(MethodKind::TraitImpl)),
1220-
Allow(Target::Method(MethodKind::Inherent)),
1221-
Allow(Target::Method(MethodKind::Trait { body: true })),
1222-
Allow(Target::ForeignFn),
1223-
Allow(Target::ForeignStatic),
1224-
Allow(Target::Impl { of_trait: false }),
1225-
]);
1226-
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
1227-
const TEMPLATE: AttributeTemplate = template!(Word);
1228-
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
1229-
if let Err(span) = args.no_args() {
1230-
cx.adcx().expected_no_args(span);
1231-
return None;
1232-
}
1233-
Some(AttributeKind::RustcSymbolName(cx.attr_span))
1234-
}
1235-
}
1236-
1237-
pub(crate) struct RustcDefPathParser;
1238-
1239-
impl<S: Stage> SingleAttributeParser<S> for RustcDefPathParser {
1240-
const PATH: &[Symbol] = &[sym::rustc_def_path];
1241-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
1242-
Allow(Target::Fn),
1243-
Allow(Target::Method(MethodKind::TraitImpl)),
1244-
Allow(Target::Method(MethodKind::Inherent)),
1245-
Allow(Target::Method(MethodKind::Trait { body: true })),
1246-
Allow(Target::ForeignFn),
1247-
Allow(Target::ForeignStatic),
1248-
Allow(Target::Impl { of_trait: false }),
1249-
]);
1250-
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
1251-
const TEMPLATE: AttributeTemplate = template!(Word);
1252-
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
1253-
if let Err(span) = args.no_args() {
1254-
cx.adcx().expected_no_args(span);
1255-
return None;
1256-
}
1257-
Some(AttributeKind::RustcDefPath(cx.attr_span))
1258-
}
1259-
}
1260-
12611146
pub(crate) struct RustcStrictCoherenceParser;
12621147

12631148
impl<S: Stage> NoArgsAttributeParser<S> for RustcStrictCoherenceParser {
@@ -1349,3 +1234,12 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcIntrinsicConstStableIndirectPar
13491234
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
13501235
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcIntrinsicConstStableIndirect;
13511236
}
1237+
1238+
pub(crate) struct RustcExhaustiveParser;
1239+
1240+
impl<S: Stage> NoArgsAttributeParser<S> for RustcExhaustiveParser {
1241+
const PATH: &'static [Symbol] = &[sym::rustc_must_match_exhaustively];
1242+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
1243+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Enum)]);
1244+
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcMustMatchExhaustively;
1245+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ attribute_parsers!(
172172
Combine<ReprParser>,
173173
Combine<RustcAllowConstFnUnstableParser>,
174174
Combine<RustcCleanParser>,
175-
Combine<RustcLayoutParser>,
175+
Combine<RustcDumpLayoutParser>,
176176
Combine<RustcMirParser>,
177177
Combine<RustcThenThisWouldNeedParser>,
178178
Combine<TargetFeatureParser>,
@@ -211,11 +211,12 @@ attribute_parsers!(
211211
Single<RustcAllocatorZeroedVariantParser>,
212212
Single<RustcAutodiffParser>,
213213
Single<RustcBuiltinMacroParser>,
214-
Single<RustcDefPathParser>,
215214
Single<RustcDeprecatedSafe2024Parser>,
216215
Single<RustcDiagnosticItemParser>,
217216
Single<RustcDocPrimitiveParser>,
218217
Single<RustcDummyParser>,
218+
Single<RustcDumpDefPathParser>,
219+
Single<RustcDumpSymbolNameParser>,
219220
Single<RustcForceInlineParser>,
220221
Single<RustcIfThisChangedParser>,
221222
Single<RustcLayoutScalarValidRangeEndParser>,
@@ -231,7 +232,6 @@ attribute_parsers!(
231232
Single<RustcScalableVectorParser>,
232233
Single<RustcSimdMonomorphizeLaneLimitParser>,
233234
Single<RustcSkipDuringMethodDispatchParser>,
234-
Single<RustcSymbolNameParser>,
235235
Single<RustcTestMarkerParser>,
236236
Single<SanitizeParser>,
237237
Single<ShouldPanicParser>,
@@ -285,6 +285,7 @@ attribute_parsers!(
285285
Single<WithoutArgs<RustcDenyExplicitImplParser>>,
286286
Single<WithoutArgs<RustcDoNotConstCheckParser>>,
287287
Single<WithoutArgs<RustcDumpDefParentsParser>>,
288+
Single<WithoutArgs<RustcDumpHiddenTypeOfOpaquesParser>>,
288289
Single<WithoutArgs<RustcDumpInferredOutlivesParser>>,
289290
Single<WithoutArgs<RustcDumpItemBoundsParser>>,
290291
Single<WithoutArgs<RustcDumpObjectLifetimeDefaultsParser>>,
@@ -297,8 +298,8 @@ attribute_parsers!(
297298
Single<WithoutArgs<RustcEffectiveVisibilityParser>>,
298299
Single<WithoutArgs<RustcEiiForeignItemParser>>,
299300
Single<WithoutArgs<RustcEvaluateWhereClausesParser>>,
301+
Single<WithoutArgs<RustcExhaustiveParser>>,
300302
Single<WithoutArgs<RustcHasIncoherentInherentImplsParser>>,
301-
Single<WithoutArgs<RustcHiddenTypeOfOpaquesParser>>,
302303
Single<WithoutArgs<RustcInheritOverflowChecksParser>>,
303304
Single<WithoutArgs<RustcInsignificantDtorParser>>,
304305
Single<WithoutArgs<RustcIntrinsicConstStableIndirectParser>>,

compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,10 @@ impl Qualif for HasMutInterior {
103103
// FIXME(#132279): Once we've got a typing mode which reveals opaque types using the HIR
104104
// typeck results without causing query cycles, we should use this here instead of defining
105105
// opaque types.
106-
let typing_env = ty::TypingEnv {
107-
typing_mode: ty::TypingMode::analysis_in_body(
108-
cx.tcx,
109-
cx.body.source.def_id().expect_local(),
110-
),
111-
param_env: cx.typing_env.param_env,
112-
};
106+
let typing_env = ty::TypingEnv::new(
107+
cx.typing_env.param_env,
108+
ty::TypingMode::analysis_in_body(cx.tcx, cx.body.source.def_id().expect_local()),
109+
);
113110
let (infcx, param_env) = cx.tcx.infer_ctxt().build_with_typing_env(typing_env);
114111
let ocx = ObligationCtxt::new(&infcx);
115112
let obligation = Obligation::new(

0 commit comments

Comments
 (0)