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 7 pull requests #79317

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b813c72
Clean up `StructuralEq` docs
camelid Nov 6, 2020
773b73c
Split iterator adaptors into individual modules
WaffleLapkin Oct 7, 2020
66d6708
Split iterator sources into different modules
WaffleLapkin Oct 7, 2020
b82a76a
Merge `use`s in core::iter
WaffleLapkin Oct 7, 2020
0dc187c
Fix doc links in core::iter::sources
WaffleLapkin Oct 8, 2020
e0e906b
Fix UI tests
WaffleLapkin Oct 8, 2020
4612658
Remove multiline `use`s
WaffleLapkin Oct 8, 2020
ee6f42b
Thread `Constness` through selection
jonas-schievink Nov 22, 2020
71d350e
winnow: drop non-const cand. in favor of const
jonas-schievink Nov 22, 2020
e69fcea
const fn: allow use of trait impls from bounds
jonas-schievink Nov 22, 2020
3ca187e
libtest: Print the total time taken to execute a test suite
jakoschiko Sep 20, 2020
0487efd
libtest: Use a number value for the key "exec_time" in the JSON output
jakoschiko Nov 22, 2020
6667c66
Add test for an unmotivated "cannot determine resolution" error
petrochenkov Nov 22, 2020
27af650
resolve: Do not put macros into `module.unexpanded_invocations` unles…
petrochenkov Nov 21, 2020
cf32afc
Stabilise `then`
varkor Nov 22, 2020
cb40684
Add some more tests
jonas-schievink Nov 22, 2020
46993ef
libtest: Normalize test suite execution time output of ui tests
jakoschiko Nov 22, 2020
5c6689b
Stabilize refcell_take
ThinkChaos Oct 31, 2020
23f631c
Rollup merge of #75752 - jakoschiko:test-suite-time, r=m-ou-se
m-ou-se Nov 22, 2020
f7b4a0c
Rollup merge of #77697 - WaffleLapkin:iter_split_adaptors, r=m-ou-se
m-ou-se Nov 22, 2020
31a2768
Rollup merge of #78608 - ThinkChaos:stabilize_refcell_take, r=m-ou-se
m-ou-se Nov 22, 2020
6abdaf8
Rollup merge of #78793 - camelid:fixup-structuraleq, r=jyn514
m-ou-se Nov 22, 2020
746f906
Rollup merge of #79287 - jonas-schievink:const-trait-impl, r=oli-obk
m-ou-se Nov 22, 2020
b987c3a
Rollup merge of #79294 - petrochenkov:determ, r=varkor
m-ou-se Nov 22, 2020
4ed2694
Rollup merge of #79299 - varkor:stabilise-then, r=m-ou-se
m-ou-se Nov 22, 2020
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: 0 additions & 1 deletion compiler/rustc_index/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(allow_internal_unstable)]
#![feature(bool_to_option)]
#![feature(const_fn)]
#![feature(const_panic)]
#![feature(extend_one)]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/traits/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ impl<'tcx, I: Iterator<Item = PredicateObligation<'tcx>>> Iterator for FilterToT
fn next(&mut self) -> Option<ty::PolyTraitRef<'tcx>> {
while let Some(obligation) = self.base_iterator.next() {
if let Some(data) = obligation.predicate.to_opt_poly_trait_ref() {
return Some(data);
return Some(data.value);
}
}
None
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_metadata/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(bool_to_option)]
#![feature(core_intrinsics)]
#![feature(crate_visibility_modifier)]
#![feature(drain_filter)]
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_middle/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::ty::{self, AdtKind, Ty, TyCtxt};
use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::Constness;
use rustc_span::symbol::Symbol;
use rustc_span::{Span, DUMMY_SP};
use smallvec::SmallVec;
Expand Down Expand Up @@ -457,7 +458,7 @@ pub enum ImplSource<'tcx, N> {
/// for some type parameter. The `Vec<N>` represents the
/// obligations incurred from normalizing the where-clause (if
/// any).
Param(Vec<N>),
Param(Vec<N>, Constness),

/// Virtual calls through an object.
Object(ImplSourceObjectData<'tcx, N>),
Expand Down Expand Up @@ -487,7 +488,7 @@ impl<'tcx, N> ImplSource<'tcx, N> {
pub fn nested_obligations(self) -> Vec<N> {
match self {
ImplSource::UserDefined(i) => i.nested,
ImplSource::Param(n) => n,
ImplSource::Param(n, _) => n,
ImplSource::Builtin(i) => i.nested,
ImplSource::AutoImpl(d) => d.nested,
ImplSource::Closure(c) => c.nested,
Expand All @@ -502,7 +503,7 @@ impl<'tcx, N> ImplSource<'tcx, N> {
pub fn borrow_nested_obligations(&self) -> &[N] {
match &self {
ImplSource::UserDefined(i) => &i.nested[..],
ImplSource::Param(n) => &n[..],
ImplSource::Param(n, _) => &n[..],
ImplSource::Builtin(i) => &i.nested[..],
ImplSource::AutoImpl(d) => &d.nested[..],
ImplSource::Closure(c) => &c.nested[..],
Expand All @@ -524,7 +525,7 @@ impl<'tcx, N> ImplSource<'tcx, N> {
substs: i.substs,
nested: i.nested.into_iter().map(f).collect(),
}),
ImplSource::Param(n) => ImplSource::Param(n.into_iter().map(f).collect()),
ImplSource::Param(n, ct) => ImplSource::Param(n.into_iter().map(f).collect(), ct),
ImplSource::Builtin(i) => ImplSource::Builtin(ImplSourceBuiltinData {
nested: i.nested.into_iter().map(f).collect(),
}),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub enum SelectionCandidate<'tcx> {
/// `false` if there are no *further* obligations.
has_nested: bool,
},
ParamCandidate(ty::PolyTraitRef<'tcx>),
ParamCandidate(ty::ConstnessAnd<ty::PolyTraitRef<'tcx>>),
ImplCandidate(DefId),
AutoImplCandidate(DefId),

Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_middle/src/traits/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ impl<'tcx, N: fmt::Debug> fmt::Debug for traits::ImplSource<'tcx, N> {

super::ImplSource::Object(ref d) => write!(f, "{:?}", d),

super::ImplSource::Param(ref n) => write!(f, "ImplSourceParamData({:?})", n),
super::ImplSource::Param(ref n, ct) => {
write!(f, "ImplSourceParamData({:?}, {:?})", n, ct)
}

super::ImplSource::Builtin(ref d) => write!(f, "{:?}", d),

Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, LocalDefId, LOCAL_CRATE};
use rustc_hir::definitions::{DefPathHash, Definitions};
use rustc_hir::intravisit::Visitor;
use rustc_hir::lang_items::LangItem;
use rustc_hir::{HirId, ItemKind, ItemLocalId, ItemLocalMap, ItemLocalSet, Node, TraitCandidate};
use rustc_hir::{
Constness, HirId, ItemKind, ItemLocalId, ItemLocalMap, ItemLocalSet, Node, TraitCandidate,
};
use rustc_index::vec::{Idx, IndexVec};
use rustc_macros::HashStable;
use rustc_session::config::{BorrowckMode, CrateType, OutputFilenames};
Expand Down Expand Up @@ -1635,6 +1637,8 @@ nop_list_lift! {projs; ProjectionKind => ProjectionKind}
// This is the impl for `&'a InternalSubsts<'a>`.
nop_list_lift! {substs; GenericArg<'a> => GenericArg<'tcx>}

CloneLiftImpls! { for<'tcx> { Constness, } }

pub mod tls {
use super::{ptr_eq, GlobalCtxt, TyCtxt};

Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1503,9 +1503,11 @@ impl<'tcx> ToPredicate<'tcx> for PolyProjectionPredicate<'tcx> {
}

impl<'tcx> Predicate<'tcx> {
pub fn to_opt_poly_trait_ref(self) -> Option<PolyTraitRef<'tcx>> {
pub fn to_opt_poly_trait_ref(self) -> Option<ConstnessAnd<PolyTraitRef<'tcx>>> {
match self.skip_binders() {
PredicateAtom::Trait(t, _) => Some(ty::Binder::bind(t.trait_ref)),
PredicateAtom::Trait(t, constness) => {
Some(ConstnessAnd { constness, value: ty::Binder::bind(t.trait_ref) })
}
PredicateAtom::Projection(..)
| PredicateAtom::Subtype(..)
| PredicateAtom::RegionOutlives(..)
Expand Down Expand Up @@ -1947,7 +1949,7 @@ impl<'tcx> ParamEnv<'tcx> {
}
}

#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, TypeFoldable)]
pub struct ConstnessAnd<T> {
pub constness: Constness,
pub value: T,
Expand Down
40 changes: 36 additions & 4 deletions compiler/rustc_mir/src/transform/check_consts/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@ use rustc_errors::{struct_span_err, Applicability, Diagnostic, ErrorReported};
use rustc_hir::def_id::DefId;
use rustc_hir::{self as hir, HirId, LangItem};
use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::traits::{ImplSource, Obligation, ObligationCause};
use rustc_middle::mir::visit::{MutatingUseContext, NonMutatingUseContext, PlaceContext, Visitor};
use rustc_middle::mir::*;
use rustc_middle::ty::cast::CastTy;
use rustc_middle::ty::subst::GenericArgKind;
use rustc_middle::ty::{
self, adjustment::PointerCast, Instance, InstanceDef, Ty, TyCtxt, TypeAndMut,
};
use rustc_middle::ty::{Binder, TraitPredicate, TraitRef};
use rustc_span::{sym, Span, Symbol};
use rustc_trait_selection::traits::error_reporting::InferCtxtExt;
use rustc_trait_selection::traits::{self, TraitEngine};
use rustc_trait_selection::traits::{self, SelectionContext, TraitEngine};

use std::mem;
use std::ops::Deref;
Expand Down Expand Up @@ -765,9 +767,39 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
}
};

// Resolve a trait method call to its concrete implementation, which may be in a
// `const` trait impl.
if self.tcx.features().const_trait_impl {
// Attempting to call a trait method?
if let Some(trait_id) = tcx.trait_of_item(callee) {
if !self.tcx.features().const_trait_impl {
self.check_op(ops::FnCallNonConst(callee));
return;
}

let trait_ref = TraitRef::from_method(tcx, trait_id, substs);
let obligation = Obligation::new(
ObligationCause::dummy(),
param_env,
Binder::bind(TraitPredicate {
trait_ref: TraitRef::from_method(tcx, trait_id, substs),
}),
);

let implsrc = tcx.infer_ctxt().enter(|infcx| {
let mut selcx = SelectionContext::new(&infcx);
selcx.select(&obligation).unwrap()
});

// If the method is provided via a where-clause that does not use the `?const`
// opt-out, the call is allowed.
if let Some(ImplSource::Param(_, hir::Constness::Const)) = implsrc {
debug!(
"const_trait_impl: provided {:?} via where-clause in {:?}",
trait_ref, param_env
);
return;
}

// Resolve a trait method call to its concrete implementation, which may be in a
// `const` trait impl.
let instance = Instance::resolve(tcx, param_env, callee, substs);
debug!("Resolving ({:?}) -> {:?}", callee, instance);
if let Ok(Some(func)) = instance {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_parse/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! The main parser interface.

#![feature(bool_to_option)]
#![feature(crate_visibility_modifier)]
#![feature(bindings_after_at)]
#![feature(iter_order_by)]
Expand Down
29 changes: 20 additions & 9 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1155,14 +1155,18 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
false
}

fn visit_invoc(&mut self, id: NodeId) -> MacroRulesScopeRef<'a> {
fn visit_invoc(&mut self, id: NodeId) -> ExpnId {
let invoc_id = id.placeholder_to_expn_id();

self.parent_scope.module.unexpanded_invocations.borrow_mut().insert(invoc_id);

let old_parent_scope = self.r.invocation_parent_scopes.insert(invoc_id, self.parent_scope);
assert!(old_parent_scope.is_none(), "invocation data is reset for an invocation");
invoc_id
}

/// Visit invocation in context in which it can emit a named item (possibly `macro_rules`)
/// directly into its parent scope's module.
fn visit_invoc_in_module(&mut self, id: NodeId) -> MacroRulesScopeRef<'a> {
let invoc_id = self.visit_invoc(id);
self.parent_scope.module.unexpanded_invocations.borrow_mut().insert(invoc_id);
self.r.arenas.alloc_macro_rules_scope(MacroRulesScope::Invocation(invoc_id))
}

Expand Down Expand Up @@ -1291,7 +1295,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
return;
}
ItemKind::MacCall(..) => {
self.parent_scope.macro_rules = self.visit_invoc(item.id);
self.parent_scope.macro_rules = self.visit_invoc_in_module(item.id);
return;
}
ItemKind::Mod(..) => self.contains_macro_use(&item.attrs),
Expand All @@ -1309,15 +1313,15 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {

fn visit_stmt(&mut self, stmt: &'b ast::Stmt) {
if let ast::StmtKind::MacCall(..) = stmt.kind {
self.parent_scope.macro_rules = self.visit_invoc(stmt.id);
self.parent_scope.macro_rules = self.visit_invoc_in_module(stmt.id);
} else {
visit::walk_stmt(self, stmt);
}
}

fn visit_foreign_item(&mut self, foreign_item: &'b ForeignItem) {
if let ForeignItemKind::MacCall(_) = foreign_item.kind {
self.visit_invoc(foreign_item.id);
self.visit_invoc_in_module(foreign_item.id);
return;
}

Expand All @@ -1336,7 +1340,14 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {

fn visit_assoc_item(&mut self, item: &'b AssocItem, ctxt: AssocCtxt) {
if let AssocItemKind::MacCall(_) = item.kind {
self.visit_invoc(item.id);
match ctxt {
AssocCtxt::Trait => {
self.visit_invoc_in_module(item.id);
}
AssocCtxt::Impl => {
self.visit_invoc(item.id);
}
}
return;
}

Expand Down Expand Up @@ -1460,7 +1471,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
// type and value namespaces.
fn visit_variant(&mut self, variant: &'b ast::Variant) {
if variant.is_placeholder {
self.visit_invoc(variant.id);
self.visit_invoc_in_module(variant.id);
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {

// Micro-optimization: filter out predicates relating to different traits.
let matching_bounds =
all_bounds.filter(|p| p.def_id() == stack.obligation.predicate.def_id());
all_bounds.filter(|p| p.value.def_id() == stack.obligation.predicate.def_id());

// Keep only those bounds which may apply, and propagate overflow if it occurs.
for bound in matching_bounds {
let wc = self.evaluate_where_clause(stack, bound)?;
let wc = self.evaluate_where_clause(stack, bound.value)?;
if wc.may_apply() {
candidates.vec.push(ParamCandidate(bound));
}
Expand Down
12 changes: 7 additions & 5 deletions compiler/rustc_trait_selection/src/traits/select/confirmation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//! https://rustc-dev-guide.rust-lang.org/traits/resolution.html#confirmation
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_hir::lang_items::LangItem;
use rustc_hir::Constness;
use rustc_index::bit_set::GrowableBitSet;
use rustc_infer::infer::InferOk;
use rustc_infer::infer::LateBoundRegionConversionTime::HigherRankedType;
Expand Down Expand Up @@ -55,8 +56,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}

ParamCandidate(param) => {
let obligations = self.confirm_param_candidate(obligation, param);
Ok(ImplSource::Param(obligations))
let obligations = self.confirm_param_candidate(obligation, param.value);
Ok(ImplSource::Param(obligations, param.constness))
}

ImplCandidate(impl_def_id) => {
Expand All @@ -70,7 +71,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {

ProjectionCandidate(idx) => {
let obligations = self.confirm_projection_candidate(obligation, idx)?;
Ok(ImplSource::Param(obligations))
// FIXME(jschievink): constness
Ok(ImplSource::Param(obligations, Constness::NotConst))
}

ObjectCandidate(idx) => {
Expand Down Expand Up @@ -106,7 +108,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
// This indicates something like `Trait + Send: Send`. In this case, we know that
// this holds because that's what the object type is telling us, and there's really
// no additional obligations to prove and no types in particular to unify, etc.
Ok(ImplSource::Param(Vec::new()))
Ok(ImplSource::Param(Vec::new(), Constness::NotConst))
}

BuiltinUnsizeCandidate => {
Expand Down Expand Up @@ -151,7 +153,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligations.extend(self.infcx.commit_if_ok(|_| {
self.infcx
.at(&obligation.cause, obligation.param_env)
.sup(placeholder_trait_predicate.trait_ref.to_poly_trait_ref(), candidate)
.sup(placeholder_trait_predicate.trait_ref.to_poly_trait_ref(), candidate.value)
.map(|InferOk { obligations, .. }| obligations)
.map_err(|_| Unimplemented)
})?);
Expand Down
16 changes: 12 additions & 4 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_errors::ErrorReported;
use rustc_hir as hir;
use rustc_hir::def_id::DefId;
use rustc_hir::Constness;
use rustc_middle::dep_graph::{DepKind, DepNodeIndex};
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::ty::fast_reject;
Expand Down Expand Up @@ -1335,7 +1336,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
(BuiltinCandidate { has_nested: false } | DiscriminantKindCandidate, _) => true,
(_, BuiltinCandidate { has_nested: false } | DiscriminantKindCandidate) => false,

(ParamCandidate(..), ParamCandidate(..)) => false,
(ParamCandidate(other), ParamCandidate(victim)) => {
if other.value == victim.value && victim.constness == Constness::NotConst {
// Drop otherwise equivalent non-const candidates in favor of const candidates.
true
} else {
false
}
}

// Global bounds from the where clause should be ignored
// here (see issue #50825). Otherwise, we have a where
Expand All @@ -1354,11 +1362,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
| TraitAliasCandidate(..)
| ObjectCandidate(_)
| ProjectionCandidate(_),
) => !is_global(cand),
) => !is_global(&cand.value),
(ObjectCandidate(_) | ProjectionCandidate(_), ParamCandidate(ref cand)) => {
// Prefer these to a global where-clause bound
// (see issue #50825).
is_global(cand)
is_global(&cand.value)
}
(
ImplCandidate(_)
Expand All @@ -1373,7 +1381,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
) => {
// Prefer these to a global where-clause bound
// (see issue #50825).
is_global(cand) && other.evaluation.must_apply_modulo_regions()
is_global(&cand.value) && other.evaluation.must_apply_modulo_regions()
}

(ProjectionCandidate(i), ProjectionCandidate(j))
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_trait_selection/src/traits/specialize/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Option<String>

for (p, _) in predicates {
if let Some(poly_trait_ref) = p.to_opt_poly_trait_ref() {
if Some(poly_trait_ref.def_id()) == sized_trait {
types_without_default_bounds.remove(poly_trait_ref.self_ty().skip_binder());
if Some(poly_trait_ref.value.def_id()) == sized_trait {
types_without_default_bounds.remove(poly_trait_ref.value.self_ty().skip_binder());
continue;
}
}
Expand Down
Loading