Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #128142

Merged
merged 27 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
91af6b5
Add edge-case examples to `{count,leading,trailing}_{ones,zeros}` met…
fitzgen Jul 2, 2024
6519c14
Reset sigpipe not supported for vxworks
Jul 8, 2024
287b66b
size_of_val_raw: for length 0 this is safe to call
RalfJung Jun 8, 2024
f6fe7e4
lib: replace some `mem::forget`'s with `ManuallyDrop`
GrigorenkoPV Jul 14, 2024
c807ac0
Use verbose suggestion for "wrong # of generics"
estebank Jul 5, 2024
5c2b36a
Change suggestion message wording
estebank Jul 5, 2024
b30fdec
On generic and lifetime removal suggestion, do not leave behind stray…
estebank Jul 5, 2024
921de9d
Revert suggestion verbosity change
estebank Jul 22, 2024
2561d91
Allow unused unsafe for vxworks in read_at and write at
Jul 23, 2024
a598ca0
Disable dirfd for vxworks, Return unsupported error from set_times an…
Jul 23, 2024
5c9f376
Cfg disable on_broken_pipe_flag_used() for vxworks
Jul 23, 2024
786ad3d
Update process vxworks, set default stack size of 256 Kib for vxworks…
Jul 23, 2024
23e346e
make tidy fast without compromising case alternation
donno2048 Jul 23, 2024
b82f878
Gate AsyncFn* under async_closure feature
compiler-errors Jul 23, 2024
0ea5694
Add chroot unsupported implementation for VxWorks
Jul 24, 2024
9b87fbc
Import `core::ffi::c_void` in more places
ChrisDenton Jul 24, 2024
7cd25b1
Forbid unsafe_op_in_unsafe_fn in sys/pal/windows
ChrisDenton Jul 24, 2024
ac26b88
Improve spans on evaluated `cfg_attr`s.
nnethercote Jul 24, 2024
130d15e
Rollup merge of #126152 - RalfJung:size_of_val_raw, r=saethlin
matthiaskrgr Jul 24, 2024
720c6f1
Rollup merge of #127252 - fitzgen:edge-cases-for-bitwise-operations, …
matthiaskrgr Jul 24, 2024
91c03ef
Rollup merge of #127374 - estebank:wrong-generic-args, r=oli-obk
matthiaskrgr Jul 24, 2024
122b0b2
Rollup merge of #127457 - donno2048:master, r=albertlarsan68
matthiaskrgr Jul 24, 2024
ce523d6
Rollup merge of #127480 - biabbas:vxworks, r=workingjubilee
matthiaskrgr Jul 24, 2024
34abb96
Rollup merge of #127733 - GrigorenkoPV:don't-forget, r=Amanieu
matthiaskrgr Jul 24, 2024
e342efe
Rollup merge of #128120 - compiler-errors:async-fn-name, r=oli-obk
matthiaskrgr Jul 24, 2024
f3a7c3f
Rollup merge of #128131 - ChrisDenton:stuff, r=workingjubilee
matthiaskrgr Jul 24, 2024
2dc88bf
Rollup merge of #128133 - nnethercote:fix-cfg_attr-spans, r=petrochenkov
matthiaskrgr Jul 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve spans on evaluated cfg_attrs.
When converting something like `#![cfg_attr(cond, attr)]` into
`#![attr]`, we currently duplicate the `#` token and the `!` token. But
weirdly, there is also this comment:

// We don't really have a good span to use for the synthesized `[]`
// in `#[attr]`, so just use the span of the `#` token.

Maybe that comment used to be true? But now it is false: we can
duplicate the existing delimiters (and their spans and spacing), much
like we do for the `#` and `!`.

This commit does that, thus removing the incorrect comment, and
improving the spans on `Group`s in a few proc-macro tests.
  • Loading branch information
nnethercote committed Jul 24, 2024
commit ac26b883bf3824de42e7adbf0fa69e24f2586ddf
56 changes: 28 additions & 28 deletions compiler/rustc_expand/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::errors::{
};
use rustc_ast::ptr::P;
use rustc_ast::token::{Delimiter, Token, TokenKind};
use rustc_ast::tokenstream::{AttrTokenStream, AttrTokenTree, DelimSpacing, DelimSpan, Spacing};
use rustc_ast::tokenstream::{AttrTokenStream, AttrTokenTree, Spacing};
use rustc_ast::tokenstream::{LazyAttrTokenStream, TokenTree};
use rustc_ast::NodeId;
use rustc_ast::{self as ast, AttrStyle, Attribute, HasAttrs, HasTokens, MetaItem};
Expand Down Expand Up @@ -298,47 +298,47 @@ impl<'a> StripUnconfigured<'a> {
cfg_attr: &Attribute,
(item, item_span): (ast::AttrItem, Span),
) -> Attribute {
// We are taking an attribute of the form `#[cfg_attr(pred, attr)]`
// and producing an attribute of the form `#[attr]`. We
// have captured tokens for `attr` itself, but we need to
// synthesize tokens for the wrapper `#` and `[]`, which
// we do below.

// Use the `#` in `#[cfg_attr(pred, attr)]` as the `#` token
// for `attr` when we expand it to `#[attr]`
// Convert `#[cfg_attr(pred, attr)]` to `#[attr]`.

// Use the `#` from `#[cfg_attr(pred, attr)]` in the result `#[attr]`.
let mut orig_trees = cfg_attr.token_trees().into_iter();
let TokenTree::Token(pound_token @ Token { kind: TokenKind::Pound, .. }, _) =
orig_trees.next().unwrap().clone()
let Some(TokenTree::Token(pound_token @ Token { kind: TokenKind::Pound, .. }, _)) =
orig_trees.next()
else {
panic!("Bad tokens for attribute {cfg_attr:?}");
};

// We don't really have a good span to use for the synthesized `[]`
// in `#[attr]`, so just use the span of the `#` token.
let bracket_group = AttrTokenTree::Delimited(
DelimSpan::from_single(pound_token.span),
DelimSpacing::new(Spacing::JointHidden, Spacing::Alone),
Delimiter::Bracket,
item.tokens
.as_ref()
.unwrap_or_else(|| panic!("Missing tokens for {item:?}"))
.to_attr_token_stream(),
);
let trees = if cfg_attr.style == AttrStyle::Inner {
// For inner attributes, we do the same thing for the `!` in `#![some_attr]`
let TokenTree::Token(bang_token @ Token { kind: TokenKind::Not, .. }, _) =
orig_trees.next().unwrap().clone()
// For inner attributes, we do the same thing for the `!` in `#![attr]`.
let mut trees = if cfg_attr.style == AttrStyle::Inner {
let Some(TokenTree::Token(bang_token @ Token { kind: TokenKind::Not, .. }, _)) =
orig_trees.next()
else {
panic!("Bad tokens for attribute {cfg_attr:?}");
};
vec![
AttrTokenTree::Token(pound_token, Spacing::Joint),
AttrTokenTree::Token(bang_token, Spacing::JointHidden),
bracket_group,
]
} else {
vec![AttrTokenTree::Token(pound_token, Spacing::JointHidden), bracket_group]
vec![AttrTokenTree::Token(pound_token, Spacing::JointHidden)]
};

// And the same thing for the `[`/`]` delimiters in `#[attr]`.
let Some(TokenTree::Delimited(delim_span, delim_spacing, Delimiter::Bracket, _)) =
orig_trees.next()
else {
panic!("Bad tokens for attribute {cfg_attr:?}");
};
trees.push(AttrTokenTree::Delimited(
delim_span,
delim_spacing,
Delimiter::Bracket,
item.tokens
.as_ref()
.unwrap_or_else(|| panic!("Missing tokens for {item:?}"))
.to_attr_token_stream(),
));

let tokens = Some(LazyAttrTokenStream::new(AttrTokenStream::new(trees)));
let attr = attr::mk_attr_from_item(
&self.sess.psess.attr_id_generator,
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/proc-macro/cfg-eval-inner.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/cfg-eval-inner.rs:19:40: 19:54 (#0),
},
],
span: $DIR/cfg-eval-inner.rs:19:5: 19:6 (#0),
span: $DIR/cfg-eval-inner.rs:19:7: 19:56 (#0),
},
Punct {
ch: '#',
Expand Down Expand Up @@ -168,7 +168,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/cfg-eval-inner.rs:23:48: 23:70 (#0),
},
],
span: $DIR/cfg-eval-inner.rs:23:13: 23:14 (#0),
span: $DIR/cfg-eval-inner.rs:23:15: 23:72 (#0),
},
Literal {
kind: Integer,
Expand Down Expand Up @@ -233,7 +233,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/cfg-eval-inner.rs:32:40: 32:56 (#0),
},
],
span: $DIR/cfg-eval-inner.rs:32:5: 32:6 (#0),
span: $DIR/cfg-eval-inner.rs:32:7: 32:58 (#0),
},
Ident {
ident: "fn",
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/proc-macro/cfg-eval.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/cfg-eval.rs:22:36: 22:38 (#0),
},
],
span: $DIR/cfg-eval.rs:22:5: 22:6 (#0),
span: $DIR/cfg-eval.rs:22:6: 22:40 (#0),
},
Ident {
ident: "field_true",
Expand Down Expand Up @@ -99,7 +99,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/cfg-eval.rs:35:62: 35:73 (#0),
},
],
span: $DIR/cfg-eval.rs:35:39: 35:40 (#0),
span: $DIR/cfg-eval.rs:35:40: 35:75 (#0),
},
Group {
delimiter: Parenthesis,
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/expand-to-derive.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
span: $DIR/expand-to-derive.rs:27:28: 27:39 (#0),
},
],
span: $DIR/expand-to-derive.rs:27:5: 27:6 (#0),
span: $DIR/expand-to-derive.rs:27:6: 27:41 (#0),
},
Ident {
ident: "struct",
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/inner-attrs.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
span: $DIR/inner-attrs.rs:41:52: 41:59 (#0),
},
],
span: $DIR/inner-attrs.rs:41:17: 41:18 (#0),
span: $DIR/inner-attrs.rs:41:19: 41:61 (#0),
},
Ident {
ident: "true",
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/proc-macro/issue-75930-derive-cfg.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/issue-75930-derive-cfg.rs:50:29: 50:40 (#0),
},
],
span: $DIR/issue-75930-derive-cfg.rs:50:1: 50:2 (#0),
span: $DIR/issue-75930-derive-cfg.rs:50:2: 50:42 (#0),
},
Punct {
ch: '#',
Expand Down Expand Up @@ -1395,7 +1395,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
span: $DIR/issue-75930-derive-cfg.rs:50:29: 50:40 (#0),
},
],
span: $DIR/issue-75930-derive-cfg.rs:50:1: 50:2 (#0),
span: $DIR/issue-75930-derive-cfg.rs:50:2: 50:42 (#0),
},
Punct {
ch: '#',
Expand Down Expand Up @@ -1571,7 +1571,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
span: $DIR/issue-75930-derive-cfg.rs:63:41: 63:51 (#0),
},
],
span: $DIR/issue-75930-derive-cfg.rs:63:13: 63:14 (#0),
span: $DIR/issue-75930-derive-cfg.rs:63:14: 63:53 (#0),
},
Ident {
ident: "false",
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/proc-macro/macro-rules-derive-cfg.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
span: $DIR/macro-rules-derive-cfg.rs:19:59: 19:66 (#3),
},
],
span: $DIR/macro-rules-derive-cfg.rs:19:25: 19:26 (#3),
span: $DIR/macro-rules-derive-cfg.rs:19:26: 19:68 (#3),
},
Punct {
ch: '#',
Expand All @@ -113,7 +113,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
span: $DIR/macro-rules-derive-cfg.rs:26:47: 26:55 (#0),
},
],
span: $DIR/macro-rules-derive-cfg.rs:26:13: 26:14 (#0),
span: $DIR/macro-rules-derive-cfg.rs:26:14: 26:57 (#0),
},
Group {
delimiter: Brace,
Expand Down Expand Up @@ -146,7 +146,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
span: $DIR/macro-rules-derive-cfg.rs:27:34: 27:42 (#0),
},
],
span: $DIR/macro-rules-derive-cfg.rs:27:5: 27:6 (#0),
span: $DIR/macro-rules-derive-cfg.rs:27:7: 27:44 (#0),
},
Literal {
kind: Integer,
Expand Down
Loading