Skip to content

Commit

Permalink
Add rust_2018_idioms and future_incompatible warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Schottkyc137 committed Aug 7, 2024
1 parent 0b1742c commit 80ebb45
Show file tree
Hide file tree
Showing 44 changed files with 260 additions and 227 deletions.
8 changes: 4 additions & 4 deletions vhdl_lang/src/analysis/association.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
let mut is_error = false;
let mut result = Vec::default();

let mut associated: FnvHashMap<usize, (TokenSpan, ResolvedFormal)> = Default::default();
let mut associated: FnvHashMap<usize, (TokenSpan, ResolvedFormal<'_>)> = Default::default();
for (actual_pos, resolved_formal) in resolved_pairs.iter() {
match resolved_formal {
Some(resolved_formal) => {
Expand Down Expand Up @@ -606,7 +606,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
scope: &Scope<'a>,
span: TokenSpan,
diagnostics: &mut dyn DiagnosticHandler,
) -> EvalResult<ResolvedName> {
) -> EvalResult<ResolvedName<'_>> {
match expr {
Expression::Name(name) => {
let resolved = self.name_resolve(scope, span, name, diagnostics)?;
Expand Down Expand Up @@ -649,8 +649,8 @@ impl Diagnostic {

pub fn invalid_type_conversion(
pos: impl AsRef<SrcPos>,
from: BaseType,
to: TypeEnt,
from: BaseType<'_>,
to: TypeEnt<'_>,
) -> Diagnostic {
Diagnostic::new(
pos,
Expand Down
89 changes: 45 additions & 44 deletions vhdl_lang/src/analysis/declarative.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Declaration {
/// ```
///
/// The context is given by the parent element of the declaration.
pub fn is_allowed_in_context(&self, parent: &AnyEntKind) -> bool {
pub fn is_allowed_in_context(&self, parent: &AnyEntKind<'_>) -> bool {
use Declaration::*;
use ObjectClass::*;
match parent {
Expand Down Expand Up @@ -758,54 +758,55 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
signature,
}) = entity_name
{
let ent: EntRef = match scope.lookup(self.ctx, designator.token, &designator.item.item)
{
Ok(NamedEntities::Single(ent)) => {
designator.set_unique_reference(ent);
let ent: EntRef<'_> =
match scope.lookup(self.ctx, designator.token, &designator.item.item) {
Ok(NamedEntities::Single(ent)) => {
designator.set_unique_reference(ent);

if let Some(signature) = signature {
diagnostics.push(Diagnostic::should_not_have_signature(
"Attribute specification",
signature.pos(self.ctx),
));
if let Some(signature) = signature {
diagnostics.push(Diagnostic::should_not_have_signature(
"Attribute specification",
signature.pos(self.ctx),
));
}
ent
}
ent
}
Ok(NamedEntities::Overloaded(overloaded)) => {
if let Some(signature) = signature {
match as_fatal(self.resolve_signature(scope, signature, diagnostics))? {
Some(signature_key) => {
if let Some(ent) =
overloaded.get(&SubprogramKey::Normal(signature_key))
{
designator.set_unique_reference(&ent);
ent.into()
} else {
diagnostics.push(Diagnostic::no_overloaded_with_signature(
designator.pos(self.ctx),
&designator.item.item,
&overloaded,
));
Ok(NamedEntities::Overloaded(overloaded)) => {
if let Some(signature) = signature {
match as_fatal(self.resolve_signature(scope, signature, diagnostics))? {
Some(signature_key) => {
if let Some(ent) =
overloaded.get(&SubprogramKey::Normal(signature_key))
{
designator.set_unique_reference(&ent);
ent.into()
} else {
diagnostics.push(Diagnostic::no_overloaded_with_signature(
designator.pos(self.ctx),
&designator.item.item,
&overloaded,
));
return Ok(());
}
}
None => {
return Ok(());
}
}
None => {
return Ok(());
}
} else if let Some(ent) = overloaded.as_unique() {
designator.set_unique_reference(ent);
ent
} else {
diagnostics
.push(Diagnostic::signature_required(designator.pos(self.ctx)));
return Ok(());
}
} else if let Some(ent) = overloaded.as_unique() {
designator.set_unique_reference(ent);
ent
} else {
diagnostics.push(Diagnostic::signature_required(designator.pos(self.ctx)));
}
Err(err) => {
diagnostics.push(err);
return Ok(());
}
}
Err(err) => {
diagnostics.push(err);
return Ok(());
}
};
};

// Attributes affect the underlying entity and cannot be set directly on aliases
let ent = ent.as_actual();
Expand Down Expand Up @@ -1177,7 +1178,7 @@ impl Diagnostic {
fn no_overloaded_with_signature(
pos: &SrcPos,
des: &Designator,
overloaded: &OverloadedName,
overloaded: &OverloadedName<'_>,
) -> Diagnostic {
let mut diagnostic = Diagnostic::new(
pos,
Expand Down Expand Up @@ -1208,7 +1209,7 @@ impl Diagnostic {
}
}

fn get_entity_class(ent: EntRef) -> Option<EntityClass> {
fn get_entity_class(ent: EntRef<'_>) -> Option<EntityClass> {
match ent.actual_kind() {
// Alias is never the direct target of attribute
AnyEntKind::ExternalAlias { .. } => None,
Expand Down Expand Up @@ -1296,7 +1297,7 @@ const UNASSOCIATED_DISPLAY_THRESHOLD: usize = 3;
/// "Missing association of element the_element1, the_element2 and the_element3"
/// * If there are more elements than [UNASSOCIATED_DISPLAY_THRESHOLD], the message will be truncated
/// to "Missing association of element the_element1, the_element2, the_element3 and 17 more"
fn pretty_format_unassociated_message(unassociated: &HashSet<&RecordElement>) -> String {
fn pretty_format_unassociated_message(unassociated: &HashSet<&RecordElement<'_>>) -> String {
assert!(
!unassociated.is_empty(),
"Should never be called with an empty set"
Expand Down
4 changes: 2 additions & 2 deletions vhdl_lang/src/analysis/design_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {

fn check_secondary_before_primary(
&self,
primary: &DesignEnt,
primary: &DesignEnt<'_>,
secondary_pos: &SrcPos,
diagnostics: &mut dyn DiagnosticHandler,
) {
Expand All @@ -394,7 +394,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
scope: &Scope<'a>,
config: &mut ConfigurationDeclaration,
diagnostics: &mut dyn DiagnosticHandler,
) -> EvalResult<DesignEnt> {
) -> EvalResult<DesignEnt<'_>> {
let ent_name = &mut config.entity_name;
let ent_name_span = ent_name.span;

Expand Down
8 changes: 4 additions & 4 deletions vhdl_lang/src/analysis/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {

match implicit_bool_types.len().cmp(&1) {
std::cmp::Ordering::Equal => {
let typ: TypeEnt = types.into_iter().next().unwrap().into();
let typ: TypeEnt<'_> = types.into_iter().next().unwrap().into();
self.expr_with_ttyp(scope, typ, expr, diagnostics)?;
}
std::cmp::Ordering::Greater => {
Expand Down Expand Up @@ -979,7 +979,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
}
Choice::Others => {
// @TODO empty others
let remaining_types: FnvHashSet<BaseType> = elems
let remaining_types: FnvHashSet<BaseType<'_>> = elems
.iter()
.filter_map(|elem| {
if !associated.is_associated(&elem) {
Expand Down Expand Up @@ -1262,7 +1262,7 @@ impl RecordAssociations {
fn associate(
&mut self,
ctx: &dyn TokenAccess,
elem: &RecordElement,
elem: &RecordElement<'_>,
pos: TokenSpan,
diagnostics: &mut dyn DiagnosticHandler,
) {
Expand All @@ -1281,7 +1281,7 @@ impl RecordAssociations {
}
}

fn is_associated(&self, elem: &RecordElement) -> bool {
fn is_associated(&self, elem: &RecordElement<'_>) -> bool {
self.0.contains_key(&elem.id())
}
}
Expand Down
6 changes: 3 additions & 3 deletions vhdl_lang/src/analysis/literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
&self,
span: TokenSpan,
string_lit: Latin1String,
target_base: TypeEnt,
target_type: TypeEnt,
target_base: TypeEnt<'_>,
target_type: TypeEnt<'_>,
diagnostics: &mut dyn DiagnosticHandler,
) {
if let Some((elem_type, literals)) = as_single_index_enum_array(target_base) {
Expand Down Expand Up @@ -214,7 +214,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
}

/// Must be an array type with a single index of enum type
fn as_single_index_enum_array(typ: TypeEnt) -> Option<(TypeEnt, &FnvHashSet<Designator>)> {
fn as_single_index_enum_array(typ: TypeEnt<'_>) -> Option<(TypeEnt<'_>, &FnvHashSet<Designator>)> {
if let Type::Array {
indexes, elem_type, ..
} = typ.kind()
Expand Down
6 changes: 3 additions & 3 deletions vhdl_lang/src/analysis/lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<T, R> AnalysisLock<T, R> {
}

/// Returns an immutable reference to the data and result if it has already been analyzed.
pub fn get(&self) -> Option<ReadGuard<T, R>> {
pub fn get(&self) -> Option<ReadGuard<'_, T, R>> {
let guard = self.state.read();
if guard.result.is_some() {
Some(ReadGuard { guard })
Expand Down Expand Up @@ -62,7 +62,7 @@ impl<T, R> AnalysisLock<T, R> {
/// Returns an immmutable reference to the data and result.
///
/// Panics if the analysis result is not available.
pub fn expect_analyzed(&self) -> ReadGuard<T, R> {
pub fn expect_analyzed(&self) -> ReadGuard<'_, T, R> {
let guard = self.state.read();

if guard.result.is_none() {
Expand All @@ -77,7 +77,7 @@ impl<T, R> AnalysisLock<T, R> {
/// This view provides:
/// - a mutable reference to the data if not analyzed
/// - an immmutable reference to the data if already analyzed
pub fn entry(&self) -> AnalysisEntry<T, R> {
pub fn entry(&self) -> AnalysisEntry<'_, T, R> {
if let Some(guard) = self.get() {
AnalysisEntry::Occupied(guard)
} else {
Expand Down
30 changes: 17 additions & 13 deletions vhdl_lang/src/analysis/names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ pub enum ResolvedName<'a> {

impl<'a> ResolvedName<'a> {
/// The name was selected out of a design unit
fn from_design_not_overloaded(ent: &'a AnyEnt) -> Result<Self, (String, ErrorCode)> {
fn from_design_not_overloaded(ent: &'a AnyEnt<'_>) -> Result<Self, (String, ErrorCode)> {
let name = match ent.kind() {
AnyEntKind::Object(_) => ResolvedName::ObjectName(ObjectName {
base: ObjectBase::Object(ObjectEnt::from_any(ent).unwrap()),
Expand Down Expand Up @@ -221,7 +221,7 @@ impl<'a> ResolvedName<'a> {
}

/// The name was looked up from the current scope
fn from_scope_not_overloaded(ent: &'a AnyEnt) -> Result<Self, (String, ErrorCode)> {
fn from_scope_not_overloaded(ent: &'a AnyEnt<'_>) -> Result<Self, (String, ErrorCode)> {
let name = match ent.kind() {
AnyEntKind::Object(_) => ResolvedName::ObjectName(ObjectName {
base: ObjectBase::Object(ObjectEnt::from_any(ent).unwrap()),
Expand Down Expand Up @@ -342,7 +342,7 @@ impl<'a> ResolvedName<'a> {
&self,
ctx: &dyn TokenAccess,
prefix_pos: TokenSpan,
attr: &AttributeSuffix,
attr: &AttributeSuffix<'_>,
diagnostics: &mut dyn DiagnosticHandler,
) -> EvalResult<TypeEnt<'a>> {
if let Some(typ) = self.type_mark() {
Expand All @@ -361,7 +361,7 @@ impl<'a> ResolvedName<'a> {
&self,
ctx: &dyn TokenAccess,
prefix_pos: TokenSpan,
attr: &AttributeSuffix,
attr: &AttributeSuffix<'_>,
diagnostics: &mut dyn DiagnosticHandler,
) -> EvalResult<TypeEnt<'a>> {
if let ResolvedName::ObjectName(oname) = self {
Expand Down Expand Up @@ -667,7 +667,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
prefix_pos: TokenSpan,
name_pos: TokenSpan,
prefix_typ: TypeEnt<'a>,
suffix: &mut Suffix,
suffix: &mut Suffix<'_>,
diagnostics: &mut dyn DiagnosticHandler,
) -> EvalResult<Option<TypeOrMethod<'a>>> {
match suffix {
Expand Down Expand Up @@ -856,7 +856,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
prefix_pos: TokenSpan,
scope: &Scope<'a>,
prefix: &ResolvedName<'a>,
attr: &mut AttributeSuffix,
attr: &mut AttributeSuffix<'_>,
diagnostics: &mut dyn DiagnosticHandler,
) -> EvalResult<AttrResolveResult<'a>> {
match attr.attr.item {
Expand Down Expand Up @@ -1717,7 +1717,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
name_pos: TokenSpan,
suffix_pos: TokenSpan,
type_mark: TypeEnt<'a>,
indexes: &mut [Index],
indexes: &mut [Index<'_>],
diagnostics: &mut dyn DiagnosticHandler,
) -> EvalResult<TypeEnt<'a>> {
let base_type = type_mark.base_type();
Expand Down Expand Up @@ -1870,7 +1870,11 @@ impl Declaration {
}

impl Diagnostic {
fn cannot_be_prefix(prefix_pos: &SrcPos, resolved: ResolvedName, suffix: Suffix) -> Diagnostic {
fn cannot_be_prefix(
prefix_pos: &SrcPos,
resolved: ResolvedName<'_>,
suffix: Suffix<'_>,
) -> Diagnostic {
let suffix_desc = match suffix {
Suffix::Selected(_) => "selected",
Suffix::All => "accessed with .all",
Expand Down Expand Up @@ -1902,8 +1906,8 @@ impl Diagnostic {

fn cannot_be_prefix_of_attribute(
prefix_pos: &SrcPos,
resolved: &ResolvedName,
attr: &AttributeSuffix,
resolved: &ResolvedName<'_>,
attr: &AttributeSuffix<'_>,
) -> Diagnostic {
Diagnostic::new(
prefix_pos,
Expand All @@ -1918,7 +1922,7 @@ impl Diagnostic {

fn dimension_mismatch(
pos: &SrcPos,
base_type: TypeEnt,
base_type: TypeEnt<'_>,
got: usize,
expected: usize,
) -> Diagnostic {
Expand Down Expand Up @@ -1971,7 +1975,7 @@ impl Diagnostic {

fn check_no_attr_argument(
ctx: &dyn TokenAccess,
suffix: &AttributeSuffix,
suffix: &AttributeSuffix<'_>,
diagnostics: &mut dyn DiagnosticHandler,
) {
if let Some(ref expr) = suffix.expr {
Expand Down Expand Up @@ -2001,7 +2005,7 @@ fn check_no_sattr_argument(
fn check_single_argument<'a>(
ctx: &dyn TokenAccess,
pos: TokenSpan,
suffix: &'a mut AttributeSuffix,
suffix: &'a mut AttributeSuffix<'_>,
diagnostics: &mut dyn DiagnosticHandler,
) -> Option<&'a mut WithTokenSpan<Expression>> {
if let Some(ref mut expr) = suffix.expr {
Expand Down
2 changes: 1 addition & 1 deletion vhdl_lang/src/analysis/package_instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl<'a, 't> AnalyzeContext<'a, 't> {
uninst_region: &Region<'a>,
generic_map: &mut Option<MapAspect>,
diagnostics: &mut dyn DiagnosticHandler,
) -> EvalResult<(Region<'a>, FnvHashMap<EntityId, TypeEnt>)> {
) -> EvalResult<(Region<'a>, FnvHashMap<EntityId, TypeEnt<'_>>)> {
let nested = scope.nested().in_package_declaration();
let (generics, other) = uninst_region.to_package_generic();

Expand Down
Loading

0 comments on commit 80ebb45

Please sign in to comment.