Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit bda32a4

Browse files
committed
Auto merge of rust-lang#108301 - Dylan-DPC:rollup-70zpkt0, r=Dylan-DPC
Rollup of 7 pull requests Successful merges: - rust-lang#108000 (lint: don't suggest MaybeUninit::assume_init for uninhabited types) - rust-lang#108105 (Explain the default panic hook better) - rust-lang#108141 (Add rpitit queries) - rust-lang#108272 (docs: wrong naming convention in struct keyword doc) - rust-lang#108285 (remove unstable `pick_stable_methods_before_any_unstable` flag) - rust-lang#108289 (Name placeholder in some region errors) - rust-lang#108290 (Add a test for default trait method with RPITITs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3fee48c + 60c0972 commit bda32a4

File tree

27 files changed

+429
-323
lines changed

27 files changed

+429
-323
lines changed

compiler/rustc_hir/src/definitions.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ pub enum DefPathData {
280280
AnonConst,
281281
/// An `impl Trait` type node.
282282
ImplTrait,
283+
/// `impl Trait` generated associated type node.
284+
ImplTraitAssocTy,
283285
}
284286

285287
impl Definitions {
@@ -403,7 +405,7 @@ impl DefPathData {
403405
TypeNs(name) | ValueNs(name) | MacroNs(name) | LifetimeNs(name) => Some(name),
404406

405407
Impl | ForeignMod | CrateRoot | Use | GlobalAsm | ClosureExpr | Ctor | AnonConst
406-
| ImplTrait => None,
408+
| ImplTrait | ImplTraitAssocTy => None,
407409
}
408410
}
409411

@@ -422,7 +424,7 @@ impl DefPathData {
422424
ClosureExpr => DefPathDataName::Anon { namespace: sym::closure },
423425
Ctor => DefPathDataName::Anon { namespace: sym::constructor },
424426
AnonConst => DefPathDataName::Anon { namespace: sym::constant },
425-
ImplTrait => DefPathDataName::Anon { namespace: sym::opaque },
427+
ImplTrait | ImplTraitAssocTy => DefPathDataName::Anon { namespace: sym::opaque },
426428
}
427429
}
428430
}

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,17 +1095,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10951095
}
10961096

10971097
fn pick_core(&self) -> Option<PickResult<'tcx>> {
1098-
let pick = self.pick_all_method(Some(&mut vec![]));
1099-
1100-
// In this case unstable picking is done by `pick_method`.
1101-
if !self.tcx.sess.opts.unstable_opts.pick_stable_methods_before_any_unstable {
1102-
return pick;
1103-
}
1104-
1105-
if pick.is_none() {
1106-
return self.pick_all_method(None);
1107-
}
1108-
pick
1098+
// Pick stable methods only first, and consider unstable candidates if not found.
1099+
self.pick_all_method(Some(&mut vec![])).or_else(|| self.pick_all_method(None))
11091100
}
11101101

11111102
fn pick_all_method(
@@ -1244,54 +1235,11 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
12441235
})
12451236
}
12461237

1247-
fn pick_method_with_unstable(&self, self_ty: Ty<'tcx>) -> Option<PickResult<'tcx>> {
1248-
debug!("pick_method_with_unstable(self_ty={})", self.ty_to_string(self_ty));
1249-
1250-
let mut possibly_unsatisfied_predicates = Vec::new();
1251-
1252-
for (kind, candidates) in
1253-
&[("inherent", &self.inherent_candidates), ("extension", &self.extension_candidates)]
1254-
{
1255-
debug!("searching {} candidates", kind);
1256-
let res = self.consider_candidates(
1257-
self_ty,
1258-
candidates,
1259-
&mut possibly_unsatisfied_predicates,
1260-
Some(&mut vec![]),
1261-
);
1262-
if res.is_some() {
1263-
return res;
1264-
}
1265-
}
1266-
1267-
for (kind, candidates) in
1268-
&[("inherent", &self.inherent_candidates), ("extension", &self.extension_candidates)]
1269-
{
1270-
debug!("searching unstable {kind} candidates");
1271-
let res = self.consider_candidates(
1272-
self_ty,
1273-
candidates,
1274-
&mut possibly_unsatisfied_predicates,
1275-
None,
1276-
);
1277-
if res.is_some() {
1278-
return res;
1279-
}
1280-
}
1281-
1282-
self.unsatisfied_predicates.borrow_mut().extend(possibly_unsatisfied_predicates);
1283-
None
1284-
}
1285-
12861238
fn pick_method(
12871239
&self,
12881240
self_ty: Ty<'tcx>,
12891241
mut unstable_candidates: Option<&mut Vec<(Candidate<'tcx>, Symbol)>>,
12901242
) -> Option<PickResult<'tcx>> {
1291-
if !self.tcx.sess.opts.unstable_opts.pick_stable_methods_before_any_unstable {
1292-
return self.pick_method_with_unstable(self_ty);
1293-
}
1294-
12951243
debug!("pick_method(self_ty={})", self.ty_to_string(self_ty));
12961244

12971245
let mut possibly_unsatisfied_predicates = Vec::new();

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,21 +129,16 @@ pub(super) fn note_and_explain_region<'tcx>(
129129
alt_span: Option<Span>,
130130
) {
131131
let (description, span) = match *region {
132-
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::ReStatic => {
133-
msg_span_from_free_region(tcx, region, alt_span)
132+
ty::ReEarlyBound(_) | ty::ReFree(_) | ty::RePlaceholder(_) | ty::ReStatic => {
133+
msg_span_from_named_region(tcx, region, alt_span)
134134
}
135135

136-
ty::RePlaceholder(_) => return,
137-
138136
ty::ReError(_) => return,
139137

140-
// FIXME(#13998) RePlaceholder should probably print like
141-
// ReFree rather than dumping Debug output on the user.
142-
//
143138
// We shouldn't really be having unification failures with ReVar
144139
// and ReLateBound though.
145140
ty::ReVar(_) | ty::ReLateBound(..) | ty::ReErased => {
146-
(format!("lifetime {:?}", region), alt_span)
141+
(format!("lifetime `{region}`"), alt_span)
147142
}
148143
};
149144

@@ -157,12 +152,12 @@ fn explain_free_region<'tcx>(
157152
region: ty::Region<'tcx>,
158153
suffix: &str,
159154
) {
160-
let (description, span) = msg_span_from_free_region(tcx, region, None);
155+
let (description, span) = msg_span_from_named_region(tcx, region, None);
161156

162157
label_msg_span(err, prefix, description, span, suffix);
163158
}
164159

165-
fn msg_span_from_free_region<'tcx>(
160+
fn msg_span_from_named_region<'tcx>(
166161
tcx: TyCtxt<'tcx>,
167162
region: ty::Region<'tcx>,
168163
alt_span: Option<Span>,
@@ -173,6 +168,18 @@ fn msg_span_from_free_region<'tcx>(
173168
(msg, Some(span))
174169
}
175170
ty::ReStatic => ("the static lifetime".to_owned(), alt_span),
171+
ty::RePlaceholder(ty::PlaceholderRegion {
172+
name: ty::BoundRegionKind::BrNamed(def_id, name),
173+
..
174+
}) => (format!("the lifetime `{name}` as defined here"), Some(tcx.def_span(def_id))),
175+
ty::RePlaceholder(ty::PlaceholderRegion {
176+
name: ty::BoundRegionKind::BrAnon(_, Some(span)),
177+
..
178+
}) => (format!("the anonymous lifetime defined here"), Some(span)),
179+
ty::RePlaceholder(ty::PlaceholderRegion {
180+
name: ty::BoundRegionKind::BrAnon(_, None),
181+
..
182+
}) => (format!("an anonymous lifetime"), None),
176183
_ => bug!("{:?}", region),
177184
}
178185
}

compiler/rustc_interface/src/tests.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,6 @@ fn test_unstable_options_tracking_hash() {
776776
tracked!(packed_bundled_libs, true);
777777
tracked!(panic_abort_tests, true);
778778
tracked!(panic_in_drop, PanicStrategy::Abort);
779-
tracked!(pick_stable_methods_before_any_unstable, false);
780779
tracked!(plt, Some(true));
781780
tracked!(polonius, true);
782781
tracked!(precise_enum_drop_elaboration, false);

compiler/rustc_lint/src/builtin.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2635,7 +2635,13 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
26352635
cx.emit_spanned_lint(
26362636
INVALID_VALUE,
26372637
expr.span,
2638-
BuiltinUnpermittedTypeInit { msg, ty: conjured_ty, label: expr.span, sub },
2638+
BuiltinUnpermittedTypeInit {
2639+
msg,
2640+
ty: conjured_ty,
2641+
label: expr.span,
2642+
sub,
2643+
tcx: cx.tcx,
2644+
},
26392645
);
26402646
}
26412647
}

compiler/rustc_lint/src/lints.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ use rustc_errors::{
88
};
99
use rustc_hir::def_id::DefId;
1010
use rustc_macros::{LintDiagnostic, Subdiagnostic};
11-
use rustc_middle::ty::{PolyExistentialTraitRef, Predicate, Ty, TyCtxt};
11+
use rustc_middle::ty::{
12+
inhabitedness::InhabitedPredicate, PolyExistentialTraitRef, Predicate, Ty, TyCtxt,
13+
};
1214
use rustc_session::parse::ParseSess;
1315
use rustc_span::{edition::Edition, sym, symbol::Ident, Span, Symbol};
1416

@@ -419,6 +421,7 @@ pub struct BuiltinUnpermittedTypeInit<'a> {
419421
pub ty: Ty<'a>,
420422
pub label: Span,
421423
pub sub: BuiltinUnpermittedTypeInitSub,
424+
pub tcx: TyCtxt<'a>,
422425
}
423426

424427
impl<'a> DecorateLint<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
@@ -428,7 +431,13 @@ impl<'a> DecorateLint<'a, ()> for BuiltinUnpermittedTypeInit<'_> {
428431
) -> &'b mut rustc_errors::DiagnosticBuilder<'a, ()> {
429432
diag.set_arg("ty", self.ty);
430433
diag.span_label(self.label, fluent::lint_builtin_unpermitted_type_init_label);
431-
diag.span_label(self.label, fluent::lint_builtin_unpermitted_type_init_label_suggestion);
434+
if let InhabitedPredicate::True = self.ty.inhabited_predicate(self.tcx) {
435+
// Only suggest late `MaybeUninit::assume_init` initialization if the type is inhabited.
436+
diag.span_label(
437+
self.label,
438+
fluent::lint_builtin_unpermitted_type_init_label_suggestion,
439+
);
440+
}
432441
self.sub.add_to_diagnostic(diag);
433442
diag
434443
}

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ provide! { tcx, def_id, other, cdata,
254254
.process_decoded(tcx, || panic!("{def_id:?} does not have trait_impl_trait_tys")))
255255
}
256256

257+
associated_items_for_impl_trait_in_trait => { table_defaulted_array }
258+
257259
visibility => { cdata.get_visibility(def_id.index) }
258260
adt_def => { cdata.get_adt_def(def_id.index, tcx) }
259261
adt_destructor => {

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,11 @@ fn should_encode_trait_impl_trait_tys(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
11291129
})
11301130
}
11311131

1132+
// Return `false` to avoid encoding impl trait in trait, while we don't use the query.
1133+
fn should_encode_fn_impl_trait_in_trait<'tcx>(_tcx: TyCtxt<'tcx>, _def_id: DefId) -> bool {
1134+
false
1135+
}
1136+
11321137
impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
11331138
fn encode_attrs(&mut self, def_id: LocalDefId) {
11341139
let tcx = self.tcx;
@@ -1137,8 +1142,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
11371142
is_doc_hidden: false,
11381143
};
11391144
let attr_iter = tcx
1140-
.hir()
1141-
.attrs(tcx.hir().local_def_id_to_hir_id(def_id))
1145+
.opt_local_def_id_to_hir_id(def_id)
1146+
.map_or(Default::default(), |hir_id| tcx.hir().attrs(hir_id))
11421147
.iter()
11431148
.filter(|attr| analyze_attr(attr, &mut state));
11441149

@@ -1211,6 +1216,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
12111216
{
12121217
record!(self.tables.trait_impl_trait_tys[def_id] <- table);
12131218
}
1219+
if should_encode_fn_impl_trait_in_trait(tcx, def_id) {
1220+
let table = tcx.associated_items_for_impl_trait_in_trait(def_id);
1221+
record_defaulted_array!(self.tables.associated_items_for_impl_trait_in_trait[def_id] <- table);
1222+
}
12141223
}
12151224

12161225
let inherent_impls = tcx.with_stable_hashing_context(|hcx| {

compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ define_tables! {
354354
explicit_item_bounds: Table<DefIndex, LazyArray<(ty::Predicate<'static>, Span)>>,
355355
inferred_outlives_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
356356
inherent_impls: Table<DefIndex, LazyArray<DefIndex>>,
357+
associated_items_for_impl_trait_in_trait: Table<DefIndex, LazyArray<DefId>>,
357358

358359
- optional:
359360
attributes: Table<DefIndex, LazyArray<ast::Attribute>>,

compiler/rustc_middle/src/hir/map/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,13 @@ impl<'hir> Map<'hir> {
849849
}
850850
}
851851

852+
pub fn get_fn_output(self, def_id: LocalDefId) -> Option<&'hir FnRetTy<'hir>> {
853+
match self.tcx.hir_owner(OwnerId { def_id }) {
854+
Some(Owner { node, .. }) => node.fn_decl().map(|fn_decl| &fn_decl.output),
855+
_ => None,
856+
}
857+
}
858+
852859
pub fn expect_variant(self, id: HirId) -> &'hir Variant<'hir> {
853860
match self.find(id) {
854861
Some(Node::Variant(variant)) => variant,

0 commit comments

Comments
 (0)