Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8462a37
avoid temporary vectors
matthiaskrgr Jul 16, 2021
d05a286
Iterate through impls only when permitted
fee1-dead Jul 19, 2021
4b82bbe
Recognize bounds on impls as const bounds
fee1-dead Jul 19, 2021
7066398
Don't render <table> in items' summary
GuillaumeGomez Jul 19, 2021
d6dc840
Add test to ensure tables are not inside items summary
GuillaumeGomez Jul 19, 2021
76ab8a6
:arrow_up: rust-analyzer
lnicola Jul 19, 2021
2a56a68
Add comments explaining the unix command-line argument support.
sunfishcode Jul 19, 2021
64f4e34
Fix typo in compile.rs
chinmaydd Jul 20, 2021
d56c02d
Allow combining -Cprofile-generate and -Cpanic=unwind when targeting
michaelwoerister Jul 19, 2021
b9b0a5e
Fix VecMap::iter_mut
oli-obk Jul 19, 2021
75d9ed7
Make mir borrowck's use of opaque types independent of the typeck que…
oli-obk Jul 19, 2021
df04b98
Use instrument debugging for more readable logs
oli-obk Jul 20, 2021
1ad1b94
Remove an unnecessary variable
oli-obk Jul 20, 2021
b3594f0
Get back the more precise suggestion spans of old regionck
oli-obk Jul 20, 2021
b3aca47
Resolve nested inference variables.
oli-obk Jul 20, 2021
db0324e
Support HIR wf checking for function signatures
Aaron1011 Jul 18, 2021
713044c
Add a regression test
oli-obk Jul 20, 2021
320d049
Add long explanation for E0722
midgleyc Jul 20, 2021
f4981b4
Update cargo
ehuss Jul 20, 2021
e09d782
add working code example
midgleyc Jul 21, 2021
adc5de6
docs: remove spurious main functions
midgleyc Jul 21, 2021
b24d491
docs: add newline before example
midgleyc Jul 21, 2021
70aa202
Rollup merge of #87206 - matthiaskrgr:clippy_collect, r=davidtwco
Dylan-DPC Jul 21, 2021
0350587
Rollup merge of #87265 - Aaron1011:hir-wf-fn, r=estebank
Dylan-DPC Jul 21, 2021
d1a3b1a
Rollup merge of #87270 - GuillaumeGomez:item-summary-table, r=notriddle
Dylan-DPC Jul 21, 2021
357cd15
Rollup merge of #87273 - fee1-dead:impl-const-impl-bounds, r=oli-obk
Dylan-DPC Jul 21, 2021
480d004
Rollup merge of #87278 - lnicola:rust-analyzer-2021-07-19, r=lnicola
Dylan-DPC Jul 21, 2021
58c0b13
Rollup merge of #87279 - sunfishcode:document-unix-argv, r=RalfJung
Dylan-DPC Jul 21, 2021
8b727eb
Rollup merge of #87287 - oli-obk:fixup_fixup_fixup_opaque_types, r=sp…
Dylan-DPC Jul 21, 2021
8d9cb66
Rollup merge of #87301 - chinmaydd:chinmaydd-patch-1-1, r=jyn514
Dylan-DPC Jul 21, 2021
7eed57b
Rollup merge of #87307 - michaelwoerister:pgo-unwind-msvc, r=nagisa
Dylan-DPC Jul 21, 2021
49e429d
Rollup merge of #87311 - oli-obk:nll_suggestion_span, r=estebank
Dylan-DPC Jul 21, 2021
0366f9a
Rollup merge of #87321 - midgleyc:add-E0722-long, r=GuillaumeGomez
Dylan-DPC Jul 21, 2021
37bb86c
Rollup merge of #87326 - ehuss:update-cargo, r=ehuss
Dylan-DPC Jul 21, 2021
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
1 change: 1 addition & 0 deletions compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#![feature(new_uninit)]
#![feature(once_cell)]
#![feature(maybe_uninit_uninit_array)]
#![feature(min_type_alias_impl_trait)]
#![allow(rustc::default_hash_types)]
#![deny(unaligned_references)]

Expand Down
14 changes: 9 additions & 5 deletions compiler/rustc_data_structures/src/vec_map.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::borrow::Borrow;
use std::iter::FromIterator;
use std::slice::{Iter, IterMut};
use std::slice::Iter;
use std::vec::IntoIter;

use crate::stable_hasher::{HashStable, StableHasher};
Expand Down Expand Up @@ -67,9 +67,13 @@ where
self.into_iter()
}

pub fn iter_mut(&mut self) -> IterMut<'_, (K, V)> {
pub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)> {
self.into_iter()
}

pub fn retain(&mut self, f: impl Fn(&(K, V)) -> bool) {
self.0.retain(f)
}
}

impl<K, V> Default for VecMap<K, V> {
Expand Down Expand Up @@ -108,12 +112,12 @@ impl<'a, K, V> IntoIterator for &'a VecMap<K, V> {
}

impl<'a, K, V> IntoIterator for &'a mut VecMap<K, V> {
type Item = &'a mut (K, V);
type IntoIter = IterMut<'a, (K, V)>;
type Item = (&'a K, &'a mut V);
type IntoIter = impl Iterator<Item = Self::Item>;

#[inline]
fn into_iter(self) -> Self::IntoIter {
self.0.iter_mut()
self.0.iter_mut().map(|(k, v)| (&*k, v))
}
}

Expand Down
140 changes: 51 additions & 89 deletions compiler/rustc_mir/src/borrow_check/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rustc_middle::mir::*;
use rustc_middle::ty::adjustment::PointerCast;
use rustc_middle::ty::cast::CastTy;
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::subst::{GenericArgKind, Subst, SubstsRef, UserSubsts};
use rustc_middle::ty::subst::{GenericArgKind, SubstsRef, UserSubsts};
use rustc_middle::ty::{
self, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, OpaqueTypeKey, RegionVid,
ToPredicate, Ty, TyCtxt, UserType, UserTypeAnnotationIndex, WithConstness,
Expand Down Expand Up @@ -60,7 +60,6 @@ use crate::borrow_check::{
LivenessValues, PlaceholderIndex, PlaceholderIndices, RegionValueElements,
},
region_infer::{ClosureRegionRequirementsExt, TypeTest},
renumber,
type_check::free_region_relations::{CreateResult, UniversalRegionRelations},
universal_regions::{DefiningTy, UniversalRegions},
Upvar,
Expand Down Expand Up @@ -180,7 +179,54 @@ pub(crate) fn type_check<'mir, 'tcx>(
liveness::generate(&mut cx, body, elements, flow_inits, move_data, location_table);

translate_outlives_facts(&mut cx);
cx.opaque_type_values
let mut opaque_type_values = cx.opaque_type_values;

for (_, revealed_ty) in &mut opaque_type_values {
*revealed_ty = infcx.resolve_vars_if_possible(*revealed_ty);
if revealed_ty.has_infer_types_or_consts() {
infcx.tcx.sess.delay_span_bug(
body.span,
&format!("could not resolve {:#?}", revealed_ty.kind()),
);
*revealed_ty = infcx.tcx.ty_error();
}
}

opaque_type_values.retain(|(opaque_type_key, resolved_ty)| {
let concrete_is_opaque = if let ty::Opaque(def_id, _) = resolved_ty.kind() {
*def_id == opaque_type_key.def_id
} else {
false
};

if concrete_is_opaque {
// We're using an opaque `impl Trait` type without
// 'revealing' it. For example, code like this:
//
// type Foo = impl Debug;
// fn foo1() -> Foo { ... }
// fn foo2() -> Foo { foo1() }
//
// In `foo2`, we're not revealing the type of `Foo` - we're
// just treating it as the opaque type.
//
// When this occurs, we do *not* want to try to equate
// the concrete type with the underlying defining type
// of the opaque type - this will always fail, since
// the defining type of an opaque type is always
// some other type (e.g. not itself)
// Essentially, none of the normal obligations apply here -
// we're just passing around some unknown opaque type,
// without actually looking at the underlying type it
// gets 'revealed' into
debug!(
"eq_opaque_type_and_type: non-defining use of {:?}",
opaque_type_key.def_id,
);
}
!concrete_is_opaque
});
opaque_type_values
},
);

Expand Down Expand Up @@ -1239,14 +1285,10 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
return Ok(());
}

let infcx = self.infcx;
let tcx = infcx.tcx;
let param_env = self.param_env;
let body = self.body;
let mir_def_id = body.source.def_id().expect_local();

// the "concrete opaque types" maps
let concrete_opaque_types = &tcx.typeck(mir_def_id).concrete_opaque_types;
let mut opaque_type_values = VecMap::new();

debug!("eq_opaque_type_and_type: mir_def_id={:?}", mir_def_id);
Expand Down Expand Up @@ -1296,88 +1338,8 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
.eq(output_ty, revealed_ty)?,
);

// For each opaque type `Foo<T>` inferred by this value, we want to equate
// the inference variable `?T` with the revealed type that was computed
// earlier by type check.
for &(opaque_type_key, opaque_decl) in &opaque_type_map {
let resolved_ty = infcx.resolve_vars_if_possible(opaque_decl.concrete_ty);
let concrete_is_opaque = if let ty::Opaque(def_id, _) = resolved_ty.kind() {
*def_id == opaque_type_key.def_id
} else {
false
};

// The revealed type computed by the earlier phase of type check.
// In our example, this would be `(U, u32)`. Note that this references
// the type parameter `U` from the definition of `Foo`.
let concrete_ty = match concrete_opaque_types
.get_by(|(key, _)| key.def_id == opaque_type_key.def_id)
{
None => {
if !concrete_is_opaque {
tcx.sess.delay_span_bug(
body.span,
&format!(
"Non-defining use of {:?} with revealed type",
opaque_type_key.def_id,
),
);
}
continue;
}
Some(concrete_ty) => concrete_ty,
};
debug!("concrete_ty = {:?}", concrete_ty);

// Apply the substitution, in this case `[U -> T]`, so that the
// concrete type becomes `Foo<(T, u32)>`
let subst_opaque_defn_ty = concrete_ty.subst(tcx, opaque_type_key.substs);

// "Renumber" this, meaning that we replace all the regions
// with fresh inference variables. Not relevant to our example.
let renumbered_opaque_defn_ty =
renumber::renumber_regions(infcx, subst_opaque_defn_ty);

debug!(
"eq_opaque_type_and_type: concrete_ty={:?}={:?} opaque_defn_ty={:?}",
concrete_ty, resolved_ty, renumbered_opaque_defn_ty,
);

if !concrete_is_opaque {
// Equate the instantiated opaque type `opaque_decl.concrete_ty` (`?T`,
// in our example) with the renumbered version that we took from
// the type check results (`Foo<(T, u32)>`).
obligations.add(
infcx
.at(&ObligationCause::dummy(), param_env)
.eq(opaque_decl.concrete_ty, renumbered_opaque_defn_ty)?,
);
opaque_type_values.insert(opaque_type_key, renumbered_opaque_defn_ty);
} else {
// We're using an opaque `impl Trait` type without
// 'revealing' it. For example, code like this:
//
// type Foo = impl Debug;
// fn foo1() -> Foo { ... }
// fn foo2() -> Foo { foo1() }
//
// In `foo2`, we're not revealing the type of `Foo` - we're
// just treating it as the opaque type.
//
// When this occurs, we do *not* want to try to equate
// the concrete type with the underlying defining type
// of the opaque type - this will always fail, since
// the defining type of an opaque type is always
// some other type (e.g. not itself)
// Essentially, none of the normal obligations apply here -
// we're just passing around some unknown opaque type,
// without actually looking at the underlying type it
// gets 'revealed' into
debug!(
"eq_opaque_type_and_type: non-defining use of {:?}",
opaque_type_key.def_id,
);
}
opaque_type_values.insert(opaque_type_key, opaque_decl.concrete_ty);
}

debug!("eq_opaque_type_and_type: equated");
Expand Down Expand Up @@ -1405,7 +1367,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
locations,
ConstraintCategory::OpaqueType,
CustomTypeOp::new(
|_cx| {
|infcx| {
infcx.constrain_opaque_type(
opaque_type_key,
&opaque_decl,
Expand Down
22 changes: 9 additions & 13 deletions compiler/rustc_trait_selection/src/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ pub struct OpaqueTypeDecl<'tcx> {
}

/// Whether member constraints should be generated for all opaque types
#[derive(Debug)]
pub enum GenerateMemberConstraints {
/// The default, used by typeck
WhenRequired,
Expand Down Expand Up @@ -354,8 +355,6 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
opaque_types: &OpaqueTypeMap<'tcx>,
free_region_relations: &FRR,
) {
debug!("constrain_opaque_types()");

for &(opaque_type_key, opaque_defn) in opaque_types {
self.constrain_opaque_type(
opaque_type_key,
Expand All @@ -367,6 +366,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
}

/// See `constrain_opaque_types` for documentation.
#[instrument(level = "debug", skip(self, free_region_relations))]
fn constrain_opaque_type<FRR: FreeRegionRelations<'tcx>>(
&self,
opaque_type_key: OpaqueTypeKey<'tcx>,
Expand All @@ -376,15 +376,11 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
) {
let def_id = opaque_type_key.def_id;

debug!("constrain_opaque_type()");
debug!("constrain_opaque_type: def_id={:?}", def_id);
debug!("constrain_opaque_type: opaque_defn={:#?}", opaque_defn);

let tcx = self.tcx;

let concrete_ty = self.resolve_vars_if_possible(opaque_defn.concrete_ty);

debug!("constrain_opaque_type: concrete_ty={:?}", concrete_ty);
debug!(?concrete_ty);

let first_own_region = match opaque_defn.origin {
hir::OpaqueTyOrigin::FnReturn | hir::OpaqueTyOrigin::AsyncFn => {
Expand All @@ -397,7 +393,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
// type foo::<'p0..'pn>::Foo<'q0..'qm>
// fn foo<l0..'ln>() -> foo::<'static..'static>::Foo<'l0..'lm>.
//
// For these types we onlt iterate over `'l0..lm` below.
// For these types we only iterate over `'l0..lm` below.
tcx.generics_of(def_id).parent_count
}
// These opaque type inherit all lifetime parameters from their
Expand All @@ -410,10 +406,10 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
// If there are required region bounds, we can use them.
if opaque_defn.has_required_region_bounds {
let bounds = tcx.explicit_item_bounds(def_id);
debug!("constrain_opaque_type: predicates: {:#?}", bounds);
debug!("{:#?}", bounds);
let bounds: Vec<_> =
bounds.iter().map(|(bound, _)| bound.subst(tcx, opaque_type_key.substs)).collect();
debug!("constrain_opaque_type: bounds={:#?}", bounds);
debug!("{:#?}", bounds);
let opaque_type = tcx.mk_opaque(def_id, opaque_type_key.substs);

let required_region_bounds =
Expand Down Expand Up @@ -452,8 +448,8 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
};

// Compute the least upper bound of it with the other regions.
debug!("constrain_opaque_types: least_region={:?}", least_region);
debug!("constrain_opaque_types: subst_region={:?}", subst_region);
debug!(?least_region);
debug!(?subst_region);
match least_region {
None => least_region = Some(subst_region),
Some(lr) => {
Expand Down Expand Up @@ -484,7 +480,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
}

let least_region = least_region.unwrap_or(tcx.lifetimes.re_static);
debug!("constrain_opaque_types: least_region={:?}", least_region);
debug!(?least_region);

if let GenerateMemberConstraints::IfNoStaticBound = mode {
if least_region != tcx.lifetimes.re_static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ impl Bar for AssocNoCopy {
impl Thing for AssocNoCopy {
type Out = Box<dyn Bar<Assoc: Copy>>;
//~^ ERROR the trait bound `String: Copy` is not satisfied
//~| ERROR the trait bound `String: Copy` is not satisfied

fn func() -> Self::Out {
Box::new(AssocNoCopy)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ error[E0277]: the trait bound `String: Copy` is not satisfied
LL | type Out = Box<dyn Bar<Assoc: Copy>>;
| ^^^^^^^^^^^ the trait `Copy` is not implemented for `String`

error[E0277]: the trait bound `String: Copy` is not satisfied
--> $DIR/assoc-type-eq-with-dyn-atb-fail.rs:30:28
|
LL | type Out = Box<dyn Bar<Assoc: Copy>>;
| ^^^^^^^^^^^ the trait `Copy` is not implemented for `String`

error: aborting due to 2 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
1 change: 0 additions & 1 deletion src/test/ui/impl-trait/auto-trait-leak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ fn main() {
fn cycle1() -> impl Clone {
//~^ ERROR cycle detected
send(cycle2().clone());
//~^ ERROR cannot be sent between threads safely

Rc::new(Cell::new(5))
}
Expand Down
Loading