avoid string dispatch in fluent
This commit is contained in:
parent
57eba4f535
commit
31c269ae75
@ -596,23 +596,25 @@ passes_unrecognized_repr_hint =
|
|||||||
unrecognized representation hint
|
unrecognized representation hint
|
||||||
.help = valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
|
.help = valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
|
||||||
|
|
||||||
passes_attribute_should_be_applied_to =
|
passes_attr_application_enum =
|
||||||
attribute should be applied to {$what ->
|
attribute should be applied to an enum
|
||||||
[enum] an enum
|
.label = not an enum
|
||||||
[struct] a struct
|
|
||||||
[struct-union] a struct or union
|
passes_attr_application_struct =
|
||||||
[struct-enum-union] a struct, enum, or union
|
attribute should be applied to a struct
|
||||||
[struct-enum-function-union] a struct, enum, function, or union
|
.label = not a struct
|
||||||
*[unspecified] (unspecified--this is a compiler bug)
|
|
||||||
}
|
passes_attr_application_struct_union =
|
||||||
.label = not {$what ->
|
attribute should be applied to a struct or union
|
||||||
[enum] an enum
|
.label = not a struct or union
|
||||||
[struct] a struct
|
|
||||||
[struct-union] a struct or union
|
passes_attr_application_struct_enum_union =
|
||||||
[struct-enum-union] a struct, enum, or union
|
attribute should be applied to a struct, enum, or union
|
||||||
[struct-enum-function-union] a struct, enum, function, or union
|
.label = not a struct, enum, or union
|
||||||
*[unspecified] (unspecified--this is a compiler bug)
|
|
||||||
}
|
passes_attr_application_struct_enum_function_union =
|
||||||
|
attribute should be applied to a struct, enum, function, or union
|
||||||
|
.label = not a struct, enum, function, or union
|
||||||
|
|
||||||
passes_transparent_incompatible =
|
passes_transparent_incompatible =
|
||||||
transparent {$target} cannot have other repr hints
|
transparent {$target} cannot have other repr hints
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
//! item.
|
//! item.
|
||||||
|
|
||||||
use crate::errors::{
|
use crate::errors::{
|
||||||
self, AttributeShouldBeAppliedTo, DebugVisualizerUnreadable, InvalidAttrAtCrateLevel,
|
self, AttrApplication, DebugVisualizerUnreadable, InvalidAttrAtCrateLevel, ObjectLifetimeErr,
|
||||||
ObjectLifetimeErr, OnlyHasEffectOn, TransparentIncompatible, UnrecognizedReprHint,
|
OnlyHasEffectOn, TransparentIncompatible, UnrecognizedReprHint,
|
||||||
};
|
};
|
||||||
use rustc_ast::{ast, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
|
use rustc_ast::{ast, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
@ -1594,12 +1594,17 @@ fn check_repr(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let what = match hint.name_or_empty() {
|
match hint.name_or_empty() {
|
||||||
sym::C => {
|
sym::C => {
|
||||||
is_c = true;
|
is_c = true;
|
||||||
match target {
|
match target {
|
||||||
Target::Struct | Target::Union | Target::Enum => continue,
|
Target::Struct | Target::Union | Target::Enum => continue,
|
||||||
_ => "struct-enum-union",
|
_ => {
|
||||||
|
self.tcx.sess.emit_err(AttrApplication::StructEnumUnion {
|
||||||
|
hint_span: hint.span(),
|
||||||
|
span,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sym::align => {
|
sym::align => {
|
||||||
@ -1615,12 +1620,20 @@ fn check_repr(
|
|||||||
|
|
||||||
match target {
|
match target {
|
||||||
Target::Struct | Target::Union | Target::Enum | Target::Fn => continue,
|
Target::Struct | Target::Union | Target::Enum | Target::Fn => continue,
|
||||||
_ => "struct-enum-function-union",
|
_ => {
|
||||||
|
self.tcx.sess.emit_err(AttrApplication::StructEnumFunctionUnion {
|
||||||
|
hint_span: hint.span(),
|
||||||
|
span,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sym::packed => {
|
sym::packed => {
|
||||||
if target != Target::Struct && target != Target::Union {
|
if target != Target::Struct && target != Target::Union {
|
||||||
"struct-union"
|
self.tcx.sess.emit_err(AttrApplication::StructUnion {
|
||||||
|
hint_span: hint.span(),
|
||||||
|
span,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1628,7 +1641,9 @@ fn check_repr(
|
|||||||
sym::simd => {
|
sym::simd => {
|
||||||
is_simd = true;
|
is_simd = true;
|
||||||
if target != Target::Struct {
|
if target != Target::Struct {
|
||||||
"struct"
|
self.tcx
|
||||||
|
.sess
|
||||||
|
.emit_err(AttrApplication::Struct { hint_span: hint.span(), span });
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1637,7 +1652,12 @@ fn check_repr(
|
|||||||
is_transparent = true;
|
is_transparent = true;
|
||||||
match target {
|
match target {
|
||||||
Target::Struct | Target::Union | Target::Enum => continue,
|
Target::Struct | Target::Union | Target::Enum => continue,
|
||||||
_ => "struct-enum-union",
|
_ => {
|
||||||
|
self.tcx.sess.emit_err(AttrApplication::StructEnumUnion {
|
||||||
|
hint_span: hint.span(),
|
||||||
|
span,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sym::i8
|
sym::i8
|
||||||
@ -1654,7 +1674,9 @@ fn check_repr(
|
|||||||
| sym::usize => {
|
| sym::usize => {
|
||||||
int_reprs += 1;
|
int_reprs += 1;
|
||||||
if target != Target::Enum {
|
if target != Target::Enum {
|
||||||
"enum"
|
self.tcx
|
||||||
|
.sess
|
||||||
|
.emit_err(AttrApplication::Enum { hint_span: hint.span(), span });
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1664,12 +1686,6 @@ fn check_repr(
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
self.tcx.sess.emit_err(AttributeShouldBeAppliedTo {
|
|
||||||
hint_span: hint.span(),
|
|
||||||
span,
|
|
||||||
what,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just point at all repr hints if there are any incompatibilities.
|
// Just point at all repr hints if there are any incompatibilities.
|
||||||
|
@ -1288,13 +1288,42 @@ pub struct UnrecognizedReprHint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(passes::attribute_should_be_applied_to, code = "E0517")]
|
pub enum AttrApplication {
|
||||||
pub struct AttributeShouldBeAppliedTo<'a> {
|
#[diag(passes::attr_application_enum, code = "E0517")]
|
||||||
|
Enum {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub hint_span: Span,
|
hint_span: Span,
|
||||||
#[label]
|
#[label]
|
||||||
pub span: Span,
|
span: Span,
|
||||||
pub what: &'a str,
|
},
|
||||||
|
#[diag(passes::attr_application_struct, code = "E0517")]
|
||||||
|
Struct {
|
||||||
|
#[primary_span]
|
||||||
|
hint_span: Span,
|
||||||
|
#[label]
|
||||||
|
span: Span,
|
||||||
|
},
|
||||||
|
#[diag(passes::attr_application_struct_union, code = "E0517")]
|
||||||
|
StructUnion {
|
||||||
|
#[primary_span]
|
||||||
|
hint_span: Span,
|
||||||
|
#[label]
|
||||||
|
span: Span,
|
||||||
|
},
|
||||||
|
#[diag(passes::attr_application_struct_enum_union, code = "E0517")]
|
||||||
|
StructEnumUnion {
|
||||||
|
#[primary_span]
|
||||||
|
hint_span: Span,
|
||||||
|
#[label]
|
||||||
|
span: Span,
|
||||||
|
},
|
||||||
|
#[diag(passes::attr_application_struct_enum_function_union, code = "E0517")]
|
||||||
|
StructEnumFunctionUnion {
|
||||||
|
#[primary_span]
|
||||||
|
hint_span: Span,
|
||||||
|
#[label]
|
||||||
|
span: Span,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
|
Loading…
Reference in New Issue
Block a user