From 2634309eb39b5af7b1d26a3656079efc0b9340d1 Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 29 Jul 2022 09:43:22 +0200 Subject: [PATCH] update comment --- .../src/traits/coherence.rs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index da17a9c3da6..337fbb2c15e 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -746,17 +746,22 @@ fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow { result } + /// All possible values for a constant parameter already exist + /// in the crate defining the trait, so they are always non-local[^1]. + /// + /// Because there's no way to have an impl where the first local + /// generic argument is a constant, we also don't have to fail + /// the orphan check when encountering a parameter or a generic constant. + /// + /// This means that we can completely ignore constants during the orphan check. + /// + /// See `src/test/ui/coherence/const-generics-orphan-check-ok.rs` for examples. + /// + /// [^1]: This might not hold for function pointers or trait objects in the future. + /// As these should be quite rare as const arguments and especially rare as impl + /// parameters, allowing uncovered const parameters in impls seems more useful + /// than allowing `impl Trait for i32` to compile. fn visit_const(&mut self, _c: ty::Const<'tcx>) -> ControlFlow { - // All possible values for a constant parameter already exist - // in the crate defining the trait, so they are always non-local. - // - // Because there's no way to have an impl where the first local - // generic argument is a constant, we also don't have to fail - // the orphan check when encountering a parameter or a generic constant. - // - // This means that we can completely ignore constants during the orphan check. - // - // See `src/test/ui/coherence/const-generics-orphan-check-ok.rs` for examples. ControlFlow::CONTINUE } }