mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
Rust: fix generated hierarchy
This commit is contained in:
2
rust/extractor/src/generated/.generated.list
generated
2
rust/extractor/src/generated/.generated.list
generated
@@ -1,2 +1,2 @@
|
||||
mod.rs 7cdfedcd68cf8e41134daf810c1af78624082b0c3e8be6570339b1a69a5d457e 7cdfedcd68cf8e41134daf810c1af78624082b0c3e8be6570339b1a69a5d457e
|
||||
top.rs 775cb04552f9242ff999b279a375f7a446124f4ef28668e42496751bf69e7dd3 775cb04552f9242ff999b279a375f7a446124f4ef28668e42496751bf69e7dd3
|
||||
top.rs 834f3eff470c256398cf3c8e876ee0d9d466c5f4f01e97588a1a1f5422b8ad0a 834f3eff470c256398cf3c8e876ee0d9d466c5f4f01e97588a1a1f5422b8ad0a
|
||||
|
||||
480
rust/extractor/src/generated/top.rs
generated
480
rust/extractor/src/generated/top.rs
generated
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
use crate::archive::Archiver;
|
||||
use crate::trap::{AsTrapKeyPart, Label, TrapEntry, TrapFile, TrapId};
|
||||
use crate::trap::{AsTrapKeyPart, Label, TrapClass, TrapFile, TrapId};
|
||||
use crate::{generated, trap_key};
|
||||
use codeql_extractor::trap;
|
||||
use ra_ap_hir::db::{DefDatabase, InternDatabase};
|
||||
@@ -71,7 +71,7 @@ impl CrateTranslator<'_> {
|
||||
})
|
||||
}
|
||||
|
||||
fn emit_location_for_ast_ptr<E: TrapEntry, T: AstNode>(
|
||||
fn emit_location_for_ast_ptr<E: TrapClass, T: AstNode>(
|
||||
&mut self,
|
||||
label: Label<E>,
|
||||
source: ra_ap_hir::InFile<ra_ap_syntax::AstPtr<T>>,
|
||||
@@ -132,7 +132,7 @@ impl CrateTranslator<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_location_for_label<E: TrapEntry>(
|
||||
fn emit_location_for_label<E: TrapClass>(
|
||||
&mut self,
|
||||
label: Label<E>,
|
||||
label_id: ra_ap_hir_def::hir::LabelId,
|
||||
@@ -144,7 +144,7 @@ impl CrateTranslator<'_> {
|
||||
self.emit_location_for_ast_ptr(label, source)
|
||||
}
|
||||
}
|
||||
fn emit_location<E: TrapEntry, T: HasSource>(&mut self, label: Label<E>, entity: T)
|
||||
fn emit_location<E: TrapClass, T: HasSource>(&mut self, label: Label<E>, entity: T)
|
||||
where
|
||||
T::Ast: AstNode,
|
||||
{
|
||||
@@ -157,7 +157,7 @@ impl CrateTranslator<'_> {
|
||||
self.emit_location_for_textrange(label, data, range);
|
||||
});
|
||||
}
|
||||
fn emit_location_for_textrange<E: TrapEntry>(
|
||||
fn emit_location_for_textrange<E: TrapClass>(
|
||||
&mut self,
|
||||
label: Label<E>,
|
||||
data: FileData,
|
||||
|
||||
@@ -35,6 +35,15 @@ impl AsTrapKeyPart for &str {
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TrapClass {
|
||||
fn class_name() -> &'static str;
|
||||
}
|
||||
|
||||
pub trait TrapEntry: Debug + Sized + TrapClass {
|
||||
fn extract_id(&mut self) -> TrapId<Self>;
|
||||
fn emit(self, id: Label<Self>, out: &mut Writer);
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum TrapId<T: TrapEntry> {
|
||||
Star,
|
||||
@@ -72,7 +81,7 @@ macro_rules! trap_key {
|
||||
}
|
||||
|
||||
#[derive(Debug, Ord, PartialOrd, Eq, PartialEq, Hash)]
|
||||
pub struct Label<T: TrapEntry> {
|
||||
pub struct Label<T: TrapClass> {
|
||||
untyped: UntypedLabel,
|
||||
phantom: PhantomData<T>, // otherwise Rust wants `T` to be used
|
||||
}
|
||||
@@ -80,15 +89,15 @@ pub struct Label<T: TrapEntry> {
|
||||
// not deriving `Clone` and `Copy` because they require `T: Clone` and `T: Copy` respectively,
|
||||
// even if `T` is not actually part of the fields.
|
||||
// see https://github.com/rust-lang/rust/issues/108894
|
||||
impl<T: TrapEntry> Clone for Label<T> {
|
||||
impl<T: TrapClass> Clone for Label<T> {
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: TrapEntry> Copy for Label<T> {}
|
||||
impl<T: TrapClass> Copy for Label<T> {}
|
||||
|
||||
impl<T: TrapEntry> Label<T> {
|
||||
impl<T: TrapClass> Label<T> {
|
||||
pub fn as_untyped(&self) -> UntypedLabel {
|
||||
self.untyped
|
||||
}
|
||||
@@ -103,24 +112,18 @@ impl<T: TrapEntry> Label<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: TrapEntry> AsTrapKeyPart for Label<T> {
|
||||
impl<T: TrapClass> AsTrapKeyPart for Label<T> {
|
||||
fn as_key_part(&self) -> String {
|
||||
self.as_untyped().as_key_part()
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: TrapEntry> From<Label<T>> for trap::Arg {
|
||||
impl<T: TrapClass> From<Label<T>> for trap::Arg {
|
||||
fn from(value: Label<T>) -> Self {
|
||||
trap::Arg::Label(value.as_untyped())
|
||||
}
|
||||
}
|
||||
|
||||
pub trait TrapEntry: std::fmt::Debug + Sized {
|
||||
fn class_name() -> &'static str;
|
||||
fn extract_id(&mut self) -> TrapId<Self>;
|
||||
fn emit(self, id: Label<Self>, out: &mut Writer);
|
||||
}
|
||||
|
||||
pub struct TrapFile {
|
||||
path: PathBuf,
|
||||
writer: Writer,
|
||||
@@ -128,10 +131,10 @@ pub struct TrapFile {
|
||||
}
|
||||
|
||||
impl TrapFile {
|
||||
pub fn emit_location<T: TrapEntry>(
|
||||
pub fn emit_location<E: TrapClass>(
|
||||
&mut self,
|
||||
file_label: UntypedLabel,
|
||||
entity_label: Label<T>,
|
||||
entity_label: Label<E>,
|
||||
start: LineCol,
|
||||
end: LineCol,
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user