Skip to content

Commit 87e5904

Browse files
committed
Auto merge of #159610 - JonathanBrouwer:rollup-Wil0K5d, r=JonathanBrouwer
Rollup of 18 pull requests Successful merges: - #159600 (`rust-analyzer` subtree update) - #158046 (proc_macro: preserve file module spans for inner attrs) - #159000 (Small cleanups to the incr comp session code) - #159189 (Account for type alias projections in E0308 "expected/found" shortening logic) - #159449 (Enable single Location to issue multiple borrows) - #159544 (Suggest valid command-line crate names) - #159587 (Improve `AttrItem::span`) - #159594 (feat(rustc_hir_typeck): suggest `impl Fn` return for capturing closures) - #159597 (std: use `arc4random_buf` from libc) - #159599 (Resolver: Record at least 1 ambiguous trait if main decl is not a trait.) - #158061 (Make `pin!()` more foolproof.) - #159460 (Do not mark unnormalized const aliases as rigid when normalizing param env) - #159529 (Add regression test for nested replacement ranges in `collect_tokens`) - #159571 (Remove unused bundled library lookup for the local crate) - #159585 (Minor `TokenStream` improvements) - #159586 (Separate `InterpCx` usage by `ConstAnalysis` phases) - #159602 (Remove `ItemLike`) - #159603 (Clarify `push_stream`/`push_tree`) Failed merges: - #159590 (Remove some dead code)
2 parents d527bc9 + c905c76 commit 87e5904

206 files changed

Lines changed: 5572 additions & 2034 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.

compiler/rustc_ast/src/ast.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3445,6 +3445,7 @@ impl NormalAttr {
34453445
unsafety: Safety::Default,
34463446
path: Path::from_ident(ident),
34473447
args: AttrArgs::Empty,
3448+
span: ident.span,
34483449
},
34493450
tokens: None,
34503451
}
@@ -3456,6 +3457,15 @@ pub struct AttrItem {
34563457
pub unsafety: Safety,
34573458
pub path: Path,
34583459
pub args: AttrArgs,
3460+
/// The span of the entire attr item. For parse attrs this excludes `#[`/`]`. E.g.:
3461+
/// ```ignore (illustrative)
3462+
/// #[foo(bar)]
3463+
/// ^^^^^^^^
3464+
/// #[unsafe(no_mangle)]
3465+
/// ^^^^^^^^^^^^^^^^^
3466+
/// ```
3467+
/// For internally constructed spans (`mk_attr_*`) the exact meaning may differ.
3468+
pub span: Span,
34593469
}
34603470

34613471
/// Synthetic attributes are inserted by the compiler. They cannot be written in source code, and
@@ -4398,7 +4408,7 @@ mod size_asserts {
43984408
static_assert_size!(MetaItem, 80);
43994409
static_assert_size!(MetaItemKind, 40);
44004410
static_assert_size!(MetaItemLit, 40);
4401-
static_assert_size!(NormalAttr, 72);
4411+
static_assert_size!(NormalAttr, 80);
44024412
static_assert_size!(Param, 40);
44034413
static_assert_size!(Pat, 64);
44044414
static_assert_size!(PatKind, 48);

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl Attribute {
315315

316316
// #[deprecated = "..."]
317317
if let Some(s) = meta.value_str() {
318-
return Some(Ident { name: s, span: meta.span() });
318+
return Some(Ident { name: s, span: meta.span });
319319
}
320320

321321
// #[deprecated(note = "...")]
@@ -342,10 +342,6 @@ impl AttrItem {
342342
if let [seg] = &*self.path.segments { Some(seg.ident.name) } else { None }
343343
}
344344

345-
pub fn span(&self) -> Span {
346-
self.args.span().map_or(self.path.span, |args_span| self.path.span.to(args_span))
347-
}
348-
349345
pub fn meta_item_list(&self) -> Option<ThinVec<MetaItemInner>> {
350346
match &self.args {
351347
AttrArgs::Delimited(args) if args.delim == Delimiter::Parenthesis => {
@@ -794,6 +790,8 @@ fn mk_attr_tokens(
794790
LazyAttrTokenStream::new_direct(AttrTokenStream::new(tokens))
795791
}
796792

793+
// `span` is used for the `Attribute` and everything within it (except for any span within
794+
// `unsafety`).
797795
pub fn mk_attr_word(
798796
g: &AttrIdGenerator,
799797
style: AttrStyle,
@@ -814,9 +812,11 @@ pub fn mk_attr_word(
814812
span,
815813
));
816814

817-
mk_attr_from_item(g, AttrItem { unsafety, path, args }, tokens, style, span)
815+
mk_attr_from_item(g, AttrItem { unsafety, path, args, span }, tokens, style, span)
818816
}
819817

818+
// `span` is used for the `Attribute` and everything within it (except for any span within
819+
// `unsafety`).
820820
pub fn mk_attr_nested_word(
821821
g: &AttrIdGenerator,
822822
style: AttrStyle,
@@ -855,9 +855,11 @@ pub fn mk_attr_nested_word(
855855
span,
856856
));
857857

858-
mk_attr_from_item(g, AttrItem { unsafety, path, args: attr_args }, tokens, style, span)
858+
mk_attr_from_item(g, AttrItem { unsafety, path, args: attr_args, span }, tokens, style, span)
859859
}
860860

861+
// `span` is used for the `Attribute` and everything within it (except for any span within
862+
// `unsafety`).
861863
pub fn mk_attr_name_value_str(
862864
g: &AttrIdGenerator,
863865
style: AttrStyle,
@@ -891,7 +893,7 @@ pub fn mk_attr_name_value_str(
891893
span,
892894
));
893895

894-
mk_attr_from_item(g, AttrItem { unsafety, path, args }, tokens, style, span)
896+
mk_attr_from_item(g, AttrItem { unsafety, path, args, span }, tokens, style, span)
895897
}
896898

897899
pub fn filter_by_name(attrs: &[Attribute], name: Symbol) -> impl Iterator<Item = &Attribute> {

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -662,13 +662,12 @@ impl TokenStream {
662662

663663
// If `vec` is not empty, try to glue `tt` onto its last token. The return
664664
// value indicates if gluing took place.
665-
fn try_glue_to_last(vec: &mut Vec<TokenTree>, tt: &TokenTree) -> bool {
665+
fn try_glue_to_last(vec: &mut [TokenTree], tt: &TokenTree) -> bool {
666666
if let Some(TokenTree::Token(last_tok, Spacing::Joint | Spacing::JointHidden)) = vec.last()
667667
&& let TokenTree::Token(tok, spacing) = tt
668668
&& let Some(glued_tok) = last_tok.glue(tok)
669669
{
670-
// ...then overwrite the last token tree in `vec` with the
671-
// glued token, and skip the first token tree from `stream`.
670+
// ...then overwrite the last token tree in `vec` with the glued token.
672671
*vec.last_mut().unwrap() = TokenTree::Token(glued_tok, *spacing);
673672
true
674673
} else {
@@ -678,7 +677,11 @@ impl TokenStream {
678677

679678
/// Push `tt` onto the end of the stream, possibly gluing it to the last
680679
/// token. Uses `make_mut` to maximize efficiency.
681-
pub fn push_tree(&mut self, tt: TokenTree) {
680+
///
681+
/// This is intended for specific proc macro use. For general `TokenStream`
682+
/// construction within the compiler just build a `Vec<TokenTree>` with
683+
/// normal `Vec` operations and then do `TokenStream::new`.
684+
pub fn push_tree_with_gluing(&mut self, tt: TokenTree) {
682685
let vec_mut = Arc::make_mut(&mut self.0);
683686

684687
if Self::try_glue_to_last(vec_mut, &tt) {
@@ -691,7 +694,11 @@ impl TokenStream {
691694
/// Push `stream` onto the end of the stream, possibly gluing the first
692695
/// token tree to the last token. (No other token trees will be glued.)
693696
/// Uses `make_mut` to maximize efficiency.
694-
pub fn push_stream(&mut self, stream: TokenStream) {
697+
///
698+
/// This is intended for specific proc macro use. For general `TokenStream`
699+
/// construction within the compiler just build a `Vec<TokenTree>` with
700+
/// normal `Vec` operations and then do `TokenStream::new`.
701+
pub fn push_stream_with_gluing(&mut self, stream: TokenStream) {
695702
let vec_mut = Arc::make_mut(&mut self.0);
696703

697704
let stream_iter = stream.0.iter().cloned();
@@ -707,10 +714,6 @@ impl TokenStream {
707714
}
708715
}
709716

710-
pub fn chunks(&self, chunk_size: usize) -> core::slice::Chunks<'_, TokenTree> {
711-
self.0.chunks(chunk_size)
712-
}
713-
714717
/// Desugar doc comments like `/// foo` in the stream into `#[doc =
715718
/// r"foo"]`. Modifies the `TokenStream` via `Arc::make_mut`, but as little
716719
/// as possible.
@@ -845,9 +848,7 @@ impl FromIterator<TokenTree> for TokenStream {
845848

846849
impl StableHash for TokenStream {
847850
fn stable_hash<Hcx: StableHashCtxt>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
848-
for sub_tt in self.iter() {
849-
sub_tt.stable_hash(hcx, hasher);
850-
}
851+
self.0.as_slice().stable_hash(hcx, hasher);
851852
}
852853
}
853854

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ fn parse_cfg_attr_internal<'a>(
406406
let cfg_predicate = AttributeParser::parse_single_args(
407407
sess,
408408
attribute.span,
409-
attribute.get_normal_item().span(),
409+
attribute.get_normal_item().span,
410410
attribute.style,
411411
AttrPath { segments: attribute.path().into_boxed_slice(), span: attribute.span },
412412
Some(attribute.get_normal_item().unsafety),

compiler/rustc_attr_parsing/src/interface.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'sess> AttributeParser<'sess> {
172172
Self::parse_single_args(
173173
sess,
174174
attr.span,
175-
attr_item.span(),
175+
attr_item.span,
176176
attr.style,
177177
path,
178178
Some(attr_item.unsafety),
@@ -334,7 +334,7 @@ impl<'sess> AttributeParser<'sess> {
334334
let attr_path = AttrPath::from_ast(&n.item.path, lower_span);
335335
let parts =
336336
n.item.path.segments.iter().map(|seg| seg.ident.name).collect::<Vec<_>>();
337-
let inner_span = lower_span(n.item.span());
337+
let inner_span = lower_span(n.item.span);
338338

339339
if let Some(accept) = ATTRIBUTE_PARSERS.accepters.get(parts.as_slice()) {
340340
self.check_attribute_safety(

0 commit comments

Comments
 (0)