Skip to content

Commit 60c2e8d

Browse files
committed
Auto merge of rust-lang#75126 - JohnTitor:rollup-aejluzx, r=JohnTitor
Rollup of 8 pull requests Successful merges: - rust-lang#74759 (add `unsigned_abs` to signed integers) - rust-lang#75043 (rustc_ast: `(Nested)MetaItem::check_name` -> `has_name`) - rust-lang#75056 (Lint path statements to suggest using drop when the type needs drop) - rust-lang#75081 (Fix logging for rustdoc) - rust-lang#75083 (Do not trigger `unused_braces` for `while let`) - rust-lang#75084 (Stabilize Ident::new_raw) - rust-lang#75103 (Disable building rust-analyzer on riscv64) - rust-lang#75106 (Enable docs on in the x86_64-unknown-linux-musl manifest) Failed merges: r? @ghost
2 parents 1d601d6 + aa84a76 commit 60c2e8d

File tree

46 files changed

+297
-149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+297
-149
lines changed

library/core/src/num/mod.rs

+23
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,29 @@ $EndFeature, "
16011601
}
16021602
}
16031603

1604+
doc_comment! {
1605+
concat!("Computes the absolute value of `self` without any wrapping
1606+
or panicking.
1607+
1608+
1609+
# Examples
1610+
1611+
Basic usage:
1612+
1613+
```
1614+
", $Feature, "#![feature(unsigned_abs)]
1615+
assert_eq!(100", stringify!($SelfT), ".unsigned_abs(), 100", stringify!($UnsignedT), ");
1616+
assert_eq!((-100", stringify!($SelfT), ").unsigned_abs(), 100", stringify!($UnsignedT), ");
1617+
assert_eq!((-128i8).unsigned_abs(), 128u8);",
1618+
$EndFeature, "
1619+
```"),
1620+
#[unstable(feature = "unsigned_abs", issue = "74913")]
1621+
#[inline]
1622+
pub const fn unsigned_abs(self) -> $UnsignedT {
1623+
self.wrapping_abs() as $UnsignedT
1624+
}
1625+
}
1626+
16041627
doc_comment! {
16051628
concat!("Wrapping (modular) exponentiation. Computes `self.pow(exp)`,
16061629
wrapping around at the boundary of the type.

library/proc_macro/src/lib.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -848,7 +848,7 @@ impl Ident {
848848
/// Creates a new `Ident` with the given `string` as well as the specified
849849
/// `span`.
850850
/// The `string` argument must be a valid identifier permitted by the
851-
/// language, otherwise the function will panic.
851+
/// language (including keywords, e.g. `self` or `fn`). Otherwise, the function will panic.
852852
///
853853
/// Note that `span`, currently in rustc, configures the hygiene information
854854
/// for this identifier.
@@ -870,7 +870,10 @@ impl Ident {
870870
}
871871

872872
/// Same as `Ident::new`, but creates a raw identifier (`r#ident`).
873-
#[unstable(feature = "proc_macro_raw_ident", issue = "54723")]
873+
/// The `string` argument be a valid identifier permitted by the language
874+
/// (including keywords, e.g. `fn`). Keywords which are usable in path segments
875+
/// (e.g. `self`, `super`) are not supported, and will cause a panic.
876+
#[stable(feature = "proc_macro_raw_ident", since = "1.47.0")]
874877
pub fn new_raw(string: &str, span: Span) -> Ident {
875878
Ident(bridge::client::Ident::new(string, span.0, true))
876879
}

src/bootstrap/dist.rs

+47-27
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ pub struct RustAnalyzer {
13551355
}
13561356

13571357
impl Step for RustAnalyzer {
1358-
type Output = PathBuf;
1358+
type Output = Option<PathBuf>;
13591359
const ONLY_HOSTS: bool = true;
13601360

13611361
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
@@ -1373,11 +1373,17 @@ impl Step for RustAnalyzer {
13731373
});
13741374
}
13751375

1376-
fn run(self, builder: &Builder<'_>) -> PathBuf {
1376+
fn run(self, builder: &Builder<'_>) -> Option<PathBuf> {
13771377
let compiler = self.compiler;
13781378
let target = self.target;
13791379
assert!(builder.config.extended);
13801380

1381+
if target.contains("riscv64") {
1382+
// riscv64 currently has an LLVM bug that makes rust-analyzer unable
1383+
// to build. See #74813 for details.
1384+
return None;
1385+
}
1386+
13811387
let src = builder.src.join("src/tools/rust-analyzer");
13821388
let release_num = builder.release_num("rust-analyzer/crates/rust-analyzer");
13831389
let name = pkgname(builder, "rust-analyzer");
@@ -1431,7 +1437,7 @@ impl Step for RustAnalyzer {
14311437
builder.info(&format!("Dist rust-analyzer stage{} ({})", compiler.stage, target));
14321438
let _time = timeit(builder);
14331439
builder.run(&mut cmd);
1434-
distdir(builder).join(format!("{}-{}.tar.gz", name, target.triple))
1440+
Some(distdir(builder).join(format!("{}-{}.tar.gz", name, target.triple)))
14351441
}
14361442
}
14371443

@@ -1789,7 +1795,7 @@ impl Step for Extended {
17891795
tarballs.push(rustc_installer);
17901796
tarballs.push(cargo_installer);
17911797
tarballs.extend(rls_installer.clone());
1792-
tarballs.push(rust_analyzer_installer.clone());
1798+
tarballs.extend(rust_analyzer_installer.clone());
17931799
tarballs.push(clippy_installer);
17941800
tarballs.extend(miri_installer.clone());
17951801
tarballs.extend(rustfmt_installer.clone());
@@ -1867,7 +1873,9 @@ impl Step for Extended {
18671873
if rls_installer.is_none() {
18681874
contents = filter(&contents, "rls");
18691875
}
1870-
contents = filter(&contents, "rust-analyzer");
1876+
if rust_analyzer_installer.is_none() {
1877+
contents = filter(&contents, "rust-analyzer");
1878+
}
18711879
if miri_installer.is_none() {
18721880
contents = filter(&contents, "miri");
18731881
}
@@ -1914,7 +1922,9 @@ impl Step for Extended {
19141922
if rls_installer.is_some() {
19151923
prepare("rls");
19161924
}
1917-
prepare("rust-analyzer");
1925+
if rust_analyzer_installer.is_some() {
1926+
prepare("rust-analyzer");
1927+
}
19181928
if miri_installer.is_some() {
19191929
prepare("miri");
19201930
}
@@ -1976,7 +1986,9 @@ impl Step for Extended {
19761986
if rls_installer.is_some() {
19771987
prepare("rls");
19781988
}
1979-
prepare("rust-analyzer");
1989+
if rust_analyzer_installer.is_some() {
1990+
prepare("rust-analyzer");
1991+
}
19801992
if miri_installer.is_some() {
19811993
prepare("miri");
19821994
}
@@ -2076,23 +2088,25 @@ impl Step for Extended {
20762088
.arg(etc.join("msi/remove-duplicates.xsl")),
20772089
);
20782090
}
2079-
builder.run(
2080-
Command::new(&heat)
2081-
.current_dir(&exe)
2082-
.arg("dir")
2083-
.arg("rust-analyzer")
2084-
.args(&heat_flags)
2085-
.arg("-cg")
2086-
.arg("RustAnalyzerGroup")
2087-
.arg("-dr")
2088-
.arg("RustAnalyzer")
2089-
.arg("-var")
2090-
.arg("var.RustAnalyzerDir")
2091-
.arg("-out")
2092-
.arg(exe.join("RustAnalyzerGroup.wxs"))
2093-
.arg("-t")
2094-
.arg(etc.join("msi/remove-duplicates.xsl")),
2095-
);
2091+
if rust_analyzer_installer.is_some() {
2092+
builder.run(
2093+
Command::new(&heat)
2094+
.current_dir(&exe)
2095+
.arg("dir")
2096+
.arg("rust-analyzer")
2097+
.args(&heat_flags)
2098+
.arg("-cg")
2099+
.arg("RustAnalyzerGroup")
2100+
.arg("-dr")
2101+
.arg("RustAnalyzer")
2102+
.arg("-var")
2103+
.arg("var.RustAnalyzerDir")
2104+
.arg("-out")
2105+
.arg(exe.join("RustAnalyzerGroup.wxs"))
2106+
.arg("-t")
2107+
.arg(etc.join("msi/remove-duplicates.xsl")),
2108+
);
2109+
}
20962110
builder.run(
20972111
Command::new(&heat)
20982112
.current_dir(&exe)
@@ -2186,7 +2200,9 @@ impl Step for Extended {
21862200
if rls_installer.is_some() {
21872201
cmd.arg("-dRlsDir=rls");
21882202
}
2189-
cmd.arg("-dRustAnalyzerDir=rust-analyzer");
2203+
if rust_analyzer_installer.is_some() {
2204+
cmd.arg("-dRustAnalyzerDir=rust-analyzer");
2205+
}
21902206
if miri_installer.is_some() {
21912207
cmd.arg("-dMiriDir=miri");
21922208
}
@@ -2206,7 +2222,9 @@ impl Step for Extended {
22062222
if rls_installer.is_some() {
22072223
candle("RlsGroup.wxs".as_ref());
22082224
}
2209-
candle("RustAnalyzerGroup.wxs".as_ref());
2225+
if rust_analyzer_installer.is_some() {
2226+
candle("RustAnalyzerGroup.wxs".as_ref());
2227+
}
22102228
if miri_installer.is_some() {
22112229
candle("MiriGroup.wxs".as_ref());
22122230
}
@@ -2244,7 +2262,9 @@ impl Step for Extended {
22442262
if rls_installer.is_some() {
22452263
cmd.arg("RlsGroup.wixobj");
22462264
}
2247-
cmd.arg("RustAnalyzerGroup.wixobj");
2265+
if rust_analyzer_installer.is_some() {
2266+
cmd.arg("RustAnalyzerGroup.wixobj");
2267+
}
22482268
if miri_installer.is_some() {
22492269
cmd.arg("MiriGroup.wixobj");
22502270
}

src/librustc_ast/attr/mod.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ impl NestedMetaItem {
100100
}
101101

102102
/// Returns `true` if this list item is a MetaItem with a name of `name`.
103-
pub fn check_name(&self, name: Symbol) -> bool {
104-
self.meta_item().map_or(false, |meta_item| meta_item.check_name(name))
103+
pub fn has_name(&self, name: Symbol) -> bool {
104+
self.meta_item().map_or(false, |meta_item| meta_item.has_name(name))
105105
}
106106

107107
/// For a single-segment meta item, returns its name; otherwise, returns `None`.
@@ -173,8 +173,13 @@ impl Attribute {
173173
}
174174
}
175175

176-
/// Returns `true` if the attribute's path matches the argument. If it matches, then the
177-
/// attribute is marked as used.
176+
/// Returns `true` if the attribute's path matches the argument.
177+
/// If it matches, then the attribute is marked as used.
178+
/// Should only be used by rustc, other tools can use `has_name` instead,
179+
/// because only rustc is supposed to report the `unused_attributes` lint.
180+
/// `MetaItem` and `NestedMetaItem` are produced by "lowering" an `Attribute`
181+
/// and don't have identity, so they only has the `has_name` method,
182+
/// and you need to mark the original `Attribute` as used when necessary.
178183
pub fn check_name(&self, name: Symbol) -> bool {
179184
let matches = self.has_name(name);
180185
if matches {
@@ -278,7 +283,7 @@ impl MetaItem {
278283
}
279284
}
280285

281-
pub fn check_name(&self, name: Symbol) -> bool {
286+
pub fn has_name(&self, name: Symbol) -> bool {
282287
self.path == name
283288
}
284289

@@ -405,7 +410,7 @@ pub fn mk_doc_comment(style: AttrStyle, comment: Symbol, span: Span) -> Attribut
405410
}
406411

407412
pub fn list_contains_name(items: &[NestedMetaItem], name: Symbol) -> bool {
408-
items.iter().any(|item| item.check_name(name))
413+
items.iter().any(|item| item.has_name(name))
409414
}
410415

411416
pub fn contains_name(attrs: &[Attribute], name: Symbol) -> bool {

src/librustc_ast_passes/feature_gate.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
243243
if attr.check_name(sym::doc) {
244244
for nested_meta in attr.meta_item_list().unwrap_or_default() {
245245
macro_rules! gate_doc { ($($name:ident => $feature:ident)*) => {
246-
$(if nested_meta.check_name(sym::$name) {
246+
$(if nested_meta.has_name(sym::$name) {
247247
let msg = concat!("`#[doc(", stringify!($name), ")]` is experimental");
248248
gate_feature_post!(self, $feature, attr.span, msg);
249249
})*
@@ -314,7 +314,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
314314
ast::ItemKind::Struct(..) => {
315315
for attr in attr::filter_by_name(&i.attrs[..], sym::repr) {
316316
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
317-
if item.check_name(sym::simd) {
317+
if item.has_name(sym::simd) {
318318
gate_feature_post!(
319319
&self,
320320
repr_simd,

src/librustc_attr/builtin.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Op
9292
if let Some(meta) = attr.meta() {
9393
if let MetaItemKind::List(items) = meta.kind {
9494
if items.len() == 1 {
95-
if items[0].check_name(sym::allowed) {
95+
if items[0].has_name(sym::allowed) {
9696
return Some(UnwindAttr::Allowed);
97-
} else if items[0].check_name(sym::aborts) {
97+
} else if items[0].has_name(sym::aborts) {
9898
return Some(UnwindAttr::Aborts);
9999
}
100100
}
@@ -168,7 +168,7 @@ pub fn contains_feature_attr(attrs: &[Attribute], feature_name: Symbol) -> bool
168168
item.check_name(sym::feature)
169169
&& item
170170
.meta_item_list()
171-
.map(|list| list.iter().any(|mi| mi.is_word() && mi.check_name(feature_name)))
171+
.map(|list| list.iter().any(|mi| mi.is_word() && mi.has_name(feature_name)))
172172
.unwrap_or(false)
173173
})
174174
}
@@ -505,7 +505,7 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat
505505
}
506506

507507
fn try_gate_cfg(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Features>) {
508-
let gate = find_gated_cfg(|sym| cfg.check_name(sym));
508+
let gate = find_gated_cfg(|sym| cfg.has_name(sym));
509509
if let (Some(feats), Some(gated_cfg)) = (features, gate) {
510510
gate_cfg(&gated_cfg, cfg.span, sess, feats);
511511
}
@@ -898,7 +898,7 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec<ReprAttr> {
898898
}
899899
} else {
900900
if let Some(meta_item) = item.meta_item() {
901-
if meta_item.check_name(sym::align) {
901+
if meta_item.has_name(sym::align) {
902902
if let MetaItemKind::NameValue(ref value) = meta_item.kind {
903903
recognised = true;
904904
let mut err = struct_span_err!(

src/librustc_builtin_macros/proc_macro_harness.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl<'a> CollectProcMacros<'a> {
143143

144144
let attributes_attr = list.get(1);
145145
let proc_attrs: Vec<_> = if let Some(attr) = attributes_attr {
146-
if !attr.check_name(sym::attributes) {
146+
if !attr.has_name(sym::attributes) {
147147
self.handler.span_err(attr.span(), "second argument must be `attributes`")
148148
}
149149
attr.meta_item_list()

src/librustc_builtin_macros/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
336336
Some(list) => {
337337
let msg = list
338338
.iter()
339-
.find(|mi| mi.check_name(sym::expected))
339+
.find(|mi| mi.has_name(sym::expected))
340340
.and_then(|mi| mi.meta_item())
341341
.and_then(|mi| mi.value_str());
342342
if list.len() != 1 || msg.is_none() {

src/librustc_expand/expand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1644,14 +1644,14 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
16441644
}
16451645

16461646
if let Some(list) = at.meta_item_list() {
1647-
if !list.iter().any(|it| it.check_name(sym::include)) {
1647+
if !list.iter().any(|it| it.has_name(sym::include)) {
16481648
return noop_visit_attribute(at, self);
16491649
}
16501650

16511651
let mut items = vec![];
16521652

16531653
for mut it in list {
1654-
if !it.check_name(sym::include) {
1654+
if !it.has_name(sym::include) {
16551655
items.push({
16561656
noop_visit_meta_list_item(&mut it, self);
16571657
it

src/librustc_incremental/assert_module_sources.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl AssertModuleSource<'tcx> {
149149

150150
fn field(&self, attr: &ast::Attribute, name: Symbol) -> Symbol {
151151
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
152-
if item.check_name(name) {
152+
if item.has_name(name) {
153153
if let Some(value) = item.value_str() {
154154
return value;
155155
} else {

src/librustc_incremental/persist/dirty_clean.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl DirtyCleanVisitor<'tcx> {
231231

232232
fn labels(&self, attr: &Attribute) -> Option<Labels> {
233233
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
234-
if item.check_name(LABEL) {
234+
if item.has_name(LABEL) {
235235
let value = expect_associated_value(self.tcx, &item);
236236
return Some(self.resolve_labels(&item, value));
237237
}
@@ -242,7 +242,7 @@ impl DirtyCleanVisitor<'tcx> {
242242
/// `except=` attribute value
243243
fn except(&self, attr: &Attribute) -> Labels {
244244
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
245-
if item.check_name(EXCEPT) {
245+
if item.has_name(EXCEPT) {
246246
let value = expect_associated_value(self.tcx, &item);
247247
return self.resolve_labels(&item, value);
248248
}
@@ -474,15 +474,15 @@ fn check_config(tcx: TyCtxt<'_>, attr: &Attribute) -> bool {
474474
debug!("check_config: config={:?}", config);
475475
let (mut cfg, mut except, mut label) = (None, false, false);
476476
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
477-
if item.check_name(CFG) {
477+
if item.has_name(CFG) {
478478
let value = expect_associated_value(tcx, &item);
479479
debug!("check_config: searching for cfg {:?}", value);
480480
cfg = Some(config.contains(&(value, None)));
481481
}
482-
if item.check_name(LABEL) {
482+
if item.has_name(LABEL) {
483483
label = true;
484484
}
485-
if item.check_name(EXCEPT) {
485+
if item.has_name(EXCEPT) {
486486
except = true;
487487
}
488488
}

src/librustc_lint/builtin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ fn has_doc(attr: &ast::Attribute) -> bool {
330330

331331
if let Some(list) = attr.meta_item_list() {
332332
for meta in list {
333-
if meta.check_name(sym::include) || meta.check_name(sym::hidden) {
333+
if meta.has_name(sym::include) || meta.has_name(sym::hidden) {
334334
return true;
335335
}
336336
}

0 commit comments

Comments
 (0)