Skip to content

Commit 4603ac3

Browse files
committed
Auto merge of #99451 - Dylan-DPC:rollup-ceghu18, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - #97183 (wf-check generators) - #98320 (Mention first and last macro in backtrace) - #99335 (Use split_once in FromStr docs) - #99347 (Use `LocalDefId` in `OpaqueTypeKey`) - #99392 (Fix debuginfo tests.) - #99404 (Use span_bug for unexpected field projection type) - #99410 (Update invalid atomic ordering lint) - #99434 (Fix `Skip::next` for non-fused inner iterators) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents c3f3550 + e301cd3 commit 4603ac3

File tree

114 files changed

+396
-514
lines changed

Some content is hidden

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

114 files changed

+396
-514
lines changed

compiler/rustc_borrowck/src/nll.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! The entry point of the NLL borrow checker.
22
33
use rustc_data_structures::vec_map::VecMap;
4-
use rustc_hir::def_id::DefId;
4+
use rustc_hir::def_id::LocalDefId;
55
use rustc_index::vec::IndexVec;
66
use rustc_infer::infer::InferCtxt;
77
use rustc_middle::mir::{create_dump_file, dump_enabled, dump_mir, PassWhere};
@@ -44,7 +44,7 @@ pub type PoloniusOutput = Output<RustcFacts>;
4444
/// closure requirements to propagate, and any generated errors.
4545
pub(crate) struct NllOutput<'tcx> {
4646
pub regioncx: RegionInferenceContext<'tcx>,
47-
pub opaque_type_values: VecMap<DefId, OpaqueHiddenType<'tcx>>,
47+
pub opaque_type_values: VecMap<LocalDefId, OpaqueHiddenType<'tcx>>,
4848
pub polonius_input: Option<Box<AllFacts>>,
4949
pub polonius_output: Option<Rc<PoloniusOutput>>,
5050
pub opt_closure_req: Option<ClosureRegionRequirements<'tcx>>,
@@ -373,7 +373,7 @@ pub(super) fn dump_annotation<'a, 'tcx>(
373373
body: &Body<'tcx>,
374374
regioncx: &RegionInferenceContext<'tcx>,
375375
closure_region_requirements: &Option<ClosureRegionRequirements<'_>>,
376-
opaque_type_values: &VecMap<DefId, OpaqueHiddenType<'tcx>>,
376+
opaque_type_values: &VecMap<LocalDefId, OpaqueHiddenType<'tcx>>,
377377
errors: &mut crate::error::BorrowckErrors<'tcx>,
378378
) {
379379
let tcx = infcx.tcx;

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_data_structures::fx::FxHashMap;
22
use rustc_data_structures::vec_map::VecMap;
3-
use rustc_hir::def_id::DefId;
3+
use rustc_hir::def_id::LocalDefId;
44
use rustc_hir::OpaqueTyOrigin;
55
use rustc_infer::infer::error_reporting::unexpected_hidden_region_diagnostic;
66
use rustc_infer::infer::InferCtxt;
@@ -63,8 +63,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
6363
&self,
6464
infcx: &InferCtxt<'_, 'tcx>,
6565
opaque_ty_decls: VecMap<OpaqueTypeKey<'tcx>, (OpaqueHiddenType<'tcx>, OpaqueTyOrigin)>,
66-
) -> VecMap<DefId, OpaqueHiddenType<'tcx>> {
67-
let mut result: VecMap<DefId, OpaqueHiddenType<'tcx>> = VecMap::new();
66+
) -> VecMap<LocalDefId, OpaqueHiddenType<'tcx>> {
67+
let mut result: VecMap<LocalDefId, OpaqueHiddenType<'tcx>> = VecMap::new();
6868
for (opaque_type_key, (concrete_type, origin)) in opaque_ty_decls {
6969
let substs = opaque_type_key.substs;
7070
debug!(?concrete_type, ?substs);
@@ -235,7 +235,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
235235
// lifetimes with 'static and remapping only those used in the
236236
// `impl Trait` return type, resulting in the parameters
237237
// shifting.
238-
let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id);
238+
let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id.to_def_id());
239239
debug!(?id_substs);
240240
let map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>> =
241241
substs.iter().enumerate().map(|(index, subst)| (subst, id_substs[index])).collect();
@@ -268,7 +268,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
268268
// This logic duplicates most of `check_opaque_meets_bounds`.
269269
// FIXME(oli-obk): Also do region checks here and then consider removing `check_opaque_meets_bounds` entirely.
270270
let param_env = self.tcx.param_env(def_id);
271-
let body_id = self.tcx.local_def_id_to_hir_id(def_id.as_local().unwrap());
271+
let body_id = self.tcx.local_def_id_to_hir_id(def_id);
272272
self.tcx.infer_ctxt().enter(move |infcx| {
273273
// Require the hidden type to be well-formed with only the generics of the opaque type.
274274
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the
@@ -296,7 +296,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
296296
infcx
297297
.report_mismatched_types(
298298
&ObligationCause::misc(instantiated_ty.span, body_id),
299-
self.tcx.mk_opaque(def_id, id_substs),
299+
self.tcx.mk_opaque(def_id.to_def_id(), id_substs),
300300
definition_ty,
301301
err,
302302
)
@@ -423,7 +423,7 @@ fn check_opaque_type_parameter_valid(
423423
struct ReverseMapper<'tcx> {
424424
tcx: TyCtxt<'tcx>,
425425

426-
opaque_type_def_id: DefId,
426+
opaque_type_def_id: LocalDefId,
427427
map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>>,
428428
map_missing_regions_to_empty: bool,
429429

@@ -437,7 +437,7 @@ struct ReverseMapper<'tcx> {
437437
impl<'tcx> ReverseMapper<'tcx> {
438438
fn new(
439439
tcx: TyCtxt<'tcx>,
440-
opaque_type_def_id: DefId,
440+
opaque_type_def_id: LocalDefId,
441441
map: FxHashMap<GenericArg<'tcx>, GenericArg<'tcx>>,
442442
hidden_ty: Ty<'tcx>,
443443
span: Span,

compiler/rustc_error_messages/locales/en-US/lint.ftl

-5
Original file line numberDiff line numberDiff line change
@@ -247,11 +247,6 @@ lint-atomic-ordering-invalid = `{$method}`'s failure ordering may not be `Releas
247247
.label = invalid failure ordering
248248
.help = consider using `Acquire` or `Relaxed` failure ordering instead
249249
250-
lint-atomic-ordering-invalid-fail-success = `{$method}`'s success ordering must be at least as strong as its failure ordering
251-
.fail-label = `{$fail_ordering}` failure ordering
252-
.success-label = `{$success_ordering}` success ordering
253-
.suggestion = consider using `{$success_suggestion}` success ordering instead
254-
255250
lint-unused-op = unused {$op} that must be used
256251
.label = the {$op} produces a value
257252
.suggestion = use `let _ = ...` to ignore the resulting value

compiler/rustc_errors/src/emitter.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,11 @@ pub trait Emitter {
399399
) {
400400
// Check for spans in macros, before `fix_multispans_in_extern_macros`
401401
// has a chance to replace them.
402-
let has_macro_spans = iter::once(&*span)
402+
let has_macro_spans: Vec<_> = iter::once(&*span)
403403
.chain(children.iter().map(|child| &child.span))
404404
.flat_map(|span| span.primary_spans())
405405
.flat_map(|sp| sp.macro_backtrace())
406-
.find_map(|expn_data| {
406+
.filter_map(|expn_data| {
407407
match expn_data.kind {
408408
ExpnKind::Root => None,
409409

@@ -413,7 +413,8 @@ pub trait Emitter {
413413

414414
ExpnKind::Macro(macro_kind, name) => Some((macro_kind, name)),
415415
}
416-
});
416+
})
417+
.collect();
417418

418419
if !backtrace {
419420
self.fix_multispans_in_extern_macros(source_map, span, children);
@@ -422,11 +423,22 @@ pub trait Emitter {
422423
self.render_multispans_macro_backtrace(span, children, backtrace);
423424

424425
if !backtrace {
425-
if let Some((macro_kind, name)) = has_macro_spans {
426-
let descr = macro_kind.descr();
426+
if let Some((macro_kind, name)) = has_macro_spans.first() {
427+
// Mark the actual macro this originates from
428+
let and_then = if let Some((macro_kind, last_name)) = has_macro_spans.last()
429+
&& last_name != name
430+
{
431+
let descr = macro_kind.descr();
432+
format!(
433+
" which comes from the expansion of the {descr} `{last_name}`",
434+
)
435+
} else {
436+
"".to_string()
437+
};
427438

439+
let descr = macro_kind.descr();
428440
let msg = format!(
429-
"this {level} originates in the {descr} `{name}` \
441+
"this {level} originates in the {descr} `{name}`{and_then} \
430442
(in Nightly builds, run with -Z macro-backtrace for more info)",
431443
);
432444

compiler/rustc_errors/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(drain_filter)]
77
#![feature(backtrace)]
88
#![feature(if_let_guard)]
9+
#![cfg_attr(bootstrap, feature(let_chains))]
910
#![feature(let_else)]
1011
#![feature(never_type)]
1112
#![feature(adt_const_params)]

compiler/rustc_infer/src/infer/canonical/query_response.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
153153
.opaque_type_storage
154154
.take_opaque_types()
155155
.into_iter()
156-
.map(|(k, v)| (self.tcx.mk_opaque(k.def_id, k.substs), v.hidden_type.ty))
156+
.map(|(k, v)| (self.tcx.mk_opaque(k.def_id.to_def_id(), k.substs), v.hidden_type.ty))
157157
.collect()
158158
}
159159

compiler/rustc_infer/src/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
938938
#[instrument(skip(self), level = "debug")]
939939
pub fn member_constraint(
940940
&self,
941-
opaque_type_def_id: DefId,
941+
opaque_type_def_id: LocalDefId,
942942
definition_span: Span,
943943
hidden_ty: Ty<'tcx>,
944944
region: ty::Region<'tcx>,

compiler/rustc_infer/src/infer/opaque_types.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
5151
return InferOk { value: ty, obligations: vec![] };
5252
}
5353
let mut obligations = vec![];
54-
let replace_opaque_type = |def_id| self.opaque_type_origin(def_id, span).is_some();
54+
let replace_opaque_type = |def_id: DefId| {
55+
def_id
56+
.as_local()
57+
.map_or(false, |def_id| self.opaque_type_origin(def_id, span).is_some())
58+
};
5559
let value = ty.fold_with(&mut ty::fold::BottomUpFolder {
5660
tcx: self.tcx,
5761
lt_op: |lt| lt,
@@ -96,6 +100,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
96100
let (a, b) = if a_is_expected { (a, b) } else { (b, a) };
97101
let process = |a: Ty<'tcx>, b: Ty<'tcx>| match *a.kind() {
98102
ty::Opaque(def_id, substs) if def_id.is_local() => {
103+
let def_id = def_id.expect_local();
99104
let origin = if self.defining_use_anchor.is_some() {
100105
// Check that this is `impl Trait` type is
101106
// declared by `parent_def_id` -- i.e., one whose
@@ -141,7 +146,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
141146
// no one encounters it in practice.
142147
// It does occur however in `fn fut() -> impl Future<Output = i32> { async { 42 } }`,
143148
// where it is of no concern, so we only check for TAITs.
144-
if let Some(OpaqueTyOrigin::TyAlias) = self.opaque_type_origin(did2, cause.span)
149+
if let Some(OpaqueTyOrigin::TyAlias) =
150+
did2.as_local().and_then(|did2| self.opaque_type_origin(did2, cause.span))
145151
{
146152
self.tcx
147153
.sess
@@ -399,8 +405,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
399405
}
400406

401407
#[instrument(skip(self), level = "trace")]
402-
pub fn opaque_type_origin(&self, opaque_def_id: DefId, span: Span) -> Option<OpaqueTyOrigin> {
403-
let def_id = opaque_def_id.as_local()?;
408+
pub fn opaque_type_origin(&self, def_id: LocalDefId, span: Span) -> Option<OpaqueTyOrigin> {
404409
let opaque_hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
405410
let parent_def_id = self.defining_use_anchor?;
406411
let item_kind = &self.tcx.hir().expect_item(def_id).kind;
@@ -409,7 +414,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
409414
span_bug!(
410415
span,
411416
"weird opaque type: {:#?}, {:#?}",
412-
opaque_def_id,
417+
def_id,
413418
item_kind
414419
)
415420
};
@@ -428,12 +433,11 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
428433
}
429434

430435
#[instrument(skip(self), level = "trace")]
431-
fn opaque_ty_origin_unchecked(&self, opaque_def_id: DefId, span: Span) -> OpaqueTyOrigin {
432-
let def_id = opaque_def_id.as_local().unwrap();
436+
fn opaque_ty_origin_unchecked(&self, def_id: LocalDefId, span: Span) -> OpaqueTyOrigin {
433437
let origin = match self.tcx.hir().expect_item(def_id).kind {
434438
hir::ItemKind::OpaqueTy(hir::OpaqueTy { origin, .. }) => origin,
435439
ref itemkind => {
436-
span_bug!(span, "weird opaque type: {:?}, {:#?}", opaque_def_id, itemkind)
440+
span_bug!(span, "weird opaque type: {:?}, {:#?}", def_id, itemkind)
437441
}
438442
};
439443
trace!(?origin);
@@ -557,7 +561,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
557561
obligations = self.at(&cause, param_env).eq(prev, hidden_ty)?.obligations;
558562
}
559563

560-
let item_bounds = tcx.bound_explicit_item_bounds(def_id);
564+
let item_bounds = tcx.bound_explicit_item_bounds(def_id.to_def_id());
561565

562566
for predicate in item_bounds.transpose_iter().map(|e| e.map_bound(|(p, _)| *p)) {
563567
debug!(?predicate);
@@ -579,7 +583,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
579583
}
580584
// Replace all other mentions of the same opaque type with the hidden type,
581585
// as the bounds must hold on the hidden type after all.
582-
ty::Opaque(def_id2, substs2) if def_id == def_id2 && substs == substs2 => {
586+
ty::Opaque(def_id2, substs2)
587+
if def_id.to_def_id() == def_id2 && substs == substs2 =>
588+
{
583589
hidden_ty
584590
}
585591
_ => ty,

compiler/rustc_infer/src/infer/region_constraints/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_data_structures::intern::Interned;
1212
use rustc_data_structures::sync::Lrc;
1313
use rustc_data_structures::undo_log::UndoLogs;
1414
use rustc_data_structures::unify as ut;
15-
use rustc_hir::def_id::DefId;
15+
use rustc_hir::def_id::LocalDefId;
1616
use rustc_index::vec::IndexVec;
1717
use rustc_middle::infer::unify_key::{RegionVidKey, UnifiedRegion};
1818
use rustc_middle::ty::ReStatic;
@@ -533,7 +533,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
533533

534534
pub fn member_constraint(
535535
&mut self,
536-
opaque_type_def_id: DefId,
536+
opaque_type_def_id: LocalDefId,
537537
definition_span: Span,
538538
hidden_ty: Ty<'tcx>,
539539
member_region: ty::Region<'tcx>,

compiler/rustc_lint/src/types.rs

+3-38
Original file line numberDiff line numberDiff line change
@@ -1434,10 +1434,6 @@ declare_lint! {
14341434
/// - Passing `Ordering::Release` or `Ordering::AcqRel` as the failure
14351435
/// ordering for any of `AtomicType::compare_exchange`,
14361436
/// `AtomicType::compare_exchange_weak`, or `AtomicType::fetch_update`.
1437-
///
1438-
/// - Passing in a pair of orderings to `AtomicType::compare_exchange`,
1439-
/// `AtomicType::compare_exchange_weak`, or `AtomicType::fetch_update`
1440-
/// where the failure ordering is stronger than the success ordering.
14411437
INVALID_ATOMIC_ORDERING,
14421438
Deny,
14431439
"usage of invalid atomic ordering in atomic operations and memory fences"
@@ -1544,9 +1540,9 @@ impl InvalidAtomicOrdering {
15441540
let Some((method, args)) = Self::inherent_atomic_method_call(cx, expr, &[sym::fetch_update, sym::compare_exchange, sym::compare_exchange_weak])
15451541
else {return };
15461542

1547-
let (success_order_arg, fail_order_arg) = match method {
1548-
sym::fetch_update => (&args[1], &args[2]),
1549-
sym::compare_exchange | sym::compare_exchange_weak => (&args[3], &args[4]),
1543+
let fail_order_arg = match method {
1544+
sym::fetch_update => &args[2],
1545+
sym::compare_exchange | sym::compare_exchange_weak => &args[4],
15501546
_ => return,
15511547
};
15521548

@@ -1568,37 +1564,6 @@ impl InvalidAtomicOrdering {
15681564
InvalidAtomicOrderingDiag { method, fail_order_arg_span: fail_order_arg.span },
15691565
);
15701566
}
1571-
1572-
let Some(success_ordering) = Self::match_ordering(cx, success_order_arg) else { return };
1573-
1574-
if matches!(
1575-
(success_ordering, fail_ordering),
1576-
(sym::Relaxed | sym::Release, sym::Acquire)
1577-
| (sym::Relaxed | sym::Release | sym::Acquire | sym::AcqRel, sym::SeqCst)
1578-
) {
1579-
let success_suggestion =
1580-
if success_ordering == sym::Release && fail_ordering == sym::Acquire {
1581-
sym::AcqRel
1582-
} else {
1583-
fail_ordering
1584-
};
1585-
cx.struct_span_lint(INVALID_ATOMIC_ORDERING, success_order_arg.span, |diag| {
1586-
diag.build(fluent::lint::atomic_ordering_invalid_fail_success)
1587-
.set_arg("method", method)
1588-
.set_arg("fail_ordering", fail_ordering)
1589-
.set_arg("success_ordering", success_ordering)
1590-
.set_arg("success_suggestion", success_suggestion)
1591-
.span_label(fail_order_arg.span, fluent::lint::fail_label)
1592-
.span_label(success_order_arg.span, fluent::lint::success_label)
1593-
.span_suggestion_short(
1594-
success_order_arg.span,
1595-
fluent::lint::suggestion,
1596-
format!("std::sync::atomic::Ordering::{success_suggestion}"),
1597-
Applicability::MaybeIncorrect,
1598-
)
1599-
.emit();
1600-
});
1601-
}
16021567
}
16031568
}
16041569

compiler/rustc_middle/src/infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub mod unify_key;
44
use crate::ty::Region;
55
use crate::ty::Ty;
66
use rustc_data_structures::sync::Lrc;
7-
use rustc_hir::def_id::DefId;
7+
use rustc_hir::def_id::LocalDefId;
88
use rustc_span::Span;
99

1010
/// Requires that `region` must be equal to one of the regions in `choice_regions`.
@@ -16,7 +16,7 @@ use rustc_span::Span;
1616
#[derive(Debug, Clone, HashStable, TypeFoldable, TypeVisitable, Lift)]
1717
pub struct MemberConstraint<'tcx> {
1818
/// The `DefId` of the opaque type causing this constraint: used for error reporting.
19-
pub opaque_type_def_id: DefId,
19+
pub opaque_type_def_id: LocalDefId,
2020

2121
/// The span where the hidden type was instantiated.
2222
pub definition_span: Span,

compiler/rustc_middle/src/mir/query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ pub struct BorrowCheckResult<'tcx> {
235235
/// All the opaque types that are restricted to concrete types
236236
/// by this function. Unlike the value in `TypeckResults`, this has
237237
/// unerased regions.
238-
pub concrete_opaque_types: VecMap<DefId, OpaqueHiddenType<'tcx>>,
238+
pub concrete_opaque_types: VecMap<LocalDefId, OpaqueHiddenType<'tcx>>,
239239
pub closure_requirements: Option<ClosureRegionRequirements<'tcx>>,
240240
pub used_mut_upvars: SmallVec<[Field; 8]>,
241241
pub tainted_by_errors: Option<ErrorGuaranteed>,

compiler/rustc_middle/src/ty/closure.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ impl<'tcx> CapturedPlace<'tcx> {
182182
.unwrap();
183183
}
184184
ty => {
185-
bug!("Unexpected type {:?} for `Field` projection", ty)
185+
span_bug!(
186+
self.get_capture_kind_span(tcx),
187+
"Unexpected type {:?} for `Field` projection",
188+
ty
189+
)
186190
}
187191
},
188192

compiler/rustc_middle/src/ty/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ pub struct TypeckResults<'tcx> {
542542
/// even if they are only set in dead code (which doesn't show up in MIR).
543543
/// For type-alias-impl-trait, this map is only used to prevent query cycles,
544544
/// so the hidden types are all `None`.
545-
pub concrete_opaque_types: VecMap<DefId, Option<Ty<'tcx>>>,
545+
pub concrete_opaque_types: VecMap<LocalDefId, Option<Ty<'tcx>>>,
546546

547547
/// Tracks the minimum captures required for a closure;
548548
/// see `MinCaptureInformationMap` for more details.

0 commit comments

Comments
 (0)