Skip to content

Commit afbac75

Browse files
committed
Completely remove ConstnessAnd
1 parent 3be7786 commit afbac75

File tree

24 files changed

+29
-74
lines changed

24 files changed

+29
-74
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc_middle::ty::fold::TypeFoldable;
3030
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef, UserSubsts};
3131
use rustc_middle::ty::{
3232
self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, OpaqueTypeKey, RegionVid,
33-
ToPredicate, Ty, TyCtxt, UserType, UserTypeAnnotationIndex, WithConstness,
33+
ToPredicate, Ty, TyCtxt, UserType, UserTypeAnnotationIndex,
3434
};
3535
use rustc_span::def_id::CRATE_DEF_ID;
3636
use rustc_span::{Span, DUMMY_SP};

compiler/rustc_infer/src/traits/engine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::infer::InferCtxt;
22
use crate::traits::Obligation;
33
use rustc_data_structures::fx::FxHashMap;
44
use rustc_hir::def_id::DefId;
5-
use rustc_middle::ty::{self, ToPredicate, Ty, WithConstness};
5+
use rustc_middle::ty::{self, ToPredicate, Ty};
66

77
use super::FulfillmentError;
88
use super::{ObligationCause, PredicateObligation};

compiler/rustc_infer/src/traits/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use smallvec::smallvec;
33
use crate::infer::outlives::components::{push_outlives_components, Component};
44
use crate::traits::{Obligation, ObligationCause, PredicateObligation};
55
use rustc_data_structures::fx::{FxHashSet, FxIndexSet};
6-
use rustc_middle::ty::{self, ToPredicate, TyCtxt, WithConstness};
6+
use rustc_middle::ty::{self, ToPredicate, TyCtxt};
77
use rustc_span::symbol::Ident;
88

99
pub fn anonymize_predicate<'tcx>(

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -841,20 +841,6 @@ impl ToPredicate<'tcx> for Binder<'tcx, PredicateKind<'tcx>> {
841841
}
842842
}
843843

844-
impl<'tcx> ToPredicate<'tcx> for ConstnessAnd<PolyTraitRef<'tcx>> {
845-
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
846-
self.value
847-
.map_bound(|trait_ref| {
848-
PredicateKind::Trait(ty::TraitPredicate {
849-
trait_ref,
850-
constness: self.constness,
851-
polarity: ty::ImplPolarity::Positive,
852-
})
853-
})
854-
.to_predicate(tcx)
855-
}
856-
}
857-
858844
impl<'tcx> ToPredicate<'tcx> for PolyTraitPredicate<'tcx> {
859845
fn to_predicate(self, tcx: TyCtxt<'tcx>) -> Predicate<'tcx> {
860846
self.map_bound(PredicateKind::Trait).to_predicate(tcx)
@@ -1386,33 +1372,23 @@ impl<'tcx> ParamEnv<'tcx> {
13861372
}
13871373
}
13881374

1389-
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TypeFoldable)]
1390-
pub struct ConstnessAnd<T> {
1391-
pub constness: BoundConstness,
1392-
pub value: T,
1393-
}
1394-
13951375
// FIXME(ecstaticmorse): Audit all occurrences of `without_const().to_predicate(tcx)` to ensure that
13961376
// the constness of trait bounds is being propagated correctly.
1397-
pub trait WithConstness: Sized {
1398-
#[inline]
1399-
fn with_constness(self, constness: BoundConstness) -> ConstnessAnd<Self> {
1400-
ConstnessAnd { constness, value: self }
1401-
}
1402-
1377+
impl PolyTraitRef<'tcx> {
14031378
#[inline]
1404-
fn with_const_if_const(self) -> ConstnessAnd<Self> {
1405-
self.with_constness(BoundConstness::ConstIfConst)
1379+
pub fn with_constness(self, constness: BoundConstness) -> PolyTraitPredicate<'tcx> {
1380+
self.map_bound(|trait_ref| ty::TraitPredicate {
1381+
trait_ref,
1382+
constness,
1383+
polarity: ty::ImplPolarity::Positive,
1384+
})
14061385
}
1407-
14081386
#[inline]
1409-
fn without_const(self) -> ConstnessAnd<Self> {
1387+
pub fn without_const(self) -> PolyTraitPredicate<'tcx> {
14101388
self.with_constness(BoundConstness::NotConst)
14111389
}
14121390
}
14131391

1414-
impl<T> WithConstness for T {}
1415-
14161392
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TypeFoldable)]
14171393
pub struct ParamEnvAnd<'tcx, T> {
14181394
pub param_env: ParamEnv<'tcx>,

compiler/rustc_middle/src/ty/relate.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -214,19 +214,6 @@ impl<'tcx> Relate<'tcx> for ty::BoundConstness {
214214
}
215215
}
216216

217-
impl<'tcx, T: Relate<'tcx>> Relate<'tcx> for ty::ConstnessAnd<T> {
218-
fn relate<R: TypeRelation<'tcx>>(
219-
relation: &mut R,
220-
a: ty::ConstnessAnd<T>,
221-
b: ty::ConstnessAnd<T>,
222-
) -> RelateResult<'tcx, ty::ConstnessAnd<T>> {
223-
Ok(ty::ConstnessAnd {
224-
constness: relation.relate(a.constness, b.constness)?,
225-
value: relation.relate(a.value, b.value)?,
226-
})
227-
}
228-
}
229-
230217
impl<'tcx> Relate<'tcx> for ast::Unsafety {
231218
fn relate<R: TypeRelation<'tcx>>(
232219
relation: &mut R,

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ use crate::infer::canonical::Canonical;
88
use crate::ty::fold::ValidateBoundVars;
99
use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef};
1010
use crate::ty::InferTy::{self, *};
11-
use crate::ty::{
12-
self, AdtDef, DefIdTree, Discr, Ty, TyCtxt, TypeFlags, TypeFoldable, WithConstness,
13-
};
11+
use crate::ty::{self, AdtDef, DefIdTree, Discr, Ty, TyCtxt, TypeFlags, TypeFoldable};
1412
use crate::ty::{DelaySpanBugEmitted, List, ParamEnv, TyS};
1513
use polonius_engine::Atom;
1614
use rustc_data_structures::captures::Captures;

compiler/rustc_trait_selection/src/autoderef.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::traits::{self, TraitEngine};
33
use rustc_errors::struct_span_err;
44
use rustc_hir as hir;
55
use rustc_infer::infer::InferCtxt;
6-
use rustc_middle::ty::{self, TraitRef, Ty, TyCtxt, WithConstness};
6+
use rustc_middle::ty::{self, TraitRef, Ty, TyCtxt};
77
use rustc_middle::ty::{ToPredicate, TypeFoldable};
88
use rustc_session::{DiagnosticMessageId, Limit};
99
use rustc_span::def_id::LOCAL_CRATE;

compiler/rustc_trait_selection/src/infer.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc_middle::infer::canonical::{Canonical, CanonicalizedQueryResponse, Quer
99
use rustc_middle::traits::query::Fallible;
1010
use rustc_middle::ty::subst::SubstsRef;
1111
use rustc_middle::ty::ToPredicate;
12-
use rustc_middle::ty::WithConstness;
1312
use rustc_middle::ty::{self, Ty, TypeFoldable};
1413
use rustc_span::{Span, DUMMY_SP};
1514

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc_middle::ty::error::ExpectedFound;
2424
use rustc_middle::ty::fold::TypeFolder;
2525
use rustc_middle::ty::{
2626
self, fast_reject, AdtKind, SubtypePredicate, ToPolyTraitRef, ToPredicate, Ty, TyCtxt,
27-
TypeFoldable, WithConstness,
27+
TypeFoldable,
2828
};
2929
use rustc_session::DiagnosticMessageId;
3030
use rustc_span::symbol::{kw, sym};

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_hir::lang_items::LangItem;
2121
use rustc_hir::{AsyncGeneratorKind, GeneratorKind, Node};
2222
use rustc_middle::ty::{
2323
self, suggest_arbitrary_trait_bound, suggest_constraining_type_param, AdtKind, DefIdTree,
24-
Infer, InferTy, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness,
24+
Infer, InferTy, ToPredicate, Ty, TyCtxt, TypeFoldable,
2525
};
2626
use rustc_middle::ty::{TypeAndMut, TypeckResults};
2727
use rustc_session::Limit;

compiler/rustc_trait_selection/src/traits/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ use rustc_hir::lang_items::LangItem;
3333
use rustc_middle::ty::fold::TypeFoldable;
3434
use rustc_middle::ty::subst::{InternalSubsts, SubstsRef};
3535
use rustc_middle::ty::{
36-
self, GenericParamDefKind, ToPredicate, Ty, TyCtxt, VtblEntry, WithConstness,
37-
COMMON_VTABLE_ENTRIES,
36+
self, GenericParamDefKind, ToPredicate, Ty, TyCtxt, VtblEntry, COMMON_VTABLE_ENTRIES,
3837
};
3938
use rustc_span::{sym, Span};
4039
use smallvec::SmallVec;

compiler/rustc_trait_selection/src/traits/object_safety.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_errors::FatalError;
1818
use rustc_hir as hir;
1919
use rustc_hir::def_id::DefId;
2020
use rustc_middle::ty::subst::{GenericArg, InternalSubsts, Subst};
21-
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeVisitor, WithConstness};
21+
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeVisitor};
2222
use rustc_middle::ty::{Predicate, ToPredicate};
2323
use rustc_session::lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY;
2424
use rustc_span::symbol::Symbol;

compiler/rustc_trait_selection/src/traits/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_hir::lang_items::LangItem;
2727
use rustc_infer::infer::resolve::OpportunisticRegionResolver;
2828
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder};
2929
use rustc_middle::ty::subst::Subst;
30-
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, WithConstness};
30+
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
3131
use rustc_span::symbol::sym;
3232

3333
use std::collections::BTreeMap;

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_infer::traits::TraitEngine;
1111
use rustc_infer::traits::{Obligation, SelectionError, TraitObligation};
1212
use rustc_lint_defs::builtin::DEREF_INTO_DYN_SUPERTRAIT;
1313
use rustc_middle::ty::print::with_no_trimmed_paths;
14-
use rustc_middle::ty::{self, ToPredicate, Ty, TypeFoldable, WithConstness};
14+
use rustc_middle::ty::{self, ToPredicate, Ty, TypeFoldable};
1515
use rustc_target::spec::abi::Abi;
1616

1717
use crate::traits;

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_infer::infer::InferOk;
1313
use rustc_infer::infer::LateBoundRegionConversionTime::HigherRankedType;
1414
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst, SubstsRef};
1515
use rustc_middle::ty::{self, Ty};
16-
use rustc_middle::ty::{ToPolyTraitRef, ToPredicate, WithConstness};
16+
use rustc_middle::ty::{ToPolyTraitRef, ToPredicate};
1717
use rustc_span::def_id::DefId;
1818

1919
use crate::traits::project::{normalize_with_depth, normalize_with_depth_to};

compiler/rustc_trait_selection/src/traits/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use smallvec::SmallVec;
66
use rustc_data_structures::fx::FxHashSet;
77
use rustc_hir::def_id::DefId;
88
use rustc_middle::ty::subst::{GenericArg, Subst, SubstsRef};
9-
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness};
9+
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable};
1010

1111
use super::{Normalized, Obligation, ObligationCause, PredicateObligation, SelectionContext};
1212
pub use rustc_infer::traits::util::*;

compiler/rustc_trait_selection/src/traits/wf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_hir as hir;
66
use rustc_hir::def_id::DefId;
77
use rustc_hir::lang_items::LangItem;
88
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, SubstsRef};
9-
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness};
9+
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable};
1010
use rustc_span::Span;
1111

1212
use std::iter;

compiler/rustc_ty_utils/src/ty.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ use rustc_data_structures::fx::FxIndexSet;
22
use rustc_hir as hir;
33
use rustc_hir::def_id::{DefId, LocalDefId};
44
use rustc_middle::ty::subst::Subst;
5-
use rustc_middle::ty::{
6-
self, Binder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt, WithConstness,
7-
};
5+
use rustc_middle::ty::{self, Binder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt};
86
use rustc_span::Span;
97
use rustc_trait_selection::traits;
108

compiler/rustc_typeck/src/bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Bounds are restrictions applied to some types after they've been converted into the
22
//! `ty` form from the HIR.
33
4-
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, WithConstness};
4+
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
55
use rustc_span::Span;
66

77
/// Collects together a list of type bounds. These lists of bounds occur in many places

compiler/rustc_typeck/src/check/method/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_infer::infer::{self, InferOk};
2121
use rustc_middle::ty::subst::Subst;
2222
use rustc_middle::ty::subst::{InternalSubsts, SubstsRef};
2323
use rustc_middle::ty::GenericParamDefKind;
24-
use rustc_middle::ty::{self, ToPredicate, Ty, TypeFoldable, WithConstness};
24+
use rustc_middle::ty::{self, ToPredicate, Ty, TypeFoldable};
2525
use rustc_span::symbol::Ident;
2626
use rustc_span::Span;
2727
use rustc_trait_selection::traits;

compiler/rustc_typeck/src/check/method/probe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_infer::infer::{self, InferOk, TyCtxtInferExt};
2121
use rustc_middle::middle::stability;
2222
use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
2323
use rustc_middle::ty::GenericParamDefKind;
24-
use rustc_middle::ty::{self, ParamEnvAnd, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness};
24+
use rustc_middle::ty::{self, ParamEnvAnd, ToPredicate, Ty, TyCtxt, TypeFoldable};
2525
use rustc_session::lint;
2626
use rustc_span::def_id::LocalDefId;
2727
use rustc_span::lev_distance::{find_best_match_for_name, lev_distance};

compiler/rustc_typeck/src/check/method/suggest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_hir::{ExprKind, Node, QPath};
1212
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
1313
use rustc_middle::ty::fast_reject::simplify_type;
1414
use rustc_middle::ty::print::with_crate_prefix;
15-
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness};
15+
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable};
1616
use rustc_span::lev_distance;
1717
use rustc_span::symbol::{kw, sym, Ident};
1818
use rustc_span::{source_map, FileName, MultiSpan, Span};

compiler/rustc_typeck/src/check/wfcheck.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ use rustc_hir::ItemKind;
1414
use rustc_middle::hir::map as hir_map;
1515
use rustc_middle::ty::subst::{InternalSubsts, Subst};
1616
use rustc_middle::ty::trait_def::TraitSpecializationKind;
17-
use rustc_middle::ty::{
18-
self, AdtKind, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable, WithConstness,
19-
};
17+
use rustc_middle::ty::{self, AdtKind, GenericParamDefKind, ToPredicate, Ty, TyCtxt, TypeFoldable};
2018
use rustc_session::parse::feature_err;
2119
use rustc_span::symbol::{sym, Ident, Symbol};
2220
use rustc_span::Span;

compiler/rustc_typeck/src/collect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use rustc_middle::ty::subst::InternalSubsts;
4141
use rustc_middle::ty::util::Discr;
4242
use rustc_middle::ty::util::IntTypeExt;
4343
use rustc_middle::ty::{self, AdtKind, Const, DefIdTree, Ty, TyCtxt};
44-
use rustc_middle::ty::{ReprOptions, ToPredicate, WithConstness};
44+
use rustc_middle::ty::{ReprOptions, ToPredicate};
4545
use rustc_session::lint;
4646
use rustc_session::parse::feature_err;
4747
use rustc_span::symbol::{kw, sym, Ident, Symbol};

0 commit comments

Comments
 (0)