Skip to content

Commit 4b7e3a7

Browse files
committed
Auto merge of #162028 - JonathanBrouwer:rollup-GlcjAND, r=JonathanBrouwer
Rollup of 11 pull requests Successful merges: - #160923 (Handle multiple action records in EH personality function) - #161788 (Check to ensure we're running against the correct LLVM version) - #158303 (Always escape grapheme extenders in `str::escape_debug`) - #161644 (bootstrap: Flatten and rename `compute_src_directory_via_git`) - #161702 (Use `drop_guard` in some places in {core,alloc,std}) - #161713 (Add config for gram editor to .gitignore) - #161792 (Fix and improve diagnostics for lint `rust_2021_prefixes_incompatible_syntax`) - #161931 (Revert "Add rustc_test_entrypoint_marker") - #162015 (touch up "get attribute" docs.) - #162019 (remove a couple of redundant clones, thanks clippy) - #162023 (Remove redundant braces from `NonZero` doctests)
2 parents 9085017 + 5c8197f commit 4b7e3a7

74 files changed

Lines changed: 1066 additions & 1163 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Session.vim
2222
.vim/
2323
.helix/
2424
.zed/
25+
.gram/
2526
.favorites.json
2627
.settings/
2728
.vs/

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4430,6 +4430,7 @@ dependencies = [
44304430
"rustc_arena",
44314431
"rustc_ast",
44324432
"rustc_ast_ir",
4433+
"rustc_attr_ir",
44334434
"rustc_crate_store",
44344435
"rustc_data_structures",
44354436
"rustc_errors",

compiler/rustc_attr_ir/src/data_structures.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,9 +1420,6 @@ pub enum AttributeKind {
14201420
/// Represents `#[rustc_strict_coherence]`.
14211421
RustcStrictCoherence(Span),
14221422

1423-
/// Represents `#[rustc_test_entrypoint_marker]`
1424-
RustcTestEntrypointMarker,
1425-
14261423
/// Represents `#[rustc_test_marker]`
14271424
RustcTestMarker(Symbol),
14281425

compiler/rustc_attr_ir/src/encode_cross_crate.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ impl AttributeKind {
191191
RustcSpecializationTrait => No,
192192
RustcStdInternalSymbol => No,
193193
RustcStrictCoherence(..) => Yes,
194-
RustcTestEntrypointMarker => No,
195194
RustcTestMarker(..) => No,
196195
RustcThenThisWouldNeed(..) => No,
197196
RustcTrivialFieldReads => Yes,

compiler/rustc_attr_ir/src/lib.rs

Lines changed: 45 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Data structures for representing parsed attributes in the Rust compiler.
22
//!
33
//! For detailed documentation about attribute processing,
4-
//! see [rustc_attr_parsing](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_attr_parsing/index.html).
4+
//! see [rustc_attr_parsing](../rustc_attr_parsing/index.html).
55
66
// tidy-alphabetical-start
77
#![feature(const_default)]
@@ -20,7 +20,6 @@ pub use lang_items::*;
2020
pub use pretty_printing::PrintAttribute;
2121
pub use stability::*;
2222

23-
// FIXME remove pub on some of these modules? It's fairly inconsistent.
2423
mod attr;
2524
mod canonical_symbols;
2625
mod data_structures;
@@ -35,40 +34,38 @@ pub mod weak_lang_items;
3534

3635
/// A trait for types that can provide a list of attributes given a `TyCtxt`.
3736
///
38-
/// It allows `find_attr!` to accept either a `DefId`, `LocalDefId`, `OwnerId`, or `HirId`.
39-
/// It is defined here with a generic `Tcx` because `rustc_hir` can't depend on `rustc_middle`.
40-
/// The concrete implementations are in `rustc_middle`.
37+
/// It is an implementation detail of the [`find_attr!`] macro to be able to accept either a
38+
/// [`DefId`], [`LocalDefId`], [`OwnerId`], or [`HirId`]. It is defined here with a generic `Tcx`
39+
/// because this crate can't depend on `rustc_middle`. The concrete implementations are in
40+
/// `rustc_middle`.
41+
///
42+
/// Not to be confused with [`rustc_ast::ast_traits::HasAttrs`].
43+
///
44+
/// [`DefId`]: rustc_span::def_id::DefId
45+
/// [`LocalDefId`]: rustc_span::def_id::LocalDefId
46+
/// [`OwnerId`]: ../rustc_hir/struct.OwnerId.html
47+
/// [`HirId`]: ../rustc_hir/struct.HirId.html
4148
pub trait HasAttrs<'tcx, Tcx> {
42-
fn get_attrs(self, tcx: &Tcx) -> &'tcx [crate::attr::Attribute];
49+
fn get_attrs(self, tcx: &Tcx) -> &'tcx [crate::Attribute];
4350
}
4451

45-
/// Finds attributes in sequences of attributes by pattern matching.
52+
/// Finds attributes by pattern matching.
4653
///
4754
/// A little like `matches` but for attributes.
4855
///
49-
/// ```rust,ignore (illustrative)
50-
/// // finds the repr attribute
51-
/// if let Some(r) = find_attr!(attrs, AttributeKind::Repr(r) => r) {
52-
///
53-
/// }
54-
///
55-
/// // checks if one has matched
56-
/// if find_attr!(attrs, AttributeKind::Repr(_)) {
57-
///
58-
/// }
59-
/// ```
56+
/// Note that this macro accepts several "id" types: [`DefId`], [`LocalDefId`], [`OwnerId`] and
57+
/// [`HirId`].
6058
///
61-
/// Often this requires you to first end up with a list of attributes.
62-
/// Often these are available through the `tcx`.
59+
/// # Examples
6360
///
64-
/// As a convenience, this macro can do that for you!
61+
/// It is most commonly used to check whether something has an attribute or to get its contents
62+
/// if it is present:
63+
/// ```rust,ignore (illustrative)
64+
/// let is_naked: bool = find_attr!(tcx, def_id, Naked(..));
6565
///
66-
/// Instead of providing an attribute list, provide the `tcx` and an id
67-
/// (a `DefId`, `LocalDefId`, `OwnerId` or `HirId`).
66+
/// let is_visible: bool = find_attr!(tcx, def_id, Doc(doc) if doc.hidden.is_none());
6867
///
69-
/// ```rust,ignore (illustrative)
70-
/// find_attr!(tcx, def_id, <pattern>)
71-
/// find_attr!(tcx, hir_id, <pattern>)
68+
/// let link_name: Option<Symbol> = find_attr!(tcx, def_id, LinkName { name, .. } => *name);
7269
/// ```
7370
///
7471
/// Another common case is finding attributes applied to the root of the current crate.
@@ -77,6 +74,27 @@ pub trait HasAttrs<'tcx, Tcx> {
7774
/// ```rust, ignore (illustrative)
7875
/// find_attr!(tcx, crate, <pattern>)
7976
/// ```
77+
///
78+
/// If you already have a list of attributes in scope, you can also use that:
79+
///
80+
/// ```rust,ignore (illustrative)
81+
/// let attrs = <list of attributes>;
82+
///
83+
/// // finds the repr attribute
84+
/// if let Some(r) = find_attr!(attrs, Repr(r) => r) {
85+
///
86+
/// }
87+
///
88+
/// // checks if one has matched
89+
/// if find_attr!(attrs, Repr(_)) {
90+
///
91+
/// }
92+
/// ```
93+
///
94+
/// [`DefId`]: rustc_span::def_id::DefId
95+
/// [`LocalDefId`]: rustc_span::def_id::LocalDefId
96+
/// [`OwnerId`]: ../rustc_hir/struct.OwnerId.html
97+
/// [`HirId`]: ../rustc_hir/struct.HirId.html
8098
#[macro_export]
8199
macro_rules! find_attr {
82100
($tcx: expr, crate, $pattern: pat $(if $guard: expr)?) => {
@@ -89,14 +107,14 @@ macro_rules! find_attr {
89107
($tcx: expr, $id: expr, $pattern: pat $(if $guard: expr)?) => {
90108
$crate::find_attr!($tcx, $id, $pattern $(if $guard)? => ()).is_some()
91109
};
110+
92111
($tcx: expr, $id: expr, $pattern: pat $(if $guard: expr)? => $e: expr) => {{
93112
$crate::find_attr!(
94113
$crate::HasAttrs::get_attrs($id, &$tcx),
95114
$pattern $(if $guard)? => $e
96115
)
97116
}};
98117

99-
100118
($attributes_list: expr, $pattern: pat $(if $guard: expr)?) => {{
101119
$crate::find_attr!($attributes_list, $pattern $(if $guard)? => ()).is_some()
102120
}};

compiler/rustc_attr_parsing/src/attributes/diagnostic/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ fn parse_directive_items<'p>(
361361
WrappedParserError {
362362
description: e.description,
363363
label: e.label,
364-
span: slice_span(input.span, e.span.clone(), is_snippet),
364+
span: slice_span(input.span, e.span, is_snippet),
365365
},
366366
input.span,
367367
);

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,3 @@ impl SingleAttributeParser for RustcTestMarkerParser {
214214
Some(AttributeKind::RustcTestMarker(value_str))
215215
}
216216
}
217-
218-
pub(crate) struct RustcTestEntrypointMarkerParser;
219-
220-
impl NoArgsAttributeParser for RustcTestEntrypointMarkerParser {
221-
const PATH: &[Symbol] = &[sym::rustc_test_entrypoint_marker];
222-
const ALLOWED_TARGETS: AllowedTargets<'_> =
223-
AllowedTargets::AllowList(&[Allow(Target::Fn), Allow(Target::Closure)]);
224-
const ON_DUPLICATE: OnDuplicate = OnDuplicate::Warn;
225-
const STABILITY: AttributeStability = unstable!(rustc_attrs);
226-
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcTestEntrypointMarker;
227-
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,6 @@ attribute_parsers!(
353353
Single<WithoutArgs<RustcSpecializationTraitParser>>,
354354
Single<WithoutArgs<RustcStdInternalSymbolParser>>,
355355
Single<WithoutArgs<RustcStrictCoherenceParser>>,
356-
Single<WithoutArgs<RustcTestEntrypointMarkerParser>>,
357356
Single<WithoutArgs<RustcTrivialFieldReadsParser>>,
358357
Single<WithoutArgs<SplatParser>>,
359358
Single<WithoutArgs<ThreadLocalParser>>,

compiler/rustc_builtin_macros/src/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub(crate) fn expand_option_env<'cx>(
4040
Err(guar) => return ExpandResult::Ready(DummyResult::any(sp, guar)),
4141
};
4242
let ExpandResult::Ready(mac) =
43-
expr_to_string(cx, var_expr.clone(), "argument must be a string literal")
43+
expr_to_string(cx, var_expr, "argument must be a string literal")
4444
else {
4545
return ExpandResult::Retry(());
4646
};

compiler/rustc_builtin_macros/src/offload.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ pub(crate) fn expand_kernel(
134134
// host function
135135
let mut host_fn = Box::new(ast::Fn {
136136
defaultness: ast::Defaultness::Implicit,
137-
sig: sig.clone(),
137+
sig,
138138
ident,
139-
generics: generics.clone(),
139+
generics,
140140
contract: None,
141141
body: Some(body),
142142
define_opaque: None,
@@ -176,7 +176,7 @@ pub(crate) fn expand_kernel(
176176
thin_vec![rustc_offload_kernel, inline_never],
177177
ast::ItemKind::Fn(host_fn),
178178
);
179-
item.vis = vis.clone();
179+
item.vis = vis;
180180
Annotatable::Item(item)
181181
};
182182

0 commit comments

Comments
 (0)