Auto merge of #95760 - Dylan-DPC:rollup-uskzggh, r=Dylan-DPC
Rollup of 4 pull requests Successful merges: - #95189 (Stop flagging unexpected inner attributes as outer ones in certain diagnostics) - #95752 (Regression test for #82866) - #95753 (Correct safety reasoning in `str::make_ascii_{lower,upper}case()`) - #95757 (Use gender neutral terms) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
ed6c958ee4
15 changed files with 86 additions and 34 deletions
|
@ -141,7 +141,7 @@ pub fn expand_include<'cx>(
|
|||
|
||||
fn make_items(mut self: Box<ExpandResult<'a>>) -> Option<SmallVec<[P<ast::Item>; 1]>> {
|
||||
let mut ret = SmallVec::new();
|
||||
while self.p.token != token::Eof {
|
||||
loop {
|
||||
match self.p.parse_item(ForceCollect::No) {
|
||||
Err(mut err) => {
|
||||
err.emit();
|
||||
|
@ -149,9 +149,12 @@ pub fn expand_include<'cx>(
|
|||
}
|
||||
Ok(Some(item)) => ret.push(item),
|
||||
Ok(None) => {
|
||||
let token = pprust::token_to_string(&self.p.token);
|
||||
let msg = format!("expected item, found `{}`", token);
|
||||
self.p.struct_span_err(self.p.token.span, &msg).emit();
|
||||
if self.p.token != token::Eof {
|
||||
let token = pprust::token_to_string(&self.p.token);
|
||||
let msg = format!("expected item, found `{}`", token);
|
||||
self.p.struct_span_err(self.p.token.span, &msg).emit();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -315,7 +315,7 @@ pub(super) fn count_metavar_decls(matcher: &[TokenTree]) -> usize {
|
|||
/// only on the nesting depth of repetitions in the originating token tree it
|
||||
/// was derived from.
|
||||
///
|
||||
/// In layman's terms: `NamedMatch` will form a tree representing nested matches of a particular
|
||||
/// In layperson's terms: `NamedMatch` will form a tree representing nested matches of a particular
|
||||
/// meta variable. For example, if we are matching the following macro against the following
|
||||
/// invocation...
|
||||
///
|
||||
|
|
|
@ -13,7 +13,7 @@ use tracing::debug;
|
|||
#[derive(Debug)]
|
||||
pub enum InnerAttrPolicy<'a> {
|
||||
Permitted,
|
||||
Forbidden { reason: &'a str, saw_doc_comment: bool, prev_attr_sp: Option<Span> },
|
||||
Forbidden { reason: &'a str, saw_doc_comment: bool, prev_outer_attr_sp: Option<Span> },
|
||||
}
|
||||
|
||||
const DEFAULT_UNEXPECTED_INNER_ATTR_ERR_MSG: &str = "an inner attribute is not \
|
||||
|
@ -22,7 +22,7 @@ const DEFAULT_UNEXPECTED_INNER_ATTR_ERR_MSG: &str = "an inner attribute is not \
|
|||
pub(super) const DEFAULT_INNER_ATTR_FORBIDDEN: InnerAttrPolicy<'_> = InnerAttrPolicy::Forbidden {
|
||||
reason: DEFAULT_UNEXPECTED_INNER_ATTR_ERR_MSG,
|
||||
saw_doc_comment: false,
|
||||
prev_attr_sp: None,
|
||||
prev_outer_attr_sp: None,
|
||||
};
|
||||
|
||||
enum OuterAttributeType {
|
||||
|
@ -34,14 +34,16 @@ enum OuterAttributeType {
|
|||
impl<'a> Parser<'a> {
|
||||
/// Parses attributes that appear before an item.
|
||||
pub(super) fn parse_outer_attributes(&mut self) -> PResult<'a, AttrWrapper> {
|
||||
let mut attrs: Vec<ast::Attribute> = Vec::new();
|
||||
let mut outer_attrs: Vec<ast::Attribute> = Vec::new();
|
||||
let mut just_parsed_doc_comment = false;
|
||||
let start_pos = self.token_cursor.num_next_calls;
|
||||
loop {
|
||||
let attr = if self.check(&token::Pound) {
|
||||
let prev_outer_attr_sp = outer_attrs.last().map(|attr| attr.span);
|
||||
|
||||
let inner_error_reason = if just_parsed_doc_comment {
|
||||
"an inner attribute is not permitted following an outer doc comment"
|
||||
} else if !attrs.is_empty() {
|
||||
} else if prev_outer_attr_sp.is_some() {
|
||||
"an inner attribute is not permitted following an outer attribute"
|
||||
} else {
|
||||
DEFAULT_UNEXPECTED_INNER_ATTR_ERR_MSG
|
||||
|
@ -49,7 +51,7 @@ impl<'a> Parser<'a> {
|
|||
let inner_parse_policy = InnerAttrPolicy::Forbidden {
|
||||
reason: inner_error_reason,
|
||||
saw_doc_comment: just_parsed_doc_comment,
|
||||
prev_attr_sp: attrs.last().map(|a| a.span),
|
||||
prev_outer_attr_sp,
|
||||
};
|
||||
just_parsed_doc_comment = false;
|
||||
Some(self.parse_attribute(inner_parse_policy)?)
|
||||
|
@ -97,12 +99,14 @@ impl<'a> Parser<'a> {
|
|||
};
|
||||
|
||||
if let Some(attr) = attr {
|
||||
attrs.push(attr);
|
||||
if attr.style == ast::AttrStyle::Outer {
|
||||
outer_attrs.push(attr);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
Ok(AttrWrapper::new(attrs.into(), start_pos))
|
||||
Ok(AttrWrapper::new(outer_attrs.into(), start_pos))
|
||||
}
|
||||
|
||||
/// Matches `attribute = # ! [ meta_item ]`.
|
||||
|
@ -215,15 +219,15 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
|
||||
pub(super) fn error_on_forbidden_inner_attr(&self, attr_sp: Span, policy: InnerAttrPolicy<'_>) {
|
||||
if let InnerAttrPolicy::Forbidden { reason, saw_doc_comment, prev_attr_sp } = policy {
|
||||
let prev_attr_note =
|
||||
if let InnerAttrPolicy::Forbidden { reason, saw_doc_comment, prev_outer_attr_sp } = policy {
|
||||
let prev_outer_attr_note =
|
||||
if saw_doc_comment { "previous doc comment" } else { "previous outer attribute" };
|
||||
|
||||
let mut diag = self.struct_span_err(attr_sp, reason);
|
||||
|
||||
if let Some(prev_attr_sp) = prev_attr_sp {
|
||||
if let Some(prev_outer_attr_sp) = prev_outer_attr_sp {
|
||||
diag.span_label(attr_sp, "not permitted following an outer attribute")
|
||||
.span_label(prev_attr_sp, prev_attr_note);
|
||||
.span_label(prev_outer_attr_sp, prev_outer_attr_note);
|
||||
}
|
||||
|
||||
diag.note(
|
||||
|
|
|
@ -1657,7 +1657,7 @@ fn receiver_is_valid<'fcx, 'tcx>(
|
|||
}
|
||||
} else {
|
||||
debug!("receiver_is_valid: type `{:?}` does not deref to `{:?}`", receiver_ty, self_ty);
|
||||
// If he receiver already has errors reported due to it, consider it valid to avoid
|
||||
// If the receiver already has errors reported due to it, consider it valid to avoid
|
||||
// unnecessary errors (#58712).
|
||||
return receiver_ty.references_error();
|
||||
}
|
||||
|
|
|
@ -2700,7 +2700,7 @@ fn linkage_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: &str) -> Linkage {
|
|||
// Use the names from src/llvm/docs/LangRef.rst here. Most types are only
|
||||
// applicable to variable declarations and may not really make sense for
|
||||
// Rust code in the first place but allow them anyway and trust that the
|
||||
// user knows what s/he's doing. Who knows, unanticipated use cases may pop
|
||||
// user knows what they're doing. Who knows, unanticipated use cases may pop
|
||||
// up in the future.
|
||||
//
|
||||
// ghost, dllimport, dllexport and linkonce_odr_autohide are not supported
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue