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 14 pull requests #82460

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3ed189e
Cleanup `PpMode` and friends
LeSeulArtichaut Feb 18, 2021
dd3772e
A few more code cleanups
LeSeulArtichaut Feb 19, 2021
7ad4b7a
Replace normalize.css 3.0.0 with unminified version.
jsha Feb 20, 2021
9bbd482
Update normalize.css to 8.0.1
jsha Feb 20, 2021
7acb105
Re-minify normalize.css.
jsha Feb 20, 2021
10f2342
Remove some P-s
bugadani Feb 20, 2021
fece59b
Change `find_anon_type` method to function
0yoyoyo Feb 21, 2021
17176cc
Add indication of anonymous lifetime position
0yoyoyo Feb 21, 2021
ce1a521
Apply tidy check
0yoyoyo Feb 21, 2021
b9449a3
Add option enabling MIR inlining independently of mir-opt-level
tmiasko Feb 21, 2021
5c546be
Use optional values for inlining thresholds
tmiasko Feb 21, 2021
5f7d663
:arrow_up: rust-analyzer
lnicola Feb 22, 2021
75d1e30
Update test cases
0yoyoyo Feb 22, 2021
24c23f5
Test hexagon-enum only when llvm target is present
nagisa Feb 22, 2021
c02d210
Add tests
petrochenkov Feb 22, 2021
fc9d578
expand: Preserve order of inert attributes during expansion
petrochenkov Feb 22, 2021
e8dcc02
Add a `size()` function to WASI's `MetadataExt`.
sunfishcode Feb 22, 2021
fa74d48
Improve error msgs when found type is deref of expected
osa1 Feb 21, 2021
132ec26
Enable API documentation for `std::os::wasi`.
sunfishcode Feb 22, 2021
a6eb836
Use #[doc = include_str!()] in std
LeSeulArtichaut Dec 30, 2020
de6f1b8
Do not consider using a semicolon inside of a different-crate macro
notriddle Feb 14, 2021
df78eea
expand: Resolve and expand inner attributes on out-of-line modules
petrochenkov Feb 21, 2021
408ccd7
Rollup merge of #80534 - LeSeulArtichaut:doc-include, r=jyn514
Dylan-DPC Feb 24, 2021
d3e3d58
Rollup merge of #82090 - notriddle:consider-using-a-semicolon-here, r…
Dylan-DPC Feb 24, 2021
1975088
Rollup merge of #82269 - LeSeulArtichaut:cleanup-ppmode, r=spastorino
Dylan-DPC Feb 24, 2021
b98f608
Rollup merge of #82313 - jsha:update-normalize-css, r=GuillaumeGomez
Dylan-DPC Feb 24, 2021
2ffc621
Rollup merge of #82321 - bugadani:ast3, r=varkor
Dylan-DPC Feb 24, 2021
b0458bc
Rollup merge of #82364 - osa1:issue82361, r=estebank
Dylan-DPC Feb 24, 2021
5fdfc09
Rollup merge of #82370 - 0yoyoyo:update-issue-81650-point-anonymous-l…
Dylan-DPC Feb 24, 2021
936a488
Rollup merge of #82376 - tmiasko:inline-options, r=oli-obk
Dylan-DPC Feb 24, 2021
5878913
Rollup merge of #82394 - lnicola:rust-analyzer-2021-02-22, r=jonas-sc…
Dylan-DPC Feb 24, 2021
cc0c8f1
Rollup merge of #82399 - petrochenkov:modin2, r=Aaron1011
Dylan-DPC Feb 24, 2021
fb19700
Rollup merge of #82404 - nagisa:nagisa/hexagon-enums-llvm-comps, r=pe…
Dylan-DPC Feb 24, 2021
4f3203f
Rollup merge of #82419 - petrochenkov:inertord, r=Aaron1011
Dylan-DPC Feb 24, 2021
2d80e0b
Rollup merge of #82420 - sunfishcode:wasi-docs, r=alexcrichton
Dylan-DPC Feb 24, 2021
ec0e4c2
Rollup merge of #82421 - sunfishcode:wasi-metadata-size, r=alexcrichton
Dylan-DPC Feb 24, 2021
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
expand: Preserve order of inert attributes during expansion
  • Loading branch information
petrochenkov committed Feb 22, 2021
commit fc9d578bc5ada5162f49ed02a547cf87f2456a93
23 changes: 14 additions & 9 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ pub enum InvocationKind {
},
Attr {
attr: ast::Attribute,
// Re-insertion position for inert attributes.
pos: usize,
item: Annotatable,
// Required for resolving derive helper attributes.
derives: Vec<Path>,
Expand Down Expand Up @@ -690,7 +692,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
}
_ => unreachable!(),
},
InvocationKind::Attr { attr, mut item, derives } => match ext {
InvocationKind::Attr { attr, pos, mut item, derives } => match ext {
SyntaxExtensionKind::Attr(expander) => {
self.gate_proc_macro_input(&item);
self.gate_proc_macro_attr_item(span, &item);
Expand Down Expand Up @@ -721,7 +723,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
ExpandResult::Retry(item) => {
// Reassemble the original invocation for retrying.
return ExpandResult::Retry(Invocation {
kind: InvocationKind::Attr { attr, item, derives },
kind: InvocationKind::Attr { attr, pos, item, derives },
..invoc
});
}
Expand All @@ -739,7 +741,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
if *mark_used {
self.cx.sess.mark_attr_used(&attr);
}
item.visit_attrs(|attrs| attrs.push(attr));
item.visit_attrs(|attrs| attrs.insert(pos, attr));
fragment_kind.expect_from_annotatables(iter::once(item))
}
_ => unreachable!(),
Expand Down Expand Up @@ -1000,17 +1002,20 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {

fn collect_attr(
&mut self,
(attr, derives): (ast::Attribute, Vec<Path>),
(attr, pos, derives): (ast::Attribute, usize, Vec<Path>),
item: Annotatable,
kind: AstFragmentKind,
) -> AstFragment {
self.collect(kind, InvocationKind::Attr { attr, item, derives })
self.collect(kind, InvocationKind::Attr { attr, pos, item, derives })
}

/// If `item` is an attribute invocation, remove the attribute and return it together with
/// derives following it. We have to collect the derives in order to resolve legacy derive
/// helpers (helpers written before derives that introduce them).
fn take_first_attr(&mut self, item: &mut impl HasAttrs) -> Option<(ast::Attribute, Vec<Path>)> {
/// its position and derives following it. We have to collect the derives in order to resolve
/// legacy derive helpers (helpers written before derives that introduce them).
fn take_first_attr(
&mut self,
item: &mut impl HasAttrs,
) -> Option<(ast::Attribute, usize, Vec<Path>)> {
let mut attr = None;

item.visit_attrs(|attrs| {
Expand All @@ -1033,7 +1038,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
})
.collect();

(attr, following_derives)
(attr, attr_pos, following_derives)
})
});

Expand Down
3 changes: 1 addition & 2 deletions src/test/ui/proc-macro/derive-helper-legacy-spurious.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
extern crate test_macros;

#[derive(Empty)] //~ ERROR cannot determine resolution for the attribute macro `derive`
#[empty_helper] //~ WARN derive helper attribute is used before it is introduced
//~| WARN this was previously accepted
#[empty_helper] //~ ERROR cannot find attribute `empty_helper` in this scope
struct Foo {}

fn main() {}
10 changes: 2 additions & 8 deletions src/test/ui/proc-macro/derive-helper-legacy-spurious.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,11 @@ LL | #[derive(Empty)]
|
= note: import resolution is stuck, try simplifying macro imports

warning: derive helper attribute is used before it is introduced
error: cannot find attribute `empty_helper` in this scope
--> $DIR/derive-helper-legacy-spurious.rs:9:3
|
LL | #[derive(Empty)]
| ----- the attribute is introduced here
LL | #[empty_helper]
| ^^^^^^^^^^^^
|
= note: `#[warn(legacy_derive_helpers)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #79202 <https://github.com/rust-lang/rust/issues/79202>

error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to 3 previous errors

12 changes: 6 additions & 6 deletions src/test/ui/proc-macro/inert-attribute-order.stdout
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PRINT-ATTR INPUT (DISPLAY): /// 1
#[doc = "3"] #[doc = "4"] #[rustfmt :: attr5] /// 6
#[print_attr(nodebug)] #[rustfmt :: attr2] struct S ;
PRINT-ATTR RE-COLLECTED (DISPLAY): #[doc = " 1"] #[doc = "3"] #[doc = "4"] #[rustfmt :: attr5] #[doc = " 6"]
#[print_attr(nodebug)] #[rustfmt :: attr2] struct S ;
PRINT-ATTR INPUT (DISPLAY): #[doc = " 1"] #[doc = "3"] #[doc = "4"] #[doc = " 6"] #[rustfmt :: attr2]
#[rustfmt :: attr5] struct S ;
#[rustfmt :: attr2] #[doc = "3"] #[doc = "4"] #[rustfmt :: attr5] /// 6
#[print_attr(nodebug)] struct S ;
PRINT-ATTR RE-COLLECTED (DISPLAY): #[doc = " 1"] #[rustfmt :: attr2] #[doc = "3"] #[doc = "4"]
#[rustfmt :: attr5] #[doc = " 6"] #[print_attr(nodebug)] struct S ;
PRINT-ATTR INPUT (DISPLAY): #[doc = " 1"] #[rustfmt :: attr2] #[doc = "3"] #[doc = "4"]
#[rustfmt :: attr5] #[doc = " 6"] struct S ;
64 changes: 32 additions & 32 deletions src/test/ui/proc-macro/issue-75930-derive-cfg.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PRINT-ATTR INPUT (DISPLAY): #[allow(dead_code)] #[derive(Print)] #[print_helper(b)] #[print_helper(a)]
PRINT-ATTR INPUT (DISPLAY): #[print_helper(a)] #[allow(dead_code)] #[derive(Print)] #[print_helper(b)]
struct Foo < #[cfg(FALSE)] A, B >
{
#[cfg(FALSE)] first : String, #[cfg_attr(FALSE, deny(warnings))] second :
Expand All @@ -23,6 +23,31 @@ struct Foo < #[cfg(FALSE)] A, B >
}], #[print_helper(d)] fourth : B
}
PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
spacing: Alone,
span: $DIR/issue-75930-derive-cfg.rs:16:1: 16:2 (#0),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "print_helper",
span: $DIR/issue-75930-derive-cfg.rs:16:3: 16:15 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "a",
span: $DIR/issue-75930-derive-cfg.rs:16:16: 16:17 (#0),
},
],
span: $DIR/issue-75930-derive-cfg.rs:16:15: 16:18 (#0),
},
],
span: $DIR/issue-75930-derive-cfg.rs:16:2: 16:19 (#0),
},
Punct {
ch: '#',
spacing: Alone,
Expand Down Expand Up @@ -98,31 +123,6 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
],
span: $DIR/issue-75930-derive-cfg.rs:21:2: 21:19 (#0),
},
Punct {
ch: '#',
spacing: Alone,
span: $DIR/issue-75930-derive-cfg.rs:16:1: 16:2 (#0),
},
Group {
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "print_helper",
span: $DIR/issue-75930-derive-cfg.rs:16:3: 16:15 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "a",
span: $DIR/issue-75930-derive-cfg.rs:16:16: 16:17 (#0),
},
],
span: $DIR/issue-75930-derive-cfg.rs:16:15: 16:18 (#0),
},
],
span: $DIR/issue-75930-derive-cfg.rs:16:2: 16:19 (#0),
},
Ident {
ident: "struct",
span: $DIR/issue-75930-derive-cfg.rs:22:1: 22:7 (#0),
Expand Down Expand Up @@ -1194,7 +1194,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/issue-75930-derive-cfg.rs:22:32: 65:2 (#0),
},
]
PRINT-DERIVE INPUT (DISPLAY): #[allow(dead_code)] #[print_helper(b)] #[print_helper(a)] struct Foo < B >
PRINT-DERIVE INPUT (DISPLAY): #[print_helper(a)] #[allow(dead_code)] #[print_helper(b)] struct Foo < B >
{
second : bool, third :
[u8 ;
Expand All @@ -1217,14 +1217,14 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "allow",
ident: "print_helper",
span: $DIR/issue-75930-derive-cfg.rs:22:1: 65:2 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "dead_code",
ident: "a",
span: $DIR/issue-75930-derive-cfg.rs:22:1: 65:2 (#0),
},
],
Expand All @@ -1242,14 +1242,14 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
delimiter: Bracket,
stream: TokenStream [
Ident {
ident: "print_helper",
ident: "allow",
span: $DIR/issue-75930-derive-cfg.rs:22:1: 65:2 (#0),
},
Group {
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "b",
ident: "dead_code",
span: $DIR/issue-75930-derive-cfg.rs:22:1: 65:2 (#0),
},
],
Expand All @@ -1274,7 +1274,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
delimiter: Parenthesis,
stream: TokenStream [
Ident {
ident: "a",
ident: "b",
span: $DIR/issue-75930-derive-cfg.rs:22:1: 65:2 (#0),
},
],
Expand Down