Skip to content

Commit 36f5e78

Browse files
committed
Rust: Remove unused impl type
1 parent cb59795 commit 36f5e78

File tree

2 files changed

+0
-120
lines changed

2 files changed

+0
-120
lines changed

rust/ql/lib/codeql/rust/internal/Type.qll

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ newtype TType =
1313
TStruct(Struct s) { Stages::TypeInferenceStage::ref() } or
1414
TEnum(Enum e) or
1515
TTrait(Trait t) or
16-
TImpl(Impl i) or
1716
TArrayType() or // todo: add size?
1817
TRefType() or // todo: add mut?
1918
TTypeParamTypeParameter(TypeParam t) or
@@ -132,75 +131,6 @@ class TraitType extends Type, TTrait {
132131
override Location getLocation() { result = trait.getLocation() }
133132
}
134133

135-
/**
136-
* An `impl` block type.
137-
*
138-
* Although `impl` blocks are not really types, we treat them as such in order
139-
* to be able to match type parameters from structs (or enums) with type
140-
* parameters from `impl` blocks. For example, in
141-
*
142-
* ```rust
143-
* struct S<T1>(T1);
144-
*
145-
* impl<T2> S<T2> {
146-
* fn id(self) -> S<T2> { self }
147-
* }
148-
*
149-
* let x : S(i64) = S(42);
150-
* x.id();
151-
* ```
152-
*
153-
* we pretend that the `impl` block is a base type mention of the struct `S`,
154-
* with type argument `T1`. This means that from knowing that `x` has type
155-
* `S(i64)`, we can first match `i64` with `T1`, and then by matching `T1` with
156-
* `T2`, we can match `i64` with `T2`.
157-
*
158-
* `impl` blocks can also have base type mentions, namely the trait that they
159-
* implement (if any). Example:
160-
*
161-
* ```rust
162-
* struct S<T1>(T1);
163-
*
164-
* trait Trait<T2> {
165-
* fn f(self) -> T2;
166-
*
167-
* fn g(self) -> T2 { self.f() }
168-
* }
169-
*
170-
* impl<T3> Trait<T3> for S<T3> { // `Trait<T3>` is a base type mention of this `impl` block
171-
* fn f(self) -> T3 {
172-
* match self {
173-
* S(x) => x
174-
* }
175-
* }
176-
* }
177-
*
178-
* let x : S(i64) = S(42);
179-
* x.g();
180-
* ```
181-
*
182-
* In this case we can match `i64` with `T1`, `T1` with `T3`, and `T3` with `T2`,
183-
* allowing us match `i64` with `T2`, and hence infer that the return type of `g`
184-
* is `i64`.
185-
*/
186-
class ImplType extends Type, TImpl {
187-
private Impl impl;
188-
189-
ImplType() { this = TImpl(impl) }
190-
191-
override StructField getStructField(string name) { none() }
192-
193-
override TupleField getTupleField(int i) { none() }
194-
195-
override TypeParameter getTypeParameter(int i) {
196-
result = TTypeParamTypeParameter(impl.getGenericParamList().getTypeParam(i))
197-
}
198-
199-
override string toString() { result = impl.toString() }
200-
201-
override Location getLocation() { result = impl.getLocation() }
202-
}
203-
204134
/**
205135
* An array type.
206136
*

rust/ql/lib/codeql/rust/internal/TypeMention.qll

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -189,56 +189,6 @@ class TypeAliasMention extends TypeMention, TypeAlias {
189189
override Type resolveType() { result = t }
190190
}
191191

192-
/**
193-
* Holds if the `i`th type argument of `selfPath`, belonging to `impl`, resolves
194-
* to type parameter `tp`.
195-
*
196-
* Example:
197-
*
198-
* ```rust
199-
* impl<T> Foo<T> for Bar<T> { ... }
200-
* // ^^^^^^ selfPath
201-
* // ^ tp
202-
* ```
203-
*/
204-
pragma[nomagic]
205-
private predicate isImplSelfTypeParam(
206-
ImplItemNode impl, PathMention selfPath, int i, TypeParameter tp
207-
) {
208-
exists(PathMention path |
209-
selfPath = impl.getSelfPath() and
210-
path = selfPath.getSegment().getGenericArgList().getTypeArg(i).(PathTypeRepr).getPath() and
211-
tp = path.resolveType()
212-
)
213-
}
214-
215-
class ImplMention extends TypeMention, ImplItemNode {
216-
override TypeReprMention getTypeArgument(int i) { none() }
217-
218-
override Type resolveType() { result = TImpl(this) }
219-
220-
override Type resolveTypeAt(TypePath path) {
221-
result = TImpl(this) and
222-
path.isEmpty()
223-
or
224-
// For example, in
225-
//
226-
// ```rust
227-
// struct S<T1>(T1);
228-
//
229-
// impl<T2> S<T2> { ... }
230-
// ```
231-
//
232-
// We get that the type path "0" resolves to `T1` for the `impl` block,
233-
// which is considered a base type mention of `S`.
234-
exists(PathMention selfPath, TypeParameter tp, int i |
235-
isImplSelfTypeParam(this, selfPath, pragma[only_bind_into](i), tp) and
236-
result = selfPath.resolveType().getTypeParameter(pragma[only_bind_into](i)) and
237-
path = TypePath::singleton(tp)
238-
)
239-
}
240-
}
241-
242192
class TraitMention extends TypeMention, TraitItemNode {
243193
override TypeMention getTypeArgument(int i) {
244194
result = this.getTypeParam(i)

0 commit comments

Comments
 (0)