cxx/syntax/names.rs
David Tolnay 7fae55596e
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 },
        |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2022-01-10 18:50:49 -08:00

65 lines
1.6 KiB
Rust

use crate::syntax::symbol::Segment;
use crate::syntax::{Lifetimes, NamedType, Pair, Symbol};
use proc_macro2::{Ident, Span};
use std::fmt::{self, Display};
use std::iter;
use syn::parse::{Error, Result};
use syn::punctuated::Punctuated;
#[derive(Clone)]
pub struct ForeignName {
text: String,
}
impl Pair {
pub fn to_symbol(&self) -> Symbol {
let segments = self
.namespace
.iter()
.map(|ident| ident as &dyn Segment)
.chain(iter::once(&self.cxx as &dyn Segment));
Symbol::from_idents(segments)
}
}
impl NamedType {
pub fn new(rust: Ident) -> Self {
let generics = Lifetimes {
lt_token: None,
lifetimes: Punctuated::new(),
gt_token: None,
};
NamedType { rust, generics }
}
pub fn span(&self) -> Span {
self.rust.span()
}
}
impl ForeignName {
pub fn parse(text: &str, span: Span) -> Result<Self> {
// TODO: support C++ names containing whitespace (`unsigned int`) or
// non-alphanumeric characters (`operator++`).
match syn::parse_str::<Ident>(text) {
Ok(ident) => {
let text = ident.to_string();
Ok(ForeignName { text })
}
Err(err) => Err(Error::new(span, err)),
}
}
}
impl Display for ForeignName {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str(&self.text)
}
}
impl PartialEq<str> for ForeignName {
fn eq(&self, rhs: &str) -> bool {
self.text == rhs
}
}