@@ -292,7 +292,7 @@ void AttributeEarlyChecker::visitTransparentAttr(TransparentAttr *attr) {
292
292
if (VD->hasStorage ())
293
293
return diagnoseAndRemoveAttr (attr,
294
294
diag::attribute_invalid_on_stored_property,
295
- attr-> getAttrName () );
295
+ attr);
296
296
}
297
297
}
298
298
@@ -1948,12 +1948,8 @@ void AttributeChecker::visitFixedLayoutAttr(FixedLayoutAttr *attr) {
1948
1948
auto access = VD->getFormalAccess (/* useDC=*/ nullptr ,
1949
1949
/* isUsageFromInline=*/ true );
1950
1950
if (access < AccessLevel::Public) {
1951
- TC.diagnose (attr->getLocation (),
1952
- diag::fixed_layout_attr_on_internal_type,
1953
- VD->getFullName (),
1954
- access)
1955
- .fixItRemove (attr->getRangeWithAt ());
1956
- attr->setInvalid ();
1951
+ diagnoseAndRemoveAttr (attr, diag::fixed_layout_attr_on_internal_type,
1952
+ VD->getFullName (), access);
1957
1953
}
1958
1954
}
1959
1955
@@ -1963,29 +1959,22 @@ void AttributeChecker::visitUsableFromInlineAttr(UsableFromInlineAttr *attr) {
1963
1959
// FIXME: Once protocols can contain nominal types, do we want to allow
1964
1960
// these nominal types to have access control (and also @usableFromInline)?
1965
1961
if (isa<ProtocolDecl>(VD->getDeclContext ())) {
1966
- TC.diagnose (attr->getLocation (),
1967
- diag::versioned_attr_in_protocol)
1968
- .fixItRemove (attr->getRangeWithAt ());
1969
- attr->setInvalid ();
1962
+ diagnoseAndRemoveAttr (attr, diag::versioned_attr_in_protocol);
1970
1963
return ;
1971
1964
}
1972
1965
1973
1966
// @usableFromInline can only be applied to internal declarations.
1974
1967
if (VD->getFormalAccess () != AccessLevel::Internal) {
1975
- TC.diagnose (attr->getLocation (), diag::versioned_attr_with_explicit_access,
1976
- VD->getFullName (),
1977
- VD->getFormalAccess ())
1978
- .fixItRemove (attr->getRangeWithAt ());
1979
- attr->setInvalid ();
1968
+ diagnoseAndRemoveAttr (attr, diag::versioned_attr_with_explicit_access,
1969
+ VD->getFullName (),
1970
+ VD->getFormalAccess ());
1980
1971
return ;
1981
1972
}
1982
1973
1983
1974
// Symbols of dynamically-dispatched declarations are never referenced
1984
1975
// directly, so marking them as @usableFromInline does not make sense.
1985
1976
if (VD->isDynamic ()) {
1986
- TC.diagnose (attr->getLocation (),
1987
- diag::versioned_dynamic_not_supported);
1988
- attr->setInvalid ();
1977
+ diagnoseAndRemoveAttr (attr, diag::versioned_dynamic_not_supported);
1989
1978
return ;
1990
1979
}
1991
1980
}
@@ -1998,11 +1987,9 @@ void AttributeChecker::visitInlinableAttr(InlinableAttr *attr) {
1998
1987
// because clients cannot directly access storage.
1999
1988
if (auto *VD = dyn_cast<VarDecl>(D)) {
2000
1989
if (VD->hasStorage () || VD->getAttrs ().hasAttribute <LazyAttr>()) {
2001
- TC.diagnose (attr->getLocation (),
2002
- diag::attribute_invalid_on_stored_property,
2003
- attr->getAttrName ())
2004
- .fixItRemove (attr->getRangeWithAt ());
2005
- attr->setInvalid ();
1990
+ diagnoseAndRemoveAttr (attr,
1991
+ diag::attribute_invalid_on_stored_property,
1992
+ attr);
2006
1993
return ;
2007
1994
}
2008
1995
}
@@ -2012,9 +1999,7 @@ void AttributeChecker::visitInlinableAttr(InlinableAttr *attr) {
2012
1999
// Calls to dynamically-dispatched declarations are never devirtualized,
2013
2000
// so marking them as @inlinable does not make sense.
2014
2001
if (VD->isDynamic ()) {
2015
- TC.diagnose (attr->getLocation (),
2016
- diag::inlinable_dynamic_not_supported);
2017
- attr->setInvalid ();
2002
+ diagnoseAndRemoveAttr (attr, diag::inlinable_dynamic_not_supported);
2018
2003
return ;
2019
2004
}
2020
2005
@@ -2023,24 +2008,19 @@ void AttributeChecker::visitInlinableAttr(InlinableAttr *attr) {
2023
2008
auto access = VD->getFormalAccess (/* useDC=*/ nullptr ,
2024
2009
/* isUsageFromInline=*/ true );
2025
2010
if (access < AccessLevel::Public) {
2026
- TC.diagnose (attr->getLocation (),
2027
- diag::inlinable_decl_not_public,
2028
- VD->getBaseName (),
2029
- access)
2030
- .fixItRemove (attr->getRangeWithAt ());
2031
- attr->setInvalid ();
2011
+ diagnoseAndRemoveAttr (attr, diag::inlinable_decl_not_public,
2012
+ VD->getBaseName (),
2013
+ access);
2032
2014
return ;
2033
2015
}
2034
2016
}
2035
2017
2036
2018
void AttributeChecker::visitOptimizeAttr (OptimizeAttr *attr) {
2037
2019
if (auto *VD = dyn_cast<VarDecl>(D)) {
2038
2020
if (VD->hasStorage ()) {
2039
- TC.diagnose (attr->getLocation (),
2040
- diag::attribute_invalid_on_stored_property,
2041
- attr->getAttrName ())
2042
- .fixItRemove (attr->getRangeWithAt ());
2043
- attr->setInvalid ();
2021
+ diagnoseAndRemoveAttr (attr,
2022
+ diag::attribute_invalid_on_stored_property,
2023
+ attr);
2044
2024
return ;
2045
2025
}
2046
2026
}
@@ -2051,10 +2031,9 @@ void AttributeChecker::visitDiscardableResultAttr(DiscardableResultAttr *attr) {
2051
2031
if (auto result = FD->getResultInterfaceType ()) {
2052
2032
auto resultIsVoid = result->isVoid ();
2053
2033
if (resultIsVoid || result->isUninhabited ()) {
2054
- auto warn = diag::discardable_result_on_void_never_function;
2055
- auto diagnostic = TC.diagnose (D->getStartLoc (), warn, resultIsVoid);
2056
- diagnostic.fixItRemove (attr->getRangeWithAt ());
2057
- attr->setInvalid ();
2034
+ diagnoseAndRemoveAttr (attr,
2035
+ diag::discardable_result_on_void_never_function,
2036
+ resultIsVoid);
2058
2037
}
2059
2038
}
2060
2039
}
0 commit comments