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

Rollup of 10 pull requests #89783

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a57c18b
add `Poll::ready`
ibraheemdev Oct 7, 2021
a3f98a7
Fix inherent impl overlap check.
cjgillot Oct 7, 2021
5f7e7d2
revert stabilization of `core::task::ready!`
ibraheemdev Oct 7, 2021
597090e
Re-use TypeChecker instead of passing around some of its fields
oli-obk Sep 30, 2021
49b06a2
Directly call relate_types function instead of having a method wrapper
oli-obk Oct 8, 2021
7f974d0
Greatly reduce amount of debuginfo compiled for bootstrap itself
jyn514 Oct 11, 2021
1b283d4
Remove hack ignoring unused attributes for stage 0 std
jyn514 Oct 11, 2021
3ac0ae2
Add #[must_use] to MaybeUninit::new
jkugelman Oct 11, 2021
6531cd8
Fix function-names test for GDB 10.1
michaelwoerister Oct 11, 2021
3d1996a
Add #[must_use] to From::from and Into::into
jkugelman Oct 11, 2021
de940fc
Use Ancestory to check default fn in const impl instead of comparing …
nbdd0121 Oct 2, 2021
0a03f8c
Split impl-with-default-fn test into a pass test and a fail test
nbdd0121 Oct 11, 2021
06e625f
Add #[must_use] to as_type conversions
jkugelman Oct 11, 2021
b0b09f0
Update library/core/src/mem/maybe_uninit.rs
jkugelman Oct 11, 2021
7a7dfa8
Remove task::ready! from 1.56.0 release notes
dtolnay Oct 11, 2021
a1e03fc
Add library tracking issue for poll_ready feature
dtolnay Oct 11, 2021
4be2dea
Rollup merge of #89471 - nbdd0121:const3, r=fee1-dead
matthiaskrgr Oct 11, 2021
8ec0e28
Rollup merge of #89643 - cjgillot:overlap, r=matthewjasper
matthiaskrgr Oct 11, 2021
ab3df12
Rollup merge of #89651 - ibraheemdev:poll-ready, r=dtolnay
matthiaskrgr Oct 11, 2021
43a94bf
Rollup merge of #89675 - oli-obk:type_checker, r=davidtwco
matthiaskrgr Oct 11, 2021
85412d4
Rollup merge of #89756 - jyn514:bootstrap-times, r=Mark-Simulacrum
matthiaskrgr Oct 11, 2021
7ebfc6c
Rollup merge of #89760 - jyn514:remove-incremental-hack, r=Mark-Simul…
matthiaskrgr Oct 11, 2021
817ccb7
Rollup merge of #89769 - jkugelman:must-use-maybe-uninit-new, r=josht…
matthiaskrgr Oct 11, 2021
18730a2
Rollup merge of #89770 - jkugelman:must-use-from-and-into, r=joshtrip…
matthiaskrgr Oct 11, 2021
4fddd9e
Rollup merge of #89772 - michaelwoerister:fix-function-names-test-gdb…
matthiaskrgr Oct 11, 2021
96fe5ad
Rollup merge of #89778 - jkugelman:must-use-as_type-conversions, r=jo…
matthiaskrgr Oct 11, 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
9 changes: 9 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ gimli.debug = 0
miniz_oxide.debug = 0
object.debug = 0

# The only package that ever uses debug builds is bootstrap.
# We care a lot about bootstrap's compile times, so don't include debug info for
# dependencies, only bootstrap itself.
[profile.dev]
debug = 0
[profile.dev.package]
# Only use debuginfo=1 to further reduce compile times.
bootstrap.debug = 1

# We want the RLS to use the version of Cargo that we've got vendored in this
# repository to ensure that the same exact version of Cargo is used by both the
# RLS and the Cargo binary itself. The RLS depends on Cargo as a git repository
Expand Down
2 changes: 0 additions & 2 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ Stabilised APIs
- [`VecDeque::shrink_to`]
- [`HashMap::shrink_to`]
- [`HashSet::shrink_to`]
- [`task::ready!`]

These APIs are now usable in const contexts:

Expand Down Expand Up @@ -128,7 +127,6 @@ and related tools.
[`VecDeque::shrink_to`]: https://doc.rust-lang.org/stable/std/collections/struct.VecDeque.html#method.shrink_to
[`HashMap::shrink_to`]: https://doc.rust-lang.org/stable/std/collections/hash_map/struct.HashMap.html#method.shrink_to
[`HashSet::shrink_to`]: https://doc.rust-lang.org/stable/std/collections/hash_set/struct.HashSet.html#method.shrink_to
[`task::ready!`]: https://doc.rust-lang.org/stable/std/task/macro.ready.html
[`std::mem::transmute`]: https://doc.rust-lang.org/stable/std/mem/fn.transmute.html
[`slice::first`]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.first
[`slice::split_first`]: https://doc.rust-lang.org/stable/std/primitive.slice.html#method.split_first
Expand Down
22 changes: 0 additions & 22 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1153,28 +1153,6 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
.convert_all(data);
}

/// Convenient wrapper around `relate_tys::relate_types` -- see
/// that fn for docs.
fn relate_types(
&mut self,
a: Ty<'tcx>,
v: ty::Variance,
b: Ty<'tcx>,
locations: Locations,
category: ConstraintCategory,
) -> Fallible<()> {
relate_tys::relate_types(
self.infcx,
self.param_env,
a,
v,
b,
locations,
category,
self.borrowck_context,
)
}

/// Try to relate `sub <: sup`
fn sub_types(
&mut self,
Expand Down
112 changes: 53 additions & 59 deletions compiler/rustc_borrowck/src/type_check/relate_tys.rs
Original file line number Diff line number Diff line change
@@ -1,54 +1,44 @@
use rustc_infer::infer::nll_relate::{NormalizationStrategy, TypeRelating, TypeRelatingDelegate};
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
use rustc_infer::infer::NllRegionVariableOrigin;
use rustc_middle::mir::ConstraintCategory;
use rustc_middle::ty::relate::TypeRelation;
use rustc_middle::ty::{self, Const, Ty};
use rustc_trait_selection::traits::query::Fallible;

use crate::constraints::OutlivesConstraint;
use crate::diagnostics::UniverseInfo;
use crate::type_check::{BorrowCheckContext, Locations};

/// Adds sufficient constraints to ensure that `a R b` where `R` depends on `v`:
///
/// - "Covariant" `a <: b`
/// - "Invariant" `a == b`
/// - "Contravariant" `a :> b`
///
/// N.B., the type `a` is permitted to have unresolved inference
/// variables, but not the type `b`.
#[instrument(skip(infcx, param_env, borrowck_context), level = "debug")]
pub(super) fn relate_types<'tcx>(
infcx: &InferCtxt<'_, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
a: Ty<'tcx>,
v: ty::Variance,
b: Ty<'tcx>,
locations: Locations,
category: ConstraintCategory,
borrowck_context: &mut BorrowCheckContext<'_, 'tcx>,
) -> Fallible<()> {
TypeRelating::new(
infcx,
NllTypeRelatingDelegate::new(
infcx,
borrowck_context,
param_env,
locations,
category,
UniverseInfo::relate(a, b),
),
v,
)
.relate(a, b)?;
Ok(())
use crate::type_check::{Locations, TypeChecker};

impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
/// Adds sufficient constraints to ensure that `a R b` where `R` depends on `v`:
///
/// - "Covariant" `a <: b`
/// - "Invariant" `a == b`
/// - "Contravariant" `a :> b`
///
/// N.B., the type `a` is permitted to have unresolved inference
/// variables, but not the type `b`.
#[instrument(skip(self), level = "debug")]
pub(super) fn relate_types(
&mut self,
a: Ty<'tcx>,
v: ty::Variance,
b: Ty<'tcx>,
locations: Locations,
category: ConstraintCategory,
) -> Fallible<()> {
TypeRelating::new(
self.infcx,
NllTypeRelatingDelegate::new(self, locations, category, UniverseInfo::relate(a, b)),
v,
)
.relate(a, b)?;
Ok(())
}
}

struct NllTypeRelatingDelegate<'me, 'bccx, 'tcx> {
infcx: &'me InferCtxt<'me, 'tcx>,
borrowck_context: &'me mut BorrowCheckContext<'bccx, 'tcx>,

param_env: ty::ParamEnv<'tcx>,
type_checker: &'me mut TypeChecker<'bccx, 'tcx>,

/// Where (and why) is this relation taking place?
locations: Locations,
Expand All @@ -63,25 +53,24 @@ struct NllTypeRelatingDelegate<'me, 'bccx, 'tcx> {

impl NllTypeRelatingDelegate<'me, 'bccx, 'tcx> {
fn new(
infcx: &'me InferCtxt<'me, 'tcx>,
borrowck_context: &'me mut BorrowCheckContext<'bccx, 'tcx>,
param_env: ty::ParamEnv<'tcx>,
type_checker: &'me mut TypeChecker<'bccx, 'tcx>,
locations: Locations,
category: ConstraintCategory,
universe_info: UniverseInfo<'tcx>,
) -> Self {
Self { infcx, borrowck_context, param_env, locations, category, universe_info }
Self { type_checker, locations, category, universe_info }
}
}

impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> {
fn param_env(&self) -> ty::ParamEnv<'tcx> {
self.param_env
self.type_checker.param_env
}

fn create_next_universe(&mut self) -> ty::UniverseIndex {
let universe = self.infcx.create_next_universe();
self.borrowck_context
let universe = self.type_checker.infcx.create_next_universe();
self.type_checker
.borrowck_context
.constraints
.universe_causes
.insert(universe, self.universe_info.clone());
Expand All @@ -90,15 +79,18 @@ impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> {

fn next_existential_region_var(&mut self, from_forall: bool) -> ty::Region<'tcx> {
let origin = NllRegionVariableOrigin::Existential { from_forall };
self.infcx.next_nll_region_var(origin)
self.type_checker.infcx.next_nll_region_var(origin)
}

fn next_placeholder_region(&mut self, placeholder: ty::PlaceholderRegion) -> ty::Region<'tcx> {
self.borrowck_context.constraints.placeholder_region(self.infcx, placeholder)
self.type_checker
.borrowck_context
.constraints
.placeholder_region(self.type_checker.infcx, placeholder)
}

fn generalize_existential(&mut self, universe: ty::UniverseIndex) -> ty::Region<'tcx> {
self.infcx.next_nll_region_var_in_universe(
self.type_checker.infcx.next_nll_region_var_in_universe(
NllRegionVariableOrigin::Existential { from_forall: false },
universe,
)
Expand All @@ -110,15 +102,17 @@ impl TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx> {
sub: ty::Region<'tcx>,
info: ty::VarianceDiagInfo<'tcx>,
) {
let sub = self.borrowck_context.universal_regions.to_region_vid(sub);
let sup = self.borrowck_context.universal_regions.to_region_vid(sup);
self.borrowck_context.constraints.outlives_constraints.push(OutlivesConstraint {
sup,
sub,
locations: self.locations,
category: self.category,
variance_info: info,
});
let sub = self.type_checker.borrowck_context.universal_regions.to_region_vid(sub);
let sup = self.type_checker.borrowck_context.universal_regions.to_region_vid(sup);
self.type_checker.borrowck_context.constraints.outlives_constraints.push(
OutlivesConstraint {
sup,
sub,
locations: self.locations,
category: self.category,
variance_info: info,
},
);
}

// We don't have to worry about the equality of consts during borrow checking
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_index/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,12 @@ impl<I: Idx, T> IndexVec<I, Option<T>> {
self.ensure_contains_elem(index, || None);
self[index].get_or_insert_with(value)
}

#[inline]
pub fn remove(&mut self, index: I) -> Option<T> {
self.ensure_contains_elem(index, || None);
self[index].take()
}
}

impl<I: Idx, T: Clone> IndexVec<I, T> {
Expand Down
44 changes: 26 additions & 18 deletions compiler/rustc_passes/src/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
//! through, but errors for structured control flow in a `const` should be emitted here.

use rustc_attr as attr;
use rustc_data_structures::stable_set::FxHashSet;
use rustc_errors::struct_span_err;
use rustc_hir as hir;
use rustc_hir::def_id::LocalDefId;
Expand Down Expand Up @@ -83,30 +82,39 @@ impl<'tcx> hir::itemlikevisit::ItemLikeVisitor<'tcx> for CheckConstTraitVisitor<
let _: Option<_> = try {
if let hir::ItemKind::Impl(ref imp) = item.kind {
if let hir::Constness::Const = imp.constness {
let did = imp.of_trait.as_ref()?.trait_def_id()?;
let mut to_implement = FxHashSet::default();

for did in self.tcx.associated_item_def_ids(did) {
let trait_def_id = imp.of_trait.as_ref()?.trait_def_id()?;
let ancestors = self
.tcx
.trait_def(trait_def_id)
.ancestors(self.tcx, item.def_id.to_def_id())
.ok()?;
let mut to_implement = Vec::new();

for trait_item in self.tcx.associated_items(trait_def_id).in_definition_order()
{
if let ty::AssocItem {
kind: ty::AssocKind::Fn, ident, defaultness, ..
} = self.tcx.associated_item(*did)
} = trait_item
{
// we can ignore functions that do not have default bodies:
// if those are unimplemented it will be catched by typeck.
if defaultness.has_value()
&& !self.tcx.has_attr(*did, sym::default_method_body_is_const)
if !defaultness.has_value()
|| self
.tcx
.has_attr(trait_item.def_id, sym::default_method_body_is_const)
{
to_implement.insert(ident);
continue;
}
}
}

for it in imp
.items
.iter()
.filter(|it| matches!(it.kind, hir::AssocItemKind::Fn { .. }))
{
to_implement.remove(&it.ident);
let is_implemented = ancestors
.leaf_def(self.tcx, trait_item.ident, trait_item.kind)
.map(|node_item| !node_item.defining_node.is_from_trait())
.unwrap_or(false);

if !is_implemented {
to_implement.push(ident.to_string());
}
}
}

// all nonconst trait functions (not marked with #[default_method_body_is_const])
Expand All @@ -118,7 +126,7 @@ impl<'tcx> hir::itemlikevisit::ItemLikeVisitor<'tcx> for CheckConstTraitVisitor<
item.span,
"const trait implementations may not use non-const default functions",
)
.note(&format!("`{}` not implemented", to_implement.into_iter().map(|id| id.to_string()).collect::<Vec<_>>().join("`, `")))
.note(&format!("`{}` not implemented", to_implement.join("`, `")))
.emit();
}
}
Expand Down
Loading