Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e7d66ea

Browse files
committedJul 24, 2024
Auto merge of #128155 - matthiaskrgr:rollup-lxtal9f, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #122192 (Do not try to reveal hidden types when trying to prove auto-traits in the defining scope) - #126042 (Implement `unsigned_signed_diff`) - #126548 (Improved clarity of documentation for std::fs::create_dir_all) - #127717 (Fix malformed suggestion for repeated maybe unsized bounds) - #128046 (Fix some `#[cfg_attr(not(doc), repr(..))]`) - #128122 (Mark `missing_fragment_specifier` as `FutureReleaseErrorReportInDeps`) - #128135 (std: use duplicate thread local state in tests) - #128140 (Remove Unnecessary `.as_str()` Conversions) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c1a6199 + 104a421 commit e7d66ea

File tree

53 files changed

+742
-335
lines changed

Some content is hidden

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

53 files changed

+742
-335
lines changed
 

‎compiler/rustc_const_eval/src/check_consts/qualifs.rs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,33 @@ impl Qualif for HasMutInterior {
100100
}
101101

102102
fn in_any_value_of_ty<'tcx>(cx: &ConstCx<'_, 'tcx>, ty: Ty<'tcx>) -> bool {
103-
!ty.is_freeze(cx.tcx, cx.param_env)
103+
// Avoid selecting for simple cases, such as builtin types.
104+
if ty.is_trivially_freeze() {
105+
return false;
106+
}
107+
108+
// We do not use `ty.is_freeze` here, because that requires revealing opaque types, which
109+
// requires borrowck, which in turn will invoke mir_const_qualifs again, causing a cycle error.
110+
// Instead we invoke an obligation context manually, and provide the opaque type inference settings
111+
// that allow the trait solver to just error out instead of cycling.
112+
let freeze_def_id = cx.tcx.require_lang_item(LangItem::Freeze, Some(cx.body.span));
113+
114+
let obligation = Obligation::new(
115+
cx.tcx,
116+
ObligationCause::dummy_with_span(cx.body.span),
117+
cx.param_env,
118+
ty::TraitRef::new(cx.tcx, freeze_def_id, [ty::GenericArg::from(ty)]),
119+
);
120+
121+
let infcx = cx
122+
.tcx
123+
.infer_ctxt()
124+
.with_opaque_type_inference(cx.body.source.def_id().expect_local())
125+
.build();
126+
let ocx = ObligationCtxt::new(&infcx);
127+
ocx.register_obligation(obligation);
128+
let errors = ocx.select_all_or_error();
129+
!errors.is_empty()
104130
}
105131

106132
fn in_adt_inherently<'tcx>(

‎compiler/rustc_hir/src/hir.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ impl<'hir> Generics<'hir> {
763763
)
764764
}
765765

766-
fn span_for_predicate_removal(&self, pos: usize) -> Span {
766+
pub fn span_for_predicate_removal(&self, pos: usize) -> Span {
767767
let predicate = &self.predicates[pos];
768768
let span = predicate.span();
769769

@@ -806,15 +806,21 @@ impl<'hir> Generics<'hir> {
806806
return self.span_for_predicate_removal(predicate_pos);
807807
}
808808

809-
let span = bounds[bound_pos].span();
810-
if bound_pos == 0 {
811-
// where T: ?Sized + Bar, Foo: Bar,
812-
// ^^^^^^^^^
813-
span.to(bounds[1].span().shrink_to_lo())
809+
let bound_span = bounds[bound_pos].span();
810+
if bound_pos < bounds.len() - 1 {
811+
// If there's another bound after the current bound
812+
// include the following '+' e.g.:
813+
//
814+
// `T: Foo + CurrentBound + Bar`
815+
// ^^^^^^^^^^^^^^^
816+
bound_span.to(bounds[bound_pos + 1].span().shrink_to_lo())
814817
} else {
815-
// where T: Bar + ?Sized, Foo: Bar,
816-
// ^^^^^^^^^
817-
bounds[bound_pos - 1].span().shrink_to_hi().to(span)
818+
// If the current bound is the last bound
819+
// include the preceding '+' E.g.:
820+
//
821+
// `T: Foo + Bar + CurrentBound`
822+
// ^^^^^^^^^^^^^^^
823+
bound_span.with_lo(bounds[bound_pos - 1].span().hi())
818824
}
819825
}
820826
}

0 commit comments

Comments
 (0)
Please sign in to comment.