Skip to content

Commit a084b7a

Browse files
committed
Auto merge of rust-lang#97135 - Dylan-DPC:rollup-06u9pqn, r=Dylan-DPC
Rollup of 6 pull requests Successful merges: - rust-lang#94639 (Suggest dereferencing non-lval mutable reference on assignment) - rust-lang#95979 (update coherence docs, fix generator + opaque type ICE) - rust-lang#96378 (Mention traits and types involved in unstable trait upcasting) - rust-lang#96917 (Make HashMap fall back to RtlGenRandom if BCryptGenRandom fails) - rust-lang#97101 (Add tracking issue for ExitCode::exit_process) - rust-lang#97123 (Clean fix for rust-lang#96223) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 77972d2 + a2c2720 commit a084b7a

29 files changed

+636
-215
lines changed

compiler/rustc_middle/src/traits/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ pub enum Reveal {
6161
/// let x: <() as Assoc>::Output = true;
6262
/// }
6363
/// ```
64+
///
65+
/// We also do not reveal the hidden type of opaque types during
66+
/// type-checking.
6467
UserFacing,
6568

6669
/// At codegen time, all monomorphic projections will succeed.

compiler/rustc_trait_selection/src/traits/coherence.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ fn orphan_check_trait_ref<'tcx>(
645645
.substs
646646
.types()
647647
.flat_map(|ty| uncover_fundamental_ty(tcx, ty, in_crate))
648-
.find(|ty| ty_is_local_constructor(*ty, in_crate));
648+
.find(|&ty| ty_is_local_constructor(tcx, ty, in_crate));
649649

650650
debug!("orphan_check_trait_ref: uncovered ty local_type: `{:?}`", local_type);
651651

@@ -677,7 +677,7 @@ fn contained_non_local_types<'tcx>(
677677
ty: Ty<'tcx>,
678678
in_crate: InCrate,
679679
) -> Vec<Ty<'tcx>> {
680-
if ty_is_local_constructor(ty, in_crate) {
680+
if ty_is_local_constructor(tcx, ty, in_crate) {
681681
Vec::new()
682682
} else {
683683
match fundamental_ty_inner_tys(tcx, ty) {
@@ -730,7 +730,7 @@ fn def_id_is_local(def_id: DefId, in_crate: InCrate) -> bool {
730730
}
731731
}
732732

733-
fn ty_is_local_constructor(ty: Ty<'_>, in_crate: InCrate) -> bool {
733+
fn ty_is_local_constructor(tcx: TyCtxt<'_>, ty: Ty<'_>, in_crate: InCrate) -> bool {
734734
debug!("ty_is_local_constructor({:?})", ty);
735735

736736
match *ty.kind() {
@@ -789,11 +789,6 @@ fn ty_is_local_constructor(ty: Ty<'_>, in_crate: InCrate) -> bool {
789789
false
790790
}
791791

792-
ty::Closure(..) => {
793-
// Similar to the `Opaque` case (#83613).
794-
false
795-
}
796-
797792
ty::Dynamic(ref tt, ..) => {
798793
if let Some(principal) = tt.principal() {
799794
def_id_is_local(principal.def_id(), in_crate)
@@ -804,8 +799,20 @@ fn ty_is_local_constructor(ty: Ty<'_>, in_crate: InCrate) -> bool {
804799

805800
ty::Error(_) => true,
806801

807-
ty::Generator(..) | ty::GeneratorWitness(..) => {
808-
bug!("ty_is_local invoked on unexpected type: {:?}", ty)
802+
// These variants should never appear during coherence checking because they
803+
// cannot be named directly.
804+
//
805+
// They could be indirectly used through an opaque type. While using opaque types
806+
// in impls causes an error, this path can still be hit afterwards.
807+
//
808+
// See `test/ui/coherence/coherence-with-closure.rs` for an example where this
809+
// could happens.
810+
ty::Closure(..) | ty::Generator(..) | ty::GeneratorWitness(..) => {
811+
tcx.sess.delay_span_bug(
812+
DUMMY_SP,
813+
format!("ty_is_local invoked on closure or generator: {:?}", ty),
814+
);
815+
true
809816
}
810817
}
811818
}

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -1384,8 +1384,7 @@ trait InferCtxtPrivExt<'hir, 'tcx> {
13841384
fn mk_trait_obligation_with_new_self_ty(
13851385
&self,
13861386
param_env: ty::ParamEnv<'tcx>,
1387-
trait_ref: ty::PolyTraitPredicate<'tcx>,
1388-
new_self_ty: Ty<'tcx>,
1387+
trait_ref_and_ty: ty::Binder<'tcx, (ty::TraitPredicate<'tcx>, Ty<'tcx>)>,
13891388
) -> PredicateObligation<'tcx>;
13901389

13911390
fn maybe_report_ambiguity(
@@ -1923,14 +1922,11 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
19231922
fn mk_trait_obligation_with_new_self_ty(
19241923
&self,
19251924
param_env: ty::ParamEnv<'tcx>,
1926-
trait_ref: ty::PolyTraitPredicate<'tcx>,
1927-
new_self_ty: Ty<'tcx>,
1925+
trait_ref_and_ty: ty::Binder<'tcx, (ty::TraitPredicate<'tcx>, Ty<'tcx>)>,
19281926
) -> PredicateObligation<'tcx> {
1929-
assert!(!new_self_ty.has_escaping_bound_vars());
1930-
1931-
let trait_pred = trait_ref.map_bound_ref(|tr| ty::TraitPredicate {
1927+
let trait_pred = trait_ref_and_ty.map_bound_ref(|(tr, new_self_ty)| ty::TraitPredicate {
19321928
trait_ref: ty::TraitRef {
1933-
substs: self.tcx.mk_substs_trait(new_self_ty, &tr.trait_ref.substs[1..]),
1929+
substs: self.tcx.mk_substs_trait(*new_self_ty, &tr.trait_ref.substs[1..]),
19341930
..tr.trait_ref
19351931
},
19361932
..*tr

0 commit comments

Comments
 (0)