Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Rework the entire const trait system #96077

Closed
wants to merge 51 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
cc5960c
Add new generic param
fee1-dead Apr 13, 2022
1933ba7
Add GenericArgDefKind::Constness and tweak generics_of
fee1-dead Apr 13, 2022
0f0f917
Small fixups
oli-obk May 31, 2022
7014e40
Update rustc_{infer,resolve,typeck,trait_selection}
fee1-dead Apr 15, 2022
1bafdc2
Fix more trivial errors
fee1-dead May 7, 2022
ab19ef3
Address trivial lints
oli-obk May 9, 2022
429f9e1
rustc_const_eval
oli-obk May 9, 2022
d9b6e50
runtime matches fall back to non-const PartialEq.
oli-obk May 9, 2022
821bb1f
Small fixups
oli-obk May 31, 2022
67e3eb3
Infer constness params from context if missing
oli-obk May 9, 2022
1b70638
Port some more crates
oli-obk May 9, 2022
11026ec
Update mir typeck
oli-obk May 9, 2022
6ce5109
typeck and borrowck compile
oli-obk May 9, 2022
7d3ee99
Get rustc_privacy to compile
oli-obk May 9, 2022
537b869
rustdoc
oli-obk May 9, 2022
69e6e63
clippy
oli-obk May 9, 2022
dd7ec37
Start poking ICEs until they melt
oli-obk May 9, 2022
77b4af3
Fix assertion ICE
fee1-dead May 10, 2022
17339ca
Add more information to substitution failure
oli-obk May 11, 2022
826f29d
Only add constness arg for const_trait traits
oli-obk May 11, 2022
0d5b724
Print GenericArg
fee1-dead May 11, 2022
e70e92e
Explicitly handle constness from parents
oli-obk May 11, 2022
7c5527d
Now that constness is optional, we default to not-const if it isn't t…
oli-obk May 11, 2022
0fe3432
Constness is optional now
oli-obk May 11, 2022
56a16f8
Remove constness arg from `mk_substs_trait`
oli-obk May 11, 2022
1727172
Remove the helper-methods for mk_substs_trait
oli-obk May 11, 2022
71bcd35
Stop appending constness to all substs
oli-obk May 11, 2022
c59a58c
Allow the constness argument anywhere in the generics list
oli-obk May 31, 2022
b8675a2
HACK: Remove all const trait impls and `~const` from libcore/libstd
oli-obk Jun 1, 2022
03d3d0d
Fix up some trivial test changes
oli-obk Jun 1, 2022
2b7ec4f
Require explicitly handling the tristate constness
oli-obk Jun 1, 2022
4c0f2d0
Actually substitute constness params
oli-obk Jun 1, 2022
d0db6fe
Some tracing for better debugging
oli-obk Jun 1, 2022
4a58caa
Fix typeck probing code to use constness from FnCtxt
fee1-dead Jun 3, 2022
57493e5
Introduce ConstnessArg::Infer and fix some tests
fee1-dead Jun 4, 2022
cbb2cf8
Handle matches added by rebase
fee1-dead Jun 4, 2022
ad467ae
More attempts to fix ui errors
fee1-dead Jun 6, 2022
84054f7
Merge ::Required and ::Param
fee1-dead Jun 6, 2022
cd2edf6
Add CosntnessArg::Const when needed
fee1-dead Jun 7, 2022
d4551d2
Fixed error with more TODOs
fee1-dead Jun 15, 2022
a319331
Don't require has_self when adding constness
fee1-dead Jun 17, 2022
d2322b2
Return unimplemented when feature is not enabled
fee1-dead Jun 19, 2022
cb8bde3
const impls have constness
fee1-dead Jun 19, 2022
6dfe452
var_for_def uses actual constness sometimes
fee1-dead Jun 19, 2022
a0cd8a2
Fix more ui tests
fee1-dead Jun 20, 2022
1ee0614
Equate candidates modulo constness
fee1-dead Jun 20, 2022
7316ca4
Revert "HACK: Remove all const trait impls and `~const` from libcore/…
fee1-dead Jun 20, 2022
25be7a4
attempt to fix std ice
fee1-dead Jun 21, 2022
4f50485
More attempts to fix ICE
fee1-dead Jun 26, 2022
4845b35
general fixes
fee1-dead Jul 13, 2022
b8bbee6
fixup
fee1-dead Jul 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
typeck and borrowck compile
oli-obk authored and fee1-dead committed Jul 15, 2022
commit 6ce510980604c1253f1ef18442c23f191fe96ce9
1 change: 1 addition & 0 deletions compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
@@ -642,6 +642,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
(
GenericArgKind::Lifetime(_)
| GenericArgKind::Type(_)
| GenericArgKind::Constness(_)
| GenericArgKind::Const(_),
_,
) => {
Original file line number Diff line number Diff line change
@@ -126,7 +126,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
.type_must_outlive(origin, t1, r2);
}

GenericArgKind::Const(_) => {
GenericArgKind::Constness(_) | GenericArgKind::Const(_) => {
// Consts cannot outlive one another, so we
// don't need to handle any relations here.
}
4 changes: 3 additions & 1 deletion compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
@@ -2608,7 +2608,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
(outlives_requirements.category, outlives_requirements.blame_span),
))
}
GenericArgKind::Type(_) | GenericArgKind::Const(_) => None,
GenericArgKind::Type(_)
| GenericArgKind::Const(_)
| GenericArgKind::Constness(_) => None,
}
})
.collect();
7 changes: 4 additions & 3 deletions compiler/rustc_mir_transform/src/shim.rs
Original file line number Diff line number Diff line change
@@ -342,7 +342,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
// we must subst the self_ty because it's
// otherwise going to be TySelf and we can't index
// or access fields of a Place of type TySelf.
let substs = tcx.mk_substs_trait(self_ty, &[]);
let substs = tcx.mk_substs_trait(self_ty, &[], ty::ConstnessArg::Not);
let sig = tcx.bound_fn_sig(def_id).subst(tcx, substs);
let sig = tcx.erase_late_bound_regions(sig);
let span = tcx.def_span(def_id);
@@ -423,7 +423,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
) {
let tcx = self.tcx;

let substs = tcx.mk_substs_trait(ty, &[]);
let substs = tcx.mk_substs_trait(ty, &[], ty::ConstnessArg::Not);

// `func == Clone::clone(&ty) -> ty`
let func_ty = tcx.mk_fn_def(self.def_id, substs);
@@ -529,7 +529,8 @@ fn build_call_shim<'tcx>(

// Create substitutions for the `Self` and `Args` generic parameters of the shim body.
let arg_tup = tcx.mk_tup(untuple_args.iter());
let sig_substs = tcx.mk_substs_trait(ty, &[ty::subst::GenericArg::from(arg_tup)]);
let sig_substs =
tcx.mk_substs_trait(ty, &[ty::subst::GenericArg::from(arg_tup)], ty::ConstnessArg::Not);

(Some(sig_substs), Some(untuple_args))
} else {
10 changes: 4 additions & 6 deletions compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
@@ -132,11 +132,9 @@ where

fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow<V::BreakTy> {
match predicate.kind().skip_binder() {
ty::PredicateKind::Trait(ty::TraitPredicate {
trait_ref,
constness: _,
polarity: _,
}) => self.visit_trait(trait_ref),
ty::PredicateKind::Trait(ty::TraitPredicate { trait_ref, polarity: _ }) => {
self.visit_trait(trait_ref)
}
ty::PredicateKind::Projection(ty::ProjectionPredicate { projection_ty, term }) => {
term.visit_with(self)?;
self.visit_projection_ty(projection_ty)
@@ -1167,7 +1165,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
self.tcx.types.never,
);

for (trait_predicate, _, _) in bounds.trait_bounds {
for (trait_predicate, _) in bounds.trait_bounds {
if self.visit_trait(trait_predicate.skip_binder()).is_break() {
return;
}
7 changes: 5 additions & 2 deletions compiler/rustc_typeck/src/check/compare_method.rs
Original file line number Diff line number Diff line change
@@ -1013,7 +1013,9 @@ fn compare_generic_param_kinds<'tcx>(
// this is exhaustive so that anyone adding new generic param kinds knows
// to make sure this error is reported for them.
(Const { .. }, Const { .. }) | (Type { .. }, Type { .. }) => false,
(Lifetime { .. }, _) | (_, Lifetime { .. }) => unreachable!(),
(Constness, _) | (_, Constness) | (Lifetime { .. }, _) | (_, Lifetime { .. }) => {
unreachable!()
}
} {
let param_impl_span = tcx.def_span(param_impl.def_id);
let param_trait_span = tcx.def_span(param_trait.def_id);
@@ -1033,7 +1035,7 @@ fn compare_generic_param_kinds<'tcx>(
format!("{} const parameter of type `{}`", prefix, tcx.type_of(param.def_id))
}
Type { .. } => format!("{} type parameter", prefix),
Lifetime { .. } => unreachable!(),
Constness | Lifetime { .. } => unreachable!(),
};

let trait_header_span = tcx.def_ident_span(tcx.parent(trait_item.def_id)).unwrap();
@@ -1376,6 +1378,7 @@ pub fn check_type_bounds<'tcx>(
})
.into()
}
GenericParamDefKind::Constness => ty::ConstnessArg::Param.into(),
});
let bound_vars = tcx.mk_bound_variable_kinds(bound_vars.into_iter());
let impl_ty_substs = tcx.intern_substs(&substs);
Original file line number Diff line number Diff line change
@@ -413,8 +413,7 @@ fn trait_predicate_kind<'tcx>(
trait_ref, // TODO review specialization check
polarity: _,
}) => Some(tcx.trait_def(trait_ref.def_id).specialization_kind),
ty::PredicateKind::Trait(_)
| ty::PredicateKind::RegionOutlives(_)
ty::PredicateKind::RegionOutlives(_)
| ty::PredicateKind::TypeOutlives(_)
| ty::PredicateKind::Projection(_)
| ty::PredicateKind::WellFormed(_)