Skip to content

Rollup of 10 pull requests #87593

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

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
2953a2f
Mir borrowck does not generate lifetime variables for 'static lifetim…
oli-obk Jul 26, 2021
624df18
Track caller of Vec::remove()
kornelski Jul 26, 2021
886dea2
Make `SEMICOLON_IN_EXPRESSIONS_FROM_MACROS` warn by default
Aaron1011 Jul 22, 2021
cf167c9
Only emit lint for local macros
Aaron1011 Jul 24, 2021
b8eb1f1
Fix assert in diy_float
frogtd Jul 27, 2021
6954f9d
Update stderr
Aaron1011 Jul 27, 2021
f9516e9
move Constness into TraitPredicate
fee1-dead Jul 22, 2021
013c621
Filter non-const impls when we expect a const one
fee1-dead Jul 22, 2021
1f2d1aa
fmt
fee1-dead Jul 22, 2021
cc4c678
Inherited use constness and assoc change predicate
fee1-dead Jul 24, 2021
334f79e
fmt
fee1-dead Jul 24, 2021
a6bdde5
Make selection and evaluation caches use constness
fee1-dead Jul 24, 2021
8f58870
Relate impl
fee1-dead Jul 24, 2021
9d6f40e
Try to fix problem
fee1-dead Jul 24, 2021
4ee8e80
Pass constness to SelectionContext
fee1-dead Jul 26, 2021
0cd8f61
Fix assoc-type test
fee1-dead Jul 26, 2021
98163b4
handle the case when container is not impl
fee1-dead Jul 26, 2021
77f309b
Don't transform predicates in Inherited
fee1-dead Jul 26, 2021
670f6dc
Fix call-generic-method-nonconst test
fee1-dead Jul 26, 2021
0f90e99
Fix tests
fee1-dead Jul 26, 2021
157ac29
Moved ui test
fee1-dead Jul 26, 2021
ca822fd
allow incomplete features for now
fee1-dead Jul 26, 2021
c12cd90
Make assoc types work with `?const `opt=out
fee1-dead Jul 26, 2021
eb99c02
Bless test
fee1-dead Jul 26, 2021
385b1ed
make check less conservative and add explanation
fee1-dead Jul 27, 2021
cd6c0e4
Fix typo in rustc_driver::version
bjorn3 Jul 28, 2021
9829efb
Range PatKind implies discr should be read
roxelo Jul 28, 2021
d380ed1
fix nit
roxelo Jul 28, 2021
cf5e48d
min_type_alias_impl_trait is going to be removed in 1.56
spastorino Jul 28, 2021
2f6662d
Use strip_prefix
bjorn3 Jul 29, 2021
a2f3e4a
Change span for intra-doc links errors
GuillaumeGomez Jul 19, 2021
cbba940
BufWriter: actually export WriterPanicked error
ijackson Jun 1, 2021
66f3807
BufWriter: rename `into_parts` from `into_raw_parts`
ijackson Jun 1, 2021
bf30c51
Rename feature gate bufwriter_into_parts from bufwriter_into_raw_parts
ijackson Jul 19, 2021
e70ce57
Remove unnecessary trailing semicolons from clippy tests
Aaron1011 Jul 29, 2021
0f7f85e
Update rustdoc-ui tests for intra-doc links errors
GuillaumeGomez Jul 19, 2021
70af726
Rollup merge of #85901 - ijackson:bufwriter-tweaks, r=joshtriplett
GuillaumeGomez Jul 29, 2021
f118328
Rollup merge of #87285 - GuillaumeGomez:intra-doc-span, r=estebank
GuillaumeGomez Jul 29, 2021
0c24e36
Rollup merge of #87375 - fee1-dead:move-constness-to-traitpred, r=oli…
GuillaumeGomez Jul 29, 2021
f3fd8fe
Rollup merge of #87385 - Aaron1011:final-enable-semi, r=petrochenkov
GuillaumeGomez Jul 29, 2021
f67a597
Rollup merge of #87483 - oli-obk:tait_ice, r=lqd
GuillaumeGomez Jul 29, 2021
d9bc2db
Rollup merge of #87488 - kornelski:track-remove, r=dtolnay
GuillaumeGomez Jul 29, 2021
8233a21
Rollup merge of #87522 - frogtd:patch-1, r=yaahc
GuillaumeGomez Jul 29, 2021
1e2eb9f
Rollup merge of #87553 - bjorn3:fix_hotplug_codegen_version, r=wesley…
GuillaumeGomez Jul 29, 2021
1a2f4bd
Rollup merge of #87554 - sexxi-goose:fix-issue-87426, r=nikomatsakis
GuillaumeGomez Jul 29, 2021
9edd490
Rollup merge of #87564 - spastorino:adjust-min-tait-removed-version, …
GuillaumeGomez Jul 29, 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
Prev Previous commit
Next Next commit
Inherited use constness and assoc change predicate
  • Loading branch information
fee1-dead committed Jul 28, 2021
commit cc4c6783eae653e3a37d2238bd98a265537ccd3c
9 changes: 9 additions & 0 deletions compiler/rustc_middle/src/ty/assoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ pub enum AssocItemContainer {
}

impl AssocItemContainer {
/// Asserts that this is the `DefId` of an associated item declared
/// in an impl, and returns the trait `DefId`.
pub fn assert_impl(&self) -> DefId {
match *self {
ImplContainer(id) => id,
_ => bug!("associated item has wrong container type: {:?}", self),
}
}

/// Asserts that this is the `DefId` of an associated item declared
/// in a trait, and returns the trait `DefId`.
pub fn assert_trait(&self) -> DefId {
Expand Down
26 changes: 23 additions & 3 deletions compiler/rustc_typeck/src/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,7 +1292,24 @@ pub fn check_type_bounds<'tcx>(
};

tcx.infer_ctxt().enter(move |infcx| {
let inh = Inherited::new(infcx, impl_ty.def_id.expect_local());
// if the item is inside a const impl, we transform the predicates to be const.
let constness = tcx.impl_constness(impl_ty.container.assert_impl());
let pred_map = match constness {
hir::Constness::NotConst => |p, _| p,
hir::Constness::Const => |p: ty::Predicate<'tcx>, tcx: TyCtxt<'tcx>| {
p.kind()
.map_bound(|kind| match kind {
ty::PredicateKind::Trait(mut tp) => {
tp.constness = hir::Constness::Const;
ty::PredicateKind::Trait(tp)
}
kind => kind,
})
.to_predicate(tcx)
},
};

let inh = Inherited::with_constness(infcx, impl_ty.def_id.expect_local(), constness);
let infcx = &inh.infcx;
let mut selcx = traits::SelectionContext::new(&infcx);

Expand All @@ -1310,7 +1327,7 @@ pub fn check_type_bounds<'tcx>(
.explicit_item_bounds(trait_ty.def_id)
.iter()
.map(|&(bound, span)| {
let concrete_ty_bound = bound.subst(tcx, rebased_substs);
let concrete_ty_bound = pred_map(bound.subst(tcx, rebased_substs), tcx);
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound);

traits::Obligation::new(mk_cause(span), param_env, concrete_ty_bound)
Expand All @@ -1328,7 +1345,10 @@ pub fn check_type_bounds<'tcx>(
debug!("compare_projection_bounds: normalized predicate = {:?}", normalized_predicate);
obligation.predicate = normalized_predicate;

inh.register_predicates(obligations);
inh.register_predicates(obligations.into_iter().map(|mut o| {
o.predicate = pred_map(o.predicate, tcx);
o
}));
inh.register_predicate(obligation);
}

Expand Down
30 changes: 28 additions & 2 deletions compiler/rustc_typeck/src/check/inherited.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_hir::HirIdMap;
use rustc_infer::infer;
use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::{self, OpaqueTypeKey, Ty, TyCtxt};
use rustc_middle::ty::{self, OpaqueTypeKey, ToPredicate, Ty, TyCtxt};
use rustc_span::{self, Span};
use rustc_trait_selection::infer::InferCtxtExt as _;
use rustc_trait_selection::opaque_types::OpaqueTypeDecl;
Expand Down Expand Up @@ -68,6 +68,9 @@ pub struct Inherited<'a, 'tcx> {
/// opaque type.
pub(super) opaque_types_vars: RefCell<FxHashMap<Ty<'tcx>, Ty<'tcx>>>,

/// Reports whether this is in a const context.
pub(super) constness: hir::Constness,

pub(super) body_id: Option<hir::BodyId>,
}

Expand Down Expand Up @@ -109,6 +112,12 @@ impl<'tcx> InheritedBuilder<'tcx> {

impl Inherited<'a, 'tcx> {
pub(super) fn new(infcx: InferCtxt<'a, 'tcx>, def_id: LocalDefId) -> Self {
let tcx = infcx.tcx;
let item_id = tcx.hir().local_def_id_to_hir_id(def_id);
Self::with_constness(infcx, def_id, tcx.hir().get(item_id).constness())
}

pub(super) fn with_constness(infcx: InferCtxt<'a, 'tcx>, def_id: LocalDefId, constness: hir::Constness) -> Self {
let tcx = infcx.tcx;
let item_id = tcx.hir().local_def_id_to_hir_id(def_id);
let body_id = tcx.hir().maybe_body_owned_by(item_id);
Expand All @@ -126,12 +135,29 @@ impl Inherited<'a, 'tcx> {
deferred_generator_interiors: RefCell::new(Vec::new()),
opaque_types: RefCell::new(Default::default()),
opaque_types_vars: RefCell::new(Default::default()),
constness,
body_id,
}
}

pub(super) fn register_predicate(&self, obligation: traits::PredicateObligation<'tcx>) {
#[instrument(level = "debug", skip(self))]
fn transform_predicate(&self, p: &mut ty::Predicate<'tcx>) {
// Don't transform non-const bounds into const bounds,
// but transform const bounds to non-const when we are
// not in a const context.
if let hir::Constness::NotConst = self.constness {
let kind = p.kind();
if let ty::PredicateKind::Trait(pred) = kind.as_ref().skip_binder() {
let mut pred = *pred;
pred.constness = hir::Constness::NotConst;
*p = kind.rebind(ty::PredicateKind::Trait(pred)).to_predicate(self.tcx);
}
}
}

pub(super) fn register_predicate(&self, mut obligation: traits::PredicateObligation<'tcx>) {
debug!("register_predicate({:?})", obligation);
self.transform_predicate(&mut obligation.predicate);
if obligation.has_escaping_bound_vars() {
span_bug!(obligation.cause.span, "escaping bound vars in predicate {:?}", obligation);
}
Expand Down