Reject const
in inherent impls
This commit is contained in:
parent
b390fc4cf1
commit
31edbe9aca
1 changed files with 12 additions and 3 deletions
|
@ -5,7 +5,7 @@ use crate::maybe_whole;
|
|||
|
||||
use rustc_error_codes::*;
|
||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, PResult, StashKey};
|
||||
use rustc_span::source_map::{self, respan, Span};
|
||||
use rustc_span::source_map::{self, respan, Span, Spanned};
|
||||
use rustc_span::symbol::{kw, sym, Symbol};
|
||||
use rustc_span::BytePos;
|
||||
use syntax::ast::{self, AttrKind, AttrStyle, AttrVec, Attribute, Ident, DUMMY_NODE_ID};
|
||||
|
@ -560,8 +560,9 @@ impl<'a> Parser<'a> {
|
|||
};
|
||||
|
||||
let constness = if self.eat_keyword(kw::Const) {
|
||||
self.sess.gated_spans.gate(sym::const_trait_impl, self.prev_span);
|
||||
Some(Constness::Const)
|
||||
let span = self.prev_span;
|
||||
self.sess.gated_spans.gate(sym::const_trait_impl, span);
|
||||
Some(respan(span, Constness::Const))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
@ -626,6 +627,7 @@ impl<'a> Parser<'a> {
|
|||
err_path(ty_first.span)
|
||||
}
|
||||
};
|
||||
let constness = constness.map(|c| c.node);
|
||||
let trait_ref = TraitRef { path, constness, ref_id: ty_first.id };
|
||||
|
||||
ItemKind::Impl(
|
||||
|
@ -639,6 +641,13 @@ impl<'a> Parser<'a> {
|
|||
)
|
||||
}
|
||||
None => {
|
||||
// Reject `impl const Type {}` here
|
||||
if let Some(Spanned { node: Constness::Const, span }) = constness {
|
||||
self.struct_span_err(span, "`const` cannot modify an inherent impl")
|
||||
.help("only a trait impl can be `const`")
|
||||
.emit();
|
||||
}
|
||||
|
||||
// impl Type
|
||||
ItemKind::Impl(
|
||||
unsafety,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue