Skip to content

Commit ed6c958

Browse files
committed
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
2 parents f565016 + d907ab8 commit ed6c958

File tree

15 files changed

+86
-34
lines changed

15 files changed

+86
-34
lines changed

compiler/rustc_builtin_macros/src/source_util.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,20 @@ pub fn expand_include<'cx>(
141141

142142
fn make_items(mut self: Box<ExpandResult<'a>>) -> Option<SmallVec<[P<ast::Item>; 1]>> {
143143
let mut ret = SmallVec::new();
144-
while self.p.token != token::Eof {
144+
loop {
145145
match self.p.parse_item(ForceCollect::No) {
146146
Err(mut err) => {
147147
err.emit();
148148
break;
149149
}
150150
Ok(Some(item)) => ret.push(item),
151151
Ok(None) => {
152-
let token = pprust::token_to_string(&self.p.token);
153-
let msg = format!("expected item, found `{}`", token);
154-
self.p.struct_span_err(self.p.token.span, &msg).emit();
152+
if self.p.token != token::Eof {
153+
let token = pprust::token_to_string(&self.p.token);
154+
let msg = format!("expected item, found `{}`", token);
155+
self.p.struct_span_err(self.p.token.span, &msg).emit();
156+
}
157+
155158
break;
156159
}
157160
}

compiler/rustc_expand/src/mbe/macro_parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ pub(super) fn count_metavar_decls(matcher: &[TokenTree]) -> usize {
315315
/// only on the nesting depth of repetitions in the originating token tree it
316316
/// was derived from.
317317
///
318-
/// In layman's terms: `NamedMatch` will form a tree representing nested matches of a particular
318+
/// In layperson's terms: `NamedMatch` will form a tree representing nested matches of a particular
319319
/// meta variable. For example, if we are matching the following macro against the following
320320
/// invocation...
321321
///

compiler/rustc_parse/src/parser/attr.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use tracing::debug;
1313
#[derive(Debug)]
1414
pub enum InnerAttrPolicy<'a> {
1515
Permitted,
16-
Forbidden { reason: &'a str, saw_doc_comment: bool, prev_attr_sp: Option<Span> },
16+
Forbidden { reason: &'a str, saw_doc_comment: bool, prev_outer_attr_sp: Option<Span> },
1717
}
1818

1919
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 \
2222
pub(super) const DEFAULT_INNER_ATTR_FORBIDDEN: InnerAttrPolicy<'_> = InnerAttrPolicy::Forbidden {
2323
reason: DEFAULT_UNEXPECTED_INNER_ATTR_ERR_MSG,
2424
saw_doc_comment: false,
25-
prev_attr_sp: None,
25+
prev_outer_attr_sp: None,
2626
};
2727

2828
enum OuterAttributeType {
@@ -34,22 +34,24 @@ enum OuterAttributeType {
3434
impl<'a> Parser<'a> {
3535
/// Parses attributes that appear before an item.
3636
pub(super) fn parse_outer_attributes(&mut self) -> PResult<'a, AttrWrapper> {
37-
let mut attrs: Vec<ast::Attribute> = Vec::new();
37+
let mut outer_attrs: Vec<ast::Attribute> = Vec::new();
3838
let mut just_parsed_doc_comment = false;
3939
let start_pos = self.token_cursor.num_next_calls;
4040
loop {
4141
let attr = if self.check(&token::Pound) {
42+
let prev_outer_attr_sp = outer_attrs.last().map(|attr| attr.span);
43+
4244
let inner_error_reason = if just_parsed_doc_comment {
4345
"an inner attribute is not permitted following an outer doc comment"
44-
} else if !attrs.is_empty() {
46+
} else if prev_outer_attr_sp.is_some() {
4547
"an inner attribute is not permitted following an outer attribute"
4648
} else {
4749
DEFAULT_UNEXPECTED_INNER_ATTR_ERR_MSG
4850
};
4951
let inner_parse_policy = InnerAttrPolicy::Forbidden {
5052
reason: inner_error_reason,
5153
saw_doc_comment: just_parsed_doc_comment,
52-
prev_attr_sp: attrs.last().map(|a| a.span),
54+
prev_outer_attr_sp,
5355
};
5456
just_parsed_doc_comment = false;
5557
Some(self.parse_attribute(inner_parse_policy)?)
@@ -97,12 +99,14 @@ impl<'a> Parser<'a> {
9799
};
98100

99101
if let Some(attr) = attr {
100-
attrs.push(attr);
102+
if attr.style == ast::AttrStyle::Outer {
103+
outer_attrs.push(attr);
104+
}
101105
} else {
102106
break;
103107
}
104108
}
105-
Ok(AttrWrapper::new(attrs.into(), start_pos))
109+
Ok(AttrWrapper::new(outer_attrs.into(), start_pos))
106110
}
107111

108112
/// Matches `attribute = # ! [ meta_item ]`.
@@ -215,15 +219,15 @@ impl<'a> Parser<'a> {
215219
}
216220

217221
pub(super) fn error_on_forbidden_inner_attr(&self, attr_sp: Span, policy: InnerAttrPolicy<'_>) {
218-
if let InnerAttrPolicy::Forbidden { reason, saw_doc_comment, prev_attr_sp } = policy {
219-
let prev_attr_note =
222+
if let InnerAttrPolicy::Forbidden { reason, saw_doc_comment, prev_outer_attr_sp } = policy {
223+
let prev_outer_attr_note =
220224
if saw_doc_comment { "previous doc comment" } else { "previous outer attribute" };
221225

222226
let mut diag = self.struct_span_err(attr_sp, reason);
223227

224-
if let Some(prev_attr_sp) = prev_attr_sp {
228+
if let Some(prev_outer_attr_sp) = prev_outer_attr_sp {
225229
diag.span_label(attr_sp, "not permitted following an outer attribute")
226-
.span_label(prev_attr_sp, prev_attr_note);
230+
.span_label(prev_outer_attr_sp, prev_outer_attr_note);
227231
}
228232

229233
diag.note(

compiler/rustc_typeck/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,7 @@ fn receiver_is_valid<'fcx, 'tcx>(
16571657
}
16581658
} else {
16591659
debug!("receiver_is_valid: type `{:?}` does not deref to `{:?}`", receiver_ty, self_ty);
1660-
// If he receiver already has errors reported due to it, consider it valid to avoid
1660+
// If the receiver already has errors reported due to it, consider it valid to avoid
16611661
// unnecessary errors (#58712).
16621662
return receiver_ty.references_error();
16631663
}

compiler/rustc_typeck/src/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2700,7 +2700,7 @@ fn linkage_by_name(tcx: TyCtxt<'_>, def_id: DefId, name: &str) -> Linkage {
27002700
// Use the names from src/llvm/docs/LangRef.rst here. Most types are only
27012701
// applicable to variable declarations and may not really make sense for
27022702
// Rust code in the first place but allow them anyway and trust that the
2703-
// user knows what s/he's doing. Who knows, unanticipated use cases may pop
2703+
// user knows what they're doing. Who knows, unanticipated use cases may pop
27042704
// up in the future.
27052705
//
27062706
// ghost, dllimport, dllexport and linkonce_odr_autohide are not supported

library/core/src/str/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2406,7 +2406,7 @@ impl str {
24062406
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
24072407
#[inline]
24082408
pub fn make_ascii_uppercase(&mut self) {
2409-
// SAFETY: safe because we transmute two types with the same layout.
2409+
// SAFETY: changing ASCII letters only does not invalidate UTF-8.
24102410
let me = unsafe { self.as_bytes_mut() };
24112411
me.make_ascii_uppercase()
24122412
}
@@ -2433,7 +2433,7 @@ impl str {
24332433
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
24342434
#[inline]
24352435
pub fn make_ascii_lowercase(&mut self) {
2436-
// SAFETY: safe because we transmute two types with the same layout.
2436+
// SAFETY: changing ASCII letters only does not invalidate UTF-8.
24372437
let me = unsafe { self.as_bytes_mut() };
24382438
me.make_ascii_lowercase()
24392439
}

library/std/src/fs/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -644,9 +644,9 @@ fn recursive_rmdir_toctou() {
644644
// Test for time-of-check to time-of-use issues.
645645
//
646646
// Scenario:
647-
// The attacker wants to get directory contents deleted, to which he does not have access.
648-
// He has a way to get a privileged Rust binary call `std::fs::remove_dir_all()` on a
649-
// directory he controls, e.g. in his home directory.
647+
// The attacker wants to get directory contents deleted, to which they do not have access.
648+
// They have a way to get a privileged Rust binary call `std::fs::remove_dir_all()` on a
649+
// directory they control, e.g. in their home directory.
650650
//
651651
// The POC sets up the `attack_dest/attack_file` which the attacker wants to have deleted.
652652
// The attacker repeatedly creates a directory and replaces it with a symlink from

library/std/src/thread/local.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ pub mod fast {
980980
unsafe fn try_initialize<F: FnOnce() -> T>(&self, init: F) -> Option<&'static T> {
981981
// SAFETY: See comment above (this function doc).
982982
if !mem::needs_drop::<T>() || unsafe { self.try_register_dtor() } {
983-
// SAFETY: See comment above (his function doc).
983+
// SAFETY: See comment above (this function doc).
984984
Some(unsafe { self.inner.initialize(init) })
985985
} else {
986986
None

src/test/ui/match/issue-82866.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
match x {
3+
//~^ ERROR cannot find value `x` in this scope
4+
Some::<v>(v) => (),
5+
//~^ ERROR cannot find type `v` in this scope
6+
}
7+
}

src/test/ui/match/issue-82866.stderr

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0425]: cannot find value `x` in this scope
2+
--> $DIR/issue-82866.rs:2:11
3+
|
4+
LL | match x {
5+
| ^ not found in this scope
6+
7+
error[E0412]: cannot find type `v` in this scope
8+
--> $DIR/issue-82866.rs:4:16
9+
|
10+
LL | Some::<v>(v) => (),
11+
| ^ not found in this scope
12+
13+
error: aborting due to 2 previous errors
14+
15+
Some errors have detailed explanations: E0412, E0425.
16+
For more information about an error, try `rustc --explain E0412`.

src/test/ui/parser/attr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
fn main() {}
44

55
#![lang = "foo"] //~ ERROR an inner attribute is not permitted in this context
6-
//~| ERROR definition of an unknown language item: `foo`
76
fn foo() {}

src/test/ui/parser/attr.stderr

+1-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ error: an inner attribute is not permitted in this context
33
|
44
LL | #![lang = "foo"]
55
| ^^^^^^^^^^^^^^^^
6-
LL |
76
LL | fn foo() {}
87
| ----------- the inner attribute doesn't annotate this function
98
|
@@ -14,12 +13,5 @@ LL - #![lang = "foo"]
1413
LL + #[lang = "foo"]
1514
|
1615

17-
error[E0522]: definition of an unknown language item: `foo`
18-
--> $DIR/attr.rs:5:1
19-
|
20-
LL | #![lang = "foo"]
21-
| ^^^^^^^^^^^^^^^^ definition of unknown language item `foo`
22-
23-
error: aborting due to 2 previous errors
16+
error: aborting due to previous error
2417

25-
For more information about this error, try `rustc --explain E0522`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// include file for issue-94340.rs
2+
#![deny(rust_2018_idioms)]
3+
#![deny(unused_must_use)]
+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// Make sure that unexpected inner attributes are not labeled as outer ones in diagnostics when
2+
// trying to parse an item and that they are subsequently ignored not triggering confusing extra
3+
// diagnostics like "expected item after attributes" which is not true for `include!` which can
4+
// include empty files.
5+
6+
include!("auxiliary/issue-94340-inc.rs");
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: an inner attribute is not permitted in this context
2+
--> $DIR/auxiliary/issue-94340-inc.rs:2:1
3+
|
4+
LL | #![deny(rust_2018_idioms)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
8+
= note: outer attributes, like `#[test]`, annotate the item following them
9+
10+
error: an inner attribute is not permitted in this context
11+
--> $DIR/auxiliary/issue-94340-inc.rs:3:1
12+
|
13+
LL | #![deny(unused_must_use)]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
15+
|
16+
= note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
17+
= note: outer attributes, like `#[test]`, annotate the item following them
18+
19+
error: aborting due to 2 previous errors
20+

0 commit comments

Comments
 (0)