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

support type annot in constants, casts #55152

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bd93741
remove outdated assertion
nikomatsakis Oct 17, 2018
ebdfda6
convert `FnDef` to `TypeOf`, which is more general
nikomatsakis Oct 17, 2018
e94959b
propagate user-type annotation for constants in expressions
nikomatsakis Oct 17, 2018
a0a3b4c
replace `UserTypeAnnotation::AdtDef` with `TypeOf`
nikomatsakis Oct 17, 2018
e7ab33e
type_check/mod.rs: rustfmt
nikomatsakis Oct 17, 2018
f99300f
pull `relate_type_and_user_type` code into `type_check` module
nikomatsakis Oct 17, 2018
121f3c8
normalize after substitution
nikomatsakis Oct 17, 2018
bfb1d95
normalize and prove predicates
nikomatsakis Oct 17, 2018
e20fa70
suppress duplicate -- or near duplicate -- type test errors
nikomatsakis Oct 18, 2018
80ad300
Wrap cast expressions inside of ValueTypeAscription
KiChjang Oct 2, 2018
2d98e9e
create type ascription for any cast
nikomatsakis Oct 17, 2018
ab79cf9
save the user-provided type immediately upon return from astconv
nikomatsakis Oct 17, 2018
26fdac6
pacify the mercilous tidy
nikomatsakis Oct 17, 2018
d5d5e8c
lowering casts in constants now creates multiple uses
nikomatsakis Oct 18, 2018
a66ab2b
skip user-type annotations if they don't have regions
nikomatsakis Oct 17, 2018
02e5a90
pacify the mercilous tidy
nikomatsakis Oct 18, 2018
061c9a2
region_infer/mod.rs: rustfmt
nikomatsakis Oct 18, 2018
820c265
add useful debug log
nikomatsakis Oct 18, 2018
16b3ea1
add a test that we enforce '`static` errors post normalization
nikomatsakis Oct 18, 2018
f5cc7db
even though we don't need it yet, fix the "fast path" code
nikomatsakis Oct 18, 2018
9a7bb0e
normalize the self-type that we extract from impl
nikomatsakis Oct 18, 2018
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
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