Change:
The following code... the following error and warning: The warning says that is not used but it clearly is, just not properly. This error is normally easier to spot when using the proper casing for constants, but that might not always be the case. Perhaps in this instance, we should look for other items with the exact same name and point out that the user is trying to use a constant as a type. <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
Every single one of these errors should point at similarly named things of the wrong namespace.
Do you know where in the code this is coming from?
running the following will tell you where the error is being emitted: From there the place you might want to start looking at is , which is a bit hard to follow at the moment (I'm doing a slight clean up of that method at the moment), but should be reasonably straight forward to add another check for this case to that pile :)
claim
Can I take this issue?
Yes feel free to take it, I removed my assignment.
I’m going to be tied up until May, feel free to take this issue:pray:
Hey I'm looking to get to know the Rust codebase better and contribute to the project - would love to take a crack at this issue!
claim

Discussion:
} ItemKind::Static(ref ty, _, ref expr) | ItemKind::Const(_, ref ty, ref expr) => { <del> debug!("resolve_item ItemKind::Const"); </del> self.with_item_rib(HasGenericParams::No, |this| { this.visit_ty(ty); if let Some(expr) = expr {

.try_resolve_as_non_binding(pat_src, pat, bmode, ident, has_sub) .unwrap_or_else(|| self.fresh_binding(ident, pat.id, pat_src, bindings)); self.r.record_partial_res(pat.id, PartialRes::new(res)); <ins> self.r.record_pat_span(pat.id, pat.span); </ins> } PatKind::TupleStruct(ref path, ref sub_patterns) => { self.smart_resolve_path(

/// "self-confirming" import resolutions during import validation. unusable_binding: Option<&'a NameBinding<'a>>, <ins> // Spans for local variables found during pattern resolution. // Used for suggestions during error reporting. pat_span_map: NodeMap<Span>, </ins> /// Resolutions for nodes that have a single resolution. partial_res_map: NodeMap<PartialRes>, /// Resolutions for import nodes, which have multiple resolutions in different namespaces.

last_import_segment: false, unusable_binding: None, <ins> pat_span_map: Default::default(), </ins> partial_res_map: Default::default(), import_res_map: Default::default(), label_res_map: Default::default(),

return Some(LexicalScopeBinding::Item(binding)); } } self.early_resolve_ident_in_lexical_scope( orig_ident, ScopeSet::Late(ns, module, record_used_id),

.next() .map_or(false, |c| c.is_ascii_uppercase()) { <del> (format!("use of undeclared type `{}`", ident), None) </del> <ins> // Check whether the name refers to an item in the value namespace. let suggestion = if ribs.is_some() { let match_span = match self.resolve_ident_in_lexical_scope( ident, ValueNS, parent_scope, None, path_span, &ribs.unwrap()[ValueNS], ) { // Name matches a local variable. For example: // ``` // fn f() { //     let Foo: &str = ""; //     println!("{}", Foo::Bar); // Name refers to local //                               // variable `Foo`. // } // ``` Some(LexicalScopeBinding::Res(Res::Local(id))) => { Some(*self.pat_span_map.get(&id).unwrap()) } // Name matches item from a local name binding // created by `use` declaration. For example: // ``` // pub Foo: &str = ""; // // mod submod { //     use super::Foo; //     println!("{}", Foo::Bar); // Name refers to local //                               // binding `Foo`. // } // ``` Some(LexicalScopeBinding::Item(name_binding)) => { Some(name_binding.span) } _ => None, }; if let Some(span) = match_span { Some(( vec![(span, String::from(""))], format!("`{}` is defined here, but is not a type", ident), Applicability::MaybeIncorrect, )) } else { None } } else { None }; (format!("use of undeclared type `{}`", ident), suggestion) </ins> } else { (format!("use of undeclared crate or module `{}`", ident), None) }

} } <ins> fn record_pat_span(&mut self, node: NodeId, span: Span) { debug!("(recording pat) recording {:?} for {:?}", node, span); self.pat_span_map.insert(node, span); } </ins> fn is_accessible_from(&self, vis: ty::Visibility, module: Module<'a>) -> bool { vis.is_accessible_from(module.nearest_parent_mod, self) }

<ins> // Confusing diagnostic when using variable as a type: // // Previous warnings indicate Foo is not used, when in fact it is // used improperly as a variable or constant. New warning points // out user may be trying to use variable as a type. Test demonstrates // cases for both local variable and const. fn main() { let Baz: &str = ""; println!("{}", Baz::Bar); //~ ERROR: failed to resolve: use of undeclared type `Baz` } #[allow(non_upper_case_globals)] pub const Foo: &str = ""; mod submod { use super::Foo; fn function() { println!("{}", Foo::Bar); //~ ERROR: failed to resolve: use of undeclared type `Foo` } } </ins>

<ins> error[E0433]: failed to resolve: use of undeclared type `Baz` --> $DIR/issue-81508.rs:11:20 | LL |     let Baz: &str = ""; |         --- help: `Baz` is defined here, but is not a type LL | LL |     println!("{}", Baz::Bar); |                    ^^^ use of undeclared type `Baz` error[E0433]: failed to resolve: use of undeclared type `Foo` --> $DIR/issue-81508.rs:20:24 | LL |     use super::Foo; |         ---------- help: `Foo` is defined here, but is not a type LL |     fn function() { LL |         println!("{}", Foo::Bar); |                        ^^^ use of undeclared type `Foo` error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0433`. </ins>