Skip to content

Commit 19ae74d

Browse files
committed
Auto merge of rust-lang#71776 - Dylan-DPC:rollup-k1iuuow, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#71018 (handle ConstValue::ByRef in relate) - rust-lang#71758 (Remove leftover chalk types) - rust-lang#71760 (Document unsafety for `*const T` and `*mut T`) - rust-lang#71761 (doc: reference does not exist, probably a typo) - rust-lang#71762 (doc: this resulted in a link pointing to a non-existent target) Failed merges: - rust-lang#71726 (Suggest deref when coercing `ty::Ref` to `ty::RawPtr` with arbitrary mutability) r? @ghost
2 parents dba944a + f2fddd3 commit 19ae74d

File tree

25 files changed

+105
-1777
lines changed

25 files changed

+105
-1777
lines changed

src/libcore/ptr/const_ptr.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ use crate::cmp::Ordering::{self, Equal, Greater, Less};
33
use crate::intrinsics;
44
use crate::mem;
55

6-
// ignore-tidy-undocumented-unsafe
7-
86
#[lang = "const_ptr"]
97
impl<T: ?Sized> *const T {
108
/// Returns `true` if the pointer is null.
@@ -215,6 +213,7 @@ impl<T: ?Sized> *const T {
215213
where
216214
T: Sized,
217215
{
216+
// SAFETY: the `arith_offset` intrinsic has no prerequisites to be called.
218217
unsafe { intrinsics::arith_offset(self, count) }
219218
}
220219

@@ -702,6 +701,7 @@ impl<T: ?Sized> *const T {
702701
if !align.is_power_of_two() {
703702
panic!("align_offset: align is not a power-of-two");
704703
}
704+
// SAFETY: `align` has been checked to be a power of 2 above
705705
unsafe { align_offset(self, align) }
706706
}
707707
}
@@ -729,6 +729,8 @@ impl<T> *const [T] {
729729
#[unstable(feature = "slice_ptr_len", issue = "71146")]
730730
#[rustc_const_unstable(feature = "const_slice_ptr_len", issue = "71146")]
731731
pub const fn len(self) -> usize {
732+
// SAFETY: this is safe because `*const [T]` and `FatPtr<T>` have the same layout.
733+
// Only `std` can make this guarantee.
732734
unsafe { Repr { rust: self }.raw }.len
733735
}
734736
}

src/libcore/ptr/mut_ptr.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ use super::*;
22
use crate::cmp::Ordering::{self, Equal, Greater, Less};
33
use crate::intrinsics;
44

5-
// ignore-tidy-undocumented-unsafe
6-
75
#[lang = "mut_ptr"]
86
impl<T: ?Sized> *mut T {
97
/// Returns `true` if the pointer is null.
@@ -208,6 +206,7 @@ impl<T: ?Sized> *mut T {
208206
where
209207
T: Sized,
210208
{
209+
// SAFETY: the `arith_offset` intrinsic has no prerequisites to be called.
211210
unsafe { intrinsics::arith_offset(self, count) as *mut T }
212211
}
213212

@@ -890,6 +889,7 @@ impl<T: ?Sized> *mut T {
890889
if !align.is_power_of_two() {
891890
panic!("align_offset: align is not a power-of-two");
892891
}
892+
// SAFETY: `align` has been checked to be a power of 2 above
893893
unsafe { align_offset(self, align) }
894894
}
895895
}
@@ -917,6 +917,8 @@ impl<T> *mut [T] {
917917
#[unstable(feature = "slice_ptr_len", issue = "71146")]
918918
#[rustc_const_unstable(feature = "const_slice_ptr_len", issue = "71146")]
919919
pub const fn len(self) -> usize {
920+
// SAFETY: this is safe because `*const [T]` and `FatPtr<T>` have the same layout.
921+
// Only `std` can make this guarantee.
920922
unsafe { Repr { rust_mut: self }.raw }.len
921923
}
922924
}

src/librustc_ast/ast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
//! - [`Generics`], [`GenericParam`], [`WhereClause`]: Metadata associated with generic parameters.
1515
//! - [`EnumDef`] and [`Variant`]: Enum declaration.
1616
//! - [`Lit`] and [`LitKind`]: Literal expressions.
17-
//! - [`MacroDef`], [`MacStmtStyle`], [`MacCall`], [`MacDelimeter`]: Macro definition and invocation.
17+
//! - [`MacroDef`], [`MacStmtStyle`], [`MacCall`], [`MacDelimiter`]: Macro definition and invocation.
1818
//! - [`Attribute`]: Metadata associated with item.
19-
//! - [`UnOp`], [`UnOpKind`], [`BinOp`], [`BinOpKind`]: Unary and binary operators.
19+
//! - [`UnOp`], [`BinOp`], and [`BinOpKind`]: Unary and binary operators.
2020
2121
pub use crate::util::parser::ExprPrecedence;
2222
pub use GenericArgs::*;

src/librustc_infer/infer/at.rs

-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ impl<'a, 'tcx> At<'a, 'tcx> {
186186
impl<'a, 'tcx> Trace<'a, 'tcx> {
187187
/// Makes `a <: b` where `a` may or may not be expected (if
188188
/// `a_is_expected` is true, then `a` is expected).
189-
/// Makes `expected <: actual`.
190189
pub fn sub<T>(self, a: &T, b: &T) -> InferResult<'tcx, ()>
191190
where
192191
T: Relate<'tcx>,

src/librustc_infer/infer/canonical/query_response.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::infer::nll_relate::{NormalizationStrategy, TypeRelating, TypeRelating
1616
use crate::infer::region_constraints::{Constraint, RegionConstraintData};
1717
use crate::infer::{InferCtxt, InferOk, InferResult, NLLRegionVariableOrigin};
1818
use crate::traits::query::{Fallible, NoSolution};
19-
use crate::traits::{DomainGoal, TraitEngine};
19+
use crate::traits::TraitEngine;
2020
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
2121
use rustc_data_structures::captures::Captures;
2222
use rustc_index::vec::Idx;
@@ -671,10 +671,6 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for QueryTypeRelatingDelegate<'_, 'tcx> {
671671
});
672672
}
673673

674-
fn push_domain_goal(&mut self, _: DomainGoal<'tcx>) {
675-
bug!("should never be invoked with eager normalization")
676-
}
677-
678674
fn normalization() -> NormalizationStrategy {
679675
NormalizationStrategy::Eager
680676
}

src/librustc_infer/infer/nll_relate/mod.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
2424
use crate::infer::InferCtxt;
2525
use crate::infer::{ConstVarValue, ConstVariableValue};
26-
use crate::traits::DomainGoal;
2726
use rustc_data_structures::fx::FxHashMap;
2827
use rustc_middle::ty::error::TypeError;
2928
use rustc_middle::ty::fold::{TypeFoldable, TypeVisitor};
@@ -78,10 +77,6 @@ pub trait TypeRelatingDelegate<'tcx> {
7877
/// delegate.
7978
fn push_outlives(&mut self, sup: ty::Region<'tcx>, sub: ty::Region<'tcx>);
8079

81-
/// Push a domain goal that will need to be proved for the two types to
82-
/// be related. Used for lazy normalization.
83-
fn push_domain_goal(&mut self, domain_goal: DomainGoal<'tcx>);
84-
8580
/// Creates a new universe index. Used when instantiating placeholders.
8681
fn create_next_universe(&mut self) -> ty::UniverseIndex;
8782

@@ -265,7 +260,6 @@ where
265260
value_ty: Ty<'tcx>,
266261
) -> Ty<'tcx> {
267262
use crate::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
268-
use crate::traits::WhereClause;
269263
use rustc_span::DUMMY_SP;
270264

271265
match value_ty.kind {
@@ -279,12 +273,7 @@ where
279273
var
280274
}
281275

282-
_ => {
283-
let projection = ty::ProjectionPredicate { projection_ty, ty: value_ty };
284-
self.delegate
285-
.push_domain_goal(DomainGoal::Holds(WhereClause::ProjectionEq(projection)));
286-
value_ty
287-
}
276+
_ => bug!("should never be invoked with eager normalization"),
288277
}
289278
}
290279

src/librustc_interface/passes.rs

-4
Original file line numberDiff line numberDiff line change
@@ -838,10 +838,6 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
838838
tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id));
839839
});
840840

841-
sess.time("dumping_chalk_like_clauses", || {
842-
rustc_traits::lowering::dump_program_clauses(tcx);
843-
});
844-
845841
sess.time("MIR_effect_checking", || {
846842
for def_id in tcx.body_owners() {
847843
mir::transform::check_unsafety::check_unsafety(tcx, def_id.to_def_id())

src/librustc_middle/dep_graph/dep_node.rs

-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
5252
use crate::mir;
5353
use crate::mir::interpret::{GlobalId, LitToConstInput};
54-
use crate::traits;
5554
use crate::traits::query::{
5655
CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal,
5756
CanonicalTypeOpAscribeUserTypeGoal, CanonicalTypeOpEqGoal, CanonicalTypeOpNormalizeGoal,

src/librustc_middle/query/mod.rs

-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::dep_graph::SerializedDepNodeIndex;
22
use crate::mir;
33
use crate::mir::interpret::{GlobalId, LitToConstInput};
4-
use crate::traits;
54
use crate::traits::query::{
65
CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal,
76
CanonicalTypeOpAscribeUserTypeGoal, CanonicalTypeOpEqGoal, CanonicalTypeOpNormalizeGoal,
@@ -224,19 +223,6 @@ rustc_queries! {
224223
anon
225224
desc { "erasing regions from `{:?}`", ty }
226225
}
227-
228-
query program_clauses_for(_: DefId) -> Clauses<'tcx> {
229-
desc { "generating chalk-style clauses" }
230-
}
231-
232-
query program_clauses_for_env(_: traits::Environment<'tcx>) -> Clauses<'tcx> {
233-
desc { "generating chalk-style clauses for environment" }
234-
}
235-
236-
// Get the chalk-style environment of the given item.
237-
query environment(_: DefId) -> traits::Environment<'tcx> {
238-
desc { "return a chalk-style environment" }
239-
}
240226
}
241227

242228
Linking {

src/librustc_middle/traits/mod.rs

+1-157
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod structural_impls;
99

1010
use crate::mir::interpret::ErrorHandled;
1111
use crate::ty::subst::SubstsRef;
12-
use crate::ty::{self, AdtKind, List, Ty, TyCtxt};
12+
use crate::ty::{self, AdtKind, Ty, TyCtxt};
1313

1414
use rustc_ast::ast;
1515
use rustc_hir as hir;
@@ -307,162 +307,6 @@ pub struct DerivedObligationCause<'tcx> {
307307
pub parent_code: Rc<ObligationCauseCode<'tcx>>,
308308
}
309309

310-
/// The following types:
311-
/// * `WhereClause`,
312-
/// * `WellFormed`,
313-
/// * `FromEnv`,
314-
/// * `DomainGoal`,
315-
/// * `Goal`,
316-
/// * `Clause`,
317-
/// * `Environment`,
318-
/// * `InEnvironment`,
319-
/// are used for representing the trait system in the form of
320-
/// logic programming clauses. They are part of the interface
321-
/// for the chalk SLG solver.
322-
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable, Lift)]
323-
pub enum WhereClause<'tcx> {
324-
Implemented(ty::TraitPredicate<'tcx>),
325-
ProjectionEq(ty::ProjectionPredicate<'tcx>),
326-
RegionOutlives(ty::RegionOutlivesPredicate<'tcx>),
327-
TypeOutlives(ty::TypeOutlivesPredicate<'tcx>),
328-
}
329-
330-
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable, Lift)]
331-
pub enum WellFormed<'tcx> {
332-
Trait(ty::TraitPredicate<'tcx>),
333-
Ty(Ty<'tcx>),
334-
}
335-
336-
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable, Lift)]
337-
pub enum FromEnv<'tcx> {
338-
Trait(ty::TraitPredicate<'tcx>),
339-
Ty(Ty<'tcx>),
340-
}
341-
342-
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable, Lift)]
343-
pub enum DomainGoal<'tcx> {
344-
Holds(WhereClause<'tcx>),
345-
WellFormed(WellFormed<'tcx>),
346-
FromEnv(FromEnv<'tcx>),
347-
Normalize(ty::ProjectionPredicate<'tcx>),
348-
}
349-
350-
pub type PolyDomainGoal<'tcx> = ty::Binder<DomainGoal<'tcx>>;
351-
352-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable)]
353-
pub enum QuantifierKind {
354-
Universal,
355-
Existential,
356-
}
357-
358-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable, Lift)]
359-
pub enum GoalKind<'tcx> {
360-
Implies(Clauses<'tcx>, Goal<'tcx>),
361-
And(Goal<'tcx>, Goal<'tcx>),
362-
Not(Goal<'tcx>),
363-
DomainGoal(DomainGoal<'tcx>),
364-
Quantified(QuantifierKind, ty::Binder<Goal<'tcx>>),
365-
Subtype(Ty<'tcx>, Ty<'tcx>),
366-
CannotProve,
367-
}
368-
369-
pub type Goal<'tcx> = &'tcx GoalKind<'tcx>;
370-
371-
pub type Goals<'tcx> = &'tcx List<Goal<'tcx>>;
372-
373-
impl<'tcx> DomainGoal<'tcx> {
374-
pub fn into_goal(self) -> GoalKind<'tcx> {
375-
GoalKind::DomainGoal(self)
376-
}
377-
378-
pub fn into_program_clause(self) -> ProgramClause<'tcx> {
379-
ProgramClause {
380-
goal: self,
381-
hypotheses: ty::List::empty(),
382-
category: ProgramClauseCategory::Other,
383-
}
384-
}
385-
}
386-
387-
impl<'tcx> GoalKind<'tcx> {
388-
pub fn from_poly_domain_goal(
389-
domain_goal: PolyDomainGoal<'tcx>,
390-
tcx: TyCtxt<'tcx>,
391-
) -> GoalKind<'tcx> {
392-
match domain_goal.no_bound_vars() {
393-
Some(p) => p.into_goal(),
394-
None => GoalKind::Quantified(
395-
QuantifierKind::Universal,
396-
domain_goal.map_bound(|p| tcx.mk_goal(p.into_goal())),
397-
),
398-
}
399-
}
400-
}
401-
402-
/// This matches the definition from Page 7 of "A Proof Procedure for the Logic of Hereditary
403-
/// Harrop Formulas".
404-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable)]
405-
pub enum Clause<'tcx> {
406-
Implies(ProgramClause<'tcx>),
407-
ForAll(ty::Binder<ProgramClause<'tcx>>),
408-
}
409-
410-
impl Clause<'tcx> {
411-
pub fn category(self) -> ProgramClauseCategory {
412-
match self {
413-
Clause::Implies(clause) => clause.category,
414-
Clause::ForAll(clause) => clause.skip_binder().category,
415-
}
416-
}
417-
}
418-
419-
/// Multiple clauses.
420-
pub type Clauses<'tcx> = &'tcx List<Clause<'tcx>>;
421-
422-
/// A "program clause" has the form `D :- G1, ..., Gn`. It is saying
423-
/// that the domain goal `D` is true if `G1...Gn` are provable. This
424-
/// is equivalent to the implication `G1..Gn => D`; we usually write
425-
/// it with the reverse implication operator `:-` to emphasize the way
426-
/// that programs are actually solved (via backchaining, which starts
427-
/// with the goal to solve and proceeds from there).
428-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable)]
429-
pub struct ProgramClause<'tcx> {
430-
/// This goal will be considered true ...
431-
pub goal: DomainGoal<'tcx>,
432-
433-
/// ... if we can prove these hypotheses (there may be no hypotheses at all):
434-
pub hypotheses: Goals<'tcx>,
435-
436-
/// Useful for filtering clauses.
437-
pub category: ProgramClauseCategory,
438-
}
439-
440-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable)]
441-
pub enum ProgramClauseCategory {
442-
ImpliedBound,
443-
WellFormed,
444-
Other,
445-
}
446-
447-
/// A set of clauses that we assume to be true.
448-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable)]
449-
pub struct Environment<'tcx> {
450-
pub clauses: Clauses<'tcx>,
451-
}
452-
453-
impl Environment<'tcx> {
454-
pub fn with<G>(self, goal: G) -> InEnvironment<'tcx, G> {
455-
InEnvironment { environment: self, goal }
456-
}
457-
}
458-
459-
/// Something (usually a goal), along with an environment.
460-
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, HashStable, TypeFoldable)]
461-
pub struct InEnvironment<'tcx, G> {
462-
pub environment: Environment<'tcx>,
463-
pub goal: G,
464-
}
465-
466310
#[derive(Clone, Debug, TypeFoldable)]
467311
pub enum SelectionError<'tcx> {
468312
Unimplemented,

0 commit comments

Comments
 (0)