-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #70062 - Centril:rollup-synwle8, r=Centril
Rollup of 7 pull requests Successful merges: - #69811 (resolve: Print import chains on privacy errors) - #69870 (expand: Implement something similar to `#[cfg(accessible(path))]`) - #69881 (VariantSizeDifferences: bail on SizeOverflow) - #70000 (resolve: Fix regression in resolution of raw keywords in paths) - #70029 (Bump the bootstrap compiler) - #70046 (Use sublice patterns to avoid computing the len) - #70049 (Fiddle `ParamEnv` through to a place that used to use `ParamEnv::empty` in a buggy manner) Failed merges: r? @ghost
- Loading branch information
Showing
52 changed files
with
679 additions
and
271 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//! Implementation of the `#[cfg_accessible(path)]` attribute macro. | ||
|
||
use rustc_ast::ast; | ||
use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, MultiItemModifier}; | ||
use rustc_feature::AttributeTemplate; | ||
use rustc_parse::validate_attr; | ||
use rustc_span::symbol::sym; | ||
use rustc_span::Span; | ||
|
||
crate struct Expander; | ||
|
||
fn validate_input<'a>(ecx: &mut ExtCtxt<'_>, mi: &'a ast::MetaItem) -> Option<&'a ast::Path> { | ||
match mi.meta_item_list() { | ||
None => {} | ||
Some([]) => ecx.span_err(mi.span, "`cfg_accessible` path is not specified"), | ||
Some([_, .., l]) => ecx.span_err(l.span(), "multiple `cfg_accessible` paths are specified"), | ||
Some([nmi]) => match nmi.meta_item() { | ||
None => ecx.span_err(nmi.span(), "`cfg_accessible` path cannot be a literal"), | ||
Some(mi) => { | ||
if !mi.is_word() { | ||
ecx.span_err(mi.span, "`cfg_accessible` path cannot accept arguments"); | ||
} | ||
return Some(&mi.path); | ||
} | ||
}, | ||
} | ||
None | ||
} | ||
|
||
impl MultiItemModifier for Expander { | ||
fn expand( | ||
&self, | ||
ecx: &mut ExtCtxt<'_>, | ||
_span: Span, | ||
meta_item: &ast::MetaItem, | ||
item: Annotatable, | ||
) -> ExpandResult<Vec<Annotatable>, Annotatable> { | ||
let template = AttributeTemplate { list: Some("path"), ..Default::default() }; | ||
let attr = &ecx.attribute(meta_item.clone()); | ||
validate_attr::check_builtin_attribute(ecx.parse_sess, attr, sym::cfg_accessible, template); | ||
|
||
let path = match validate_input(ecx, meta_item) { | ||
Some(path) => path, | ||
None => return ExpandResult::Ready(Vec::new()), | ||
}; | ||
|
||
let failure_msg = "cannot determine whether the path is accessible or not"; | ||
match ecx.resolver.cfg_accessible(ecx.current_expansion.id, path) { | ||
Ok(true) => ExpandResult::Ready(vec![item]), | ||
Ok(false) => ExpandResult::Ready(Vec::new()), | ||
Err(_) => ExpandResult::Retry(item, failure_msg.into()), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.