Skip to content

Commit

Permalink
unused_qualifications
Browse files Browse the repository at this point in the history
  • Loading branch information
kennykerr committed Dec 13, 2023
1 parent a6bdfc8 commit fd936f5
Show file tree
Hide file tree
Showing 48 changed files with 832 additions and 827 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ exclude = [

[workspace.lints.rust]
rust_2018_idioms = "warn"
unused_qualifications = "warn"
34 changes: 17 additions & 17 deletions crates/libs/bindgen/src/rdl/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Writer {
}

impl Writer {
pub fn new(file: &rdl::File) -> Self {
pub fn new(file: &File) -> Self {
let mut writer = Self::default();
writer.rdl_file(file);
writer
Expand All @@ -37,7 +37,7 @@ impl Writer {
self.newline = true;
}

fn rdl_file(&mut self, file: &rdl::File) {
fn rdl_file(&mut self, file: &File) {
if file.winrt {
self.word("#![winrt]\n");
} else {
Expand All @@ -55,7 +55,7 @@ impl Writer {
}
}

fn rdl_module(&mut self, module: &rdl::Module) {
fn rdl_module(&mut self, module: &Module) {
self.word("mod ");
self.word(module.name());
self.word(" {");
Expand All @@ -73,19 +73,19 @@ impl Writer {
self.newline();
}

fn rdl_module_member(&mut self, member: &rdl::ModuleMember) {
fn rdl_module_member(&mut self, member: &ModuleMember) {
match member {
rdl::ModuleMember::Module(member) => self.rdl_module(member),
rdl::ModuleMember::Interface(member) => self.rdl_interface(member),
rdl::ModuleMember::Struct(member) => self.rdl_struct(member),
rdl::ModuleMember::Enum(member) => self.rdl_enum(member),
rdl::ModuleMember::Class(member) => self.rdl_class(member),
rdl::ModuleMember::Constant(member) => self.rdl_constant(member),
rdl::ModuleMember::Function(member) => self.rdl_function(member),
ModuleMember::Module(member) => self.rdl_module(member),
ModuleMember::Interface(member) => self.rdl_interface(member),
ModuleMember::Struct(member) => self.rdl_struct(member),
ModuleMember::Enum(member) => self.rdl_enum(member),
ModuleMember::Class(member) => self.rdl_class(member),
ModuleMember::Constant(member) => self.rdl_constant(member),
ModuleMember::Function(member) => self.rdl_function(member),
}
}

fn rdl_class(&mut self, member: &rdl::Class) {
fn rdl_class(&mut self, member: &Class) {
self.attrs(&member.attributes);
self.word("class ");
self.word(&member.name);
Expand Down Expand Up @@ -117,7 +117,7 @@ impl Writer {
self.newline();
}

fn rdl_interface(&mut self, member: &rdl::Interface) {
fn rdl_interface(&mut self, member: &Interface) {
self.attrs(&member.attributes);
self.word("interface ");
self.word(&member.name);
Expand Down Expand Up @@ -167,11 +167,11 @@ impl Writer {
self.word("}");
}

fn rdl_constant(&mut self, member: &rdl::Constant) {
fn rdl_constant(&mut self, member: &Constant) {
self.item_const(&member.item);
}

fn rdl_function(&mut self, member: &rdl::Function) {
fn rdl_function(&mut self, member: &Function) {
self.trait_item_fn(&member.item);
self.word(";");
self.newline();
Expand Down Expand Up @@ -222,7 +222,7 @@ impl Writer {
self.expr(&meta.value);
}

fn rdl_struct(&mut self, member: &rdl::Struct) {
fn rdl_struct(&mut self, member: &Struct) {
self.attrs(&member.attributes);

self.word("struct ");
Expand All @@ -244,7 +244,7 @@ impl Writer {
self.word("}");
}

fn rdl_enum(&mut self, member: &rdl::Enum) {
fn rdl_enum(&mut self, member: &Enum) {
self.attrs(&member.item.attrs);

self.word("enum ");
Expand Down
15 changes: 7 additions & 8 deletions crates/libs/bindgen/src/rdl/from_reader.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use super::*;
use crate::tokens::{quote, to_ident, TokenStream};
use crate::{rdl, Error, Result, Tree};
use metadata::*;
use tokens::{quote, to_ident, TokenStream};
use {crate::Result, rdl, Error, Tree};

pub fn from_reader(reader: &'static metadata::Reader, mut config: std::collections::BTreeMap<&str, &str>, output: &str) -> Result<()> {
let dialect = match config.remove("type") {
Expand Down Expand Up @@ -30,7 +29,7 @@ pub fn from_reader(reader: &'static metadata::Reader, mut config: std::collectio

fn gen_split(writer: &Writer) -> Result<()> {
let tree = Tree::new(writer.reader);
let directory = crate::directory(&writer.output);
let directory = directory(&writer.output);

// TODO: parallelize
for tree in tree.flatten() {
Expand Down Expand Up @@ -86,8 +85,8 @@ impl Writer {
};

let file = rdl::File::parse_str(&tokens.into_string())?;
crate::write_to_file(output, file.fmt())
//crate::write_to_file(output, tokens.into_string())
write_to_file(output, file.fmt())
//write_to_file(output, tokens.into_string())
}

fn tree(&self, tree: &Tree) -> TokenStream {
Expand Down Expand Up @@ -286,8 +285,8 @@ impl Writer {
// TODO: then list default interface first
// Then everything else

for interface in type_def_interfaces(def, generics) {
if interface.kind == InterfaceKind::Default {
for interface in metadata::type_def_interfaces(def, generics) {
if interface.kind == metadata::InterfaceKind::Default {
types.insert(0, self.ty(&interface.ty));
} else {
types.push(self.ty(&interface.ty));
Expand Down
2 changes: 1 addition & 1 deletion crates/libs/bindgen/src/rdl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub enum ModuleMember {
impl ModuleMember {
pub fn name(&self) -> &str {
match self {
Self::Module(module) => crate::extension(&module.namespace),
Self::Module(module) => extension(&module.namespace),
Self::Interface(member) => &member.name,
Self::Struct(member) => &member.name,
Self::Enum(member) => &member.name,
Expand Down
32 changes: 16 additions & 16 deletions crates/libs/bindgen/src/rdl/to_winmd.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::*;
use crate::winmd::{self, writer};
use crate::{rdl, Result};
use crate::Result;

// TODO: store span in winmd so that errors resolving type references can be traced back to file/line/column
use std::collections::HashMap;
Expand All @@ -9,7 +9,7 @@ use std::collections::HashMap;
// TODO: this creates a temporary in-memory winmd used to treat the IDL content uniformly as metadata.
// The winmd_to_winmd does the harder job of validating and producing canonical winmd for public consumption.

pub fn rdl_to_winmd(file: &rdl::File) -> Result<Vec<u8>> {
pub fn rdl_to_winmd(file: &File) -> Result<Vec<u8>> {
// Local-to-qualified type names found in use declaration - e.g. "IStringable" -> "Windows.Foundation.IStringable"
// This is just a convenience for the developer to shorten common references like this but would not support globs or renames.
// Note that none of these are verified to be real until much later when the winmd is validated since we don't
Expand All @@ -20,7 +20,7 @@ pub fn rdl_to_winmd(file: &rdl::File) -> Result<Vec<u8>> {

// Types are collected here in two passes - this allows us to figure out whether a local name points to a relative type
// or a type from a use declaration...?
let mut collector = HashMap::<String, HashMap<&str, rdl::ModuleMember>>::new();
let mut collector = HashMap::<String, HashMap<&str, ModuleMember>>::new();

file.modules.iter().for_each(|module| collect_module(&mut collector, module));

Expand All @@ -36,14 +36,14 @@ pub fn rdl_to_winmd(file: &rdl::File) -> Result<Vec<u8>> {
Ok(writer.into_stream())
}

fn collect_module<'a>(collector: &mut HashMap<String, HashMap<&'a str, rdl::ModuleMember>>, module: &'a rdl::Module) {
fn collect_module<'a>(collector: &mut HashMap<String, HashMap<&'a str, ModuleMember>>, module: &'a Module) {
module.members.iter().for_each(|member| collect_member(collector, module, member));
}

fn collect_member<'a>(collector: &mut HashMap<String, HashMap<&'a str, rdl::ModuleMember>>, module: &'a rdl::Module, member: &'a rdl::ModuleMember) {
fn collect_member<'a>(collector: &mut HashMap<String, HashMap<&'a str, ModuleMember>>, module: &'a Module, member: &'a ModuleMember) {
match member {
rdl::ModuleMember::Module(module) => collect_module(collector, module),
rdl::ModuleMember::Constant(_) | rdl::ModuleMember::Function(_) => {
ModuleMember::Module(module) => collect_module(collector, module),
ModuleMember::Constant(_) | ModuleMember::Function(_) => {
collector.entry(module.namespace.to_string()).or_default().entry("Apis").or_insert(member.clone());
}
_ => {
Expand All @@ -52,17 +52,17 @@ fn collect_member<'a>(collector: &mut HashMap<String, HashMap<&'a str, rdl::Modu
}
}

fn write_member(writer: &mut winmd::Writer, namespace: &str, name: &str, member: &rdl::ModuleMember) {
fn write_member(writer: &mut winmd::Writer, namespace: &str, name: &str, member: &ModuleMember) {
match member {
rdl::ModuleMember::Interface(member) => write_interface(writer, namespace, name, member),
rdl::ModuleMember::Struct(member) => write_struct(writer, namespace, name, member),
rdl::ModuleMember::Enum(member) => write_enum(writer, namespace, name, member),
rdl::ModuleMember::Class(member) => write_class(writer, namespace, name, member),
ModuleMember::Interface(member) => write_interface(writer, namespace, name, member),
ModuleMember::Struct(member) => write_struct(writer, namespace, name, member),
ModuleMember::Enum(member) => write_enum(writer, namespace, name, member),
ModuleMember::Class(member) => write_class(writer, namespace, name, member),
rest => unimplemented!("{rest:?}"),
}
}

fn write_interface(writer: &mut winmd::Writer, namespace: &str, name: &str, member: &rdl::Interface) {
fn write_interface(writer: &mut winmd::Writer, namespace: &str, name: &str, member: &Interface) {
let mut flags = metadata::TypeAttributes::Public | metadata::TypeAttributes::Interface | metadata::TypeAttributes::Abstract;

if member.winrt {
Expand Down Expand Up @@ -123,7 +123,7 @@ fn write_interface(writer: &mut winmd::Writer, namespace: &str, name: &str, memb
}
}

fn write_struct(writer: &mut winmd::Writer, namespace: &str, name: &str, member: &rdl::Struct) {
fn write_struct(writer: &mut winmd::Writer, namespace: &str, name: &str, member: &Struct) {
let mut flags = metadata::TypeAttributes::Public | metadata::TypeAttributes::Sealed | metadata::TypeAttributes::SequentialLayout;

if member.winrt {
Expand All @@ -150,9 +150,9 @@ fn write_struct(writer: &mut winmd::Writer, namespace: &str, name: &str, member:
}
}

fn write_enum(_writer: &mut winmd::Writer, _namespace: &str, _name: &str, _member: &rdl::Enum) {}
fn write_enum(_writer: &mut winmd::Writer, _namespace: &str, _name: &str, _member: &Enum) {}

fn write_class(writer: &mut winmd::Writer, namespace: &str, name: &str, member: &rdl::Class) {
fn write_class(writer: &mut winmd::Writer, namespace: &str, name: &str, member: &Class) {
let flags = metadata::TypeAttributes::Public | metadata::TypeAttributes::Sealed | metadata::TypeAttributes::WindowsRuntime;

let extends = if let Some(base) = &member.base {
Expand Down
Loading

0 comments on commit fd936f5

Please sign in to comment.