1use std::borrow::Cow;
2use std::fmt::Display;
3
4use rustc_ast::AttrId;
5use rustc_ast::attr::AttributeExt;
6use rustc_data_structures::fx::FxIndexSet;
7use rustc_data_structures::stable_hasher::{
8 HashStable, StableCompare, StableHasher, ToStableHashKey,
9};
10use rustc_error_messages::{DiagArgValue, IntoDiagArg, MultiSpan};
11use rustc_hir_id::{HashStableContext, HirId, ItemLocalId};
12use rustc_macros::{Decodable, Encodable, HashStable_Generic};
13use rustc_span::def_id::DefPathHash;
14pub use rustc_span::edition::Edition;
15use rustc_span::{Ident, Span, Symbol, sym};
16use serde::{Deserialize, Serialize};
17
18pub use self::Level::*;
19
20pub mod builtin;
21
22#[macro_export]
23macro_rules! pluralize {
24 ($x:expr) => {
26 if $x == 1 { "" } else { "s" }
27 };
28 ("has", $x:expr) => {
29 if $x == 1 { "has" } else { "have" }
30 };
31 ("is", $x:expr) => {
32 if $x == 1 { "is" } else { "are" }
33 };
34 ("was", $x:expr) => {
35 if $x == 1 { "was" } else { "were" }
36 };
37 ("this", $x:expr) => {
38 if $x == 1 { "this" } else { "these" }
39 };
40}
41
42pub fn listify<T>(list: &[T], fmt: impl Fn(&T) -> String) -> Option<String> {
48 Some(match list {
49 [only] => fmt(&only),
50 [others @ .., last] => ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0} and {1}",
others.iter().map(|i| fmt(i)).collect::<Vec<_>>().join(", "),
fmt(&last)))
})format!(
51 "{} and {}",
52 others.iter().map(|i| fmt(i)).collect::<Vec<_>>().join(", "),
53 fmt(&last),
54 ),
55 [] => return None,
56 })
57}
58
59#[derive(#[automatically_derived]
impl ::core::marker::Copy for Applicability { }Copy, #[automatically_derived]
impl ::core::clone::Clone for Applicability {
#[inline]
fn clone(&self) -> Applicability { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for Applicability {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
Applicability::MachineApplicable => "MachineApplicable",
Applicability::MaybeIncorrect => "MaybeIncorrect",
Applicability::HasPlaceholders => "HasPlaceholders",
Applicability::Unspecified => "Unspecified",
})
}
}Debug, #[automatically_derived]
impl ::core::hash::Hash for Applicability {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state)
}
}Hash, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for Applicability {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
Applicability::MachineApplicable => { 0usize }
Applicability::MaybeIncorrect => { 1usize }
Applicability::HasPlaceholders => { 2usize }
Applicability::Unspecified => { 3usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
Applicability::MachineApplicable => {}
Applicability::MaybeIncorrect => {}
Applicability::HasPlaceholders => {}
Applicability::Unspecified => {}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for Applicability {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { Applicability::MachineApplicable }
1usize => { Applicability::MaybeIncorrect }
2usize => { Applicability::HasPlaceholders }
3usize => { Applicability::Unspecified }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `Applicability`, expected 0..4, actual {0}",
n));
}
}
}
}
};Decodable, #[doc(hidden)]
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications,
clippy :: absolute_paths,)]
const _: () =
{
#[allow(unused_extern_crates, clippy :: useless_attribute)]
extern crate serde as _serde;
;
#[automatically_derived]
impl _serde::Serialize for Applicability {
fn serialize<__S>(&self, __serializer: __S)
-> _serde::__private228::Result<__S::Ok, __S::Error> where
__S: _serde::Serializer {
match *self {
Applicability::MachineApplicable =>
_serde::Serializer::serialize_unit_variant(__serializer,
"Applicability", 0u32, "MachineApplicable"),
Applicability::MaybeIncorrect =>
_serde::Serializer::serialize_unit_variant(__serializer,
"Applicability", 1u32, "MaybeIncorrect"),
Applicability::HasPlaceholders =>
_serde::Serializer::serialize_unit_variant(__serializer,
"Applicability", 2u32, "HasPlaceholders"),
Applicability::Unspecified =>
_serde::Serializer::serialize_unit_variant(__serializer,
"Applicability", 3u32, "Unspecified"),
}
}
}
};Serialize, #[doc(hidden)]
#[allow(non_upper_case_globals, unused_attributes, unused_qualifications,
clippy :: absolute_paths,)]
const _: () =
{
#[allow(unused_extern_crates, clippy :: useless_attribute)]
extern crate serde as _serde;
;
#[automatically_derived]
impl<'de> _serde::Deserialize<'de> for Applicability {
fn deserialize<__D>(__deserializer: __D)
-> _serde::__private228::Result<Self, __D::Error> where
__D: _serde::Deserializer<'de> {
#[allow(non_camel_case_types)]
#[doc(hidden)]
enum __Field { __field0, __field1, __field2, __field3, }
#[doc(hidden)]
struct __FieldVisitor;
#[automatically_derived]
impl<'de> _serde::de::Visitor<'de> for __FieldVisitor {
type Value = __Field;
fn expecting(&self,
__formatter: &mut _serde::__private228::Formatter)
-> _serde::__private228::fmt::Result {
_serde::__private228::Formatter::write_str(__formatter,
"variant identifier")
}
fn visit_u64<__E>(self, __value: u64)
-> _serde::__private228::Result<Self::Value, __E> where
__E: _serde::de::Error {
match __value {
0u64 => _serde::__private228::Ok(__Field::__field0),
1u64 => _serde::__private228::Ok(__Field::__field1),
2u64 => _serde::__private228::Ok(__Field::__field2),
3u64 => _serde::__private228::Ok(__Field::__field3),
_ =>
_serde::__private228::Err(_serde::de::Error::invalid_value(_serde::de::Unexpected::Unsigned(__value),
&"variant index 0 <= i < 4")),
}
}
fn visit_str<__E>(self, __value: &str)
-> _serde::__private228::Result<Self::Value, __E> where
__E: _serde::de::Error {
match __value {
"MachineApplicable" =>
_serde::__private228::Ok(__Field::__field0),
"MaybeIncorrect" =>
_serde::__private228::Ok(__Field::__field1),
"HasPlaceholders" =>
_serde::__private228::Ok(__Field::__field2),
"Unspecified" =>
_serde::__private228::Ok(__Field::__field3),
_ => {
_serde::__private228::Err(_serde::de::Error::unknown_variant(__value,
VARIANTS))
}
}
}
fn visit_bytes<__E>(self, __value: &[u8])
-> _serde::__private228::Result<Self::Value, __E> where
__E: _serde::de::Error {
match __value {
b"MachineApplicable" =>
_serde::__private228::Ok(__Field::__field0),
b"MaybeIncorrect" =>
_serde::__private228::Ok(__Field::__field1),
b"HasPlaceholders" =>
_serde::__private228::Ok(__Field::__field2),
b"Unspecified" =>
_serde::__private228::Ok(__Field::__field3),
_ => {
let __value =
&_serde::__private228::from_utf8_lossy(__value);
_serde::__private228::Err(_serde::de::Error::unknown_variant(__value,
VARIANTS))
}
}
}
}
#[automatically_derived]
impl<'de> _serde::Deserialize<'de> for __Field {
#[inline]
fn deserialize<__D>(__deserializer: __D)
-> _serde::__private228::Result<Self, __D::Error> where
__D: _serde::Deserializer<'de> {
_serde::Deserializer::deserialize_identifier(__deserializer,
__FieldVisitor)
}
}
#[doc(hidden)]
struct __Visitor<'de> {
marker: _serde::__private228::PhantomData<Applicability>,
lifetime: _serde::__private228::PhantomData<&'de ()>,
}
#[automatically_derived]
impl<'de> _serde::de::Visitor<'de> for __Visitor<'de> {
type Value = Applicability;
fn expecting(&self,
__formatter: &mut _serde::__private228::Formatter)
-> _serde::__private228::fmt::Result {
_serde::__private228::Formatter::write_str(__formatter,
"enum Applicability")
}
fn visit_enum<__A>(self, __data: __A)
-> _serde::__private228::Result<Self::Value, __A::Error>
where __A: _serde::de::EnumAccess<'de> {
match _serde::de::EnumAccess::variant(__data)? {
(__Field::__field0, __variant) => {
_serde::de::VariantAccess::unit_variant(__variant)?;
_serde::__private228::Ok(Applicability::MachineApplicable)
}
(__Field::__field1, __variant) => {
_serde::de::VariantAccess::unit_variant(__variant)?;
_serde::__private228::Ok(Applicability::MaybeIncorrect)
}
(__Field::__field2, __variant) => {
_serde::de::VariantAccess::unit_variant(__variant)?;
_serde::__private228::Ok(Applicability::HasPlaceholders)
}
(__Field::__field3, __variant) => {
_serde::de::VariantAccess::unit_variant(__variant)?;
_serde::__private228::Ok(Applicability::Unspecified)
}
}
}
}
#[doc(hidden)]
const VARIANTS: &'static [&'static str] =
&["MachineApplicable", "MaybeIncorrect", "HasPlaceholders",
"Unspecified"];
_serde::Deserializer::deserialize_enum(__deserializer,
"Applicability", VARIANTS,
__Visitor {
marker: _serde::__private228::PhantomData::<Applicability>,
lifetime: _serde::__private228::PhantomData,
})
}
}
};Deserialize)]
65#[derive(#[automatically_derived]
impl ::core::cmp::PartialEq for Applicability {
#[inline]
fn eq(&self, other: &Applicability) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Applicability {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {}
}Eq, #[automatically_derived]
impl ::core::cmp::PartialOrd for Applicability {
#[inline]
fn partial_cmp(&self, other: &Applicability)
-> ::core::option::Option<::core::cmp::Ordering> {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
::core::cmp::PartialOrd::partial_cmp(&__self_discr, &__arg1_discr)
}
}PartialOrd, #[automatically_derived]
impl ::core::cmp::Ord for Applicability {
#[inline]
fn cmp(&self, other: &Applicability) -> ::core::cmp::Ordering {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr)
}
}Ord)]
66pub enum Applicability {
67 MachineApplicable,
74
75 MaybeIncorrect,
78
79 HasPlaceholders,
83
84 Unspecified,
86}
87
88#[derive(#[automatically_derived]
impl ::core::clone::Clone for LintExpectationId {
#[inline]
fn clone(&self) -> LintExpectationId {
let _: ::core::clone::AssertParamIsClone<AttrId>;
let _: ::core::clone::AssertParamIsClone<Option<u16>>;
let _: ::core::clone::AssertParamIsClone<HirId>;
let _: ::core::clone::AssertParamIsClone<u16>;
let _: ::core::clone::AssertParamIsClone<Option<u16>>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for LintExpectationId { }Copy, #[automatically_derived]
impl ::core::cmp::PartialEq for LintExpectationId {
#[inline]
fn eq(&self, other: &LintExpectationId) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(LintExpectationId::Unstable {
attr_id: __self_0, lint_index: __self_1 },
LintExpectationId::Unstable {
attr_id: __arg1_0, lint_index: __arg1_1 }) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
(LintExpectationId::Stable {
hir_id: __self_0, attr_index: __self_1, lint_index: __self_2
}, LintExpectationId::Stable {
hir_id: __arg1_0, attr_index: __arg1_1, lint_index: __arg1_2
}) =>
__self_1 == __arg1_1 && __self_0 == __arg1_0 &&
__self_2 == __arg1_2,
_ => unsafe { ::core::intrinsics::unreachable() }
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for LintExpectationId {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {
let _: ::core::cmp::AssertParamIsEq<AttrId>;
let _: ::core::cmp::AssertParamIsEq<Option<u16>>;
let _: ::core::cmp::AssertParamIsEq<HirId>;
let _: ::core::cmp::AssertParamIsEq<u16>;
let _: ::core::cmp::AssertParamIsEq<Option<u16>>;
}
}Eq, #[automatically_derived]
impl ::core::fmt::Debug for LintExpectationId {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
LintExpectationId::Unstable {
attr_id: __self_0, lint_index: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Unstable", "attr_id", __self_0, "lint_index", &__self_1),
LintExpectationId::Stable {
hir_id: __self_0, attr_index: __self_1, lint_index: __self_2 }
=>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"Stable", "hir_id", __self_0, "attr_index", __self_1,
"lint_index", &__self_2),
}
}
}Debug, #[automatically_derived]
impl ::core::hash::Hash for LintExpectationId {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state);
match self {
LintExpectationId::Unstable {
attr_id: __self_0, lint_index: __self_1 } => {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state)
}
LintExpectationId::Stable {
hir_id: __self_0, attr_index: __self_1, lint_index: __self_2 }
=> {
::core::hash::Hash::hash(__self_0, state);
::core::hash::Hash::hash(__self_1, state);
::core::hash::Hash::hash(__self_2, state)
}
}
}
}Hash, const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for LintExpectationId {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
LintExpectationId::Unstable {
attr_id: ref __binding_0, lint_index: ref __binding_1 } => {
0usize
}
LintExpectationId::Stable {
hir_id: ref __binding_0,
attr_index: ref __binding_1,
lint_index: ref __binding_2 } => {
1usize
}
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
LintExpectationId::Unstable {
attr_id: ref __binding_0, lint_index: ref __binding_1 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
}
LintExpectationId::Stable {
hir_id: ref __binding_0,
attr_index: ref __binding_1,
lint_index: ref __binding_2 } => {
::rustc_serialize::Encodable::<__E>::encode(__binding_0,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_1,
__encoder);
::rustc_serialize::Encodable::<__E>::encode(__binding_2,
__encoder);
}
}
}
}
};Encodable, const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for LintExpectationId {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => {
LintExpectationId::Unstable {
attr_id: ::rustc_serialize::Decodable::decode(__decoder),
lint_index: ::rustc_serialize::Decodable::decode(__decoder),
}
}
1usize => {
LintExpectationId::Stable {
hir_id: ::rustc_serialize::Decodable::decode(__decoder),
attr_index: ::rustc_serialize::Decodable::decode(__decoder),
lint_index: ::rustc_serialize::Decodable::decode(__decoder),
}
}
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `LintExpectationId`, expected 0..2, actual {0}",
n));
}
}
}
}
};Decodable)]
107pub enum LintExpectationId {
108 Unstable { attr_id: AttrId, lint_index: Option<u16> },
111 Stable { hir_id: HirId, attr_index: u16, lint_index: Option<u16> },
116}
117
118impl LintExpectationId {
119 pub fn is_stable(&self) -> bool {
120 match self {
121 LintExpectationId::Unstable { .. } => false,
122 LintExpectationId::Stable { .. } => true,
123 }
124 }
125
126 pub fn get_lint_index(&self) -> Option<u16> {
127 let (LintExpectationId::Unstable { lint_index, .. }
128 | LintExpectationId::Stable { lint_index, .. }) = self;
129
130 *lint_index
131 }
132
133 pub fn set_lint_index(&mut self, new_lint_index: Option<u16>) {
134 let (LintExpectationId::Unstable { lint_index, .. }
135 | LintExpectationId::Stable { lint_index, .. }) = self;
136
137 *lint_index = new_lint_index
138 }
139}
140
141impl<HCX: HashStableContext> HashStable<HCX> for LintExpectationId {
142 #[inline]
143 fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
144 match self {
145 LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => {
146 hir_id.hash_stable(hcx, hasher);
147 attr_index.hash_stable(hcx, hasher);
148 lint_index.hash_stable(hcx, hasher);
149 }
150 _ => {
151 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("HashStable should only be called for filled and stable `LintExpectationId`")));
}unreachable!(
152 "HashStable should only be called for filled and stable `LintExpectationId`"
153 )
154 }
155 }
156 }
157}
158
159impl<HCX: HashStableContext> ToStableHashKey<HCX> for LintExpectationId {
160 type KeyType = (DefPathHash, ItemLocalId, u16, u16);
161
162 #[inline]
163 fn to_stable_hash_key(&self, hcx: &HCX) -> Self::KeyType {
164 match self {
165 LintExpectationId::Stable { hir_id, attr_index, lint_index: Some(lint_index) } => {
166 let (def_path_hash, lint_idx) = hir_id.to_stable_hash_key(hcx);
167 (def_path_hash, lint_idx, *attr_index, *lint_index)
168 }
169 _ => {
170 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("HashStable should only be called for a filled `LintExpectationId`")));
}unreachable!("HashStable should only be called for a filled `LintExpectationId`")
171 }
172 }
173 }
174}
175
176#[derive(
180 #[automatically_derived]
impl ::core::clone::Clone for Level {
#[inline]
fn clone(&self) -> Level { *self }
}Clone,
181 #[automatically_derived]
impl ::core::marker::Copy for Level { }Copy,
182 #[automatically_derived]
impl ::core::cmp::PartialEq for Level {
#[inline]
fn eq(&self, other: &Level) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq,
183 #[automatically_derived]
impl ::core::cmp::PartialOrd for Level {
#[inline]
fn partial_cmp(&self, other: &Level)
-> ::core::option::Option<::core::cmp::Ordering> {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
::core::cmp::PartialOrd::partial_cmp(&__self_discr, &__arg1_discr)
}
}PartialOrd,
184 #[automatically_derived]
impl ::core::cmp::Eq for Level {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_receiver_is_total_eq(&self) -> () {}
}Eq,
185 #[automatically_derived]
impl ::core::cmp::Ord for Level {
#[inline]
fn cmp(&self, other: &Level) -> ::core::cmp::Ordering {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
::core::cmp::Ord::cmp(&__self_discr, &__arg1_discr)
}
}Ord,
186 #[automatically_derived]
impl ::core::fmt::Debug for Level {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
Level::Allow => "Allow",
Level::Expect => "Expect",
Level::Warn => "Warn",
Level::ForceWarn => "ForceWarn",
Level::Deny => "Deny",
Level::Forbid => "Forbid",
})
}
}Debug,
187 #[automatically_derived]
impl ::core::hash::Hash for Level {
#[inline]
fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () {
let __self_discr = ::core::intrinsics::discriminant_value(self);
::core::hash::Hash::hash(&__self_discr, state)
}
}Hash,
188 const _: () =
{
impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E>
for Level {
fn encode(&self, __encoder: &mut __E) {
let disc =
match *self {
Level::Allow => { 0usize }
Level::Expect => { 1usize }
Level::Warn => { 2usize }
Level::ForceWarn => { 3usize }
Level::Deny => { 4usize }
Level::Forbid => { 5usize }
};
::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8);
match *self {
Level::Allow => {}
Level::Expect => {}
Level::Warn => {}
Level::ForceWarn => {}
Level::Deny => {}
Level::Forbid => {}
}
}
}
};Encodable,
189 const _: () =
{
impl<__D: ::rustc_span::SpanDecoder> ::rustc_serialize::Decodable<__D>
for Level {
fn decode(__decoder: &mut __D) -> Self {
match ::rustc_serialize::Decoder::read_u8(__decoder) as usize
{
0usize => { Level::Allow }
1usize => { Level::Expect }
2usize => { Level::Warn }
3usize => { Level::ForceWarn }
4usize => { Level::Deny }
5usize => { Level::Forbid }
n => {
::core::panicking::panic_fmt(format_args!("invalid enum variant tag while decoding `Level`, expected 0..6, actual {0}",
n));
}
}
}
}
};Decodable,
190 const _: () =
{
impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
for Level where __CTX: crate::HashStableContext {
#[inline]
fn hash_stable(&self, __hcx: &mut __CTX,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
match *self {
Level::Allow => {}
Level::Expect => {}
Level::Warn => {}
Level::ForceWarn => {}
Level::Deny => {}
Level::Forbid => {}
}
}
}
};HashStable_Generic
191)]
192pub enum Level {
193 Allow,
195 Expect,
207 Warn,
210 ForceWarn,
217 Deny,
220 Forbid,
223}
224
225impl Level {
226 pub fn as_str(self) -> &'static str {
228 match self {
229 Level::Allow => "allow",
230 Level::Expect => "expect",
231 Level::Warn => "warn",
232 Level::ForceWarn => "force-warn",
233 Level::Deny => "deny",
234 Level::Forbid => "forbid",
235 }
236 }
237
238 pub fn from_str(x: &str) -> Option<Self> {
241 match x {
242 "allow" => Some(Level::Allow),
243 "warn" => Some(Level::Warn),
244 "deny" => Some(Level::Deny),
245 "forbid" => Some(Level::Forbid),
246 "expect" | _ => None,
247 }
248 }
249
250 pub fn from_attr(attr: &impl AttributeExt) -> Option<(Self, Option<LintExpectationId>)> {
252 attr.name().and_then(|name| Self::from_symbol(name, || Some(attr.id())))
253 }
254
255 pub fn from_symbol(
257 s: Symbol,
258 id: impl FnOnce() -> Option<AttrId>,
259 ) -> Option<(Self, Option<LintExpectationId>)> {
260 match s {
261 sym::allow => Some((Level::Allow, None)),
262 sym::expect => {
263 if let Some(attr_id) = id() {
264 Some((
265 Level::Expect,
266 Some(LintExpectationId::Unstable { attr_id, lint_index: None }),
267 ))
268 } else {
269 None
270 }
271 }
272 sym::warn => Some((Level::Warn, None)),
273 sym::deny => Some((Level::Deny, None)),
274 sym::forbid => Some((Level::Forbid, None)),
275 _ => None,
276 }
277 }
278
279 pub fn to_cmd_flag(self) -> &'static str {
280 match self {
281 Level::Warn => "-W",
282 Level::Deny => "-D",
283 Level::Forbid => "-F",
284 Level::Allow => "-A",
285 Level::ForceWarn => "--force-warn",
286 Level::Expect => {
287 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("the expect level does not have a commandline flag")));
}unreachable!("the expect level does not have a commandline flag")
288 }
289 }
290 }
291
292 pub fn is_error(self) -> bool {
293 match self {
294 Level::Allow | Level::Expect | Level::Warn | Level::ForceWarn => false,
295 Level::Deny | Level::Forbid => true,
296 }
297 }
298}
299
300impl IntoDiagArg for Level {
301 fn into_diag_arg(self, _: &mut Option<std::path::PathBuf>) -> DiagArgValue {
302 DiagArgValue::Str(Cow::Borrowed(self.to_cmd_flag()))
303 }
304}
305
306#[derive(#[automatically_derived]
impl ::core::marker::Copy for Lint { }Copy, #[automatically_derived]
impl ::core::clone::Clone for Lint {
#[inline]
fn clone(&self) -> Lint {
let _: ::core::clone::AssertParamIsClone<&'static str>;
let _: ::core::clone::AssertParamIsClone<Level>;
let _: ::core::clone::AssertParamIsClone<&'static str>;
let _: ::core::clone::AssertParamIsClone<Option<(Edition, Level)>>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _:
::core::clone::AssertParamIsClone<Option<FutureIncompatibleInfo>>;
let _: ::core::clone::AssertParamIsClone<Option<Symbol>>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for Lint {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["name", "default_level", "desc", "edition_lint_opts",
"report_in_external_macro", "future_incompatible",
"is_externally_loaded", "feature_gate", "crate_level_only",
"eval_always"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.name, &self.default_level, &self.desc,
&self.edition_lint_opts, &self.report_in_external_macro,
&self.future_incompatible, &self.is_externally_loaded,
&self.feature_gate, &self.crate_level_only,
&&self.eval_always];
::core::fmt::Formatter::debug_struct_fields_finish(f, "Lint", names,
values)
}
}Debug)]
308pub struct Lint {
309 pub name: &'static str,
323
324 pub default_level: Level,
329
330 pub desc: &'static str,
334
335 pub edition_lint_opts: Option<(Edition, Level)>,
338
339 pub report_in_external_macro: bool,
341
342 pub future_incompatible: Option<FutureIncompatibleInfo>,
343
344 pub is_externally_loaded: bool,
346
347 pub feature_gate: Option<Symbol>,
349
350 pub crate_level_only: bool,
351
352 pub eval_always: bool,
355}
356
357#[derive(#[automatically_derived]
impl ::core::marker::Copy for FutureIncompatibleInfo { }Copy, #[automatically_derived]
impl ::core::clone::Clone for FutureIncompatibleInfo {
#[inline]
fn clone(&self) -> FutureIncompatibleInfo {
let _: ::core::clone::AssertParamIsClone<FutureIncompatibilityReason>;
let _: ::core::clone::AssertParamIsClone<bool>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for FutureIncompatibleInfo {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f,
"FutureIncompatibleInfo", "reason", &self.reason,
"explain_reason", &self.explain_reason, "report_in_deps",
&&self.report_in_deps)
}
}Debug)]
359pub struct FutureIncompatibleInfo {
360 pub reason: FutureIncompatibilityReason,
363 pub explain_reason: bool,
368 pub report_in_deps: bool,
380}
381
382#[derive(#[automatically_derived]
impl ::core::marker::Copy for EditionFcw { }Copy, #[automatically_derived]
impl ::core::clone::Clone for EditionFcw {
#[inline]
fn clone(&self) -> EditionFcw {
let _: ::core::clone::AssertParamIsClone<Edition>;
let _: ::core::clone::AssertParamIsClone<&'static str>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for EditionFcw {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "EditionFcw",
"edition", &self.edition, "page_slug", &&self.page_slug)
}
}Debug)]
383pub struct EditionFcw {
384 pub edition: Edition,
385 pub page_slug: &'static str,
386}
387
388#[derive(#[automatically_derived]
impl ::core::marker::Copy for ReleaseFcw { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ReleaseFcw {
#[inline]
fn clone(&self) -> ReleaseFcw {
let _: ::core::clone::AssertParamIsClone<usize>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for ReleaseFcw {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f, "ReleaseFcw",
"issue_number", &&self.issue_number)
}
}Debug)]
389pub struct ReleaseFcw {
390 pub issue_number: usize,
391}
392
393#[derive(#[automatically_derived]
impl ::core::marker::Copy for FutureIncompatibilityReason { }Copy, #[automatically_derived]
impl ::core::clone::Clone for FutureIncompatibilityReason {
#[inline]
fn clone(&self) -> FutureIncompatibilityReason {
let _: ::core::clone::AssertParamIsClone<ReleaseFcw>;
let _: ::core::clone::AssertParamIsClone<EditionFcw>;
let _: ::core::clone::AssertParamIsClone<&'static str>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for FutureIncompatibilityReason {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
FutureIncompatibilityReason::FutureReleaseError(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"FutureReleaseError", &__self_0),
FutureIncompatibilityReason::FutureReleaseSemanticsChange(__self_0)
=>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"FutureReleaseSemanticsChange", &__self_0),
FutureIncompatibilityReason::EditionError(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"EditionError", &__self_0),
FutureIncompatibilityReason::EditionSemanticsChange(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"EditionSemanticsChange", &__self_0),
FutureIncompatibilityReason::EditionAndFutureReleaseError(__self_0)
=>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"EditionAndFutureReleaseError", &__self_0),
FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange(__self_0)
=>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"EditionAndFutureReleaseSemanticsChange", &__self_0),
FutureIncompatibilityReason::Custom(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f, "Custom",
__self_0, &__self_1),
FutureIncompatibilityReason::Unreachable =>
::core::fmt::Formatter::write_str(f, "Unreachable"),
}
}
}Debug)]
407pub enum FutureIncompatibilityReason {
408 FutureReleaseError(ReleaseFcw),
423 FutureReleaseSemanticsChange(ReleaseFcw),
430 EditionError(EditionFcw),
451 EditionSemanticsChange(EditionFcw),
459 EditionAndFutureReleaseError(EditionFcw),
469 EditionAndFutureReleaseSemanticsChange(EditionFcw),
480 Custom(&'static str, ReleaseFcw),
487
488 Unreachable,
492}
493
494impl FutureIncompatibleInfo {
495 pub const fn default_fields_for_macro() -> Self {
496 FutureIncompatibleInfo {
497 reason: FutureIncompatibilityReason::Unreachable,
498 explain_reason: true,
499 report_in_deps: false,
500 }
501 }
502}
503
504impl FutureIncompatibilityReason {
505 pub fn edition(self) -> Option<Edition> {
506 match self {
507 Self::EditionError(e)
508 | Self::EditionSemanticsChange(e)
509 | Self::EditionAndFutureReleaseError(e)
510 | Self::EditionAndFutureReleaseSemanticsChange(e) => Some(e.edition),
511
512 FutureIncompatibilityReason::FutureReleaseError(_)
513 | FutureIncompatibilityReason::FutureReleaseSemanticsChange(_)
514 | FutureIncompatibilityReason::Custom(_, _) => None,
515 Self::Unreachable => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
516 }
517 }
518
519 pub fn reference(&self) -> String {
520 match self {
521 Self::FutureReleaseSemanticsChange(release_fcw)
522 | Self::FutureReleaseError(release_fcw)
523 | Self::Custom(_, release_fcw) => release_fcw.to_string(),
524 Self::EditionError(edition_fcw)
525 | Self::EditionSemanticsChange(edition_fcw)
526 | Self::EditionAndFutureReleaseError(edition_fcw)
527 | Self::EditionAndFutureReleaseSemanticsChange(edition_fcw) => edition_fcw.to_string(),
528 Self::Unreachable => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
529 }
530 }
531}
532
533impl Display for ReleaseFcw {
534 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
535 let issue_number = self.issue_number;
536 f.write_fmt(format_args!("issue #{0} <https://github.com/rust-lang/rust/issues/{0}>",
issue_number))write!(f, "issue #{issue_number} <https://github.com/rust-lang/rust/issues/{issue_number}>")
537 }
538}
539
540impl Display for EditionFcw {
541 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
542 f.write_fmt(format_args!("<https://doc.rust-lang.org/edition-guide/{0}/{1}.html>",
match self.edition {
Edition::Edition2015 => "rust-2015",
Edition::Edition2018 => "rust-2018",
Edition::Edition2021 => "rust-2021",
Edition::Edition2024 => "rust-2024",
Edition::EditionFuture => "future",
}, self.page_slug))write!(
543 f,
544 "<https://doc.rust-lang.org/edition-guide/{}/{}.html>",
545 match self.edition {
546 Edition::Edition2015 => "rust-2015",
547 Edition::Edition2018 => "rust-2018",
548 Edition::Edition2021 => "rust-2021",
549 Edition::Edition2024 => "rust-2024",
550 Edition::EditionFuture => "future",
551 },
552 self.page_slug,
553 )
554 }
555}
556
557impl Lint {
558 pub const fn default_fields_for_macro() -> Self {
559 Lint {
560 name: "",
561 default_level: Level::Forbid,
562 desc: "",
563 edition_lint_opts: None,
564 is_externally_loaded: false,
565 report_in_external_macro: false,
566 future_incompatible: None,
567 feature_gate: None,
568 crate_level_only: false,
569 eval_always: false,
570 }
571 }
572
573 pub fn name_lower(&self) -> String {
575 self.name.to_ascii_lowercase()
576 }
577
578 pub fn default_level(&self, edition: Edition) -> Level {
579 self.edition_lint_opts
580 .filter(|(e, _)| *e <= edition)
581 .map(|(_, l)| l)
582 .unwrap_or(self.default_level)
583 }
584}
585
586#[derive(#[automatically_derived]
impl ::core::clone::Clone for LintId {
#[inline]
fn clone(&self) -> LintId {
let _: ::core::clone::AssertParamIsClone<&'static Lint>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for LintId { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for LintId {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field1_finish(f, "LintId",
"lint", &&self.lint)
}
}Debug)]
588pub struct LintId {
589 pub lint: &'static Lint,
591}
592
593impl PartialEq for LintId {
594 fn eq(&self, other: &LintId) -> bool {
595 std::ptr::eq(self.lint, other.lint)
596 }
597}
598
599impl Eq for LintId {}
600
601impl std::hash::Hash for LintId {
602 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
603 let ptr = self.lint as *const Lint;
604 ptr.hash(state);
605 }
606}
607
608impl LintId {
609 pub fn of(lint: &'static Lint) -> LintId {
611 LintId { lint }
612 }
613
614 pub fn lint_name_raw(&self) -> &'static str {
615 self.lint.name
616 }
617
618 pub fn to_string(&self) -> String {
620 self.lint.name_lower()
621 }
622}
623
624impl<HCX> HashStable<HCX> for LintId {
625 #[inline]
626 fn hash_stable(&self, hcx: &mut HCX, hasher: &mut StableHasher) {
627 self.lint_name_raw().hash_stable(hcx, hasher);
628 }
629}
630
631impl<HCX> ToStableHashKey<HCX> for LintId {
632 type KeyType = &'static str;
633
634 #[inline]
635 fn to_stable_hash_key(&self, _: &HCX) -> &'static str {
636 self.lint_name_raw()
637 }
638}
639
640impl StableCompare for LintId {
641 const CAN_USE_UNSTABLE_SORT: bool = true;
642
643 fn stable_cmp(&self, other: &Self) -> std::cmp::Ordering {
644 self.lint_name_raw().cmp(&other.lint_name_raw())
645 }
646}
647
648#[derive(#[automatically_derived]
impl ::core::fmt::Debug for DeprecatedSinceKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
DeprecatedSinceKind::InEffect =>
::core::fmt::Formatter::write_str(f, "InEffect"),
DeprecatedSinceKind::InFuture =>
::core::fmt::Formatter::write_str(f, "InFuture"),
DeprecatedSinceKind::InVersion(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"InVersion", &__self_0),
}
}
}Debug, #[automatically_derived]
impl ::core::clone::Clone for DeprecatedSinceKind {
#[inline]
fn clone(&self) -> DeprecatedSinceKind {
match self {
DeprecatedSinceKind::InEffect => DeprecatedSinceKind::InEffect,
DeprecatedSinceKind::InFuture => DeprecatedSinceKind::InFuture,
DeprecatedSinceKind::InVersion(__self_0) =>
DeprecatedSinceKind::InVersion(::core::clone::Clone::clone(__self_0)),
}
}
}Clone)]
649pub enum DeprecatedSinceKind {
650 InEffect,
651 InFuture,
652 InVersion(String),
653}
654
655#[derive(#[automatically_derived]
impl ::core::fmt::Debug for BuiltinLintDiag {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
BuiltinLintDiag::AbsPathWithModule(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"AbsPathWithModule", &__self_0),
BuiltinLintDiag::ElidedLifetimesInPaths(__self_0, __self_1,
__self_2, __self_3) =>
::core::fmt::Formatter::debug_tuple_field4_finish(f,
"ElidedLifetimesInPaths", __self_0, __self_1, __self_2,
&__self_3),
BuiltinLintDiag::UnusedImports {
remove_whole_use: __self_0,
num_to_remove: __self_1,
remove_spans: __self_2,
test_module_span: __self_3,
span_snippets: __self_4 } =>
::core::fmt::Formatter::debug_struct_field5_finish(f,
"UnusedImports", "remove_whole_use", __self_0,
"num_to_remove", __self_1, "remove_spans", __self_2,
"test_module_span", __self_3, "span_snippets", &__self_4),
BuiltinLintDiag::RedundantImport(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"RedundantImport", __self_0, &__self_1),
BuiltinLintDiag::DeprecatedMacro {
suggestion: __self_0,
suggestion_span: __self_1,
note: __self_2,
path: __self_3,
since_kind: __self_4 } =>
::core::fmt::Formatter::debug_struct_field5_finish(f,
"DeprecatedMacro", "suggestion", __self_0,
"suggestion_span", __self_1, "note", __self_2, "path",
__self_3, "since_kind", &__self_4),
BuiltinLintDiag::PatternsInFnsWithoutBody {
span: __self_0, ident: __self_1, is_foreign: __self_2 } =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"PatternsInFnsWithoutBody", "span", __self_0, "ident",
__self_1, "is_foreign", &__self_2),
BuiltinLintDiag::ReservedPrefix(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"ReservedPrefix", __self_0, &__self_1),
BuiltinLintDiag::RawPrefix(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"RawPrefix", &__self_0),
BuiltinLintDiag::ReservedString {
is_string: __self_0, suggestion: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"ReservedString", "is_string", __self_0, "suggestion",
&__self_1),
BuiltinLintDiag::BreakWithLabelAndLoop(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"BreakWithLabelAndLoop", &__self_0),
BuiltinLintDiag::UnicodeTextFlow(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"UnicodeTextFlow", __self_0, &__self_1),
BuiltinLintDiag::DeprecatedWhereclauseLocation(__self_0, __self_1)
=>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"DeprecatedWhereclauseLocation", __self_0, &__self_1),
BuiltinLintDiag::SingleUseLifetime {
param_span: __self_0,
deletion_span: __self_1,
use_span: __self_2,
ident: __self_3 } =>
::core::fmt::Formatter::debug_struct_field4_finish(f,
"SingleUseLifetime", "param_span", __self_0,
"deletion_span", __self_1, "use_span", __self_2, "ident",
&__self_3),
BuiltinLintDiag::NamedArgumentUsedPositionally {
position_sp_to_replace: __self_0,
position_sp_for_msg: __self_1,
named_arg_sp: __self_2,
named_arg_name: __self_3,
is_formatting_arg: __self_4 } =>
::core::fmt::Formatter::debug_struct_field5_finish(f,
"NamedArgumentUsedPositionally", "position_sp_to_replace",
__self_0, "position_sp_for_msg", __self_1, "named_arg_sp",
__self_2, "named_arg_name", __self_3, "is_formatting_arg",
&__self_4),
BuiltinLintDiag::AmbiguousGlobReexports {
name: __self_0,
namespace: __self_1,
first_reexport_span: __self_2,
duplicate_reexport_span: __self_3 } =>
::core::fmt::Formatter::debug_struct_field4_finish(f,
"AmbiguousGlobReexports", "name", __self_0, "namespace",
__self_1, "first_reexport_span", __self_2,
"duplicate_reexport_span", &__self_3),
BuiltinLintDiag::HiddenGlobReexports {
name: __self_0,
namespace: __self_1,
glob_reexport_span: __self_2,
private_item_span: __self_3 } =>
::core::fmt::Formatter::debug_struct_field4_finish(f,
"HiddenGlobReexports", "name", __self_0, "namespace",
__self_1, "glob_reexport_span", __self_2,
"private_item_span", &__self_3),
BuiltinLintDiag::UnusedQualifications { removal_span: __self_0 }
=>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"UnusedQualifications", "removal_span", &__self_0),
BuiltinLintDiag::AssociatedConstElidedLifetime {
elided: __self_0, span: __self_1, lifetimes_in_scope: __self_2
} =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"AssociatedConstElidedLifetime", "elided", __self_0, "span",
__self_1, "lifetimes_in_scope", &__self_2),
BuiltinLintDiag::UnusedCrateDependency {
extern_crate: __self_0, local_crate: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"UnusedCrateDependency", "extern_crate", __self_0,
"local_crate", &__self_1),
BuiltinLintDiag::UnusedVisibility(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"UnusedVisibility", &__self_0),
BuiltinLintDiag::AttributeLint(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"AttributeLint", &__self_0),
}
}
}Debug)]
658pub enum BuiltinLintDiag {
659 AbsPathWithModule(Span),
660 ElidedLifetimesInPaths(usize, Span, bool, Span),
661 UnusedImports {
662 remove_whole_use: bool,
663 num_to_remove: usize,
664 remove_spans: Vec<Span>,
665 test_module_span: Option<Span>,
666 span_snippets: Vec<String>,
667 },
668 RedundantImport(Vec<(Span, bool)>, Ident),
669 DeprecatedMacro {
670 suggestion: Option<Symbol>,
671 suggestion_span: Span,
672 note: Option<Symbol>,
673 path: String,
674 since_kind: DeprecatedSinceKind,
675 },
676 PatternsInFnsWithoutBody {
677 span: Span,
678 ident: Ident,
679 is_foreign: bool,
680 },
681 ReservedPrefix(Span, String),
682 RawPrefix(Span),
684 ReservedString {
686 is_string: bool,
687 suggestion: Span,
688 },
689 BreakWithLabelAndLoop(Span),
690 UnicodeTextFlow(Span, String),
691 DeprecatedWhereclauseLocation(Span, Option<(Span, String)>),
692 SingleUseLifetime {
693 param_span: Span,
695 deletion_span: Option<Span>,
698 use_span: Option<(Span, bool)>,
701 ident: Ident,
702 },
703 NamedArgumentUsedPositionally {
704 position_sp_to_replace: Option<Span>,
707 position_sp_for_msg: Option<Span>,
709 named_arg_sp: Span,
711 named_arg_name: String,
713 is_formatting_arg: bool,
715 },
716 AmbiguousGlobReexports {
717 name: String,
719 namespace: String,
721 first_reexport_span: Span,
723 duplicate_reexport_span: Span,
725 },
726 HiddenGlobReexports {
727 name: String,
729 namespace: String,
731 glob_reexport_span: Span,
733 private_item_span: Span,
735 },
736 UnusedQualifications {
737 removal_span: Span,
739 },
740 AssociatedConstElidedLifetime {
741 elided: bool,
742 span: Span,
743 lifetimes_in_scope: MultiSpan,
744 },
745 UnusedCrateDependency {
746 extern_crate: Symbol,
747 local_crate: Symbol,
748 },
749 UnusedVisibility(Span),
750 AttributeLint(AttributeLintKind),
751}
752
753#[derive(#[automatically_derived]
impl ::core::fmt::Debug for AttributeLintKind {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
AttributeLintKind::UnusedDuplicate {
this: __self_0, other: __self_1, warning: __self_2 } =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"UnusedDuplicate", "this", __self_0, "other", __self_1,
"warning", &__self_2),
AttributeLintKind::IllFormedAttributeInput {
suggestions: __self_0, docs: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"IllFormedAttributeInput", "suggestions", __self_0, "docs",
&__self_1),
AttributeLintKind::EmptyAttribute {
first_span: __self_0,
attr_path: __self_1,
valid_without_list: __self_2 } =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"EmptyAttribute", "first_span", __self_0, "attr_path",
__self_1, "valid_without_list", &__self_2),
AttributeLintKind::InvalidTarget {
name: __self_0,
target: __self_1,
applied: __self_2,
only: __self_3,
attr_span: __self_4 } =>
::core::fmt::Formatter::debug_struct_field5_finish(f,
"InvalidTarget", "name", __self_0, "target", __self_1,
"applied", __self_2, "only", __self_3, "attr_span",
&__self_4),
AttributeLintKind::InvalidStyle {
name: __self_0,
is_used_as_inner: __self_1,
target: __self_2,
target_span: __self_3 } =>
::core::fmt::Formatter::debug_struct_field4_finish(f,
"InvalidStyle", "name", __self_0, "is_used_as_inner",
__self_1, "target", __self_2, "target_span", &__self_3),
AttributeLintKind::UnsafeAttrOutsideUnsafe {
attribute_name_span: __self_0, sugg_spans: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"UnsafeAttrOutsideUnsafe", "attribute_name_span", __self_0,
"sugg_spans", &__self_1),
AttributeLintKind::UnexpectedCfgName(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"UnexpectedCfgName", __self_0, &__self_1),
AttributeLintKind::UnexpectedCfgValue(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"UnexpectedCfgValue", __self_0, &__self_1),
AttributeLintKind::DuplicateDocAlias { first_definition: __self_0
} =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"DuplicateDocAlias", "first_definition", &__self_0),
AttributeLintKind::DocAutoCfgExpectsHideOrShow =>
::core::fmt::Formatter::write_str(f,
"DocAutoCfgExpectsHideOrShow"),
AttributeLintKind::DocAutoCfgHideShowUnexpectedItem {
attr_name: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"DocAutoCfgHideShowUnexpectedItem", "attr_name", &__self_0),
AttributeLintKind::DocAutoCfgHideShowExpectsList {
attr_name: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"DocAutoCfgHideShowExpectsList", "attr_name", &__self_0),
AttributeLintKind::DocInvalid =>
::core::fmt::Formatter::write_str(f, "DocInvalid"),
AttributeLintKind::DocUnknownInclude {
span: __self_0, inner: __self_1, value: __self_2 } =>
::core::fmt::Formatter::debug_struct_field3_finish(f,
"DocUnknownInclude", "span", __self_0, "inner", __self_1,
"value", &__self_2),
AttributeLintKind::DocUnknownSpotlight { span: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"DocUnknownSpotlight", "span", &__self_0),
AttributeLintKind::DocUnknownPasses {
name: __self_0, span: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"DocUnknownPasses", "name", __self_0, "span", &__self_1),
AttributeLintKind::DocUnknownPlugins { span: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"DocUnknownPlugins", "span", &__self_0),
AttributeLintKind::DocUnknownAny { name: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"DocUnknownAny", "name", &__self_0),
AttributeLintKind::DocAutoCfgWrongLiteral =>
::core::fmt::Formatter::write_str(f,
"DocAutoCfgWrongLiteral"),
AttributeLintKind::DocTestTakesList =>
::core::fmt::Formatter::write_str(f, "DocTestTakesList"),
AttributeLintKind::DocTestUnknown { name: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"DocTestUnknown", "name", &__self_0),
AttributeLintKind::DocTestLiteral =>
::core::fmt::Formatter::write_str(f, "DocTestLiteral"),
AttributeLintKind::AttrCrateLevelOnly =>
::core::fmt::Formatter::write_str(f, "AttrCrateLevelOnly"),
AttributeLintKind::DoNotRecommendDoesNotExpectArgs =>
::core::fmt::Formatter::write_str(f,
"DoNotRecommendDoesNotExpectArgs"),
}
}
}Debug, const _: () =
{
impl<__CTX> ::rustc_data_structures::stable_hasher::HashStable<__CTX>
for AttributeLintKind where __CTX: crate::HashStableContext {
#[inline]
fn hash_stable(&self, __hcx: &mut __CTX,
__hasher:
&mut ::rustc_data_structures::stable_hasher::StableHasher) {
::std::mem::discriminant(self).hash_stable(__hcx, __hasher);
match *self {
AttributeLintKind::UnusedDuplicate {
this: ref __binding_0,
other: ref __binding_1,
warning: ref __binding_2 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
{ __binding_2.hash_stable(__hcx, __hasher); }
}
AttributeLintKind::IllFormedAttributeInput {
suggestions: ref __binding_0, docs: ref __binding_1 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
AttributeLintKind::EmptyAttribute {
first_span: ref __binding_0,
attr_path: ref __binding_1,
valid_without_list: ref __binding_2 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
{ __binding_2.hash_stable(__hcx, __hasher); }
}
AttributeLintKind::InvalidTarget {
name: ref __binding_0,
target: ref __binding_1,
applied: ref __binding_2,
only: ref __binding_3,
attr_span: ref __binding_4 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
{ __binding_2.hash_stable(__hcx, __hasher); }
{ __binding_3.hash_stable(__hcx, __hasher); }
{ __binding_4.hash_stable(__hcx, __hasher); }
}
AttributeLintKind::InvalidStyle {
name: ref __binding_0,
is_used_as_inner: ref __binding_1,
target: ref __binding_2,
target_span: ref __binding_3 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
{ __binding_2.hash_stable(__hcx, __hasher); }
{ __binding_3.hash_stable(__hcx, __hasher); }
}
AttributeLintKind::UnsafeAttrOutsideUnsafe {
attribute_name_span: ref __binding_0,
sugg_spans: ref __binding_1 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
AttributeLintKind::UnexpectedCfgName(ref __binding_0,
ref __binding_1) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
AttributeLintKind::UnexpectedCfgValue(ref __binding_0,
ref __binding_1) => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
AttributeLintKind::DuplicateDocAlias {
first_definition: ref __binding_0 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
AttributeLintKind::DocAutoCfgExpectsHideOrShow => {}
AttributeLintKind::DocAutoCfgHideShowUnexpectedItem {
attr_name: ref __binding_0 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
AttributeLintKind::DocAutoCfgHideShowExpectsList {
attr_name: ref __binding_0 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
AttributeLintKind::DocInvalid => {}
AttributeLintKind::DocUnknownInclude {
span: ref __binding_0,
inner: ref __binding_1,
value: ref __binding_2 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
{ __binding_2.hash_stable(__hcx, __hasher); }
}
AttributeLintKind::DocUnknownSpotlight {
span: ref __binding_0 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
AttributeLintKind::DocUnknownPasses {
name: ref __binding_0, span: ref __binding_1 } => {
{ __binding_0.hash_stable(__hcx, __hasher); }
{ __binding_1.hash_stable(__hcx, __hasher); }
}
AttributeLintKind::DocUnknownPlugins { span: ref __binding_0
} => {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
AttributeLintKind::DocUnknownAny { name: ref __binding_0 }
=> {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
AttributeLintKind::DocAutoCfgWrongLiteral => {}
AttributeLintKind::DocTestTakesList => {}
AttributeLintKind::DocTestUnknown { name: ref __binding_0 }
=> {
{ __binding_0.hash_stable(__hcx, __hasher); }
}
AttributeLintKind::DocTestLiteral => {}
AttributeLintKind::AttrCrateLevelOnly => {}
AttributeLintKind::DoNotRecommendDoesNotExpectArgs => {}
}
}
}
};HashStable_Generic)]
754pub enum AttributeLintKind {
755 UnusedDuplicate {
756 this: Span,
757 other: Span,
758 warning: bool,
759 },
760 IllFormedAttributeInput {
761 suggestions: Vec<String>,
762 docs: Option<&'static str>,
763 },
764 EmptyAttribute {
765 first_span: Span,
766 attr_path: String,
767 valid_without_list: bool,
768 },
769 InvalidTarget {
770 name: String,
771 target: &'static str,
772 applied: Vec<String>,
773 only: &'static str,
774 attr_span: Span,
775 },
776 InvalidStyle {
777 name: String,
778 is_used_as_inner: bool,
779 target: &'static str,
780 target_span: Span,
781 },
782 UnsafeAttrOutsideUnsafe {
783 attribute_name_span: Span,
784 sugg_spans: Option<(Span, Span)>,
785 },
786 UnexpectedCfgName((Symbol, Span), Option<(Symbol, Span)>),
787 UnexpectedCfgValue((Symbol, Span), Option<(Symbol, Span)>),
788 DuplicateDocAlias {
789 first_definition: Span,
790 },
791 DocAutoCfgExpectsHideOrShow,
792 DocAutoCfgHideShowUnexpectedItem {
793 attr_name: Symbol,
794 },
795 DocAutoCfgHideShowExpectsList {
796 attr_name: Symbol,
797 },
798 DocInvalid,
799 DocUnknownInclude {
800 span: Span,
801 inner: &'static str,
802 value: Symbol,
803 },
804 DocUnknownSpotlight {
805 span: Span,
806 },
807 DocUnknownPasses {
808 name: Symbol,
809 span: Span,
810 },
811 DocUnknownPlugins {
812 span: Span,
813 },
814 DocUnknownAny {
815 name: Symbol,
816 },
817 DocAutoCfgWrongLiteral,
818 DocTestTakesList,
819 DocTestUnknown {
820 name: Symbol,
821 },
822 DocTestLiteral,
823 AttrCrateLevelOnly,
824 DoNotRecommendDoesNotExpectArgs,
825}
826
827pub type RegisteredTools = FxIndexSet<Ident>;
828
829#[macro_export]
887macro_rules! declare_lint {
888 ($(#[$attr:meta])* $vis: vis $NAME: ident, $Level: ident, $desc: expr) => (
889 $crate::declare_lint!(
890 $(#[$attr])* $vis $NAME, $Level, $desc,
891 );
892 );
893 ($(#[$attr:meta])* $vis: vis $NAME: ident, $Level: ident, $desc: expr,
894 $(@eval_always = $eval_always:literal)?
895 $(@feature_gate = $gate:ident;)?
896 $(@future_incompatible = FutureIncompatibleInfo {
897 reason: $reason:expr,
898 $($field:ident : $val:expr),* $(,)*
899 }; )?
900 $(@edition $lint_edition:ident => $edition_level:ident;)?
901 $($v:ident),*) => (
902 $(#[$attr])*
903 $vis static $NAME: &$crate::Lint = &$crate::Lint {
904 name: stringify!($NAME),
905 default_level: $crate::$Level,
906 desc: $desc,
907 is_externally_loaded: false,
908 $($v: true,)*
909 $(feature_gate: Some(rustc_span::sym::$gate),)?
910 $(future_incompatible: Some($crate::FutureIncompatibleInfo {
911 reason: $reason,
912 $($field: $val,)*
913 ..$crate::FutureIncompatibleInfo::default_fields_for_macro()
914 }),)?
915 $(edition_lint_opts: Some(($crate::Edition::$lint_edition, $crate::$edition_level)),)?
916 $(eval_always: $eval_always,)?
917 ..$crate::Lint::default_fields_for_macro()
918 };
919 );
920}
921
922#[macro_export]
923macro_rules! declare_tool_lint {
924 (
925 $(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level: ident, $desc: expr
926 $(, @eval_always = $eval_always:literal)?
927 $(, @feature_gate = $gate:ident;)?
928 ) => (
929 $crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, false $(, @eval_always = $eval_always)? $(, @feature_gate = $gate;)?}
930 );
931 (
932 $(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
933 report_in_external_macro: $rep:expr
934 $(, @eval_always = $eval_always: literal)?
935 $(, @feature_gate = $gate:ident;)?
936 ) => (
937 $crate::declare_tool_lint!{$(#[$attr])* $vis $tool::$NAME, $Level, $desc, $rep $(, @eval_always = $eval_always)? $(, @feature_gate = $gate;)?}
938 );
939 (
940 $(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level:ident, $desc:expr,
941 $external:expr
942 $(, @eval_always = $eval_always: literal)?
943 $(, @feature_gate = $gate:ident;)?
944 ) => (
945 $(#[$attr])*
946 $vis static $NAME: &$crate::Lint = &$crate::Lint {
947 name: &concat!(stringify!($tool), "::", stringify!($NAME)),
948 default_level: $crate::$Level,
949 desc: $desc,
950 edition_lint_opts: None,
951 report_in_external_macro: $external,
952 future_incompatible: None,
953 is_externally_loaded: true,
954 $(feature_gate: Some(rustc_span::sym::$gate),)?
955 crate_level_only: false,
956 $(eval_always: $eval_always,)?
957 ..$crate::Lint::default_fields_for_macro()
958 };
959 );
960}
961
962pub type LintVec = Vec<&'static Lint>;
963
964pub trait LintPass {
965 fn name(&self) -> &'static str;
966 fn get_lints(&self) -> LintVec;
967}
968
969#[macro_export]
971macro_rules! impl_lint_pass {
972 ($ty:ty => [$($lint:expr),* $(,)?]) => {
973 impl $crate::LintPass for $ty {
974 fn name(&self) -> &'static str { stringify!($ty) }
975 fn get_lints(&self) -> $crate::LintVec { vec![$($lint),*] }
976 }
977 impl $ty {
978 #[allow(unused)]
979 pub fn lint_vec() -> $crate::LintVec { vec![$($lint),*] }
980 }
981 };
982}
983
984#[macro_export]
987macro_rules! declare_lint_pass {
988 ($(#[$m:meta])* $name:ident => [$($lint:expr),* $(,)?]) => {
989 $(#[$m])* #[derive(Copy, Clone)] pub struct $name;
990 $crate::impl_lint_pass!($name => [$($lint),*]);
991 };
992}
993
994#[macro_export]
995macro_rules! fcw {
996 (FutureReleaseError # $issue_number: literal) => {
997 $crate:: FutureIncompatibilityReason::FutureReleaseError($crate::ReleaseFcw { issue_number: $issue_number })
998 };
999 (FutureReleaseSemanticsChange # $issue_number: literal) => {
1000 $crate::FutureIncompatibilityReason::FutureReleaseSemanticsChange($crate::ReleaseFcw {
1001 issue_number: $issue_number,
1002 })
1003 };
1004 ($description: literal # $issue_number: literal) => {
1005 $crate::FutureIncompatibilityReason::Custom($description, $crate::ReleaseFcw {
1006 issue_number: $issue_number,
1007 })
1008 };
1009 (EditionError $edition_name: tt $page_slug: literal) => {
1010 $crate::FutureIncompatibilityReason::EditionError($crate::EditionFcw {
1011 edition: fcw!(@edition $edition_name),
1012 page_slug: $page_slug,
1013 })
1014 };
1015 (EditionSemanticsChange $edition_name: tt $page_slug: literal) => {
1016 $crate::FutureIncompatibilityReason::EditionSemanticsChange($crate::EditionFcw {
1017 edition: fcw!(@edition $edition_name),
1018 page_slug: $page_slug,
1019 })
1020 };
1021 (EditionAndFutureReleaseSemanticsChange $edition_name: tt $page_slug: literal) => {
1022 $crate::FutureIncompatibilityReason::EditionAndFutureReleaseSemanticsChange($crate::EditionFcw {
1023 edition: fcw!(@edition $edition_name),
1024 page_slug: $page_slug,
1025 })
1026 };
1027 (EditionAndFutureReleaseError $edition_name: tt $page_slug: literal) => {
1028 $crate::FutureIncompatibilityReason::EditionAndFutureReleaseError($crate::EditionFcw {
1029 edition: fcw!(@edition $edition_name),
1030 page_slug: $page_slug,
1031 })
1032 };
1033 (@edition 2024) => {
1034 rustc_span::edition::Edition::Edition2024
1035 };
1036 (@edition 2021) => {
1037 rustc_span::edition::Edition::Edition2021
1038 };
1039 (@edition 2018) => {
1040 rustc_span::edition::Edition::Edition2018
1041 };
1042}