Skip to content

Commit 2f2c438

Browse files
committed
Auto merge of rust-lang#111358 - compiler-errors:rollup-yv27vrp, r=compiler-errors
Rollup of 6 pull requests Successful merges: - rust-lang#104070 (Prevent aborting guard from aborting the process in a forced unwind) - rust-lang#109410 (Introduce `AliasKind::Inherent` for inherent associated types) - rust-lang#111004 (Migrate `mir_transform` to translatable diagnostics) - rust-lang#111118 (Suggest struct when we get colon in fileds in enum) - rust-lang#111170 (Diagnostic args are still args if they're documented) - rust-lang#111354 (Fix miscompilation when calling default methods on `Future`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents dfe3188 + bbea63f commit 2f2c438

File tree

133 files changed

+2066
-485
lines changed

Some content is hidden

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

133 files changed

+2066
-485
lines changed

Cargo.lock

+3
Original file line numberDiff line numberDiff line change
@@ -3353,6 +3353,7 @@ dependencies = [
33533353
"rustc_middle",
33543354
"rustc_mir_build",
33553355
"rustc_mir_dataflow",
3356+
"rustc_mir_transform",
33563357
"rustc_monomorphize",
33573358
"rustc_parse",
33583359
"rustc_passes",
@@ -3861,8 +3862,10 @@ dependencies = [
38613862
"rustc_const_eval",
38623863
"rustc_data_structures",
38633864
"rustc_errors",
3865+
"rustc_fluent_macro",
38643866
"rustc_hir",
38653867
"rustc_index",
3868+
"rustc_macros",
38663869
"rustc_middle",
38673870
"rustc_mir_dataflow",
38683871
"rustc_serialize",

compiler/rustc_codegen_gcc/src/builder.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1227,6 +1227,11 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
12271227
(value1, value2)
12281228
}
12291229

1230+
fn filter_landing_pad(&mut self, pers_fn: RValue<'gcc>) -> (RValue<'gcc>, RValue<'gcc>) {
1231+
// TODO(antoyo): generate the correct landing pad
1232+
self.cleanup_landing_pad(pers_fn)
1233+
}
1234+
12301235
#[cfg(feature="master")]
12311236
fn resume(&mut self, exn0: RValue<'gcc>, _exn1: RValue<'gcc>) {
12321237
let exn_type = exn0.get_type();

compiler/rustc_codegen_llvm/src/builder.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -985,13 +985,20 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
985985

986986
fn cleanup_landing_pad(&mut self, pers_fn: &'ll Value) -> (&'ll Value, &'ll Value) {
987987
let ty = self.type_struct(&[self.type_i8p(), self.type_i32()], false);
988-
let landing_pad = self.landing_pad(ty, pers_fn, 1 /* FIXME should this be 0? */);
988+
let landing_pad = self.landing_pad(ty, pers_fn, 0);
989989
unsafe {
990990
llvm::LLVMSetCleanup(landing_pad, llvm::True);
991991
}
992992
(self.extract_value(landing_pad, 0), self.extract_value(landing_pad, 1))
993993
}
994994

995+
fn filter_landing_pad(&mut self, pers_fn: &'ll Value) -> (&'ll Value, &'ll Value) {
996+
let ty = self.type_struct(&[self.type_i8p(), self.type_i32()], false);
997+
let landing_pad = self.landing_pad(ty, pers_fn, 1);
998+
self.add_clause(landing_pad, self.const_array(self.type_i8p(), &[]));
999+
(self.extract_value(landing_pad, 0), self.extract_value(landing_pad, 1))
1000+
}
1001+
9951002
fn resume(&mut self, exn0: &'ll Value, exn1: &'ll Value) {
9961003
let ty = self.type_struct(&[self.type_i8p(), self.type_i32()], false);
9971004
let mut exn = self.const_poison(ty);

compiler/rustc_codegen_ssa/src/mir/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
16001600
bx = Bx::build(self.cx, llbb);
16011601

16021602
let llpersonality = self.cx.eh_personality();
1603-
bx.cleanup_landing_pad(llpersonality);
1603+
bx.filter_landing_pad(llpersonality);
16041604

16051605
funclet = None;
16061606
}

compiler/rustc_codegen_ssa/src/traits/builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ pub trait BuilderMethods<'a, 'tcx>:
274274

275275
// These are used by everyone except msvc
276276
fn cleanup_landing_pad(&mut self, pers_fn: Self::Value) -> (Self::Value, Self::Value);
277+
fn filter_landing_pad(&mut self, pers_fn: Self::Value) -> (Self::Value, Self::Value);
277278
fn resume(&mut self, exn0: Self::Value, exn1: Self::Value);
278279

279280
// These are used only by msvc

compiler/rustc_driver_impl/Cargo.toml

+6-2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ rustc_interface = { path = "../rustc_interface" }
5151
rustc_ast = { path = "../rustc_ast" }
5252
rustc_span = { path = "../rustc_span" }
5353
rustc_hir_analysis = { path = "../rustc_hir_analysis" }
54+
rustc_mir_transform = { path = "../rustc_mir_transform" }
5455

5556
[target.'cfg(unix)'.dependencies]
5657
libc = "0.2"
@@ -64,5 +65,8 @@ features = [
6465
[features]
6566
llvm = ['rustc_interface/llvm']
6667
max_level_info = ['rustc_log/max_level_info']
67-
rustc_use_parallel_compiler = ['rustc_data_structures/rustc_use_parallel_compiler', 'rustc_interface/rustc_use_parallel_compiler',
68-
'rustc_middle/rustc_use_parallel_compiler']
68+
rustc_use_parallel_compiler = [
69+
'rustc_data_structures/rustc_use_parallel_compiler',
70+
'rustc_interface/rustc_use_parallel_compiler',
71+
'rustc_middle/rustc_use_parallel_compiler'
72+
]

compiler/rustc_driver_impl/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[
9999
rustc_middle::DEFAULT_LOCALE_RESOURCE,
100100
rustc_mir_build::DEFAULT_LOCALE_RESOURCE,
101101
rustc_mir_dataflow::DEFAULT_LOCALE_RESOURCE,
102+
rustc_mir_transform::DEFAULT_LOCALE_RESOURCE,
102103
rustc_monomorphize::DEFAULT_LOCALE_RESOURCE,
103104
rustc_parse::DEFAULT_LOCALE_RESOURCE,
104105
rustc_passes::DEFAULT_LOCALE_RESOURCE,

compiler/rustc_errors/src/diagnostic_builder.rs

+8
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,14 @@ impl<'a, G: EmissionGuarantee> DiagnosticBuilder<'a, G> {
571571
Some((diagnostic, handler))
572572
}
573573

574+
/// Retrieves the [`Handler`] if available
575+
pub fn handler(&self) -> Option<&Handler> {
576+
match self.inner.state {
577+
DiagnosticBuilderState::Emittable(handler) => Some(handler),
578+
DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => None,
579+
}
580+
}
581+
574582
/// Buffers the diagnostic for later emission,
575583
/// unless handler has disabled such buffering.
576584
pub fn buffer(self, buffered_diagnostics: &mut Vec<Diagnostic>) {

compiler/rustc_hir_analysis/src/astconv/mod.rs

+35-26
Original file line numberDiff line numberDiff line change
@@ -2419,6 +2419,10 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
24192419
return Ok(None);
24202420
}
24212421

2422+
//
2423+
// Select applicable inherent associated type candidates modulo regions.
2424+
//
2425+
24222426
// In contexts that have no inference context, just make a new one.
24232427
// We do need a local variable to store it, though.
24242428
let infcx_;
@@ -2431,14 +2435,18 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
24312435
}
24322436
};
24332437

2434-
let param_env = tcx.param_env(block.owner.to_def_id());
2438+
// FIXME(inherent_associated_types): Acquiring the ParamEnv this early leads to cycle errors
2439+
// when inside of an ADT (#108491) or where clause.
2440+
let param_env = tcx.param_env(block.owner);
24352441
let cause = ObligationCause::misc(span, block.owner.def_id);
24362442

24372443
let mut fulfillment_errors = Vec::new();
24382444
let mut applicable_candidates: Vec<_> = infcx.probe(|_| {
24392445
let universe = infcx.create_next_universe();
24402446

24412447
// Regions are not considered during selection.
2448+
// FIXME(non_lifetime_binders): Here we are "truncating" or "flattening" the universes
2449+
// of type and const binders. Is that correct in the selection phase? See also #109505.
24422450
let self_ty = tcx.replace_escaping_bound_vars_uncached(
24432451
self_ty,
24442452
FnMutDelegate {
@@ -2454,41 +2462,40 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
24542462

24552463
candidates
24562464
.iter()
2457-
.filter_map(|&(impl_, (assoc_item, def_scope))| {
2465+
.copied()
2466+
.filter(|&(impl_, _)| {
24582467
infcx.probe(|_| {
24592468
let ocx = ObligationCtxt::new_in_snapshot(&infcx);
24602469

2461-
let impl_ty = tcx.type_of(impl_);
24622470
let impl_substs = infcx.fresh_item_substs(impl_);
2463-
let impl_ty = impl_ty.subst(tcx, impl_substs);
2471+
let impl_ty = tcx.type_of(impl_).subst(tcx, impl_substs);
24642472
let impl_ty = ocx.normalize(&cause, param_env, impl_ty);
24652473

2466-
// Check that the Self-types can be related.
2467-
// FIXME(fmease): Should we use `eq` here?
2468-
ocx.sup(&ObligationCause::dummy(), param_env, impl_ty, self_ty).ok()?;
2474+
// Check that the self types can be related.
2475+
// FIXME(inherent_associated_types): Should we use `eq` here? Method probing uses
2476+
// `sup` for this situtation, too. What for? To constrain inference variables?
2477+
if ocx.sup(&ObligationCause::dummy(), param_env, impl_ty, self_ty).is_err()
2478+
{
2479+
return false;
2480+
}
24692481

24702482
// Check whether the impl imposes obligations we have to worry about.
2471-
let impl_bounds = tcx.predicates_of(impl_);
2472-
let impl_bounds = impl_bounds.instantiate(tcx, impl_substs);
2473-
2483+
let impl_bounds = tcx.predicates_of(impl_).instantiate(tcx, impl_substs);
24742484
let impl_bounds = ocx.normalize(&cause, param_env, impl_bounds);
2475-
24762485
let impl_obligations = traits::predicates_for_generics(
24772486
|_, _| cause.clone(),
24782487
param_env,
24792488
impl_bounds,
24802489
);
2481-
24822490
ocx.register_obligations(impl_obligations);
24832491

24842492
let mut errors = ocx.select_where_possible();
24852493
if !errors.is_empty() {
24862494
fulfillment_errors.append(&mut errors);
2487-
return None;
2495+
return false;
24882496
}
24892497

2490-
// FIXME(fmease): Unsolved vars can escape this InferCtxt snapshot.
2491-
Some((assoc_item, def_scope, infcx.resolve_vars_if_possible(impl_substs)))
2498+
true
24922499
})
24932500
})
24942501
.collect()
@@ -2497,24 +2504,26 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
24972504
if applicable_candidates.len() > 1 {
24982505
return Err(self.complain_about_ambiguous_inherent_assoc_type(
24992506
name,
2500-
applicable_candidates.into_iter().map(|(candidate, ..)| candidate).collect(),
2507+
applicable_candidates.into_iter().map(|(_, (candidate, _))| candidate).collect(),
25012508
span,
25022509
));
25032510
}
25042511

2505-
if let Some((assoc_item, def_scope, impl_substs)) = applicable_candidates.pop() {
2512+
if let Some((impl_, (assoc_item, def_scope))) = applicable_candidates.pop() {
25062513
self.check_assoc_ty(assoc_item, name, def_scope, block, span);
25072514

2508-
// FIXME(inherent_associated_types): To fully *confirm* the *probed* candidate, we still
2509-
// need to relate the Self-type with fresh item substs & register region obligations for
2510-
// regionck to prove/disprove.
2511-
2512-
let item_substs =
2513-
self.create_substs_for_associated_item(span, assoc_item, segment, impl_substs);
2515+
// FIXME(fmease): Currently creating throwaway `parent_substs` to please
2516+
// `create_substs_for_associated_item`. Modify the latter instead (or sth. similar) to
2517+
// not require the parent substs logic.
2518+
let parent_substs = InternalSubsts::identity_for_item(tcx, impl_);
2519+
let substs =
2520+
self.create_substs_for_associated_item(span, assoc_item, segment, parent_substs);
2521+
let substs = tcx.mk_substs_from_iter(
2522+
std::iter::once(ty::GenericArg::from(self_ty))
2523+
.chain(substs.into_iter().skip(parent_substs.len())),
2524+
);
25142525

2515-
// FIXME(fmease, #106722): Check if the bounds on the parameters of the
2516-
// associated type hold, if any.
2517-
let ty = tcx.type_of(assoc_item).subst(tcx, item_substs);
2526+
let ty = tcx.mk_alias(ty::Inherent, tcx.mk_alias_ty(assoc_item, substs));
25182527

25192528
return Ok(Some((ty, assoc_item)));
25202529
}

compiler/rustc_hir_analysis/src/coherence/orphan.rs

+13
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,19 @@ fn do_orphan_check_impl<'tcx>(
210210
NonlocalImpl::DisallowOther,
211211
),
212212

213+
// ```
214+
// struct S<T>(T);
215+
// impl<T: ?Sized> S<T> {
216+
// type This = T;
217+
// }
218+
// impl<T: ?Sized> AutoTrait for S<T>::This {}
219+
// ```
220+
// FIXME(inherent_associated_types): The example code above currently leads to a cycle
221+
ty::Alias(AliasKind::Inherent, _) => (
222+
LocalImpl::Disallow { problematic_kind: "associated type" },
223+
NonlocalImpl::DisallowOther,
224+
),
225+
213226
// type Opaque = impl Trait;
214227
// impl AutoTrait for Opaque {}
215228
ty::Alias(AliasKind::Opaque, _) => (

compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1948,7 +1948,7 @@ fn is_late_bound_map(
19481948
ty::Param(param_ty) => {
19491949
self.arg_is_constrained[param_ty.index as usize] = true;
19501950
}
1951-
ty::Alias(ty::Projection, _) => return ControlFlow::Continue(()),
1951+
ty::Alias(ty::Projection | ty::Inherent, _) => return ControlFlow::Continue(()),
19521952
_ => (),
19531953
}
19541954
t.super_visit_with(self)

compiler/rustc_hir_analysis/src/collect/type_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
127127
// the def_id that this query was called with. We filter to only type and const args here
128128
// as a precaution for if it's ever allowed to elide lifetimes in GAT's. It currently isn't
129129
// but it can't hurt to be safe ^^
130-
if let ty::Alias(ty::Projection, projection) = ty.kind() {
130+
if let ty::Alias(ty::Projection | ty::Inherent, projection) = ty.kind() {
131131
let generics = tcx.generics_of(projection.def_id);
132132

133133
let arg_index = segment

compiler/rustc_hir_analysis/src/constrained_generic_params.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct ParameterCollector {
5959
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParameterCollector {
6060
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
6161
match *t.kind() {
62-
ty::Alias(ty::Projection, ..) if !self.include_nonconstraining => {
62+
ty::Alias(ty::Projection | ty::Inherent, ..) if !self.include_nonconstraining => {
6363
// projections are not injective
6464
return ControlFlow::Continue(());
6565
}

compiler/rustc_hir_analysis/src/outlives/implicit_infer.rs

+3
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,9 @@ fn insert_required_predicates_to_be_wf<'tcx>(
210210
);
211211
}
212212

213+
// FIXME(inherent_associated_types): Handle this case properly.
214+
ty::Alias(ty::Inherent, _) => {}
215+
213216
_ => {}
214217
}
215218
}

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -843,7 +843,7 @@ fn find_param_in_ty<'tcx>(
843843
return true;
844844
}
845845
if let ty::GenericArgKind::Type(ty) = arg.unpack()
846-
&& let ty::Alias(ty::Projection, ..) = ty.kind()
846+
&& let ty::Alias(ty::Projection | ty::Inherent, ..) = ty.kind()
847847
{
848848
// This logic may seem a bit strange, but typically when
849849
// we have a projection type in a function signature, the

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
300300
match ty.kind() {
301301
ty::Adt(adt_def, _) => Some(*adt_def),
302302
// FIXME(#104767): Should we handle bound regions here?
303-
ty::Alias(ty::Projection, _) if !ty.has_escaping_bound_vars() => {
303+
ty::Alias(ty::Projection | ty::Inherent, _) if !ty.has_escaping_bound_vars() => {
304304
self.normalize(span, ty).ty_adt_def()
305305
}
306306
_ => None,

compiler/rustc_hir_typeck/src/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2211,7 +2211,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22112211
| ty::Float(_)
22122212
| ty::Adt(_, _)
22132213
| ty::Str
2214-
| ty::Alias(ty::Projection, _)
2214+
| ty::Alias(ty::Projection | ty::Inherent, _)
22152215
| ty::Param(_) => format!("{deref_ty}"),
22162216
// we need to test something like <&[_]>::len or <(&[u32])>::len
22172217
// and Vec::function();

compiler/rustc_infer/src/infer/combine.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ impl<'tcx> InferCtxt<'tcx> {
127127
bug!()
128128
}
129129

130-
(_, ty::Alias(AliasKind::Projection, _)) | (ty::Alias(AliasKind::Projection, _), _)
130+
(_, ty::Alias(AliasKind::Projection | AliasKind::Inherent, _))
131+
| (ty::Alias(AliasKind::Projection | AliasKind::Inherent, _), _)
131132
if self.tcx.trait_solver_next() =>
132133
{
133134
relation.register_type_relate_obligation(a, b);

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -2354,7 +2354,9 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
23542354
let labeled_user_string = match bound_kind {
23552355
GenericKind::Param(ref p) => format!("the parameter type `{}`", p),
23562356
GenericKind::Alias(ref p) => match p.kind(self.tcx) {
2357-
ty::AliasKind::Projection => format!("the associated type `{}`", p),
2357+
ty::AliasKind::Projection | ty::AliasKind::Inherent => {
2358+
format!("the associated type `{}`", p)
2359+
}
23582360
ty::AliasKind::Opaque => format!("the opaque type `{}`", p),
23592361
},
23602362
};

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
7171
#traits-as-parameters",
7272
);
7373
}
74-
(ty::Alias(ty::Projection, _), ty::Alias(ty::Projection, _)) => {
74+
(ty::Alias(ty::Projection | ty::Inherent, _), ty::Alias(ty::Projection | ty::Inherent, _)) => {
7575
diag.note("an associated type was expected, but a different one was found");
7676
}
77+
// FIXME(inherent_associated_types): Extend this to support `ty::Inherent`, too.
7778
(ty::Param(p), ty::Alias(ty::Projection, proj)) | (ty::Alias(ty::Projection, proj), ty::Param(p))
7879
if !tcx.is_impl_trait_in_trait(proj.def_id) =>
7980
{
@@ -222,7 +223,7 @@ impl<T> Trait<T> for X {
222223
diag.span_label(p_span, "this type parameter");
223224
}
224225
}
225-
(ty::Alias(ty::Projection, proj_ty), _) if !tcx.is_impl_trait_in_trait(proj_ty.def_id) => {
226+
(ty::Alias(ty::Projection | ty::Inherent, proj_ty), _) if !tcx.is_impl_trait_in_trait(proj_ty.def_id) => {
226227
self.expected_projection(
227228
diag,
228229
proj_ty,
@@ -231,7 +232,7 @@ impl<T> Trait<T> for X {
231232
cause.code(),
232233
);
233234
}
234-
(_, ty::Alias(ty::Projection, proj_ty)) if !tcx.is_impl_trait_in_trait(proj_ty.def_id) => {
235+
(_, ty::Alias(ty::Projection | ty::Inherent, proj_ty)) if !tcx.is_impl_trait_in_trait(proj_ty.def_id) => {
235236
let msg = format!(
236237
"consider constraining the associated type `{}` to `{}`",
237238
values.found, values.expected,

compiler/rustc_infer/src/infer/opaque_types.rs

+2
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ impl<'tcx> InferCtxt<'tcx> {
549549
// We can't normalize associated types from `rustc_infer`,
550550
// but we can eagerly register inference variables for them.
551551
// FIXME(RPITIT): Don't replace RPITITs with inference vars.
552+
// FIXME(inherent_associated_types): Extend this to support `ty::Inherent`, too.
552553
ty::Alias(ty::Projection, projection_ty)
553554
if !projection_ty.has_escaping_bound_vars()
554555
&& !tcx.is_impl_trait_in_trait(projection_ty.def_id) =>
@@ -569,6 +570,7 @@ impl<'tcx> InferCtxt<'tcx> {
569570
hidden_ty
570571
}
571572
// FIXME(RPITIT): This can go away when we move to associated types
573+
// FIXME(inherent_associated_types): Extend this to support `ty::Inherent`, too.
572574
ty::Alias(
573575
ty::Projection,
574576
ty::AliasTy { def_id: def_id2, substs: substs2, .. },

0 commit comments

Comments
 (0)