}
match item.kind {
- ItemKind::Impl(unsafety, polarity, _, _, Some(..), ref ty, ref impl_items) => {
+ ItemKind::Impl {
+ unsafety,
+ polarity,
+ defaultness: _,
+ constness: _,
+ generics: _,
+ of_trait: Some(_),
+ ref self_ty,
+ ref items,
+ } => {
self.invalid_visibility(&item.vis, None);
- if let TyKind::Err = ty.kind {
+ if let TyKind::Err = self_ty.kind {
self.err_handler()
.struct_span_err(item.span, "`impl Trait for .. {}` is an obsolete syntax")
.help("use `auto trait Trait {}` instead")
)
.emit();
}
- for impl_item in impl_items {
+ for impl_item in items {
self.invalid_visibility(&impl_item.vis, None);
if let AssocItemKind::Fn(ref sig, _) = impl_item.kind {
self.check_trait_fn_not_const(sig.header.constness);
}
}
}
- ItemKind::Impl(unsafety, polarity, defaultness, _, None, _, _) => {
+ ItemKind::Impl {
+ unsafety,
+ polarity,
+ defaultness,
+ constness,
+ generics: _,
+ of_trait: None,
+ self_ty: _,
+ items: _,
+ } => {
self.invalid_visibility(
&item.vis,
Some("place qualifiers on individual impl items instead"),
.note("only trait implementations may be annotated with default")
.emit();
}
+ if constness == Constness::Const {
+ self.err_handler()
+ .struct_span_err(item.span, "inherent impls cannot be `const`")
+ .note("only trait implementations may be annotated with `const`")
+ .emit();
+ }
}
ItemKind::Fn(ref sig, ref generics, _) => {
self.visit_fn_header(&sig.header);
}
fn visit_param_bound(&mut self, bound: &'a GenericBound) {
- if let GenericBound::Trait(poly, maybe_bound) = bound {
- match poly.trait_ref.constness {
- Some(Constness::NotConst) => {
- if *maybe_bound == TraitBoundModifier::Maybe {
- self.err_handler()
- .span_err(bound.span(), "`?const` and `?` are mutually exclusive");
- }
-
- if let Some(ctx) = self.bound_context {
- let msg = format!("`?const` is not permitted in {}", ctx.description());
- self.err_handler().span_err(bound.span(), &msg);
- }
- }
-
- Some(Constness::Const) => panic!("Parser should reject bare `const` on bounds"),
- None => {}
+ if let GenericBound::Trait(_, TraitBoundModifier::MaybeConst) = bound {
+ if let Some(ctx) = self.bound_context {
+ let msg = format!("`?const` is not permitted in {}", ctx.description());
+ self.err_handler().span_err(bound.span(), &msg);
}
}