Skip to content

Commit 351af79

Browse files
committed
Auto merge of #152571 - JonathanBrouwer:rollup-Z7HIFXL, r=<try>
Rollup of 14 pull requests try-job: x86_64-msvc-1 try-job: i686-msvc-1 try-job: x86_64-mingw-1 try-job: test-various try-job: armhf-gnu try-job: aarch64-apple try-job: x86_64-gnu-llvm-20-3 try-job: dist-various-2
2 parents 47611e1 + ec211c5 commit 351af79

File tree

101 files changed

+1039
-652
lines changed

Some content is hidden

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

101 files changed

+1039
-652
lines changed

compiler/rustc_abi/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// tidy-alphabetical-start
2-
#![cfg_attr(all(feature = "nightly", bootstrap), feature(assert_matches))]
2+
#![cfg_attr(all(feature = "nightly", bootstrap, test), feature(assert_matches))]
33
#![cfg_attr(feature = "nightly", allow(internal_features))]
44
#![cfg_attr(feature = "nightly", feature(rustc_attrs))]
55
#![cfg_attr(feature = "nightly", feature(step_trait))]

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,45 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcEffectiveVisibilityParser {
11031103
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcEffectiveVisibility;
11041104
}
11051105

1106+
pub(crate) struct RustcDiagnosticItemParser;
1107+
1108+
impl<S: Stage> SingleAttributeParser<S> for RustcDiagnosticItemParser {
1109+
const PATH: &[Symbol] = &[sym::rustc_diagnostic_item];
1110+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
1111+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
1112+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
1113+
Allow(Target::Trait),
1114+
Allow(Target::Struct),
1115+
Allow(Target::Enum),
1116+
Allow(Target::MacroDef),
1117+
Allow(Target::TyAlias),
1118+
Allow(Target::AssocTy),
1119+
Allow(Target::AssocConst),
1120+
Allow(Target::Fn),
1121+
Allow(Target::Const),
1122+
Allow(Target::Mod),
1123+
Allow(Target::Impl { of_trait: false }),
1124+
Allow(Target::Method(MethodKind::Inherent)),
1125+
Allow(Target::Method(MethodKind::Trait { body: false })),
1126+
Allow(Target::Method(MethodKind::Trait { body: true })),
1127+
Allow(Target::Method(MethodKind::TraitImpl)),
1128+
Allow(Target::Crate),
1129+
]);
1130+
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name");
1131+
1132+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
1133+
let Some(nv) = args.name_value() else {
1134+
cx.expected_name_value(cx.attr_span, None);
1135+
return None;
1136+
};
1137+
let Some(value) = nv.value_as_str() else {
1138+
cx.expected_string_literal(nv.value_span, Some(nv.value_as_lit()));
1139+
return None;
1140+
};
1141+
Some(AttributeKind::RustcDiagnosticItem(value))
1142+
}
1143+
}
1144+
11061145
pub(crate) struct RustcSymbolName;
11071146

11081147
impl<S: Stage> SingleAttributeParser<S> for RustcSymbolName {

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,36 @@ impl<S: Stage> SingleAttributeParser<S> for TestRunnerParser {
257257
Some(AttributeKind::TestRunner(meta.path().0.clone()))
258258
}
259259
}
260+
261+
pub(crate) struct RustcTestMarkerParser;
262+
263+
impl<S: Stage> SingleAttributeParser<S> for RustcTestMarkerParser {
264+
const PATH: &[Symbol] = &[sym::rustc_test_marker];
265+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
266+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
267+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
268+
Allow(Target::Const),
269+
Allow(Target::Fn),
270+
Allow(Target::Static),
271+
]);
272+
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "test_path");
273+
274+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
275+
let Some(name_value) = args.name_value() else {
276+
cx.expected_name_value(cx.attr_span, Some(sym::rustc_test_marker));
277+
return None;
278+
};
279+
280+
let Some(value_str) = name_value.value_as_str() else {
281+
cx.expected_string_literal(name_value.value_span, None);
282+
return None;
283+
};
284+
285+
if value_str.as_str().trim().is_empty() {
286+
cx.expected_non_empty_string_literal(name_value.value_span);
287+
return None;
288+
}
289+
290+
Some(AttributeKind::RustcTestMarker(value_str))
291+
}
292+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ attribute_parsers!(
203203
Single<RustcBuiltinMacroParser>,
204204
Single<RustcDefPath>,
205205
Single<RustcDeprecatedSafe2024Parser>,
206+
Single<RustcDiagnosticItemParser>,
206207
Single<RustcForceInlineParser>,
207208
Single<RustcIfThisChangedParser>,
208209
Single<RustcLayoutScalarValidRangeEndParser>,
@@ -215,6 +216,7 @@ attribute_parsers!(
215216
Single<RustcScalableVectorParser>,
216217
Single<RustcSimdMonomorphizeLaneLimitParser>,
217218
Single<RustcSymbolName>,
219+
Single<RustcTestMarkerParser>,
218220
Single<SanitizeParser>,
219221
Single<ShouldPanicParser>,
220222
Single<SkipDuringMethodDispatchParser>,

compiler/rustc_borrowck/src/region_infer/opaque_types/mod.rs

Lines changed: 89 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ use rustc_trait_selection::traits::query::type_op::custom::CustomTypeOp;
2424
use tracing::{debug, instrument};
2525

2626
use super::reverse_sccs::ReverseSccGraph;
27-
use crate::BorrowckInferCtxt;
2827
use crate::consumers::RegionInferenceContext;
2928
use crate::session_diagnostics::LifetimeMismatchOpaqueParam;
3029
use crate::type_check::canonical::fully_perform_op_raw;
3130
use crate::type_check::free_region_relations::UniversalRegionRelations;
3231
use crate::type_check::{Locations, MirTypeckRegionConstraints};
3332
use crate::universal_regions::{RegionClassification, UniversalRegions};
33+
use crate::{BorrowckInferCtxt, CollectRegionConstraintsResult};
3434

3535
mod member_constraints;
3636
mod region_ctxt;
@@ -126,6 +126,31 @@ fn nll_var_to_universal_region<'tcx>(
126126
}
127127
}
128128

129+
/// Record info needed to report the same name error later.
130+
#[derive(Copy, Clone, Debug)]
131+
pub(crate) struct UnexpectedHiddenRegion<'tcx> {
132+
// The def_id of the body where this error occurs.
133+
// Needed to handle region vars with their corresponding `infcx`.
134+
def_id: LocalDefId,
135+
opaque_type_key: OpaqueTypeKey<'tcx>,
136+
hidden_type: ProvisionalHiddenType<'tcx>,
137+
member_region: Region<'tcx>,
138+
}
139+
140+
impl<'tcx> UnexpectedHiddenRegion<'tcx> {
141+
pub(crate) fn to_error(self) -> (LocalDefId, DeferredOpaqueTypeError<'tcx>) {
142+
let UnexpectedHiddenRegion { def_id, opaque_type_key, hidden_type, member_region } = self;
143+
(
144+
def_id,
145+
DeferredOpaqueTypeError::UnexpectedHiddenRegion {
146+
opaque_type_key,
147+
hidden_type,
148+
member_region,
149+
},
150+
)
151+
}
152+
}
153+
129154
/// Collect all defining uses of opaque types inside of this typeck root. This
130155
/// expects the hidden type to be mapped to the definition parameters of the opaque
131156
/// and errors if we end up with distinct hidden types.
@@ -176,11 +201,13 @@ struct DefiningUse<'tcx> {
176201
/// It also means that this whole function is not really soundness critical as we
177202
/// recheck all uses of the opaques regardless.
178203
pub(crate) fn compute_definition_site_hidden_types<'tcx>(
204+
def_id: LocalDefId,
179205
infcx: &BorrowckInferCtxt<'tcx>,
180206
universal_region_relations: &Frozen<UniversalRegionRelations<'tcx>>,
181207
constraints: &MirTypeckRegionConstraints<'tcx>,
182208
location_map: Rc<DenseLocationMap>,
183209
hidden_types: &mut FxIndexMap<LocalDefId, ty::DefinitionSiteHiddenType<'tcx>>,
210+
unconstrained_hidden_type_errors: &mut Vec<UnexpectedHiddenRegion<'tcx>>,
184211
opaque_types: &[(OpaqueTypeKey<'tcx>, ProvisionalHiddenType<'tcx>)],
185212
) -> Vec<DeferredOpaqueTypeError<'tcx>> {
186213
let mut errors = Vec::new();
@@ -204,8 +231,10 @@ pub(crate) fn compute_definition_site_hidden_types<'tcx>(
204231
// up equal to one of their choice regions and compute the actual hidden type of
205232
// the opaque type definition. This is stored in the `root_cx`.
206233
compute_definition_site_hidden_types_from_defining_uses(
234+
def_id,
207235
&rcx,
208236
hidden_types,
237+
unconstrained_hidden_type_errors,
209238
&defining_uses,
210239
&mut errors,
211240
);
@@ -274,8 +303,10 @@ fn collect_defining_uses<'tcx>(
274303

275304
#[instrument(level = "debug", skip(rcx, hidden_types, defining_uses, errors))]
276305
fn compute_definition_site_hidden_types_from_defining_uses<'tcx>(
306+
def_id: LocalDefId,
277307
rcx: &RegionCtxt<'_, 'tcx>,
278308
hidden_types: &mut FxIndexMap<LocalDefId, ty::DefinitionSiteHiddenType<'tcx>>,
309+
unconstrained_hidden_type_errors: &mut Vec<UnexpectedHiddenRegion<'tcx>>,
279310
defining_uses: &[DefiningUse<'tcx>],
280311
errors: &mut Vec<DeferredOpaqueTypeError<'tcx>>,
281312
) {
@@ -293,16 +324,29 @@ fn compute_definition_site_hidden_types_from_defining_uses<'tcx>(
293324
Ok(hidden_type) => hidden_type,
294325
Err(r) => {
295326
debug!("UnexpectedHiddenRegion: {:?}", r);
296-
errors.push(DeferredOpaqueTypeError::UnexpectedHiddenRegion {
297-
hidden_type,
298-
opaque_type_key,
299-
member_region: ty::Region::new_var(tcx, r),
300-
});
301-
let guar = tcx.dcx().span_delayed_bug(
302-
hidden_type.span,
303-
"opaque type with non-universal region args",
304-
);
305-
ty::ProvisionalHiddenType::new_error(tcx, guar)
327+
// If we're using the next solver, the unconstrained region may be resolved by a
328+
// fully defining use from another body.
329+
// So we don't generate error eagerly here.
330+
if rcx.infcx.tcx.use_typing_mode_borrowck() {
331+
unconstrained_hidden_type_errors.push(UnexpectedHiddenRegion {
332+
def_id,
333+
hidden_type,
334+
opaque_type_key,
335+
member_region: ty::Region::new_var(tcx, r),
336+
});
337+
continue;
338+
} else {
339+
errors.push(DeferredOpaqueTypeError::UnexpectedHiddenRegion {
340+
hidden_type,
341+
opaque_type_key,
342+
member_region: ty::Region::new_var(tcx, r),
343+
});
344+
let guar = tcx.dcx().span_delayed_bug(
345+
hidden_type.span,
346+
"opaque type with non-universal region args",
347+
);
348+
ty::ProvisionalHiddenType::new_error(tcx, guar)
349+
}
306350
}
307351
};
308352

@@ -570,6 +614,40 @@ pub(crate) fn apply_definition_site_hidden_types<'tcx>(
570614
errors
571615
}
572616

617+
/// We handle `UnexpectedHiddenRegion` error lazily in the next solver as
618+
/// there may be a fully defining use in another body.
619+
///
620+
/// In case such a defining use does not exist, we register an error here.
621+
pub(crate) fn handle_unconstrained_hidden_type_errors<'tcx>(
622+
tcx: TyCtxt<'tcx>,
623+
hidden_types: &mut FxIndexMap<LocalDefId, ty::DefinitionSiteHiddenType<'tcx>>,
624+
unconstrained_hidden_type_errors: &mut Vec<UnexpectedHiddenRegion<'tcx>>,
625+
collect_region_constraints_results: &mut FxIndexMap<
626+
LocalDefId,
627+
CollectRegionConstraintsResult<'tcx>,
628+
>,
629+
) {
630+
let mut unconstrained_hidden_type_errors = std::mem::take(unconstrained_hidden_type_errors);
631+
unconstrained_hidden_type_errors
632+
.retain(|unconstrained| !hidden_types.contains_key(&unconstrained.opaque_type_key.def_id));
633+
634+
unconstrained_hidden_type_errors.iter().for_each(|t| {
635+
tcx.dcx()
636+
.span_delayed_bug(t.hidden_type.span, "opaque type with non-universal region args");
637+
});
638+
639+
// `UnexpectedHiddenRegion` error contains region var which only makes sense in the
640+
// corresponding `infcx`.
641+
// So we need to insert the error to the body where it originates from.
642+
for error in unconstrained_hidden_type_errors {
643+
let (def_id, error) = error.to_error();
644+
let Some(result) = collect_region_constraints_results.get_mut(&def_id) else {
645+
unreachable!("the body should depend on opaques type if it has opaque use");
646+
};
647+
result.deferred_opaque_type_errors.push(error);
648+
}
649+
}
650+
573651
/// In theory `apply_definition_site_hidden_types` could introduce new uses of opaque types.
574652
/// We do not check these new uses so this could be unsound.
575653
///

compiler/rustc_borrowck/src/root_cx.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ use smallvec::SmallVec;
1212
use crate::consumers::BorrowckConsumer;
1313
use crate::nll::compute_closure_requirements_modulo_opaques;
1414
use crate::region_infer::opaque_types::{
15-
apply_definition_site_hidden_types, clone_and_resolve_opaque_types,
15+
UnexpectedHiddenRegion, apply_definition_site_hidden_types, clone_and_resolve_opaque_types,
1616
compute_definition_site_hidden_types, detect_opaque_types_added_while_handling_opaque_types,
17+
handle_unconstrained_hidden_type_errors,
1718
};
1819
use crate::type_check::{Locations, constraint_conversion};
1920
use crate::{
@@ -26,7 +27,12 @@ use crate::{
2627
pub(super) struct BorrowCheckRootCtxt<'tcx> {
2728
pub tcx: TyCtxt<'tcx>,
2829
root_def_id: LocalDefId,
30+
/// This contains fully resolved hidden types or `ty::Error`.
2931
hidden_types: FxIndexMap<LocalDefId, ty::DefinitionSiteHiddenType<'tcx>>,
32+
/// This contains unconstrained regions in hidden types.
33+
/// Only used for deferred error reporting. See
34+
/// [`crate::region_infer::opaque_types::handle_unconstrained_hidden_type_errors`]
35+
unconstrained_hidden_type_errors: Vec<UnexpectedHiddenRegion<'tcx>>,
3036
/// The region constraints computed by [borrowck_collect_region_constraints]. This uses
3137
/// an [FxIndexMap] to guarantee that iterating over it visits nested bodies before
3238
/// their parents.
@@ -49,6 +55,7 @@ impl<'tcx> BorrowCheckRootCtxt<'tcx> {
4955
tcx,
5056
root_def_id,
5157
hidden_types: Default::default(),
58+
unconstrained_hidden_type_errors: Default::default(),
5259
collect_region_constraints_results: Default::default(),
5360
propagated_borrowck_results: Default::default(),
5461
tainted_by_errors: None,
@@ -84,23 +91,32 @@ impl<'tcx> BorrowCheckRootCtxt<'tcx> {
8491

8592
fn handle_opaque_type_uses(&mut self) {
8693
let mut per_body_info = Vec::new();
87-
for input in self.collect_region_constraints_results.values_mut() {
94+
for (def_id, input) in &mut self.collect_region_constraints_results {
8895
let (num_entries, opaque_types) = clone_and_resolve_opaque_types(
8996
&input.infcx,
9097
&input.universal_region_relations,
9198
&mut input.constraints,
9299
);
93100
input.deferred_opaque_type_errors = compute_definition_site_hidden_types(
101+
*def_id,
94102
&input.infcx,
95103
&input.universal_region_relations,
96104
&input.constraints,
97105
Rc::clone(&input.location_map),
98106
&mut self.hidden_types,
107+
&mut self.unconstrained_hidden_type_errors,
99108
&opaque_types,
100109
);
101110
per_body_info.push((num_entries, opaque_types));
102111
}
103112

113+
handle_unconstrained_hidden_type_errors(
114+
self.tcx,
115+
&mut self.hidden_types,
116+
&mut self.unconstrained_hidden_type_errors,
117+
&mut self.collect_region_constraints_results,
118+
);
119+
104120
for (input, (opaque_types_storage_num_entries, opaque_types)) in
105121
self.collect_region_constraints_results.values_mut().zip(per_body_info)
106122
{

compiler/rustc_codegen_cranelift/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Note: please avoid adding other feature gates where possible
33
#![feature(rustc_private)]
44
// Only used to define intrinsics in `compiler_builtins.rs`.
5-
#![feature(f16)]
6-
#![feature(f128)]
5+
#![cfg_attr(feature = "jit", feature(f16))]
6+
#![cfg_attr(feature = "jit", feature(f128))]
77
// Note: please avoid adding other feature gates where possible
88
#![warn(rust_2018_idioms)]
99
#![warn(unreachable_pub)]

compiler/rustc_codegen_llvm/src/debuginfo/doc.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module to generate correct metadata and insert it into the LLVM IR.
1616
As the exact format of metadata trees may change between different LLVM
1717
versions, we now use LLVM
1818
[DIBuilder](https://llvm.org/docs/doxygen/html/classllvm_1_1DIBuilder.html)
19-
to create metadata where possible. This will hopefully ease the adaption of
19+
to create metadata where possible. This will hopefully ease the adaptation of
2020
this module to future LLVM versions.
2121

2222
The public API of the module is a set of functions that will insert the
@@ -87,19 +87,19 @@ describe the type anew. This behavior is encapsulated in the
8787
## Source Locations and Line Information
8888

8989
In addition to data type descriptions the debugging information must also
90-
allow to map machine code locations back to source code locations in order
90+
allow mapping machine code locations back to source code locations in order
9191
to be useful. This functionality is also handled in this module. The
92-
following functions allow to control source mappings:
92+
following functions allow controlling source mappings:
9393

9494
+ `set_source_location()`
9595
+ `clear_source_location()`
9696
+ `start_emitting_source_locations()`
9797

98-
`set_source_location()` allows to set the current source location. All IR
98+
`set_source_location()` allows setting the current source location. All IR
9999
instructions created after a call to this function will be linked to the
100100
given source location, until another location is specified with
101101
`set_source_location()` or the source location is cleared with
102-
`clear_source_location()`. In the later case, subsequent IR instruction
102+
`clear_source_location()`. In the latter case, subsequent IR instructions
103103
will not be linked to any source location. As you can see, this is a
104104
stateful API (mimicking the one in LLVM), so be careful with source
105105
locations set by previous calls. It's probably best to not rely on any

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -471,9 +471,9 @@ fn report_eval_error<'tcx>(
471471
span,
472472
inline_fluent!(
473473
"evaluation of `{$instance}` failed {$num_frames ->
474-
[0] here
475-
*[other] inside this call
476-
}"
474+
[0] here
475+
*[other] inside this call
476+
}"
477477
),
478478
);
479479
for frame in frames {

0 commit comments

Comments
 (0)