Skip to content

Commit d9417b3

Browse files
committed
Auto merge of rust-lang#72433 - RalfJung:rollup-srft8nx, r=RalfJung
Rollup of 7 pull requests Successful merges: - rust-lang#72055 (Intern predicates) - rust-lang#72149 (Don't `type_of` on trait assoc ty without default) - rust-lang#72347 (Make intra-link resolve links for both trait and impl items) - rust-lang#72350 (Improve documentation of `slice::from_raw_parts`) - rust-lang#72382 (Show default values for debug-assertions & debug-assertions-std) - rust-lang#72421 (Fix anchor display when hovering impl) - rust-lang#72425 (fix discriminant_value sign extension) Failed merges: r? @ghost
2 parents 9310e3b + 74b5c50 commit d9417b3

Some content is hidden

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

72 files changed

+941
-682
lines changed

config.toml.example

+2-2
Original file line numberDiff line numberDiff line change
@@ -312,11 +312,11 @@
312312

313313
# Whether or not debug assertions are enabled for the compiler and standard
314314
# library.
315-
#debug-assertions = false
315+
#debug-assertions = debug
316316

317317
# Whether or not debug assertions are enabled for the standard library.
318318
# Overrides the `debug-assertions` option, if defined.
319-
#debug-assertions-std = false
319+
#debug-assertions-std = debug-assertions
320320

321321
# Debuginfo level for most of Rust code, corresponds to the `-C debuginfo=N` option of `rustc`.
322322
# `0` - no debug info

src/libcore/slice/mod.rs

+30-1
Original file line numberDiff line numberDiff line change
@@ -5740,7 +5740,8 @@ unsafe impl<'a, T> TrustedRandomAccess for RChunksExactMut<'a, T> {
57405740
/// and it must be properly aligned. This means in particular:
57415741
///
57425742
/// * The entire memory range of this slice must be contained within a single allocated object!
5743-
/// Slices can never span across multiple allocated objects.
5743+
/// Slices can never span across multiple allocated objects. See [below](#incorrect-usage)
5744+
/// for an example incorrectly not taking this into account.
57445745
/// * `data` must be non-null and aligned even for zero-length slices. One
57455746
/// reason for this is that enum layout optimizations may rely on references
57465747
/// (including slices of any length) being aligned and non-null to distinguish
@@ -5773,6 +5774,34 @@ unsafe impl<'a, T> TrustedRandomAccess for RChunksExactMut<'a, T> {
57735774
/// assert_eq!(slice[0], 42);
57745775
/// ```
57755776
///
5777+
/// ### Incorrect usage
5778+
///
5779+
/// The following `join_slices` function is **unsound** ⚠️
5780+
///
5781+
/// ```rust,no_run
5782+
/// use std::slice;
5783+
///
5784+
/// fn join_slices<'a, T>(fst: &'a [T], snd: &'a [T]) -> &'a [T] {
5785+
/// let fst_end = fst.as_ptr().wrapping_add(fst.len());
5786+
/// let snd_start = snd.as_ptr();
5787+
/// assert_eq!(fst_end, snd_start, "Slices must be contiguous!");
5788+
/// unsafe {
5789+
/// // The assertion above ensures `fst` and `snd` are contiguous, but they might
5790+
/// // still be contained within _different allocated objects_, in which case
5791+
/// // creating this slice is undefined behavior.
5792+
/// slice::from_raw_parts(fst.as_ptr(), fst.len() + snd.len())
5793+
/// }
5794+
/// }
5795+
///
5796+
/// fn main() {
5797+
/// // `a` and `b` are different allocated objects...
5798+
/// let a = 42;
5799+
/// let b = 27;
5800+
/// // ... which may nevertheless be laid out contiguously in memory: | a | b |
5801+
/// let _ = join_slices(slice::from_ref(&a), slice::from_ref(&b)); // UB
5802+
/// }
5803+
/// ```
5804+
///
57765805
/// [valid]: ../../std/ptr/index.html#safety
57775806
/// [`NonNull::dangling()`]: ../../std/ptr/struct.NonNull.html#method.dangling
57785807
/// [`pointer::offset`]: ../../std/primitive.pointer.html#method.offset

src/librustc_infer/infer/canonical/query_response.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_middle::arena::ArenaAllocatable;
2525
use rustc_middle::ty::fold::TypeFoldable;
2626
use rustc_middle::ty::relate::TypeRelation;
2727
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
28-
use rustc_middle::ty::{self, BoundVar, Const, Ty, TyCtxt};
28+
use rustc_middle::ty::{self, BoundVar, Const, ToPredicate, Ty, TyCtxt};
2929
use std::fmt::Debug;
3030

3131
impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
@@ -532,12 +532,14 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
532532
cause.clone(),
533533
param_env,
534534
match k1.unpack() {
535-
GenericArgKind::Lifetime(r1) => ty::Predicate::RegionOutlives(
535+
GenericArgKind::Lifetime(r1) => ty::PredicateKind::RegionOutlives(
536536
ty::Binder::bind(ty::OutlivesPredicate(r1, r2)),
537-
),
538-
GenericArgKind::Type(t1) => {
539-
ty::Predicate::TypeOutlives(ty::Binder::bind(ty::OutlivesPredicate(t1, r2)))
540-
}
537+
)
538+
.to_predicate(self.tcx),
539+
GenericArgKind::Type(t1) => ty::PredicateKind::TypeOutlives(ty::Binder::bind(
540+
ty::OutlivesPredicate(t1, r2),
541+
))
542+
.to_predicate(self.tcx),
541543
GenericArgKind::Const(..) => {
542544
// Consts cannot outlive one another, so we don't expect to
543545
// ecounter this branch.
@@ -664,9 +666,10 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
664666
self.obligations.push(Obligation {
665667
cause: self.cause.clone(),
666668
param_env: self.param_env,
667-
predicate: ty::Predicate::RegionOutlives(ty::Binder::dummy(ty::OutlivesPredicate(
669+
predicate: ty::PredicateKind::RegionOutlives(ty::Binder::dummy(ty::OutlivesPredicate(
668670
sup, sub,
669-
))),
671+
)))
672+
.to_predicate(self.infcx.tcx),
670673
recursion_depth: 0,
671674
});
672675
}

src/librustc_infer/infer/combine.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ use rustc_hir::def_id::DefId;
3939
use rustc_middle::ty::error::TypeError;
4040
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
4141
use rustc_middle::ty::subst::SubstsRef;
42-
use rustc_middle::ty::{self, InferConst, Ty, TyCtxt, TypeFoldable};
42+
use rustc_middle::ty::{self, InferConst, ToPredicate, Ty, TyCtxt, TypeFoldable};
4343
use rustc_middle::ty::{IntType, UintType};
4444
use rustc_span::{Span, DUMMY_SP};
4545

@@ -307,7 +307,7 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
307307
self.obligations.push(Obligation::new(
308308
self.trace.cause.clone(),
309309
self.param_env,
310-
ty::Predicate::WellFormed(b_ty),
310+
ty::PredicateKind::WellFormed(b_ty).to_predicate(self.infcx.tcx),
311311
));
312312
}
313313

@@ -398,11 +398,15 @@ impl<'infcx, 'tcx> CombineFields<'infcx, 'tcx> {
398398
b: &'tcx ty::Const<'tcx>,
399399
) {
400400
let predicate = if a_is_expected {
401-
ty::Predicate::ConstEquate(a, b)
401+
ty::PredicateKind::ConstEquate(a, b)
402402
} else {
403-
ty::Predicate::ConstEquate(b, a)
403+
ty::PredicateKind::ConstEquate(b, a)
404404
};
405-
self.obligations.push(Obligation::new(self.trace.cause.clone(), self.param_env, predicate));
405+
self.obligations.push(Obligation::new(
406+
self.trace.cause.clone(),
407+
self.param_env,
408+
predicate.to_predicate(self.tcx()),
409+
));
406410
}
407411
}
408412

src/librustc_infer/infer/outlives/mod.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ pub fn explicit_outlives_bounds<'tcx>(
1111
param_env: ty::ParamEnv<'tcx>,
1212
) -> impl Iterator<Item = OutlivesBound<'tcx>> + 'tcx {
1313
debug!("explicit_outlives_bounds()");
14-
param_env.caller_bounds.into_iter().filter_map(move |predicate| match predicate {
15-
ty::Predicate::Projection(..)
16-
| ty::Predicate::Trait(..)
17-
| ty::Predicate::Subtype(..)
18-
| ty::Predicate::WellFormed(..)
19-
| ty::Predicate::ObjectSafe(..)
20-
| ty::Predicate::ClosureKind(..)
21-
| ty::Predicate::TypeOutlives(..)
22-
| ty::Predicate::ConstEvaluatable(..)
23-
| ty::Predicate::ConstEquate(..) => None,
24-
ty::Predicate::RegionOutlives(ref data) => data
14+
param_env.caller_bounds.into_iter().filter_map(move |predicate| match predicate.kind() {
15+
ty::PredicateKind::Projection(..)
16+
| ty::PredicateKind::Trait(..)
17+
| ty::PredicateKind::Subtype(..)
18+
| ty::PredicateKind::WellFormed(..)
19+
| ty::PredicateKind::ObjectSafe(..)
20+
| ty::PredicateKind::ClosureKind(..)
21+
| ty::PredicateKind::TypeOutlives(..)
22+
| ty::PredicateKind::ConstEvaluatable(..)
23+
| ty::PredicateKind::ConstEquate(..) => None,
24+
ty::PredicateKind::RegionOutlives(ref data) => data
2525
.no_bound_vars()
2626
.map(|ty::OutlivesPredicate(r_a, r_b)| OutlivesBound::RegionSubRegion(r_b, r_a)),
2727
})

src/librustc_infer/infer/sub.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::traits::Obligation;
66
use rustc_middle::ty::fold::TypeFoldable;
77
use rustc_middle::ty::relate::{Cause, Relate, RelateResult, TypeRelation};
88
use rustc_middle::ty::TyVar;
9-
use rustc_middle::ty::{self, Ty, TyCtxt};
9+
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
1010
use std::mem;
1111

1212
/// Ensures `a` is made a subtype of `b`. Returns `a` on success.
@@ -100,11 +100,12 @@ impl TypeRelation<'tcx> for Sub<'combine, 'infcx, 'tcx> {
100100
self.fields.obligations.push(Obligation::new(
101101
self.fields.trace.cause.clone(),
102102
self.fields.param_env,
103-
ty::Predicate::Subtype(ty::Binder::dummy(ty::SubtypePredicate {
103+
ty::PredicateKind::Subtype(ty::Binder::dummy(ty::SubtypePredicate {
104104
a_is_expected: self.a_is_expected,
105105
a,
106106
b,
107-
})),
107+
}))
108+
.to_predicate(self.tcx()),
108109
));
109110

110111
Ok(a)

src/librustc_infer/traits/engine.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub trait TraitEngine<'tcx>: 'tcx {
3333
cause,
3434
recursion_depth: 0,
3535
param_env,
36-
predicate: trait_ref.without_const().to_predicate(),
36+
predicate: trait_ref.without_const().to_predicate(infcx.tcx),
3737
},
3838
);
3939
}

src/librustc_infer/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub type TraitObligation<'tcx> = Obligation<'tcx, ty::PolyTraitPredicate<'tcx>>;
5959

6060
// `PredicateObligation` is used a lot. Make sure it doesn't unintentionally get bigger.
6161
#[cfg(target_arch = "x86_64")]
62-
static_assert_size!(PredicateObligation<'_>, 112);
62+
static_assert_size!(PredicateObligation<'_>, 88);
6363

6464
pub type Obligations<'tcx, O> = Vec<Obligation<'tcx, O>>;
6565
pub type PredicateObligations<'tcx> = Vec<PredicateObligation<'tcx>>;

src/librustc_infer/traits/util.rs

+46-36
Original file line numberDiff line numberDiff line change
@@ -10,40 +10,49 @@ pub fn anonymize_predicate<'tcx>(
1010
tcx: TyCtxt<'tcx>,
1111
pred: &ty::Predicate<'tcx>,
1212
) -> ty::Predicate<'tcx> {
13-
match *pred {
14-
ty::Predicate::Trait(ref data, constness) => {
15-
ty::Predicate::Trait(tcx.anonymize_late_bound_regions(data), constness)
13+
match pred.kind() {
14+
&ty::PredicateKind::Trait(ref data, constness) => {
15+
ty::PredicateKind::Trait(tcx.anonymize_late_bound_regions(data), constness)
16+
.to_predicate(tcx)
1617
}
1718

18-
ty::Predicate::RegionOutlives(ref data) => {
19-
ty::Predicate::RegionOutlives(tcx.anonymize_late_bound_regions(data))
19+
ty::PredicateKind::RegionOutlives(data) => {
20+
ty::PredicateKind::RegionOutlives(tcx.anonymize_late_bound_regions(data))
21+
.to_predicate(tcx)
2022
}
2123

22-
ty::Predicate::TypeOutlives(ref data) => {
23-
ty::Predicate::TypeOutlives(tcx.anonymize_late_bound_regions(data))
24+
ty::PredicateKind::TypeOutlives(data) => {
25+
ty::PredicateKind::TypeOutlives(tcx.anonymize_late_bound_regions(data))
26+
.to_predicate(tcx)
2427
}
2528

26-
ty::Predicate::Projection(ref data) => {
27-
ty::Predicate::Projection(tcx.anonymize_late_bound_regions(data))
29+
ty::PredicateKind::Projection(data) => {
30+
ty::PredicateKind::Projection(tcx.anonymize_late_bound_regions(data)).to_predicate(tcx)
2831
}
2932

30-
ty::Predicate::WellFormed(data) => ty::Predicate::WellFormed(data),
33+
&ty::PredicateKind::WellFormed(data) => {
34+
ty::PredicateKind::WellFormed(data).to_predicate(tcx)
35+
}
3136

32-
ty::Predicate::ObjectSafe(data) => ty::Predicate::ObjectSafe(data),
37+
&ty::PredicateKind::ObjectSafe(data) => {
38+
ty::PredicateKind::ObjectSafe(data).to_predicate(tcx)
39+
}
3340

34-
ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind) => {
35-
ty::Predicate::ClosureKind(closure_def_id, closure_substs, kind)
41+
&ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind) => {
42+
ty::PredicateKind::ClosureKind(closure_def_id, closure_substs, kind).to_predicate(tcx)
3643
}
3744

38-
ty::Predicate::Subtype(ref data) => {
39-
ty::Predicate::Subtype(tcx.anonymize_late_bound_regions(data))
45+
ty::PredicateKind::Subtype(data) => {
46+
ty::PredicateKind::Subtype(tcx.anonymize_late_bound_regions(data)).to_predicate(tcx)
4047
}
4148

42-
ty::Predicate::ConstEvaluatable(def_id, substs) => {
43-
ty::Predicate::ConstEvaluatable(def_id, substs)
49+
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
50+
ty::PredicateKind::ConstEvaluatable(def_id, substs).to_predicate(tcx)
4451
}
4552

46-
ty::Predicate::ConstEquate(c1, c2) => ty::Predicate::ConstEquate(c1, c2),
53+
ty::PredicateKind::ConstEquate(c1, c2) => {
54+
ty::PredicateKind::ConstEquate(c1, c2).to_predicate(tcx)
55+
}
4756
}
4857
}
4958

@@ -99,14 +108,14 @@ pub fn elaborate_trait_ref<'tcx>(
99108
tcx: TyCtxt<'tcx>,
100109
trait_ref: ty::PolyTraitRef<'tcx>,
101110
) -> Elaborator<'tcx> {
102-
elaborate_predicates(tcx, std::iter::once(trait_ref.without_const().to_predicate()))
111+
elaborate_predicates(tcx, std::iter::once(trait_ref.without_const().to_predicate(tcx)))
103112
}
104113

105114
pub fn elaborate_trait_refs<'tcx>(
106115
tcx: TyCtxt<'tcx>,
107116
trait_refs: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
108117
) -> Elaborator<'tcx> {
109-
let predicates = trait_refs.map(|trait_ref| trait_ref.without_const().to_predicate());
118+
let predicates = trait_refs.map(|trait_ref| trait_ref.without_const().to_predicate(tcx));
110119
elaborate_predicates(tcx, predicates)
111120
}
112121

@@ -145,8 +154,8 @@ impl Elaborator<'tcx> {
145154

146155
fn elaborate(&mut self, obligation: &PredicateObligation<'tcx>) {
147156
let tcx = self.visited.tcx;
148-
match obligation.predicate {
149-
ty::Predicate::Trait(ref data, _) => {
157+
match obligation.predicate.kind() {
158+
ty::PredicateKind::Trait(ref data, _) => {
150159
// Get predicates declared on the trait.
151160
let predicates = tcx.super_predicates_of(data.def_id());
152161

@@ -167,36 +176,36 @@ impl Elaborator<'tcx> {
167176

168177
self.stack.extend(obligations);
169178
}
170-
ty::Predicate::WellFormed(..) => {
179+
ty::PredicateKind::WellFormed(..) => {
171180
// Currently, we do not elaborate WF predicates,
172181
// although we easily could.
173182
}
174-
ty::Predicate::ObjectSafe(..) => {
183+
ty::PredicateKind::ObjectSafe(..) => {
175184
// Currently, we do not elaborate object-safe
176185
// predicates.
177186
}
178-
ty::Predicate::Subtype(..) => {
187+
ty::PredicateKind::Subtype(..) => {
179188
// Currently, we do not "elaborate" predicates like `X <: Y`,
180189
// though conceivably we might.
181190
}
182-
ty::Predicate::Projection(..) => {
191+
ty::PredicateKind::Projection(..) => {
183192
// Nothing to elaborate in a projection predicate.
184193
}
185-
ty::Predicate::ClosureKind(..) => {
194+
ty::PredicateKind::ClosureKind(..) => {
186195
// Nothing to elaborate when waiting for a closure's kind to be inferred.
187196
}
188-
ty::Predicate::ConstEvaluatable(..) => {
197+
ty::PredicateKind::ConstEvaluatable(..) => {
189198
// Currently, we do not elaborate const-evaluatable
190199
// predicates.
191200
}
192-
ty::Predicate::ConstEquate(..) => {
201+
ty::PredicateKind::ConstEquate(..) => {
193202
// Currently, we do not elaborate const-equate
194203
// predicates.
195204
}
196-
ty::Predicate::RegionOutlives(..) => {
205+
ty::PredicateKind::RegionOutlives(..) => {
197206
// Nothing to elaborate from `'a: 'b`.
198207
}
199-
ty::Predicate::TypeOutlives(ref data) => {
208+
ty::PredicateKind::TypeOutlives(ref data) => {
200209
// We know that `T: 'a` for some type `T`. We can
201210
// often elaborate this. For example, if we know that
202211
// `[U]: 'a`, that implies that `U: 'a`. Similarly, if
@@ -228,15 +237,15 @@ impl Elaborator<'tcx> {
228237
if r.is_late_bound() {
229238
None
230239
} else {
231-
Some(ty::Predicate::RegionOutlives(ty::Binder::dummy(
240+
Some(ty::PredicateKind::RegionOutlives(ty::Binder::dummy(
232241
ty::OutlivesPredicate(r, r_min),
233242
)))
234243
}
235244
}
236245

237246
Component::Param(p) => {
238247
let ty = tcx.mk_ty_param(p.index, p.name);
239-
Some(ty::Predicate::TypeOutlives(ty::Binder::dummy(
248+
Some(ty::PredicateKind::TypeOutlives(ty::Binder::dummy(
240249
ty::OutlivesPredicate(ty, r_min),
241250
)))
242251
}
@@ -250,8 +259,9 @@ impl Elaborator<'tcx> {
250259
None
251260
}
252261
})
253-
.filter(|p| visited.insert(p))
254-
.map(|p| predicate_obligation(p, None)),
262+
.map(|predicate_kind| predicate_kind.to_predicate(tcx))
263+
.filter(|predicate| visited.insert(predicate))
264+
.map(|predicate| predicate_obligation(predicate, None)),
255265
);
256266
}
257267
}
@@ -317,7 +327,7 @@ impl<'tcx, I: Iterator<Item = PredicateObligation<'tcx>>> Iterator for FilterToT
317327

318328
fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> {
319329
while let Some(obligation) = self.base_iterator.next() {
320-
if let ty::Predicate::Trait(data, _) = obligation.predicate {
330+
if let ty::PredicateKind::Trait(data, _) = obligation.predicate.kind() {
321331
return Some(data.to_poly_trait_ref());
322332
}
323333
}

0 commit comments

Comments
 (0)