Resolve dead code warnings uncovered by rustc_privacy/rustc_resolve refactor

warning: associated function is never used: `checked_succ`
       --> gen/build/src/syntax/discriminant.rs:183:18
        |
    183 |     pub const fn checked_succ(self) -> Option<Self> {
        |                  ^^^^^^^^^^^^
        |
        = note: `#[warn(dead_code)]` on by default

    warning: associated function is never used: `ty`
       --> gen/build/src/syntax/tokens.rs:305:12
        |
    305 |     pub fn ty(&self) -> ReceiverType {
        |            ^^

    warning: associated function is never used: `ty_self`
       --> gen/build/src/syntax/tokens.rs:310:12
        |
    310 |     pub fn ty_self(&self) -> ReceiverTypeSelf {
        |            ^^^^^^^

    warning: variant is never constructed: `Foreign`
       --> gen/build/src/syntax/mod.rs:122:5
        |
    122 |     Foreign { rust_type: Path },
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^

    warning: associated function is never used: `checked_succ`
       --> macro/src/syntax/discriminant.rs:183:18
        |
    183 |     pub const fn checked_succ(self) -> Option<Self> {
        |                  ^^^^^^^^^^^^
        |
        = note: `#[warn(dead_code)]` on by default

    warning: associated function is never used: `is_empty`
      --> macro/src/syntax/doc.rs:22:12
       |
    22 |     pub fn is_empty(&self) -> bool {
       |            ^^^^^^^^

    warning: associated function is never used: `to_string`
      --> macro/src/syntax/doc.rs:26:12
       |
    26 |     pub fn to_string(&self) -> String {
       |            ^^^^^^^^^

    warning: associated function is never used: `remove`
       --> macro/src/syntax/map.rs:127:16
        |
    127 |         pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
        |                ^^^^^^

    warning: associated function is never used: `to_fully_qualified`
      --> macro/src/syntax/names.rs:24:12
       |
    24 |     pub fn to_fully_qualified(&self) -> String {
       |            ^^^^^^^^^^^^^^^^^^

    warning: associated function is never used: `prefix_with`
      --> macro/src/syntax/symbol.rs:44:12
       |
    44 |     pub fn prefix_with(&self, prefix: &str) -> Symbol {
       |            ^^^^^^^^^^^

    warning: variant is never constructed: `Foreign`
       --> macro/src/syntax/mod.rs:122:5
        |
    122 |     Foreign { rust_type: Path },
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
This commit is contained in:
David Tolnay 2022-01-10 18:42:02 -08:00
parent bbcb85f9b2
commit 7fae55596e
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
13 changed files with 108 additions and 93 deletions

View File

@ -9,6 +9,7 @@ mod file;
pub(super) mod fs;
mod ifndef;
pub(super) mod include;
mod names;
mod namespace;
mod nested;
pub(super) mod out;

14
gen/src/names.rs Normal file
View File

@ -0,0 +1,14 @@
use crate::syntax::Pair;
impl Pair {
pub fn to_fully_qualified(&self) -> String {
let mut fully_qualified = String::new();
for segment in &self.namespace {
fully_qualified += "::";
fully_qualified += &segment.to_string();
}
fully_qualified += "::";
fully_qualified += &self.cxx.to_string();
fully_qualified
}
}

View File

@ -6,7 +6,7 @@ use crate::syntax::atom::Atom::{self, *};
use crate::syntax::instantiate::{ImplKey, NamedImplKey};
use crate::syntax::map::UnorderedMap as Map;
use crate::syntax::set::UnorderedSet;
use crate::syntax::symbol::Symbol;
use crate::syntax::symbol::{self, Symbol};
use crate::syntax::trivial::{self, TrivialReason};
use crate::syntax::{
derive, mangle, Api, Doc, Enum, EnumRepr, ExternFn, ExternType, Pair, Signature, Struct, Trait,
@ -318,6 +318,7 @@ fn write_struct_decl(out: &mut OutFile, ident: &Pair) {
fn write_enum_decl(out: &mut OutFile, enm: &Enum) {
let repr = match &enm.repr {
#[cfg(feature = "experimental")]
EnumRepr::Foreign { .. } => return,
EnumRepr::Native { atom, .. } => *atom,
};
@ -381,6 +382,7 @@ fn write_opaque_type<'a>(out: &mut OutFile<'a>, ety: &'a ExternType, methods: &[
fn write_enum<'a>(out: &mut OutFile<'a>, enm: &'a Enum) {
let repr = match &enm.repr {
#[cfg(feature = "experimental")]
EnumRepr::Foreign { .. } => return,
EnumRepr::Native { atom, .. } => *atom,
};
@ -406,6 +408,7 @@ fn write_enum<'a>(out: &mut OutFile<'a>, enm: &'a Enum) {
fn check_enum<'a>(out: &mut OutFile<'a>, enm: &'a Enum) {
let repr = match &enm.repr {
#[cfg(feature = "experimental")]
EnumRepr::Foreign { .. } => return,
EnumRepr::Native { atom, .. } => *atom,
};
@ -1372,7 +1375,9 @@ impl<'a> ToMangled for UniquePtr<'a> {
fn to_mangled(&self, types: &Types) -> Symbol {
match self {
UniquePtr::Ident(ident) => ident.to_mangled(types),
UniquePtr::CxxVector(element) => element.to_mangled(types).prefix_with("std$vector$"),
UniquePtr::CxxVector(element) => {
symbol::join(&[&"std", &"vector", &element.to_mangled(types)])
}
}
}
}

View File

@ -34,6 +34,7 @@ mod derive;
mod expand;
mod generics;
mod syntax;
mod tokens;
mod type_id;
#[cfg(feature = "experimental")]

75
macro/src/tokens.rs Normal file
View File

@ -0,0 +1,75 @@
use crate::syntax::Receiver;
use proc_macro2::TokenStream;
use quote::{quote_spanned, ToTokens};
use syn::Token;
pub struct ReceiverType<'a>(&'a Receiver);
pub struct ReceiverTypeSelf<'a>(&'a Receiver);
impl Receiver {
// &TheType
pub fn ty(&self) -> ReceiverType {
ReceiverType(self)
}
// &Self
pub fn ty_self(&self) -> ReceiverTypeSelf {
ReceiverTypeSelf(self)
}
}
impl ToTokens for ReceiverType<'_> {
fn to_tokens(&self, tokens: &mut TokenStream) {
let Receiver {
pinned: _,
ampersand,
lifetime,
mutable: _,
var: _,
colon_token: _,
ty,
shorthand: _,
pin_tokens,
mutability,
} = &self.0;
if let Some((pin, langle, _rangle)) = pin_tokens {
tokens.extend(quote_spanned!(pin.span=> ::std::pin::Pin));
langle.to_tokens(tokens);
}
ampersand.to_tokens(tokens);
lifetime.to_tokens(tokens);
mutability.to_tokens(tokens);
ty.to_tokens(tokens);
if let Some((_pin, _langle, rangle)) = pin_tokens {
rangle.to_tokens(tokens);
}
}
}
impl ToTokens for ReceiverTypeSelf<'_> {
fn to_tokens(&self, tokens: &mut TokenStream) {
let Receiver {
pinned: _,
ampersand,
lifetime,
mutable: _,
var: _,
colon_token: _,
ty,
shorthand: _,
pin_tokens,
mutability,
} = &self.0;
if let Some((pin, langle, _rangle)) = pin_tokens {
tokens.extend(quote_spanned!(pin.span=> ::std::pin::Pin));
langle.to_tokens(tokens);
}
ampersand.to_tokens(tokens);
lifetime.to_tokens(tokens);
mutability.to_tokens(tokens);
Token![Self](ty.rust.span()).to_tokens(tokens);
if let Some((_pin, _langle, rangle)) = pin_tokens {
rangle.to_tokens(tokens);
}
}
}

View File

@ -180,6 +180,7 @@ impl Discriminant {
}
}
#[cfg(feature = "experimental")]
pub const fn checked_succ(self) -> Option<Self> {
match self.sign {
Sign::Negative => {

View File

@ -19,10 +19,12 @@ impl Doc {
self.fragments.push(lit);
}
#[allow(dead_code)] // only used by cxx-build, not cxxbridge-macro
pub fn is_empty(&self) -> bool {
self.fragments.is_empty()
}
#[allow(dead_code)] // only used by cxx-build, not cxxbridge-macro
pub fn to_string(&self) -> String {
let mut doc = String::new();
for lit in &self.fragments {

View File

@ -124,6 +124,7 @@ mod unordered {
self.0.entry(key)
}
#[allow(dead_code)] // only used by cxx-build, not cxxbridge-macro
pub fn remove<Q>(&mut self, key: &Q) -> Option<V>
where
K: Borrow<Q>,

View File

@ -36,7 +36,7 @@ use self::symbol::Symbol;
use proc_macro2::{Ident, Span};
use syn::punctuated::Punctuated;
use syn::token::{Brace, Bracket, Paren};
use syn::{Attribute, Expr, Generics, Lifetime, LitInt, Path, Token, Type as RustType};
use syn::{Attribute, Expr, Generics, Lifetime, LitInt, Token, Type as RustType};
pub use self::atom::Atom;
pub use self::derive::{Derive, Trait};
@ -119,7 +119,8 @@ pub struct Enum {
pub enum EnumRepr {
Native { atom: Atom, repr_type: Type },
Foreign { rust_type: Path },
#[cfg(feature = "experimental")]
Foreign { rust_type: syn::Path },
}
pub struct ExternFn {

View File

@ -20,17 +20,6 @@ impl Pair {
.chain(iter::once(&self.cxx as &dyn Segment));
Symbol::from_idents(segments)
}
pub fn to_fully_qualified(&self) -> String {
let mut fully_qualified = String::new();
for segment in &self.namespace {
fully_qualified += "::";
fully_qualified += &segment.to_string();
}
fully_qualified += "::";
fully_qualified += &self.cxx.to_string();
fully_qualified
}
}
impl NamedType {

View File

@ -38,12 +38,6 @@ impl Symbol {
assert!(!symbol.0.is_empty());
symbol
}
/// For example, for taking a symbol and then making a new symbol
/// for a vec of that symbol.
pub fn prefix_with(&self, prefix: &str) -> Symbol {
Symbol(format!("{}{}", prefix, self))
}
}
pub trait Segment {

View File

@ -1,7 +1,7 @@
use crate::syntax::atom::Atom::*;
use crate::syntax::{
Array, Atom, Derive, Enum, EnumRepr, ExternFn, ExternType, Impl, Lifetimes, NamedType, Ptr,
Receiver, Ref, Signature, SliceRef, Struct, Ty1, Type, TypeAlias, Var,
Ref, Signature, SliceRef, Struct, Ty1, Type, TypeAlias, Var,
};
use proc_macro2::{Ident, Span, TokenStream};
use quote::{quote_spanned, ToTokens};
@ -284,6 +284,7 @@ impl ToTokens for EnumRepr {
fn to_tokens(&self, tokens: &mut TokenStream) {
match self {
EnumRepr::Native { atom, repr_type: _ } => atom.to_tokens(tokens),
#[cfg(feature = "experimental")]
EnumRepr::Foreign { rust_type } => rust_type.to_tokens(tokens),
}
}
@ -296,74 +297,3 @@ impl ToTokens for NamedType {
generics.to_tokens(tokens);
}
}
pub struct ReceiverType<'a>(&'a Receiver);
pub struct ReceiverTypeSelf<'a>(&'a Receiver);
impl Receiver {
// &TheType
pub fn ty(&self) -> ReceiverType {
ReceiverType(self)
}
// &Self
pub fn ty_self(&self) -> ReceiverTypeSelf {
ReceiverTypeSelf(self)
}
}
impl ToTokens for ReceiverType<'_> {
fn to_tokens(&self, tokens: &mut TokenStream) {
let Receiver {
pinned: _,
ampersand,
lifetime,
mutable: _,
var: _,
colon_token: _,
ty,
shorthand: _,
pin_tokens,
mutability,
} = &self.0;
if let Some((pin, langle, _rangle)) = pin_tokens {
tokens.extend(quote_spanned!(pin.span=> ::std::pin::Pin));
langle.to_tokens(tokens);
}
ampersand.to_tokens(tokens);
lifetime.to_tokens(tokens);
mutability.to_tokens(tokens);
ty.to_tokens(tokens);
if let Some((_pin, _langle, rangle)) = pin_tokens {
rangle.to_tokens(tokens);
}
}
}
impl ToTokens for ReceiverTypeSelf<'_> {
fn to_tokens(&self, tokens: &mut TokenStream) {
let Receiver {
pinned: _,
ampersand,
lifetime,
mutable: _,
var: _,
colon_token: _,
ty,
shorthand: _,
pin_tokens,
mutability,
} = &self.0;
if let Some((pin, langle, _rangle)) = pin_tokens {
tokens.extend(quote_spanned!(pin.span=> ::std::pin::Pin));
langle.to_tokens(tokens);
}
ampersand.to_tokens(tokens);
lifetime.to_tokens(tokens);
mutability.to_tokens(tokens);
Token![Self](ty.rust.span()).to_tokens(tokens);
if let Some((_pin, _langle, rangle)) = pin_tokens {
rangle.to_tokens(tokens);
}
}
}

View File

@ -92,6 +92,7 @@ impl<'a> Types<'a> {
EnumRepr::Native { atom: _, repr_type } => {
all.insert(repr_type);
}
#[cfg(feature = "experimental")]
EnumRepr::Foreign { rust_type: _ } => {}
}
let ident = &enm.name.rust;