Skip to content

Commit 369715b

Browse files
Remove lint allows from new solver stuff
1 parent 6232ba8 commit 369715b

Some content is hidden

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

57 files changed

+526
-1267
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/builder.rs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
//! `TyBuilder`, a helper for building instances of `Ty` and related types.
22
33
use chalk_ir::{
4-
DebruijnIndex, Scalar,
4+
DebruijnIndex,
55
cast::{Cast, Caster},
66
};
7-
use hir_def::{GenericDefId, GenericParamId, TraitId, builtin_type::BuiltinType};
7+
use hir_def::{GenericDefId, GenericParamId, TraitId};
88
use smallvec::SmallVec;
99

1010
use crate::{
@@ -18,7 +18,7 @@ use crate::{
1818
DbInterner, EarlyBinder,
1919
mapping::{ChalkToNextSolver, NextSolverToChalk},
2020
},
21-
primitive, to_chalk_trait_id,
21+
to_chalk_trait_id,
2222
};
2323

2424
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -137,23 +137,6 @@ impl TyBuilder<()> {
137137
TyKind::Scalar(chalk_ir::Scalar::Uint(chalk_ir::UintTy::Usize)).intern(Interner)
138138
}
139139

140-
pub(crate) fn builtin(builtin: BuiltinType) -> Ty {
141-
match builtin {
142-
BuiltinType::Char => TyKind::Scalar(Scalar::Char).intern(Interner),
143-
BuiltinType::Bool => TyKind::Scalar(Scalar::Bool).intern(Interner),
144-
BuiltinType::Str => TyKind::Str.intern(Interner),
145-
BuiltinType::Int(t) => {
146-
TyKind::Scalar(Scalar::Int(primitive::int_ty_from_builtin(t))).intern(Interner)
147-
}
148-
BuiltinType::Uint(t) => {
149-
TyKind::Scalar(Scalar::Uint(primitive::uint_ty_from_builtin(t))).intern(Interner)
150-
}
151-
BuiltinType::Float(t) => {
152-
TyKind::Scalar(Scalar::Float(primitive::float_ty_from_builtin(t))).intern(Interner)
153-
}
154-
}
155-
}
156-
157140
pub(crate) fn unknown_subst(
158141
db: &dyn HirDatabase,
159142
def: impl Into<GenericDefId>,

src/tools/rust-analyzer/crates/hir-ty/src/consteval.rs

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,74 +6,28 @@ mod tests;
66
use base_db::Crate;
77
use hir_def::{
88
EnumVariantId, GeneralConstId, HasModule, StaticId,
9-
expr_store::{Body, HygieneId, path::Path},
9+
expr_store::Body,
1010
hir::{Expr, ExprId},
11-
resolver::{Resolver, ValueNs},
1211
type_ref::LiteralConstRef,
1312
};
1413
use hir_expand::Lookup;
15-
use rustc_type_ir::{UnevaluatedConst, inherent::IntoKind};
16-
use stdx::never;
14+
use rustc_type_ir::inherent::IntoKind;
1715
use triomphe::Arc;
1816

1917
use crate::{
20-
MemoryMap, TraitEnvironment,
18+
LifetimeElisionKind, MemoryMap, TraitEnvironment, TyLoweringContext,
2119
db::HirDatabase,
2220
display::DisplayTarget,
23-
generics::Generics,
2421
infer::InferenceContext,
2522
mir::{MirEvalError, MirLowerError},
2623
next_solver::{
2724
Const, ConstBytes, ConstKind, DbInterner, ErrorGuaranteed, GenericArg, GenericArgs,
28-
ParamConst, SolverDefId, Ty, ValueConst,
25+
SolverDefId, Ty, ValueConst,
2926
},
3027
};
3128

3229
use super::mir::{interpret_mir, lower_to_mir, pad16};
3330

34-
pub(crate) fn path_to_const<'a, 'g>(
35-
db: &'a dyn HirDatabase,
36-
resolver: &Resolver<'a>,
37-
path: &Path,
38-
args: impl FnOnce() -> &'g Generics,
39-
_expected_ty: Ty<'a>,
40-
) -> Option<Const<'a>> {
41-
let interner = DbInterner::new_with(db, Some(resolver.krate()), None);
42-
match resolver.resolve_path_in_value_ns_fully(db, path, HygieneId::ROOT) {
43-
Some(ValueNs::GenericParam(p)) => {
44-
let args = args();
45-
match args
46-
.type_or_const_param(p.into())
47-
.and_then(|(idx, p)| p.const_param().map(|p| (idx, p.clone())))
48-
{
49-
Some((idx, _param)) => {
50-
Some(Const::new_param(interner, ParamConst { index: idx as u32, id: p }))
51-
}
52-
None => {
53-
never!(
54-
"Generic list doesn't contain this param: {:?}, {:?}, {:?}",
55-
args,
56-
path,
57-
p
58-
);
59-
None
60-
}
61-
}
62-
}
63-
Some(ValueNs::ConstId(c)) => {
64-
let args = GenericArgs::new_from_iter(interner, []);
65-
Some(Const::new(
66-
interner,
67-
rustc_type_ir::ConstKind::Unevaluated(UnevaluatedConst::new(
68-
SolverDefId::ConstId(c),
69-
args,
70-
)),
71-
))
72-
}
73-
_ => None,
74-
}
75-
}
76-
7731
pub fn unknown_const<'db>(_ty: Ty<'db>) -> Const<'db> {
7832
Const::new(DbInterner::conjure(), rustc_type_ir::ConstKind::Error(ErrorGuaranteed))
7933
}
@@ -279,8 +233,14 @@ pub(crate) fn eval_to_const<'db>(expr: ExprId, ctx: &mut InferenceContext<'_, 'd
279233
return unknown_const(infer[expr]);
280234
}
281235
if let Expr::Path(p) = &ctx.body[expr] {
282-
let resolver = &ctx.resolver;
283-
if let Some(c) = path_to_const(ctx.db, resolver, p, || ctx.generics(), infer[expr]) {
236+
let mut ctx = TyLoweringContext::new(
237+
ctx.db,
238+
&ctx.resolver,
239+
ctx.body,
240+
ctx.generic_def,
241+
LifetimeElisionKind::Infer,
242+
);
243+
if let Some(c) = ctx.path_to_const(p) {
284244
return c;
285245
}
286246
}

src/tools/rust-analyzer/crates/hir-ty/src/display.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,9 +1062,9 @@ impl<'db> HirDisplay<'db> for Ty<'db> {
10621062
TyKind::Str => write!(f, "str")?,
10631063
TyKind::Bool => write!(f, "bool")?,
10641064
TyKind::Char => write!(f, "char")?,
1065-
TyKind::Float(t) => write!(f, "{}", primitive::float_ty_to_string_ns(t))?,
1066-
TyKind::Int(t) => write!(f, "{}", primitive::int_ty_to_string_ns(t))?,
1067-
TyKind::Uint(t) => write!(f, "{}", primitive::uint_ty_to_string_ns(t))?,
1065+
TyKind::Float(t) => write!(f, "{}", primitive::float_ty_to_string(t))?,
1066+
TyKind::Int(t) => write!(f, "{}", primitive::int_ty_to_string(t))?,
1067+
TyKind::Uint(t) => write!(f, "{}", primitive::uint_ty_to_string(t))?,
10681068
TyKind::Slice(t) => {
10691069
write!(f, "[")?;
10701070
t.hir_fmt(f)?;

src/tools/rust-analyzer/crates/hir-ty/src/dyn_compatibility.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use hir_def::{
77
TypeAliasId, TypeOrConstParamId, TypeParamId, hir::generics::LocalTypeOrConstParamId,
88
lang_item::LangItem, signatures::TraitFlags,
99
};
10-
use intern::Symbol;
1110
use rustc_hash::FxHashSet;
1211
use rustc_type_ir::{
1312
AliasTyKind, ClauseKind, PredicatePolarity, TypeSuperVisitable as _, TypeVisitable as _,
@@ -441,8 +440,7 @@ fn receiver_is_dispatchable<'db>(
441440

442441
// Type `U`
443442
// FIXME: That seems problematic to fake a generic param like that?
444-
let unsized_self_ty =
445-
crate::next_solver::Ty::new_param(interner, self_param_id, u32::MAX, Symbol::empty());
443+
let unsized_self_ty = crate::next_solver::Ty::new_param(interner, self_param_id, u32::MAX);
446444
// `Receiver[Self => U]`
447445
let unsized_receiver_ty = receiver_for_self_ty(interner, func, receiver_ty, unsized_self_ty);
448446

@@ -454,8 +452,8 @@ fn receiver_is_dispatchable<'db>(
454452
TraitRef::new(interner, unsize_did.into(), [self_param_ty, unsized_self_ty]);
455453

456454
// U: Trait<Arg1, ..., ArgN>
457-
let args = GenericArgs::for_item(interner, trait_.into(), |name, index, kind, _| {
458-
if index == 0 { unsized_self_ty.into() } else { mk_param(interner, index, name, kind) }
455+
let args = GenericArgs::for_item(interner, trait_.into(), |index, kind, _| {
456+
if index == 0 { unsized_self_ty.into() } else { mk_param(interner, index, kind) }
459457
});
460458
let trait_predicate = TraitRef::new_from_args(interner, trait_.into(), args);
461459

@@ -494,8 +492,8 @@ fn receiver_for_self_ty<'db>(
494492
let args = crate::next_solver::GenericArgs::for_item(
495493
interner,
496494
SolverDefId::FunctionId(func),
497-
|name, index, kind, _| {
498-
if index == 0 { self_ty.into() } else { mk_param(interner, index, name, kind) }
495+
|index, kind, _| {
496+
if index == 0 { self_ty.into() } else { mk_param(interner, index, kind) }
499497
},
500498
);
501499

src/tools/rust-analyzer/crates/hir-ty/src/generics.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl Generics {
258258
}
259259

260260
/// Returns a Substitution that replaces each parameter by itself (i.e. `Ty::Param`).
261-
pub fn placeholder_subst(&self, db: &dyn HirDatabase) -> Substitution {
261+
pub(crate) fn placeholder_subst(&self, db: &dyn HirDatabase) -> Substitution {
262262
Substitution::from_iter(
263263
Interner,
264264
self.iter_id().enumerate().map(|(index, id)| match id {

src/tools/rust-analyzer/crates/hir-ty/src/infer.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ use triomphe::Arc;
5757
use crate::{
5858
ImplTraitId, IncorrectGenericsLenKind, PathLoweringDiagnostic, TargetFeatures,
5959
db::{HirDatabase, InternedClosureId, InternedOpaqueTyId},
60-
generics::Generics,
6160
infer::{
6261
coerce::{CoerceMany, DynamicCoerceMany},
6362
diagnostics::{Diagnostics, InferenceTyLoweringContext as TyLoweringContext},
@@ -72,10 +71,7 @@ use crate::{
7271
Tys,
7372
abi::Safety,
7473
fold::fold_tys,
75-
infer::{
76-
DefineOpaqueTypes,
77-
traits::{Obligation, ObligationCause},
78-
},
74+
infer::traits::{Obligation, ObligationCause},
7975
mapping::ChalkToNextSolver,
8076
},
8177
traits::FnTrait,
@@ -763,8 +759,7 @@ pub(crate) struct InferenceContext<'body, 'db> {
763759
/// and resolve the path via its methods. This will ensure proper error reporting.
764760
pub(crate) resolver: Resolver<'db>,
765761
target_features: OnceCell<(TargetFeatures, TargetFeatureIsSafeInTarget)>,
766-
generic_def: GenericDefId,
767-
generics: OnceCell<Generics>,
762+
pub(crate) generic_def: GenericDefId,
768763
table: unify::InferenceTable<'db>,
769764
/// The traits in scope, disregarding block modules. This is used for caching purposes.
770765
traits_in_scope: FxHashSet<TraitId>,
@@ -873,7 +868,6 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
873868
return_ty: types.error, // set in collect_* calls
874869
types,
875870
target_features: OnceCell::new(),
876-
generics: OnceCell::new(),
877871
table,
878872
tuple_field_accesses_rev: Default::default(),
879873
resume_yield_tys: None,
@@ -902,10 +896,6 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
902896
}
903897
}
904898

905-
pub(crate) fn generics(&self) -> &Generics {
906-
self.generics.get_or_init(|| crate::generics::generics(self.db, self.generic_def))
907-
}
908-
909899
#[inline]
910900
fn krate(&self) -> Crate {
911901
self.resolver.krate()
@@ -1133,7 +1123,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
11331123
GenericArgs::for_item_with_defaults(
11341124
self.interner(),
11351125
va_list.into(),
1136-
|_, _, id, _| self.table.next_var_for_param(id),
1126+
|_, id, _| self.table.next_var_for_param(id),
11371127
),
11381128
),
11391129
None => self.err_ty(),
@@ -1676,7 +1666,7 @@ impl<'body, 'db> InferenceContext<'body, 'db> {
16761666
.table
16771667
.infer_ctxt
16781668
.at(&ObligationCause::new(), self.table.trait_env.env)
1679-
.eq(DefineOpaqueTypes::Yes, expected, actual)
1669+
.eq(expected, actual)
16801670
.map(|infer_ok| self.table.register_infer_ok(infer_ok));
16811671
if let Err(_err) = result {
16821672
// FIXME: Emit diagnostic.

src/tools/rust-analyzer/crates/hir-ty/src/infer/closure.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::{
2626
PolyProjectionPredicate, Predicate, PredicateKind, SolverDefId, Ty, TyKind,
2727
abi::Safety,
2828
infer::{
29-
BoundRegionConversionTime, DefineOpaqueTypes, InferOk, InferResult,
29+
BoundRegionConversionTime, InferOk, InferResult,
3030
traits::{ObligationCause, PredicateObligations},
3131
},
3232
util::explicit_item_bounds,
@@ -307,7 +307,7 @@ impl<'db> InferenceContext<'_, 'db> {
307307
.table
308308
.infer_ctxt
309309
.at(&ObligationCause::new(), self.table.trait_env.env)
310-
.eq(DefineOpaqueTypes::Yes, inferred_fnptr_sig, generalized_fnptr_sig)
310+
.eq(inferred_fnptr_sig, generalized_fnptr_sig)
311311
.map(|infer_ok| self.table.register_infer_ok(infer_ok));
312312

313313
let resolved_sig =
@@ -692,18 +692,16 @@ impl<'db> InferenceContext<'_, 'db> {
692692
let InferOk { value: (), obligations } = table
693693
.infer_ctxt
694694
.at(&cause, table.trait_env.env)
695-
.eq(DefineOpaqueTypes::Yes, expected_ty, supplied_ty)?;
695+
.eq(expected_ty, supplied_ty)?;
696696
all_obligations.extend(obligations);
697697
}
698698

699699
let supplied_output_ty = supplied_sig.output();
700700
let cause = ObligationCause::new();
701-
let InferOk { value: (), obligations } =
702-
table.infer_ctxt.at(&cause, table.trait_env.env).eq(
703-
DefineOpaqueTypes::Yes,
704-
expected_sigs.liberated_sig.output(),
705-
supplied_output_ty,
706-
)?;
701+
let InferOk { value: (), obligations } = table
702+
.infer_ctxt
703+
.at(&cause, table.trait_env.env)
704+
.eq(expected_sigs.liberated_sig.output(), supplied_output_ty)?;
707705
all_obligations.extend(obligations);
708706

709707
let inputs = supplied_sig

src/tools/rust-analyzer/crates/hir-ty/src/infer/coerce.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ use crate::{
6363
GenericArgs, PolyFnSig, PredicateKind, Region, RegionKind, SolverDefId, TraitRef, Ty,
6464
TyKind,
6565
infer::{
66-
DefineOpaqueTypes, InferCtxt, InferOk, InferResult,
66+
InferCtxt, InferOk, InferResult,
6767
relate::RelateResult,
6868
select::{ImplSource, SelectionError},
6969
traits::{Obligation, ObligationCause, PredicateObligation, PredicateObligations},
@@ -149,7 +149,7 @@ impl<'a, 'b, 'db> Coerce<'a, 'b, 'db> {
149149
let res = if this.use_lub {
150150
at.lub(b, a)
151151
} else {
152-
at.sup(DefineOpaqueTypes::Yes, b, a)
152+
at.sup(b, a)
153153
.map(|InferOk { value: (), obligations }| InferOk { value: b, obligations })
154154
};
155155

@@ -1460,19 +1460,12 @@ impl<'db, 'exprs> CoerceMany<'db, 'exprs> {
14601460
//
14611461
// Another example is `break` with no argument expression.
14621462
assert!(expression_ty.is_unit(), "if let hack without unit type");
1463-
icx.table
1464-
.infer_ctxt
1465-
.at(cause, icx.table.trait_env.env)
1466-
.eq(
1467-
// needed for tests/ui/type-alias-impl-trait/issue-65679-inst-opaque-ty-from-val-twice.rs
1468-
DefineOpaqueTypes::Yes,
1469-
expected,
1470-
found,
1471-
)
1472-
.map(|infer_ok| {
1463+
icx.table.infer_ctxt.at(cause, icx.table.trait_env.env).eq(expected, found).map(
1464+
|infer_ok| {
14731465
icx.table.register_infer_ok(infer_ok);
14741466
expression_ty
1475-
})
1467+
},
1468+
)
14761469
};
14771470

14781471
debug!(?result);

src/tools/rust-analyzer/crates/hir-ty/src/infer/expr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use crate::{
4646
AliasTy, Const, DbInterner, ErrorGuaranteed, GenericArg, GenericArgs, TraitRef, Ty, TyKind,
4747
TypeError,
4848
infer::{
49-
DefineOpaqueTypes, InferOk,
49+
InferOk,
5050
traits::{Obligation, ObligationCause},
5151
},
5252
obligation_ctxt::ObligationCtxt,
@@ -1333,7 +1333,7 @@ impl<'db> InferenceContext<'_, 'db> {
13331333
self.interner(),
13341334
box_id.into(),
13351335
[inner_ty.into()],
1336-
|_, _, id, _| self.table.next_var_for_param(id),
1336+
|_, id, _| self.table.next_var_for_param(id),
13371337
),
13381338
)
13391339
} else {
@@ -2122,7 +2122,7 @@ impl<'db> InferenceContext<'_, 'db> {
21222122
.table
21232123
.infer_ctxt
21242124
.at(&ObligationCause::new(), this.table.trait_env.env)
2125-
.eq(DefineOpaqueTypes::Yes, formal_input_ty, coerced_ty);
2125+
.eq(formal_input_ty, coerced_ty);
21262126

21272127
// If neither check failed, the types are compatible
21282128
match formal_ty_error {

src/tools/rust-analyzer/crates/hir-ty/src/infer/pat.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ impl<'db> InferenceContext<'_, 'db> {
358358
self.interner(),
359359
box_adt.into(),
360360
std::iter::once(inner_ty.into()).chain(alloc_ty.map(Into::into)),
361-
|_, _, id, _| self.table.next_var_for_param(id),
361+
|_, id, _| self.table.next_var_for_param(id),
362362
),
363363
)
364364
}

0 commit comments

Comments
 (0)