Skip to content

Commit 0bbbe71

Browse files
committed
Implement soundness check for min_specialization
1 parent 32d330d commit 0bbbe71

24 files changed

+796
-5
lines changed

src/librustc_typeck/constrained_generic_params.rs

+11-3
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,18 @@ impl<'tcx> TypeVisitor<'tcx> for ParameterCollector {
7979
}
8080

8181
fn visit_const(&mut self, c: &'tcx ty::Const<'tcx>) -> bool {
82-
if let ty::ConstKind::Param(data) = c.val {
83-
self.parameters.push(Parameter::from(data));
82+
match c.val {
83+
ty::ConstKind::Unevaluated(..) if !self.include_nonconstraining => {
84+
// Constant expressions are not injective
85+
return c.ty.visit_with(self);
86+
}
87+
ty::ConstKind::Param(data) => {
88+
self.parameters.push(Parameter::from(data));
89+
}
90+
_ => {}
8491
}
85-
false
92+
93+
c.super_visit_with(self)
8694
}
8795
}
8896

src/librustc_typeck/impl_wf_check.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@
99
//! fixed, but for the moment it's easier to do these checks early.
1010
1111
use crate::constrained_generic_params as cgp;
12+
use min_specialization::check_min_specialization;
13+
1214
use rustc::ty::query::Providers;
1315
use rustc::ty::{self, TyCtxt, TypeFoldable};
1416
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1517
use rustc_errors::struct_span_err;
1618
use rustc_hir as hir;
1719
use rustc_hir::def_id::DefId;
1820
use rustc_hir::itemlikevisit::ItemLikeVisitor;
21+
use rustc_span::Span;
22+
1923
use std::collections::hash_map::Entry::{Occupied, Vacant};
2024

21-
use rustc_span::Span;
25+
mod min_specialization;
2226

2327
/// Checks that all the type/lifetime parameters on an impl also
2428
/// appear in the trait ref or self type (or are constrained by a
@@ -60,7 +64,9 @@ pub fn impl_wf_check(tcx: TyCtxt<'_>) {
6064
}
6165

6266
fn check_mod_impl_wf(tcx: TyCtxt<'_>, module_def_id: DefId) {
63-
tcx.hir().visit_item_likes_in_module(module_def_id, &mut ImplWfCheck { tcx });
67+
let min_specialization = tcx.features().min_specialization;
68+
tcx.hir()
69+
.visit_item_likes_in_module(module_def_id, &mut ImplWfCheck { tcx, min_specialization });
6470
}
6571

6672
pub fn provide(providers: &mut Providers<'_>) {
@@ -69,6 +75,7 @@ pub fn provide(providers: &mut Providers<'_>) {
6975

7076
struct ImplWfCheck<'tcx> {
7177
tcx: TyCtxt<'tcx>,
78+
min_specialization: bool,
7279
}
7380

7481
impl ItemLikeVisitor<'tcx> for ImplWfCheck<'tcx> {
@@ -77,6 +84,9 @@ impl ItemLikeVisitor<'tcx> for ImplWfCheck<'tcx> {
7784
let impl_def_id = self.tcx.hir().local_def_id(item.hir_id);
7885
enforce_impl_params_are_constrained(self.tcx, impl_def_id, items);
7986
enforce_impl_items_are_distinct(self.tcx, items);
87+
if self.min_specialization {
88+
check_min_specialization(self.tcx, impl_def_id, item.span);
89+
}
8090
}
8191
}
8292

0 commit comments

Comments
 (0)