fn from_impl_item<'tcx>(tcx: TyCtxt<'tcx>, impl_item: &hir::ImplItem) -> Target {
match impl_item.kind {
- hir::ImplItemKind::Const(..) => Target::Const,
+ hir::ImplItemKind::Const(..) => Target::AssocConst,
hir::ImplItemKind::Method(..) => {
let parent_hir_id = tcx.hir().get_parent_item(impl_item.hir_id);
let containing_item = tcx.hir().expect_item(parent_hir_id);
Target::Method(MethodKind::Inherent)
}
}
- hir::ImplItemKind::TyAlias(..) => Target::TyAlias,
- hir::ImplItemKind::OpaqueTy(..) => Target::OpaqueTy,
+ hir::ImplItemKind::TyAlias(..) | hir::ImplItemKind::OpaqueTy(..) => Target::AssocTy,
}
}
}
).emit();
true
}
+ // FIXME(#65833): We permit associated consts to have an `#[inline]` attribute with
+ // just a lint, because we previously erroneously allowed it and some crates used it
+ // accidentally, to to be compatible with crates depending on them, we can't throw an
+ // error here.
+ Target::AssocConst => {
+ self.tcx.struct_span_lint_hir(
+ UNUSED_ATTRIBUTES,
+ hir_id,
+ attr.span,
+ "`#[inline]` is ignored on constants",
+ ).warn("this was previously accepted by the compiler but is \
+ being phased out; it will become a hard error in \
+ a future release!")
+ .note("for more information, see issue #65833 \
+ <https://github.com/rust-lang/rust/issues/65833>")
+ .emit();
+ true
+ }
_ => {
- struct_span_err!(self.tcx.sess,
- attr.span,
- E0518,
- "attribute should be applied to function or closure")
- .span_label(*span, "not a function or closure")
+ struct_span_err!(
+ self.tcx.sess,
+ attr.span,
+ E0518,
+ "attribute should be applied to function or closure",
+ ).span_label(*span, "not a function or closure")
.emit();
false
}
#![feature(extern_types)]
#![feature(type_alias_impl_trait)]
+#![warn(unused_attributes)]
+
trait Trait {
- #[inline] //~ ERROR attribute should be applied to function or closure
+ #[inline] //~ WARN `#[inline]` is ignored on constants
+ //~^ WARN this was previously accepted
const X: u32;
#[inline] //~ ERROR attribute should be applied to function or closure
}
impl Trait for () {
- #[inline] //~ ERROR attribute should be applied to function or closure
+ #[inline] //~ WARN `#[inline]` is ignored on constants
+ //~^ WARN this was previously accepted
const X: u32 = 0;
#[inline] //~ ERROR attribute should be applied to function or closure
error[E0518]: attribute should be applied to function or closure
- --> $DIR/inline-trait-and-foreign-items.rs:26:5
+ --> $DIR/inline-trait-and-foreign-items.rs:30:5
|
LL | #[inline]
| ^^^^^^^^^
| -------------- not a function or closure
error[E0518]: attribute should be applied to function or closure
- --> $DIR/inline-trait-and-foreign-items.rs:29:5
+ --> $DIR/inline-trait-and-foreign-items.rs:33:5
|
LL | #[inline]
| ^^^^^^^^^
LL | type T;
| ------- not a function or closure
-error[E0518]: attribute should be applied to function or closure
- --> $DIR/inline-trait-and-foreign-items.rs:5:5
+warning: `#[inline]` is ignored on constants
+ --> $DIR/inline-trait-and-foreign-items.rs:7:5
|
LL | #[inline]
| ^^^^^^^^^
-LL | const X: u32;
- | ------------- not a function or closure
+ |
+note: lint level defined here
+ --> $DIR/inline-trait-and-foreign-items.rs:4:9
+ |
+LL | #![warn(unused_attributes)]
+ | ^^^^^^^^^^^^^^^^^
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #65833 <https://github.com/rust-lang/rust/issues/65833>
error[E0518]: attribute should be applied to function or closure
- --> $DIR/inline-trait-and-foreign-items.rs:8:5
+ --> $DIR/inline-trait-and-foreign-items.rs:11:5
|
LL | #[inline]
| ^^^^^^^^^
LL | type T;
| ------- not a function or closure
-error[E0518]: attribute should be applied to function or closure
- --> $DIR/inline-trait-and-foreign-items.rs:15:5
+warning: `#[inline]` is ignored on constants
+ --> $DIR/inline-trait-and-foreign-items.rs:18:5
|
LL | #[inline]
| ^^^^^^^^^
-LL | const X: u32 = 0;
- | ----------------- not a function or closure
+ |
+ = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+ = note: for more information, see issue #65833 <https://github.com/rust-lang/rust/issues/65833>
error[E0518]: attribute should be applied to function or closure
- --> $DIR/inline-trait-and-foreign-items.rs:18:5
+ --> $DIR/inline-trait-and-foreign-items.rs:22:5
|
LL | #[inline]
| ^^^^^^^^^
| -------------- not a function or closure
error[E0518]: attribute should be applied to function or closure
- --> $DIR/inline-trait-and-foreign-items.rs:21:5
+ --> $DIR/inline-trait-and-foreign-items.rs:25:5
|
LL | #[inline]
| ^^^^^^^^^
| -------------------- not a function or closure
error: could not find defining uses
- --> $DIR/inline-trait-and-foreign-items.rs:22:5
+ --> $DIR/inline-trait-and-foreign-items.rs:26:5
|
LL | type U = impl Trait;
| ^^^^^^^^^^^^^^^^^^^^
-error: aborting due to 8 previous errors
+error: aborting due to 6 previous errors
For more information about this error, try `rustc --explain E0518`.