Skip to content

Commit

Permalink
Auto merge of #103220 - compiler-errors:deny-infers, r=lcnr
Browse files Browse the repository at this point in the history
Deny hashing ty/re/ct inference variables

cc `@cjgillot` and #102695 (comment)
r? `@lcnr`

best reviewed one commit at a time, mostly because the second commit that fixes `ClosureOutlivesRequirement` is mostly noise because of losing its `<'tcx>` lifetime parameter.
  • Loading branch information
bors committed Oct 20, 2022
2 parents ebdde35 + 6b0ef9c commit 4b3b731
Show file tree
Hide file tree
Showing 27 changed files with 119 additions and 120 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub struct OutlivesConstraint<'tcx> {
pub span: Span,

/// What caused this constraint?
pub category: ConstraintCategory<'tcx>,
pub category: ConstraintCategory,

/// Variance diagnostic information
pub variance_info: VarianceDiagInfo<'tcx>,
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
err: &mut Diagnostic,
location: Location,
issued_borrow: &BorrowData<'tcx>,
explanation: BorrowExplanation<'tcx>,
explanation: BorrowExplanation,
) {
let used_in_call = matches!(
explanation,
Expand Down Expand Up @@ -1326,7 +1326,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
borrow: &BorrowData<'tcx>,
drop_span: Span,
borrow_spans: UseSpans<'tcx>,
explanation: BorrowExplanation<'tcx>,
explanation: BorrowExplanation,
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
debug!(
"report_local_value_does_not_live_long_enough(\
Expand Down Expand Up @@ -1532,7 +1532,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
drop_span: Span,
borrow_spans: UseSpans<'tcx>,
proper_span: Span,
explanation: BorrowExplanation<'tcx>,
explanation: BorrowExplanation,
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
if let BorrowExplanation::MustBeValidFor { category, span, from_closure: false, .. } =
explanation
Expand Down Expand Up @@ -1646,7 +1646,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
borrow: &BorrowData<'tcx>,
borrow_span: Span,
return_span: Span,
category: ConstraintCategory<'tcx>,
category: ConstraintCategory,
opt_place_desc: Option<&String>,
) -> Option<DiagnosticBuilder<'cx, ErrorGuaranteed>> {
let return_kind = match category {
Expand Down Expand Up @@ -1741,7 +1741,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
use_span: UseSpans<'tcx>,
var_span: Span,
fr_name: &RegionName,
category: ConstraintCategory<'tcx>,
category: ConstraintCategory,
constraint_span: Span,
captured_var: &str,
) -> DiagnosticBuilder<'cx, ErrorGuaranteed> {
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_borrowck/src/diagnostics/explain_borrow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::{
use super::{find_use, RegionName, UseSpans};

#[derive(Debug)]
pub(crate) enum BorrowExplanation<'tcx> {
pub(crate) enum BorrowExplanation {
UsedLater(LaterUseKind, Span, Option<Span>),
UsedLaterInLoop(LaterUseKind, Span, Option<Span>),
UsedLaterWhenDropped {
Expand All @@ -30,7 +30,7 @@ pub(crate) enum BorrowExplanation<'tcx> {
should_note_order: bool,
},
MustBeValidFor {
category: ConstraintCategory<'tcx>,
category: ConstraintCategory,
from_closure: bool,
span: Span,
region_name: RegionName,
Expand All @@ -49,7 +49,7 @@ pub(crate) enum LaterUseKind {
Other,
}

impl<'tcx> BorrowExplanation<'tcx> {
impl<'tcx> BorrowExplanation {
pub(crate) fn is_explained(&self) -> bool {
!matches!(self, BorrowExplanation::Unexplained)
}
Expand Down Expand Up @@ -284,7 +284,7 @@ impl<'tcx> BorrowExplanation<'tcx> {
fn add_lifetime_bound_suggestion_to_diagnostic(
&self,
err: &mut Diagnostic,
category: &ConstraintCategory<'tcx>,
category: &ConstraintCategory,
span: Span,
region_name: &RegionName,
) {
Expand Down Expand Up @@ -316,7 +316,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&self,
borrow_region: RegionVid,
outlived_region: RegionVid,
) -> (ConstraintCategory<'tcx>, bool, Span, Option<RegionName>, Vec<ExtraConstraintInfo>) {
) -> (ConstraintCategory, bool, Span, Option<RegionName>, Vec<ExtraConstraintInfo>) {
let (blame_constraint, extra_info) = self.regioncx.best_blame_constraint(
borrow_region,
NllRegionVariableOrigin::FreeRegion,
Expand Down Expand Up @@ -348,7 +348,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
location: Location,
borrow: &BorrowData<'tcx>,
kind_place: Option<(WriteKind, Place<'tcx>)>,
) -> BorrowExplanation<'tcx> {
) -> BorrowExplanation {
let regioncx = &self.regioncx;
let body: &Body<'_> = &self.body;
let tcx = self.infcx.tcx;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ impl OutlivesSuggestionBuilder {
pub(crate) fn intermediate_suggestion(
&mut self,
mbcx: &MirBorrowckCtxt<'_, '_>,
errci: &ErrorConstraintInfo<'_>,
errci: &ErrorConstraintInfo,
diag: &mut Diagnostic,
) {
// Emit an intermediate note.
Expand Down
24 changes: 15 additions & 9 deletions compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![deny(rustc::diagnostic_outside_of_impl)]
//! Error reporting machinery for lifetime errors.
use either::Either;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan};
use rustc_hir::def_id::DefId;
Expand All @@ -16,7 +17,7 @@ use rustc_infer::infer::{
NllRegionVariableOrigin, RelateParamBound,
};
use rustc_middle::hir::place::PlaceBase;
use rustc_middle::mir::{ConstraintCategory, ReturnConstraint};
use rustc_middle::mir::{ConstraintCategory, ReturnConstraint, TerminatorKind};
use rustc_middle::ty::subst::InternalSubsts;
use rustc_middle::ty::Region;
use rustc_middle::ty::TypeVisitor;
Expand All @@ -39,7 +40,7 @@ use crate::{
MirBorrowckCtxt,
};

impl<'tcx> ConstraintDescription for ConstraintCategory<'tcx> {
impl ConstraintDescription for ConstraintCategory {
fn description(&self) -> &'static str {
// Must end with a space. Allows for empty names to be provided.
match self {
Expand Down Expand Up @@ -115,15 +116,15 @@ pub(crate) enum RegionErrorKind<'tcx> {

/// Information about the various region constraints involved in a borrow checker error.
#[derive(Clone, Debug)]
pub struct ErrorConstraintInfo<'tcx> {
pub struct ErrorConstraintInfo {
// fr: outlived_fr
pub(super) fr: RegionVid,
pub(super) fr_is_local: bool,
pub(super) outlived_fr: RegionVid,
pub(super) outlived_fr_is_local: bool,

// Category and span for best blame constraint
pub(super) category: ConstraintCategory<'tcx>,
pub(super) category: ConstraintCategory,
pub(super) span: Span,
}

Expand Down Expand Up @@ -498,7 +499,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
/// ```
fn report_fnmut_error(
&self,
errci: &ErrorConstraintInfo<'tcx>,
errci: &ErrorConstraintInfo,
kind: ReturnConstraint,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
let ErrorConstraintInfo { outlived_fr, span, .. } = errci;
Expand Down Expand Up @@ -571,7 +572,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
#[instrument(level = "debug", skip(self))]
fn report_escaping_data_error(
&self,
errci: &ErrorConstraintInfo<'tcx>,
errci: &ErrorConstraintInfo,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
let ErrorConstraintInfo { span, category, .. } = errci;

Expand Down Expand Up @@ -675,7 +676,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
/// ```
fn report_general_error(
&self,
errci: &ErrorConstraintInfo<'tcx>,
errci: &ErrorConstraintInfo,
) -> DiagnosticBuilder<'tcx, ErrorGuaranteed> {
let ErrorConstraintInfo {
fr,
Expand Down Expand Up @@ -788,15 +789,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
diag: &mut Diagnostic,
f: Region<'tcx>,
o: Region<'tcx>,
category: &ConstraintCategory<'tcx>,
category: &ConstraintCategory,
) {
if !o.is_static() {
return;
}

let tcx = self.infcx.tcx;

let instance = if let ConstraintCategory::CallArgument(Some(func_ty)) = category {
let instance =
if let ConstraintCategory::CallArgument(location) = category
&& let Either::Right(term) = self.body.stmt_at(*location)
&& let TerminatorKind::Call { func, .. } = &term.kind
{
let func_ty = func.ty(self.body, tcx);
let (fn_did, substs) = match func_ty.kind() {
ty::FnDef(fn_did, substs) => (fn_did, substs),
_ => return,
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_borrowck/src/region_infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub struct RegionInferenceContext<'tcx> {

/// Map closure bounds to a `Span` that should be used for error reporting.
closure_bounds_mapping:
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory<'tcx>, Span)>>,
FxHashMap<Location, FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>>,

/// Map universe indexes to information on why we created it.
universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
Expand Down Expand Up @@ -267,7 +267,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
member_constraints_in: MemberConstraintSet<'tcx, RegionVid>,
closure_bounds_mapping: FxHashMap<
Location,
FxHashMap<(RegionVid, RegionVid), (ConstraintCategory<'tcx>, Span)>,
FxHashMap<(RegionVid, RegionVid), (ConstraintCategory, Span)>,
>,
universe_causes: FxHashMap<ty::UniverseIndex, UniverseInfo<'tcx>>,
type_tests: Vec<TypeTest<'tcx>>,
Expand Down Expand Up @@ -1807,7 +1807,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
pub(crate) fn retrieve_closure_constraint_info(
&self,
constraint: OutlivesConstraint<'tcx>,
) -> Option<(ConstraintCategory<'tcx>, Span)> {
) -> Option<(ConstraintCategory, Span)> {
match constraint.locations {
Locations::All(_) => None,
Locations::Single(loc) => {
Expand All @@ -1822,7 +1822,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
fr1: RegionVid,
fr1_origin: NllRegionVariableOrigin,
fr2: RegionVid,
) -> (ConstraintCategory<'tcx>, ObligationCause<'tcx>) {
) -> (ConstraintCategory, ObligationCause<'tcx>) {
let BlameConstraint { category, cause, .. } = self
.best_blame_constraint(fr1, fr1_origin, |r| self.provides_universal_region(r, fr1, fr2))
.0;
Expand Down Expand Up @@ -2362,7 +2362,7 @@ impl<'tcx> ClosureRegionRequirementsExt<'tcx> for ClosureRegionRequirements<'tcx

#[derive(Clone, Debug)]
pub struct BlameConstraint<'tcx> {
pub category: ConstraintCategory<'tcx>,
pub category: ConstraintCategory,
pub from_closure: bool,
pub cause: ObligationCause<'tcx>,
pub variance_info: ty::VarianceDiagInfo<'tcx>,
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_borrowck/src/type_check/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
pub(super) fn fully_perform_op<R: fmt::Debug, Op>(
&mut self,
locations: Locations,
category: ConstraintCategory<'tcx>,
category: ConstraintCategory,
op: Op,
) -> Fallible<R>
where
Expand Down Expand Up @@ -85,7 +85,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
&mut self,
trait_ref: ty::TraitRef<'tcx>,
locations: Locations,
category: ConstraintCategory<'tcx>,
category: ConstraintCategory,
) {
self.prove_predicate(
ty::Binder::dummy(ty::PredicateKind::Trait(ty::TraitPredicate {
Expand Down Expand Up @@ -124,7 +124,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
&mut self,
predicates: impl IntoIterator<Item = impl ToPredicate<'tcx>>,
locations: Locations,
category: ConstraintCategory<'tcx>,
category: ConstraintCategory,
) {
for predicate in predicates {
let predicate = predicate.to_predicate(self.tcx());
Expand All @@ -139,7 +139,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
&mut self,
predicate: ty::Predicate<'tcx>,
locations: Locations,
category: ConstraintCategory<'tcx>,
category: ConstraintCategory,
) {
let param_env = self.param_env;
self.fully_perform_op(
Expand All @@ -164,7 +164,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
&mut self,
value: T,
location: impl NormalizeLocation,
category: ConstraintCategory<'tcx>,
category: ConstraintCategory,
) -> T
where
T: type_op::normalize::Normalizable<'tcx> + fmt::Display + Copy + 'tcx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub(crate) struct ConstraintConversion<'a, 'tcx> {
param_env: ty::ParamEnv<'tcx>,
locations: Locations,
span: Span,
category: ConstraintCategory<'tcx>,
category: ConstraintCategory,
constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
}

Expand All @@ -50,7 +50,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
param_env: ty::ParamEnv<'tcx>,
locations: Locations,
span: Span,
category: ConstraintCategory<'tcx>,
category: ConstraintCategory,
constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
) -> Self {
Self {
Expand Down Expand Up @@ -175,7 +175,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
&mut self,
sup: ty::RegionVid,
sub: ty::RegionVid,
category: ConstraintCategory<'tcx>,
category: ConstraintCategory,
) {
let category = match self.category {
ConstraintCategory::Boring | ConstraintCategory::BoringNoLocation => category,
Expand Down Expand Up @@ -203,7 +203,7 @@ impl<'a, 'b, 'tcx> TypeOutlivesDelegate<'tcx> for &'a mut ConstraintConversion<'
_origin: SubregionOrigin<'tcx>,
a: ty::Region<'tcx>,
b: ty::Region<'tcx>,
constraint_category: ConstraintCategory<'tcx>,
constraint_category: ConstraintCategory,
) {
let b = self.to_region_vid(b);
let a = self.to_region_vid(a);
Expand Down
Loading

0 comments on commit 4b3b731

Please sign in to comment.