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 #79345

Merged
merged 26 commits into from
Nov 23, 2020
Merged
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
f7bf282
MIR visitor: Don't treat debuginfo field access as a use of the struct
camelid Nov 15, 2020
34ea5d0
const_generics: assert resolve hack causes an error
lcnr Nov 20, 2020
c85af74
update bug message for cg
lcnr Nov 20, 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
cb40684
Add some more tests
jonas-schievink Nov 22, 2020
674f196
Use Option::and_then instead of open-coding it
LingMan Oct 11, 2020
e0871cc
Reduce boilerplate with the `?` operator
LingMan Oct 11, 2020
aca37b6
stabilize const_int_pow
tspiteri Oct 2, 2020
a6bcf7a
const_int_pow will be stabilized in 1.50.0, not in 1.49.0
tspiteri Nov 23, 2020
432a33e
Fix typo in comment
jyn514 Nov 23, 2020
b196bec
Add comment and remove obsolete special case
camelid Nov 23, 2020
a804e38
doc typo
Nov 23, 2020
cd89732
Use Option::map instead of open coding it
LingMan Nov 23, 2020
c7d1189
Add my (@flip1995) work mail to the mailmap
flip1995 Nov 23, 2020
703f176
Rollup merge of #76829 - tspiteri:const-int-pow, r=oli-obk
jonas-schievink Nov 23, 2020
d4a0569
Rollup merge of #79080 - camelid:mir-visit-debuginfo-project, r=jonas…
jonas-schievink Nov 23, 2020
c58c245
Rollup merge of #79236 - lcnr:mcg-resolve-dsb, r=eddyb
jonas-schievink Nov 23, 2020
c7a6720
Rollup merge of #79287 - jonas-schievink:const-trait-impl, r=oli-obk
jonas-schievink Nov 23, 2020
32be3ae
Rollup merge of #79324 - LingMan:and_then, r=jonas-schievink
jonas-schievink Nov 23, 2020
b4db342
Rollup merge of #79325 - LingMan:try_op, r=jonas-schievink
jonas-schievink Nov 23, 2020
b48ebc6
Rollup merge of #79330 - jyn514:typo, r=jyn514
jonas-schievink Nov 23, 2020
a0cf162
Rollup merge of #79333 - o752d:patch-3, r=Mark-Simulacrum
jonas-schievink Nov 23, 2020
064c3c1
Rollup merge of #79337 - LingMan:map, r=jyn514
jonas-schievink Nov 23, 2020
ea3c269
Rollup merge of #79343 - flip1995:mailmap, r=Mark-Simulacrum
jonas-schievink Nov 23, 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: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ Phil Dawes <[email protected]> Phil Dawes <[email protected]>
Philipp Brüschweiler <[email protected]> <[email protected]>
Philipp Brüschweiler <[email protected]> <[email protected]>
Philipp Krones <[email protected]> flip1995 <[email protected]>
Philipp Krones <[email protected]> <[email protected]>
Philipp Matthias Schäfer <[email protected]>
Przemysław Wesołek <[email protected]> Przemek Wesołek <[email protected]>
Rafael Ávila de Espíndola <[email protected]> Rafael Avila de Espindola <espindola@dream.(none)>
Expand Down
16 changes: 6 additions & 10 deletions compiler/rustc_builtin_macros/src/format_foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -649,17 +649,13 @@ pub mod shell {
impl<'a> Iterator for Substitutions<'a> {
type Item = Substitution<'a>;
fn next(&mut self) -> Option<Self::Item> {
match parse_next_substitution(self.s) {
Some((mut sub, tail)) => {
self.s = tail;
if let Some(InnerSpan { start, end }) = sub.position() {
sub.set_position(start + self.pos, end + self.pos);
self.pos += end;
}
Some(sub)
}
None => None,
let (mut sub, tail) = parse_next_substitution(self.s)?;
self.s = tail;
if let Some(InnerSpan { start, end }) = sub.position() {
sub.set_position(start + self.pos, end + self.pos);
self.pos += end;
}
Some(sub)
}

fn size_hint(&self) -> (usize, Option<usize>) {
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,10 +1152,7 @@ impl<'ll> MemberDescription<'ll> {
self.size.bits(),
self.align.bits() as u32,
self.offset.bits(),
match self.discriminant {
None => None,
Some(value) => Some(cx.const_u64(value)),
},
self.discriminant.map(|v| cx.const_u64(v)),
self.flags,
self.type_metadata,
)
Expand Down
7 changes: 2 additions & 5 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,9 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
/// `funclet_bb` member if it is not `None`.
fn funclet<'b, Bx: BuilderMethods<'a, 'tcx>>(
&self,
fx: &'b mut FunctionCx<'a, 'tcx, Bx>,
fx: &'b FunctionCx<'a, 'tcx, Bx>,
) -> Option<&'b Bx::Funclet> {
match self.funclet_bb {
Some(funcl) => fx.funclets[funcl].as_ref(),
None => None,
}
self.funclet_bb.and_then(|funcl| fx.funclets[funcl].as_ref())
}

fn lltarget<Bx: BuilderMethods<'a, 'tcx>>(
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
13 changes: 8 additions & 5 deletions compiler/rustc_middle/src/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,11 +1017,14 @@ macro_rules! visit_place_fns {
let mut context = context;

if !place.projection.is_empty() {
context = if context.is_mutating_use() {
PlaceContext::MutatingUse(MutatingUseContext::Projection)
} else {
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
};
if context.is_use() {
// ^ Only change the context if it is a real use, not a "use" in debuginfo.
context = if context.is_mutating_use() {
PlaceContext::MutatingUse(MutatingUseContext::Projection)
} else {
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection)
};
}
}

self.visit_local(&place.local, context, location);
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
5 changes: 1 addition & 4 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1106,10 +1106,7 @@ impl<T> Binder<T> {

impl<T> Binder<Option<T>> {
pub fn transpose(self) -> Option<Binder<T>> {
match self.0 {
Some(v) => Some(Binder(v)),
None => None,
}
self.0.map(Binder)
}
}

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
8 changes: 1 addition & 7 deletions compiler/rustc_mir/src/transform/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_middle::mir::traversal;
use rustc_middle::mir::visit::{PlaceContext, Visitor};
use rustc_middle::mir::{
AggregateKind, BasicBlock, Body, BorrowKind, Local, Location, MirPhase, Operand, PlaceRef,
Rvalue, SourceScope, Statement, StatementKind, Terminator, TerminatorKind, VarDebugInfo,
Rvalue, SourceScope, Statement, StatementKind, Terminator, TerminatorKind,
};
use rustc_middle::ty::fold::BottomUpFolder;
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt, TypeFoldable};
Expand Down Expand Up @@ -200,12 +200,6 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
}
}

fn visit_var_debug_info(&mut self, var_debug_info: &VarDebugInfo<'tcx>) {
// Debuginfo can contain field projections, which count as a use of the base local. Skip
// debuginfo so that we avoid the storage liveness assertion in that case.
self.visit_source_info(&var_debug_info.source_info);
}

fn visit_operand(&mut self, operand: &Operand<'tcx>, location: Location) {
// This check is somewhat expensive, so only run it when -Zvalidate-mir is passed.
if self.tcx.sess.opts.debugging_opts.validate_mir {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_privacy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ impl Visitor<'tcx> for EmbargoVisitor<'tcx> {
hir::ItemKind::GlobalAsm(..) => {}
hir::ItemKind::OpaqueTy(..) => {
// HACK(jynelson): trying to infer the type of `impl trait` breaks `async-std` (and `pub async fn` in general)
// Since rustdoc never need to do codegen and doesn't care about link-time reachability,
// Since rustdoc never needs to do codegen and doesn't care about link-time reachability,
// mark this as unreachable.
// See https://github.com/rust-lang/rust/issues/75100
if !self.tcx.sess.opts.actually_rustdoc {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl<'a> Resolver<'a> {
_ => {
bug!(
"GenericParamsFromOuterFunction should only be used with Res::SelfTy, \
DefKind::TyParam"
DefKind::TyParam or DefKind::ConstParam"
);
}
}
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2539,6 +2539,7 @@ impl<'a> Resolver<'a> {
span: Span,
all_ribs: &[Rib<'a>],
) -> Res {
const CG_BUG_STR: &str = "min_const_generics resolve check didn't stop compilation";
debug!("validate_res_from_ribs({:?})", res);
let ribs = &all_ribs[rib_index + 1..];

Expand Down Expand Up @@ -2639,6 +2640,8 @@ impl<'a> Resolver<'a> {
},
);
}

self.session.delay_span_bug(span, CG_BUG_STR);
return Res::Err;
}
}
Expand Down Expand Up @@ -2720,6 +2723,8 @@ impl<'a> Resolver<'a> {
},
);
}

self.session.delay_span_bug(span, CG_BUG_STR);
return Res::Err;
}

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
Loading