Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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_attr_parsing/src/attributes/rustc_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ impl NoArgsAttributeParser for RustcDumpInferredOutlivesParser {
Allow(Target::Enum),
Allow(Target::Union),
Allow(Target::TyAlias),
Allow(Target::Const),
]);
const STABILITY: AttributeStability = unstable!(rustc_attrs);
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcDumpInferredOutlives;
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_hir_analysis/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1834,9 +1834,7 @@ fn const_of_item<'tcx>(
};
let ct_arg = match ct_rhs {
hir::ConstItemRhs::Direct(ct_arg) => ct_arg,
hir::ConstItemRhs::Body(_) => {
return None;
}
hir::ConstItemRhs::Body(_) => return None,
};
let icx = ItemCtxt::new(tcx, def_id);
let identity_args = ty::GenericArgs::identity_for_item(tcx, def_id);
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_hir_analysis/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,10 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
}
}
}
ItemKind::Const(ident, _, ty, rhs) => {
if ty.is_suggestable_infer_ty() {
ItemKind::Const(ident, generics, ty, rhs) => {
// We can't infer the type of parameterized const items without causing a query
// cycle (typeck -..> inferred_outlives_of -..> type_of -> typeck), so let's not.
if generics.params.is_empty() && ty.is_suggestable_infer_ty() {
let hir_body_id = match rhs {
ConstItemRhs::Body(body) => Some(body.hir_id),
ConstItemRhs::Direct(_) => None,
Expand Down
30 changes: 12 additions & 18 deletions compiler/rustc_hir_analysis/src/outlives/explicit.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,35 @@
use rustc_data_structures::fx::FxIndexMap;
use rustc_hir::def_id::DefId;
use rustc_middle::ty::{self, OutlivesClause, TyCtxt};

use super::utils::*;

#[derive(Debug)]
pub(crate) struct ExplicitClausesMap<'tcx> {
map: FxIndexMap<DefId, ty::EarlyBinder<'tcx, RequiredClauses<'tcx>>>,
#[derive(Default, Debug)]
pub(crate) struct GlobalExplicitOutlivesClauses<'tcx> {
map: GlobalOutlivesClauses<'tcx>,
}

impl<'tcx> ExplicitClausesMap<'tcx> {
pub(crate) fn new() -> ExplicitClausesMap<'tcx> {
ExplicitClausesMap { map: FxIndexMap::default() }
}

pub(crate) fn explicit_clauses_of(
impl<'tcx> GlobalExplicitOutlivesClauses<'tcx> {
pub(crate) fn explicit_outlives_clauses_of(
&mut self,
tcx: TyCtxt<'tcx>,
def_id: DefId,
) -> &ty::EarlyBinder<'tcx, RequiredClauses<'tcx>> {
) -> &ty::EarlyBinder<'tcx, OutlivesClauses<'tcx>> {
self.map.entry(def_id).or_insert_with(|| {
let gen_clauses = if def_id.is_local() {
let clauses = if def_id.is_local() {
tcx.explicit_clauses_of(def_id)
} else {
tcx.clauses_of(def_id)
};
let mut required_clauses = RequiredClauses::default();
let mut outlives_clauses = OutlivesClauses::default();

// Process clauses and convert to `RequiredClauses` entry, see below.
for &(clause, span) in gen_clauses.clauses {
for &(clause, span) in clauses.clauses {
match clause.kind().skip_binder() {
ty::ClauseKind::TypeOutlives(OutlivesClause(ty, reg)) => {
insert_outlives_clause(tcx, ty.into(), reg, span, &mut required_clauses)
insert_outlives_clause(tcx, ty.into(), reg, span, &mut outlives_clauses)
}

ty::ClauseKind::RegionOutlives(OutlivesClause(reg1, reg2)) => {
insert_outlives_clause(tcx, reg1.into(), reg2, span, &mut required_clauses)
insert_outlives_clause(tcx, reg1.into(), reg2, span, &mut outlives_clauses)
}
ty::ClauseKind::Trait(_)
| ty::ClauseKind::Projection(_)
Expand All @@ -47,7 +41,7 @@ impl<'tcx> ExplicitClausesMap<'tcx> {
}
}

ty::EarlyBinder::bind_iter(required_clauses)
ty::EarlyBinder::bind_iter(outlives_clauses)
})
}
}
Loading
Loading