Skip to content

Commit

Permalink
Auto merge of #55152 - nikomatsakis:nll-issue-54571-type-annot-in-con…
Browse files Browse the repository at this point in the history
…stants, r=pnkfelix

support type annot in constants, casts

Fixes #54571
Fixes #54332
Fixes #55183

r? @pnkfelix
  • Loading branch information
bors committed Oct 19, 2018
2 parents 74ff7dc + 9a7bb0e commit 78ff609
Show file tree
Hide file tree
Showing 29 changed files with 553 additions and 276 deletions.
6 changes: 1 addition & 5 deletions src/librustc/ich/impls_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,7 @@ impl<'a, 'gcx> HashStable<StableHashingContext<'a>> for mir::UserTypeAnnotation<
mir::UserTypeAnnotation::Ty(ref ty) => {
ty.hash_stable(hcx, hasher);
}
mir::UserTypeAnnotation::FnDef(ref def_id, ref substs) => {
def_id.hash_stable(hcx, hasher);
substs.hash_stable(hcx, hasher);
}
mir::UserTypeAnnotation::AdtDef(ref def_id, ref substs) => {
mir::UserTypeAnnotation::TypeOf(ref def_id, ref substs) => {
def_id.hash_stable(hcx, hasher);
substs.hash_stable(hcx, hasher);
}
Expand Down
9 changes: 1 addition & 8 deletions src/librustc/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use infer::canonical::substitute::substitute_value;
use infer::canonical::{
Canonical, CanonicalVarKind, CanonicalVarValues, CanonicalizedQueryResponse, Certainty,
Canonical, CanonicalVarValues, CanonicalizedQueryResponse, Certainty,
OriginalQueryValues, QueryRegionConstraint, QueryResponse,
};
use infer::region_constraints::{Constraint, RegionConstraintData};
Expand Down Expand Up @@ -262,13 +262,6 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
where
R: Debug + TypeFoldable<'tcx>,
{
// In an NLL query, there should be no type variables in the
// query, only region variables.
debug_assert!(query_response.variables.iter().all(|v| match v.kind {
CanonicalVarKind::Ty(_) => false,
CanonicalVarKind::Region => true,
}));

let result_subst =
self.query_response_substitution_guess(cause, original_values, query_response);

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/infer/region_constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub struct Verify<'tcx> {
pub bound: VerifyBound<'tcx>,
}

#[derive(Copy, Clone, PartialEq, Eq)]
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
pub enum GenericKind<'tcx> {
Param(ty::ParamTy),
Projection(ty::ProjectionTy<'tcx>),
Expand Down
9 changes: 5 additions & 4 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2425,15 +2425,16 @@ pub struct Constant<'tcx> {
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)]
pub enum UserTypeAnnotation<'tcx> {
Ty(CanonicalTy<'tcx>),
FnDef(DefId, CanonicalUserSubsts<'tcx>),
AdtDef(&'tcx AdtDef, CanonicalUserSubsts<'tcx>),

/// The canonical type is the result of `type_of(def_id)` with the
/// given substitutions applied.
TypeOf(DefId, CanonicalUserSubsts<'tcx>),
}

EnumTypeFoldableImpl! {
impl<'tcx> TypeFoldable<'tcx> for UserTypeAnnotation<'tcx> {
(UserTypeAnnotation::Ty)(ty),
(UserTypeAnnotation::FnDef)(def, substs),
(UserTypeAnnotation::AdtDef)(def, substs),
(UserTypeAnnotation::TypeOf)(def, substs),
}
}

Expand Down
38 changes: 30 additions & 8 deletions src/librustc_mir/borrow_check/nll/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use rustc::mir::{
use rustc::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable};
use rustc::util::common;
use rustc_data_structures::bit_set::BitSet;
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::graph::scc::Sccs;
use rustc_data_structures::indexed_vec::IndexVec;
use rustc_errors::{Diagnostic, DiagnosticBuilder};
Expand Down Expand Up @@ -67,10 +67,8 @@ pub struct RegionInferenceContext<'tcx> {
constraint_sccs: Rc<Sccs<RegionVid, ConstraintSccIndex>>,

/// Map closure bounds to a `Span` that should be used for error reporting.
closure_bounds_mapping: FxHashMap<
Location,
FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>,
>,
closure_bounds_mapping:
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>>,

/// Contains the minimum universe of any variable within the same
/// SCC. We will ensure that no SCC contains values that are not
Expand Down Expand Up @@ -580,6 +578,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
) {
let tcx = infcx.tcx;

// Sometimes we register equivalent type-tests that would
// result in basically the exact same error being reported to
// the user. Avoid that.
let mut deduplicate_errors = FxHashSet::default();

for type_test in &self.type_tests {
debug!("check_type_test: {:?}", type_test);

Expand All @@ -605,11 +608,31 @@ impl<'tcx> RegionInferenceContext<'tcx> {
}
}

// Oh the humanity. Obviously we will do better than this error eventually.
// Type-test failed. Report the error.

// Try to convert the lower-bound region into something named we can print for the user.
let lower_bound_region = self.to_error_region(type_test.lower_bound);

// Skip duplicate-ish errors.
let type_test_span = type_test.locations.span(mir);
let erased_generic_kind = tcx.erase_regions(&type_test.generic_kind);
if !deduplicate_errors.insert((
erased_generic_kind,
lower_bound_region,
type_test.locations,
)) {
continue;
} else {
debug!(
"check_type_test: reporting error for erased_generic_kind={:?}, \
lower_bound_region={:?}, \
type_test.locations={:?}",
erased_generic_kind, lower_bound_region, type_test.locations,
);
}

if let Some(lower_bound_region) = lower_bound_region {
let region_scope_tree = &tcx.region_scope_tree(mir_def_id);
let type_test_span = type_test.locations.span(mir);
infcx
.construct_generic_bound_failure(
region_scope_tree,
Expand All @@ -629,7 +652,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// to report it; we could probably handle it by
// iterating over the universal regions and reporting
// an error that multiple bounds are required.
let type_test_span = type_test.locations.span(mir);
tcx.sess
.struct_span_err(
type_test_span,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ impl<'a, 'gcx, 'tcx> ConstraintConversion<'a, 'gcx, 'tcx> {
}

fn add_type_test(&mut self, type_test: TypeTest<'tcx>) {
debug!("add_type_test(type_test={:?})", type_test);
self.type_tests.push(type_test);
}
}
Expand Down
Loading

0 comments on commit 78ff609

Please sign in to comment.