Skip to content

Compute underlying type of impl trait types later in compilation #77236

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

Merged
merged 2 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
29 changes: 19 additions & 10 deletions compiler/rustc_mir/src/borrow_check/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
mir_def_id: DefId,
polonius_output: Option<Rc<PoloniusOutput>>,
) -> (Option<ClosureRegionRequirements<'tcx>>, RegionErrors<'tcx>) {
self.propagate_constraints(body);
self.propagate_constraints(body, infcx.tcx);

let mut errors_buffer = RegionErrors::new();

Expand Down Expand Up @@ -599,7 +599,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// for each region variable until all the constraints are
/// satisfied. Note that some values may grow **too** large to be
/// feasible, but we check this later.
fn propagate_constraints(&mut self, _body: &Body<'tcx>) {
fn propagate_constraints(&mut self, _body: &Body<'tcx>, tcx: TyCtxt<'tcx>) {
debug!("propagate_constraints()");

debug!("propagate_constraints: constraints={:#?}", {
Expand All @@ -617,7 +617,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// own.
let constraint_sccs = self.constraint_sccs.clone();
for scc in constraint_sccs.all_sccs() {
self.compute_value_for_scc(scc);
self.compute_value_for_scc(scc, tcx);
}

// Sort the applied member constraints so we can binary search
Expand All @@ -629,7 +629,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// computed, by unioning the values of its successors.
/// Assumes that all successors have been computed already
/// (which is assured by iterating over SCCs in dependency order).
fn compute_value_for_scc(&mut self, scc_a: ConstraintSccIndex) {
fn compute_value_for_scc(&mut self, scc_a: ConstraintSccIndex, tcx: TyCtxt<'tcx>) {
let constraint_sccs = self.constraint_sccs.clone();

// Walk each SCC `B` such that `A: B`...
Expand All @@ -652,7 +652,12 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// Now take member constraints into account.
let member_constraints = self.member_constraints.clone();
for m_c_i in member_constraints.indices(scc_a) {
self.apply_member_constraint(scc_a, m_c_i, member_constraints.choice_regions(m_c_i));
self.apply_member_constraint(
tcx,
scc_a,
m_c_i,
member_constraints.choice_regions(m_c_i),
);
}

debug!(
Expand All @@ -675,6 +680,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
/// If we make any changes, returns true, else false.
fn apply_member_constraint(
&mut self,
tcx: TyCtxt<'tcx>,
scc: ConstraintSccIndex,
member_constraint_index: NllMemberConstraintIndex,
choice_regions: &[ty::RegionVid],
Expand All @@ -688,12 +694,15 @@ impl<'tcx> RegionInferenceContext<'tcx> {
// `impl_trait_in_bindings`, I believe, and we are just
// opting not to handle it for now. See #61773 for
// details.
bug!(
"member constraint for `{:?}` has an option region `{:?}` \
that is not a universal region",
self.member_constraints[member_constraint_index].opaque_type_def_id,
uh_oh,
tcx.sess.delay_span_bug(
self.member_constraints[member_constraint_index].definition_span,
&format!(
"member constraint for `{:?}` has an option region `{:?}` \
that is not a universal region",
self.member_constraints[member_constraint_index].opaque_type_def_id, uh_oh,
),
);
return false;
}

// Create a mutable vector of the options. We'll try to winnow
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_typeck/src/check/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ pub(super) fn check_opaque<'tcx>(
origin: &hir::OpaqueTyOrigin,
) {
check_opaque_for_inheriting_lifetimes(tcx, def_id, span);
tcx.ensure().type_of(def_id);
check_opaque_for_cycles(tcx, def_id, substs, span, origin);
}

Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_typeck/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,14 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::HirId) {
// Desugared from `impl Trait`, so visited by the function's return type.
hir::ItemKind::OpaqueTy(hir::OpaqueTy { impl_trait_fn: Some(_), .. }) => {}

hir::ItemKind::OpaqueTy(..)
| hir::ItemKind::TyAlias(..)
// Don't call `type_of` on opaque types, since that depends on type
// checking function bodies. `check_item_type` ensures that it's called
// instead.
hir::ItemKind::OpaqueTy(..) => {
tcx.ensure().generics_of(def_id);
tcx.ensure().predicates_of(def_id);
}
hir::ItemKind::TyAlias(..)
| hir::ItemKind::Static(..)
| hir::ItemKind::Const(..)
| hir::ItemKind::Fn(..) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ pub fn check_crate(tcx: TyCtxt<'_>) -> Result<(), ErrorReported> {

// this ensures that later parts of type checking can assume that items
// have valid types and not error
// FIXME(matthewjasper) We shouldn't need to do this.
// FIXME(matthewjasper) We shouldn't need to use `track_errors`.
tcx.sess.track_errors(|| {
tcx.sess.time("type_collecting", || {
for &module in tcx.hir().krate().modules.keys() {
Expand Down
21 changes: 0 additions & 21 deletions src/test/ui/associated-type-bounds/duplicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@ fn FW3<T>() where T: Iterator<Item: 'static, Item: 'static> {}
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]

fn FRPIT1() -> impl Iterator<Item: Copy, Item: Send> { iter::empty() }
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
fn FRPIT2() -> impl Iterator<Item: Copy, Item: Copy> { iter::empty() }
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
fn FRPIT3() -> impl Iterator<Item: 'static, Item: 'static> { iter::empty() }
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
fn FAPIT1(_: impl Iterator<Item: Copy, Item: Send>) {}
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
fn FAPIT2(_: impl Iterator<Item: Copy, Item: Copy>) {}
Expand Down Expand Up @@ -107,28 +104,16 @@ type TAW3<T> where T: Iterator<Item: 'static, Item: 'static> = T;

type ETAI1<T: Iterator<Item: Copy, Item: Send>> = impl Copy;
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
//~| ERROR could not find defining uses
type ETAI2<T: Iterator<Item: Copy, Item: Copy>> = impl Copy;
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
//~| ERROR could not find defining uses
type ETAI3<T: Iterator<Item: 'static, Item: 'static>> = impl Copy;
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
//~| ERROR could not find defining uses
type ETAI4 = impl Iterator<Item: Copy, Item: Send>;
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
//~| ERROR could not find defining uses
//~| ERROR could not find defining uses
//~| ERROR could not find defining uses
type ETAI5 = impl Iterator<Item: Copy, Item: Copy>;
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
//~| ERROR could not find defining uses
//~| ERROR could not find defining uses
//~| ERROR could not find defining uses
type ETAI6 = impl Iterator<Item: 'static, Item: 'static>;
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
//~| ERROR could not find defining uses
//~| ERROR could not find defining uses
//~| ERROR could not find defining uses

trait TRI1<T: Iterator<Item: Copy, Item: Send>> {}
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
Expand Down Expand Up @@ -166,15 +151,9 @@ trait TRA3 { type A: Iterator<Item: 'static, Item: 'static>; }

type TADyn1 = dyn Iterator<Item: Copy, Item: Send>;
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
//~| ERROR could not find defining uses
//~| ERROR could not find defining uses
type TADyn2 = Box<dyn Iterator<Item: Copy, Item: Copy>>;
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
//~| ERROR could not find defining uses
//~| ERROR could not find defining uses
type TADyn3 = dyn Iterator<Item: 'static, Item: 'static>;
//~^ ERROR the value of the associated type `Item` (from trait `Iterator`) is already specified [E0719]
//~| ERROR could not find defining uses
//~| ERROR could not find defining uses

fn main() {}
Loading