Error during Writing New Lint for Clippy

I am following this link Writing New lint . Although, author of this tutorial did’t mentioned, but i have added following code at top of my foo_functions.rs, otherwise my file is showing errors.

use syntax::visit::FnKind;
use syntax::ast::FnDecl;
use syntax::source_map::Span;
use syntax::ast::NodeId;
use crate::utils::span_help_and_lint;

When i run cargo test in my directory c:\master_clippy, then i faced this error .

Whats going wrong ?

It seems like that guide might be outdated - in the latest version of Rust’s AST, ident.name is a Symbol, not a string. I think you might need to change that to:

ident.as_str() == "foo"

Clippy relies quite heavily on the compiler’s internals, so little breakages like this can happen quite easily. If this fixes your issue, I’d recommend submitting a pull request to update the guide :slight_smile:

2 Likes

i have done as you said and also added use syntax::source_map::symbol::Ident; but still facing problem

ident.name == Ident::from_str(“foo”)
| ^^^^^^^^^^^^^^^^^^^^^^ expected struct syntax_pos::Symbol, found struct syntax::ast::Ident
note: expected type syntax_pos::Symbol
found type syntax::ast::Ident

I have updated my reply - to check the name alone, it seems like you need to call as_str on the Ident or the Symbol. I can see several instances of this in the Clippy codebase.

If you try to do ident == Ident::from_str("foo") as I originally suggested, it’ll likely always fail, because the location data of the two Ident instances will be different. Apologies for the misinformation!

thanks its works for me but with little changes ident.name.as_str() == "foo" Because you forget to mention ident.name.as_str() rather than ident.as_str()