Skip to content

Commit 468310e

Browse files
committed
Auto merge of rust-lang#126108 - workingjubilee:rollup-g7m92b6, r=workingjubilee
Rollup of 7 pull requests Successful merges: - rust-lang#125606 (Size optimize int formatting) - rust-lang#125724 (Uplift `Relate`/`TypeRelation` into `rustc_next_trait_solver`) - rust-lang#126040 (Don't warn on fields in the `unreachable_pub` lint ) - rust-lang#126098 (Remove `same-lib-two-locations-no-panic` run-make test) - rust-lang#126099 (Crate loader cleanups) - rust-lang#126101 (Revert "Disallow ambiguous attributes on expressions" on nightly) - rust-lang#126103 (Improve Docs for `hir::Impl` and `hir::ImplItem`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b74702f + 9436304 commit 468310e

File tree

77 files changed

+1485
-1305
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1485
-1305
lines changed

Cargo.lock

+2-1
Original file line numberDiff line numberDiff line change
@@ -4201,6 +4201,7 @@ dependencies = [
42014201
"rustc_middle",
42024202
"rustc_span",
42034203
"rustc_target",
4204+
"rustc_type_ir",
42044205
"smallvec",
42054206
"tracing",
42064207
]
@@ -4392,7 +4393,6 @@ dependencies = [
43924393
"rustc_hir_pretty",
43934394
"rustc_index",
43944395
"rustc_macros",
4395-
"rustc_next_trait_solver",
43964396
"rustc_query_system",
43974397
"rustc_serialize",
43984398
"rustc_session",
@@ -4509,6 +4509,7 @@ dependencies = [
45094509
"rustc_serialize",
45104510
"rustc_type_ir",
45114511
"rustc_type_ir_macros",
4512+
"tracing",
45124513
]
45134514

45144515
[[package]]

compiler/rustc_borrowck/src/constraints/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use rustc_data_structures::graph::scc::Sccs;
22
use rustc_index::{IndexSlice, IndexVec};
33
use rustc_middle::mir::ConstraintCategory;
4-
use rustc_middle::ty::{RegionVid, VarianceDiagInfo};
4+
use rustc_middle::ty::{RegionVid, TyCtxt, VarianceDiagInfo};
55
use rustc_span::Span;
66
use std::fmt;
77
use std::ops::Index;
@@ -97,7 +97,7 @@ pub struct OutlivesConstraint<'tcx> {
9797
pub category: ConstraintCategory<'tcx>,
9898

9999
/// Variance diagnostic information
100-
pub variance_info: VarianceDiagInfo<'tcx>,
100+
pub variance_info: VarianceDiagInfo<TyCtxt<'tcx>>,
101101

102102
/// If this constraint is promoted from closure requirements.
103103
pub from_closure: bool,

compiler/rustc_borrowck/src/region_infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2304,5 +2304,5 @@ pub struct BlameConstraint<'tcx> {
23042304
pub category: ConstraintCategory<'tcx>,
23052305
pub from_closure: bool,
23062306
pub cause: ObligationCause<'tcx>,
2307-
pub variance_info: ty::VarianceDiagInfo<'tcx>,
2307+
pub variance_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
23082308
}

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
use rustc_data_structures::fx::FxHashMap;
22
use rustc_errors::ErrorGuaranteed;
3+
use rustc_infer::infer::relate::{ObligationEmittingRelation, StructurallyRelateAliases};
4+
use rustc_infer::infer::relate::{Relate, RelateResult, TypeRelation};
35
use rustc_infer::infer::NllRegionVariableOrigin;
4-
use rustc_infer::infer::{ObligationEmittingRelation, StructurallyRelateAliases};
56
use rustc_infer::traits::{Obligation, PredicateObligations};
67
use rustc_middle::mir::ConstraintCategory;
78
use rustc_middle::span_bug;
89
use rustc_middle::traits::query::NoSolution;
910
use rustc_middle::traits::ObligationCause;
1011
use rustc_middle::ty::fold::FnMutDelegate;
11-
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
1212
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
1313
use rustc_span::symbol::sym;
1414
use rustc_span::{Span, Symbol};
@@ -82,7 +82,7 @@ pub struct NllTypeRelating<'me, 'bccx, 'tcx> {
8282
/// - Bivariant means that it doesn't matter.
8383
ambient_variance: ty::Variance,
8484

85-
ambient_variance_info: ty::VarianceDiagInfo<'tcx>,
85+
ambient_variance_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
8686
}
8787

8888
impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
@@ -296,7 +296,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
296296
&mut self,
297297
sup: ty::Region<'tcx>,
298298
sub: ty::Region<'tcx>,
299-
info: ty::VarianceDiagInfo<'tcx>,
299+
info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
300300
) {
301301
let sub = self.type_checker.borrowck_context.universal_regions.to_region_vid(sub);
302302
let sup = self.type_checker.borrowck_context.universal_regions.to_region_vid(sup);
@@ -314,7 +314,7 @@ impl<'me, 'bccx, 'tcx> NllTypeRelating<'me, 'bccx, 'tcx> {
314314
}
315315
}
316316

317-
impl<'bccx, 'tcx> TypeRelation<'tcx> for NllTypeRelating<'_, 'bccx, 'tcx> {
317+
impl<'bccx, 'tcx> TypeRelation<TyCtxt<'tcx>> for NllTypeRelating<'_, 'bccx, 'tcx> {
318318
fn tcx(&self) -> TyCtxt<'tcx> {
319319
self.type_checker.infcx.tcx
320320
}
@@ -324,10 +324,10 @@ impl<'bccx, 'tcx> TypeRelation<'tcx> for NllTypeRelating<'_, 'bccx, 'tcx> {
324324
}
325325

326326
#[instrument(skip(self, info), level = "trace", ret)]
327-
fn relate_with_variance<T: Relate<'tcx>>(
327+
fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>(
328328
&mut self,
329329
variance: ty::Variance,
330-
info: ty::VarianceDiagInfo<'tcx>,
330+
info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
331331
a: T,
332332
b: T,
333333
) -> RelateResult<'tcx, T> {
@@ -445,7 +445,7 @@ impl<'bccx, 'tcx> TypeRelation<'tcx> for NllTypeRelating<'_, 'bccx, 'tcx> {
445445
b: ty::Binder<'tcx, T>,
446446
) -> RelateResult<'tcx, ty::Binder<'tcx, T>>
447447
where
448-
T: Relate<'tcx>,
448+
T: Relate<TyCtxt<'tcx>>,
449449
{
450450
// We want that
451451
//

compiler/rustc_hir/src/hir.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2345,7 +2345,9 @@ impl ImplItemId {
23452345
}
23462346
}
23472347

2348-
/// Represents anything within an `impl` block.
2348+
/// Represents an associated item within an impl block.
2349+
///
2350+
/// Refer to [`Impl`] for an impl block declaration.
23492351
#[derive(Debug, Clone, Copy, HashStable_Generic)]
23502352
pub struct ImplItem<'hir> {
23512353
pub ident: Ident,
@@ -3327,6 +3329,10 @@ pub enum ItemKind<'hir> {
33273329
Impl(&'hir Impl<'hir>),
33283330
}
33293331

3332+
/// Represents an impl block declaration.
3333+
///
3334+
/// E.g., `impl $Type { .. }` or `impl $Trait for $Type { .. }`
3335+
/// Refer to [`ImplItem`] for an associated item within an impl block.
33303336
#[derive(Debug, Clone, Copy, HashStable_Generic)]
33313337
pub struct Impl<'hir> {
33323338
pub safety: Safety,

compiler/rustc_hir_analysis/src/check/check.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc_lint_defs::builtin::REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS;
1515
use rustc_middle::middle::resolve_bound_vars::ResolvedArg;
1616
use rustc_middle::middle::stability::EvalResult;
1717
use rustc_middle::span_bug;
18+
use rustc_middle::ty::error::TypeErrorToStringExt;
1819
use rustc_middle::ty::fold::BottomUpFolder;
1920
use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES};
2021
use rustc_middle::ty::util::{Discr, InspectCoroutineFields, IntTypeExt};

compiler/rustc_hir_typeck/src/coercion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ use rustc_errors::{codes::*, struct_span_code_err, Applicability, Diag};
4141
use rustc_hir as hir;
4242
use rustc_hir::def_id::{DefId, LocalDefId};
4343
use rustc_hir_analysis::hir_ty_lowering::HirTyLowerer;
44+
use rustc_infer::infer::relate::RelateResult;
4445
use rustc_infer::infer::{Coercion, DefineOpaqueTypes, InferOk, InferResult};
4546
use rustc_infer::traits::{IfExpressionCause, MatchExpressionArmCause};
4647
use rustc_infer::traits::{Obligation, PredicateObligation};
@@ -51,7 +52,6 @@ use rustc_middle::ty::adjustment::{
5152
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCoercion,
5253
};
5354
use rustc_middle::ty::error::TypeError;
54-
use rustc_middle::ty::relate::RelateResult;
5555
use rustc_middle::ty::visit::TypeVisitableExt;
5656
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt};
5757
use rustc_session::parse::feature_err;

compiler/rustc_hir_typeck/src/expr.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use rustc_infer::infer::InferOk;
4040
use rustc_infer::traits::query::NoSolution;
4141
use rustc_infer::traits::ObligationCause;
4242
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
43-
use rustc_middle::ty::error::{ExpectedFound, TypeError::Sorts};
43+
use rustc_middle::ty::error::{ExpectedFound, TypeError};
4444
use rustc_middle::ty::GenericArgsRef;
4545
use rustc_middle::ty::{self, AdtKind, Ty, TypeVisitableExt};
4646
use rustc_middle::{bug, span_bug};
@@ -682,7 +682,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
682682
self.suggest_mismatched_types_on_tail(
683683
&mut err, expr, ty, e_ty, target_id,
684684
);
685-
let error = Some(Sorts(ExpectedFound { expected: ty, found: e_ty }));
685+
let error =
686+
Some(TypeError::Sorts(ExpectedFound { expected: ty, found: e_ty }));
686687
self.annotate_loop_expected_due_to_inference(err, expr, error);
687688
if let Some(val) =
688689
self.err_ctxt().ty_kind_suggestion(self.param_env, ty)

compiler/rustc_infer/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ rustc_macros = { path = "../rustc_macros" }
1818
rustc_middle = { path = "../rustc_middle" }
1919
rustc_span = { path = "../rustc_span" }
2020
rustc_target = { path = "../rustc_target" }
21+
rustc_type_ir = { path = "../rustc_type_ir" }
2122
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
2223
tracing = "0.1"
2324
# tidy-alphabetical-end

compiler/rustc_infer/src/infer/at.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
2828
use super::*;
2929

30+
use crate::infer::relate::{Relate, StructurallyRelateAliases, TypeRelation};
3031
use rustc_middle::bug;
31-
use rustc_middle::ty::relate::{Relate, TypeRelation};
3232
use rustc_middle::ty::{Const, ImplSubject};
3333

3434
/// Whether we should define opaque types or just treat them opaquely.
@@ -90,7 +90,7 @@ impl<'tcx> InferCtxt<'tcx> {
9090
}
9191
}
9292

93-
pub trait ToTrace<'tcx>: Relate<'tcx> + Copy {
93+
pub trait ToTrace<'tcx>: Relate<TyCtxt<'tcx>> + Copy {
9494
fn to_trace(
9595
cause: &ObligationCause<'tcx>,
9696
a_is_expected: bool,

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ use crate::traits::{
5858
PredicateObligation,
5959
};
6060

61+
use crate::infer::relate::{self, RelateResult, TypeRelation};
6162
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
6263
use rustc_errors::{
6364
codes::*, pluralize, struct_span_code_err, Applicability, Diag, DiagCtxt, DiagStyledString,
@@ -71,8 +72,8 @@ use rustc_hir::lang_items::LangItem;
7172
use rustc_macros::extension;
7273
use rustc_middle::bug;
7374
use rustc_middle::dep_graph::DepContext;
75+
use rustc_middle::ty::error::TypeErrorToStringExt;
7476
use rustc_middle::ty::print::{with_forced_trimmed_paths, PrintError, PrintTraitRefExt as _};
75-
use rustc_middle::ty::relate::{self, RelateResult, TypeRelation};
7677
use rustc_middle::ty::Upcast;
7778
use rustc_middle::ty::{
7879
self, error::TypeError, IsSuggestable, List, Region, Ty, TyCtxt, TypeFoldable,
@@ -2686,15 +2687,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
26862687
/// with the other type. A TyVar inference type is compatible with any type, and an IntVar or
26872688
/// FloatVar inference type are compatible with themselves or their concrete types (Int and
26882689
/// Float types, respectively). When comparing two ADTs, these rules apply recursively.
2689-
pub fn same_type_modulo_infer<T: relate::Relate<'tcx>>(&self, a: T, b: T) -> bool {
2690+
pub fn same_type_modulo_infer<T: relate::Relate<TyCtxt<'tcx>>>(&self, a: T, b: T) -> bool {
26902691
let (a, b) = self.resolve_vars_if_possible((a, b));
26912692
SameTypeModuloInfer(self).relate(a, b).is_ok()
26922693
}
26932694
}
26942695

26952696
struct SameTypeModuloInfer<'a, 'tcx>(&'a InferCtxt<'tcx>);
26962697

2697-
impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
2698+
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for SameTypeModuloInfer<'_, 'tcx> {
26982699
fn tcx(&self) -> TyCtxt<'tcx> {
26992700
self.0.tcx
27002701
}
@@ -2703,10 +2704,10 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
27032704
"SameTypeModuloInfer"
27042705
}
27052706

2706-
fn relate_with_variance<T: relate::Relate<'tcx>>(
2707+
fn relate_with_variance<T: relate::Relate<TyCtxt<'tcx>>>(
27072708
&mut self,
27082709
_variance: ty::Variance,
2709-
_info: ty::VarianceDiagInfo<'tcx>,
2710+
_info: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
27102711
a: T,
27112712
b: T,
27122713
) -> relate::RelateResult<'tcx, T> {
@@ -2754,7 +2755,7 @@ impl<'tcx> TypeRelation<'tcx> for SameTypeModuloInfer<'_, 'tcx> {
27542755
b: ty::Binder<'tcx, T>,
27552756
) -> relate::RelateResult<'tcx, ty::Binder<'tcx, T>>
27562757
where
2757-
T: relate::Relate<'tcx>,
2758+
T: relate::Relate<TyCtxt<'tcx>>,
27582759
{
27592760
Ok(a.rebind(self.relate(a.skip_binder(), b.skip_binder())?))
27602761
}

compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2121
sp: Span,
2222
body_owner_def_id: DefId,
2323
) {
24-
use ty::error::TypeError::*;
2524
debug!("note_and_explain_type_err err={:?} cause={:?}", err, cause);
2625

2726
let tcx = self.tcx;
2827

2928
match err {
30-
ArgumentSorts(values, _) | Sorts(values) => {
29+
TypeError::ArgumentSorts(values, _) | TypeError::Sorts(values) => {
3130
match (*values.expected.kind(), *values.found.kind()) {
3231
(ty::Closure(..), ty::Closure(..)) => {
3332
diag.note("no two closures, even if identical, have the same type");
@@ -483,7 +482,7 @@ impl<T> Trait<T> for X {
483482
values.found.kind(),
484483
);
485484
}
486-
CyclicTy(ty) => {
485+
TypeError::CyclicTy(ty) => {
487486
// Watch out for various cases of cyclic types and try to explain.
488487
if ty.is_closure() || ty.is_coroutine() || ty.is_coroutine_closure() {
489488
diag.note(
@@ -494,7 +493,7 @@ impl<T> Trait<T> for X {
494493
);
495494
}
496495
}
497-
TargetFeatureCast(def_id) => {
496+
TypeError::TargetFeatureCast(def_id) => {
498497
let target_spans = tcx.get_attrs(def_id, sym::target_feature).map(|attr| attr.span);
499498
diag.note(
500499
"functions with `#[target_feature]` can only be coerced to `unsafe` function pointers"

compiler/rustc_infer/src/infer/mod.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
pub use at::DefineOpaqueTypes;
22
pub use freshen::TypeFreshener;
33
pub use lexical_region_resolve::RegionResolutionError;
4-
pub use relate::combine::CombineFields;
5-
pub use relate::combine::ObligationEmittingRelation;
6-
pub use relate::StructurallyRelateAliases;
74
pub use rustc_macros::{TypeFoldable, TypeVisitable};
85
pub use rustc_middle::ty::IntVarValue;
96
pub use BoundRegionConversionTime::*;
107
pub use RegionVariableOrigin::*;
118
pub use SubregionOrigin::*;
129
pub use ValuePairs::*;
1310

11+
use crate::infer::relate::{CombineFields, RelateResult};
1412
use crate::traits::{
1513
self, ObligationCause, ObligationInspector, PredicateObligations, TraitEngine,
1614
};
@@ -39,7 +37,6 @@ use rustc_middle::traits::select;
3937
use rustc_middle::ty::error::{ExpectedFound, TypeError};
4038
use rustc_middle::ty::fold::BoundVarReplacerDelegate;
4139
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
42-
use rustc_middle::ty::relate::RelateResult;
4340
use rustc_middle::ty::visit::TypeVisitableExt;
4441
use rustc_middle::ty::{self, GenericParamDefKind, InferConst, Ty, TyCtxt};
4542
use rustc_middle::ty::{ConstVid, EffectVid, FloatVid, IntVid, TyVid};
@@ -62,7 +59,7 @@ pub mod opaque_types;
6259
pub mod outlives;
6360
mod projection;
6461
pub mod region_constraints;
65-
mod relate;
62+
pub mod relate;
6663
pub mod resolve;
6764
pub(crate) mod snapshot;
6865
pub mod type_variable;

compiler/rustc_infer/src/infer/outlives/test_type_match.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
use std::collections::hash_map::Entry;
22

33
use rustc_data_structures::fx::FxHashMap;
4+
use rustc_middle::ty::error::TypeError;
45
use rustc_middle::ty::TypeVisitableExt;
5-
use rustc_middle::ty::{
6-
self,
7-
error::TypeError,
8-
relate::{self, Relate, RelateResult, TypeRelation},
9-
Ty, TyCtxt,
10-
};
6+
use rustc_middle::ty::{self, Ty, TyCtxt};
117

128
use crate::infer::region_constraints::VerifyIfEq;
9+
use crate::infer::relate::{self as relate, Relate, RelateResult, TypeRelation};
1310

1411
/// Given a "verify-if-eq" type test like:
1512
///
@@ -135,7 +132,7 @@ impl<'tcx> MatchAgainstHigherRankedOutlives<'tcx> {
135132
}
136133
}
137134

138-
impl<'tcx> TypeRelation<'tcx> for MatchAgainstHigherRankedOutlives<'tcx> {
135+
impl<'tcx> TypeRelation<TyCtxt<'tcx>> for MatchAgainstHigherRankedOutlives<'tcx> {
139136
fn tag(&self) -> &'static str {
140137
"MatchAgainstHigherRankedOutlives"
141138
}
@@ -145,10 +142,10 @@ impl<'tcx> TypeRelation<'tcx> for MatchAgainstHigherRankedOutlives<'tcx> {
145142
}
146143

147144
#[instrument(level = "trace", skip(self))]
148-
fn relate_with_variance<T: Relate<'tcx>>(
145+
fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>(
149146
&mut self,
150147
variance: ty::Variance,
151-
_: ty::VarianceDiagInfo<'tcx>,
148+
_: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
152149
a: T,
153150
b: T,
154151
) -> RelateResult<'tcx, T> {
@@ -208,7 +205,7 @@ impl<'tcx> TypeRelation<'tcx> for MatchAgainstHigherRankedOutlives<'tcx> {
208205
value: ty::Binder<'tcx, T>,
209206
) -> RelateResult<'tcx, ty::Binder<'tcx, T>>
210207
where
211-
T: Relate<'tcx>,
208+
T: Relate<TyCtxt<'tcx>>,
212209
{
213210
self.pattern_depth.shift_in(1);
214211
let result = Ok(pattern.rebind(self.relate(pattern.skip_binder(), value.skip_binder())?));

0 commit comments

Comments
 (0)