Auto merge of #75126 - JohnTitor:rollup-aejluzx, r=JohnTitor

Rollup of 8 pull requests

Successful merges:

 - #74759 (add `unsigned_abs` to signed integers)
 - #75043 (rustc_ast: `(Nested)MetaItem::check_name` -> `has_name`)
 - #75056 (Lint path statements to suggest using drop when the type needs drop)
 - #75081 (Fix logging for rustdoc)
 - #75083 (Do not trigger `unused_braces` for `while let`)
 - #75084 (Stabilize Ident::new_raw)
 - #75103 (Disable building rust-analyzer on riscv64)
 - #75106 (Enable docs on in the x86_64-unknown-linux-musl manifest)

Failed merges:

r? @ghost
This commit is contained in:
bors 2020-08-04 01:48:32 +00:00
commit 60c2e8d438
46 changed files with 297 additions and 149 deletions

View File

@ -1601,6 +1601,29 @@ $EndFeature, "
}
}
doc_comment! {
concat!("Computes the absolute value of `self` without any wrapping
or panicking.
# Examples
Basic usage:
```
", $Feature, "#![feature(unsigned_abs)]
assert_eq!(100", stringify!($SelfT), ".unsigned_abs(), 100", stringify!($UnsignedT), ");
assert_eq!((-100", stringify!($SelfT), ").unsigned_abs(), 100", stringify!($UnsignedT), ");
assert_eq!((-128i8).unsigned_abs(), 128u8);",
$EndFeature, "
```"),
#[unstable(feature = "unsigned_abs", issue = "74913")]
#[inline]
pub const fn unsigned_abs(self) -> $UnsignedT {
self.wrapping_abs() as $UnsignedT
}
}
doc_comment! {
concat!("Wrapping (modular) exponentiation. Computes `self.pow(exp)`,
wrapping around at the boundary of the type.

View File

@ -848,7 +848,7 @@ impl Ident {
/// Creates a new `Ident` with the given `string` as well as the specified
/// `span`.
/// The `string` argument must be a valid identifier permitted by the
/// language, otherwise the function will panic.
/// language (including keywords, e.g. `self` or `fn`). Otherwise, the function will panic.
///
/// Note that `span`, currently in rustc, configures the hygiene information
/// for this identifier.
@ -870,7 +870,10 @@ impl Ident {
}
/// Same as `Ident::new`, but creates a raw identifier (`r#ident`).
#[unstable(feature = "proc_macro_raw_ident", issue = "54723")]
/// The `string` argument be a valid identifier permitted by the language
/// (including keywords, e.g. `fn`). Keywords which are usable in path segments
/// (e.g. `self`, `super`) are not supported, and will cause a panic.
#[stable(feature = "proc_macro_raw_ident", since = "1.47.0")]
pub fn new_raw(string: &str, span: Span) -> Ident {
Ident(bridge::client::Ident::new(string, span.0, true))
}

View File

@ -1355,7 +1355,7 @@ pub struct RustAnalyzer {
}
impl Step for RustAnalyzer {
type Output = PathBuf;
type Output = Option<PathBuf>;
const ONLY_HOSTS: bool = true;
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
@ -1373,11 +1373,17 @@ impl Step for RustAnalyzer {
});
}
fn run(self, builder: &Builder<'_>) -> PathBuf {
fn run(self, builder: &Builder<'_>) -> Option<PathBuf> {
let compiler = self.compiler;
let target = self.target;
assert!(builder.config.extended);
if target.contains("riscv64") {
// riscv64 currently has an LLVM bug that makes rust-analyzer unable
// to build. See #74813 for details.
return None;
}
let src = builder.src.join("src/tools/rust-analyzer");
let release_num = builder.release_num("rust-analyzer/crates/rust-analyzer");
let name = pkgname(builder, "rust-analyzer");
@ -1431,7 +1437,7 @@ impl Step for RustAnalyzer {
builder.info(&format!("Dist rust-analyzer stage{} ({})", compiler.stage, target));
let _time = timeit(builder);
builder.run(&mut cmd);
distdir(builder).join(format!("{}-{}.tar.gz", name, target.triple))
Some(distdir(builder).join(format!("{}-{}.tar.gz", name, target.triple)))
}
}
@ -1789,7 +1795,7 @@ impl Step for Extended {
tarballs.push(rustc_installer);
tarballs.push(cargo_installer);
tarballs.extend(rls_installer.clone());
tarballs.push(rust_analyzer_installer.clone());
tarballs.extend(rust_analyzer_installer.clone());
tarballs.push(clippy_installer);
tarballs.extend(miri_installer.clone());
tarballs.extend(rustfmt_installer.clone());
@ -1867,7 +1873,9 @@ impl Step for Extended {
if rls_installer.is_none() {
contents = filter(&contents, "rls");
}
contents = filter(&contents, "rust-analyzer");
if rust_analyzer_installer.is_none() {
contents = filter(&contents, "rust-analyzer");
}
if miri_installer.is_none() {
contents = filter(&contents, "miri");
}
@ -1914,7 +1922,9 @@ impl Step for Extended {
if rls_installer.is_some() {
prepare("rls");
}
prepare("rust-analyzer");
if rust_analyzer_installer.is_some() {
prepare("rust-analyzer");
}
if miri_installer.is_some() {
prepare("miri");
}
@ -1976,7 +1986,9 @@ impl Step for Extended {
if rls_installer.is_some() {
prepare("rls");
}
prepare("rust-analyzer");
if rust_analyzer_installer.is_some() {
prepare("rust-analyzer");
}
if miri_installer.is_some() {
prepare("miri");
}
@ -2076,23 +2088,25 @@ impl Step for Extended {
.arg(etc.join("msi/remove-duplicates.xsl")),
);
}
builder.run(
Command::new(&heat)
.current_dir(&exe)
.arg("dir")
.arg("rust-analyzer")
.args(&heat_flags)
.arg("-cg")
.arg("RustAnalyzerGroup")
.arg("-dr")
.arg("RustAnalyzer")
.arg("-var")
.arg("var.RustAnalyzerDir")
.arg("-out")
.arg(exe.join("RustAnalyzerGroup.wxs"))
.arg("-t")
.arg(etc.join("msi/remove-duplicates.xsl")),
);
if rust_analyzer_installer.is_some() {
builder.run(
Command::new(&heat)
.current_dir(&exe)
.arg("dir")
.arg("rust-analyzer")
.args(&heat_flags)
.arg("-cg")
.arg("RustAnalyzerGroup")
.arg("-dr")
.arg("RustAnalyzer")
.arg("-var")
.arg("var.RustAnalyzerDir")
.arg("-out")
.arg(exe.join("RustAnalyzerGroup.wxs"))
.arg("-t")
.arg(etc.join("msi/remove-duplicates.xsl")),
);
}
builder.run(
Command::new(&heat)
.current_dir(&exe)
@ -2186,7 +2200,9 @@ impl Step for Extended {
if rls_installer.is_some() {
cmd.arg("-dRlsDir=rls");
}
cmd.arg("-dRustAnalyzerDir=rust-analyzer");
if rust_analyzer_installer.is_some() {
cmd.arg("-dRustAnalyzerDir=rust-analyzer");
}
if miri_installer.is_some() {
cmd.arg("-dMiriDir=miri");
}
@ -2206,7 +2222,9 @@ impl Step for Extended {
if rls_installer.is_some() {
candle("RlsGroup.wxs".as_ref());
}
candle("RustAnalyzerGroup.wxs".as_ref());
if rust_analyzer_installer.is_some() {
candle("RustAnalyzerGroup.wxs".as_ref());
}
if miri_installer.is_some() {
candle("MiriGroup.wxs".as_ref());
}
@ -2244,7 +2262,9 @@ impl Step for Extended {
if rls_installer.is_some() {
cmd.arg("RlsGroup.wixobj");
}
cmd.arg("RustAnalyzerGroup.wixobj");
if rust_analyzer_installer.is_some() {
cmd.arg("RustAnalyzerGroup.wixobj");
}
if miri_installer.is_some() {
cmd.arg("MiriGroup.wixobj");
}

View File

@ -100,8 +100,8 @@ impl NestedMetaItem {
}
/// Returns `true` if this list item is a MetaItem with a name of `name`.
pub fn check_name(&self, name: Symbol) -> bool {
self.meta_item().map_or(false, |meta_item| meta_item.check_name(name))
pub fn has_name(&self, name: Symbol) -> bool {
self.meta_item().map_or(false, |meta_item| meta_item.has_name(name))
}
/// For a single-segment meta item, returns its name; otherwise, returns `None`.
@ -173,8 +173,13 @@ impl Attribute {
}
}
/// Returns `true` if the attribute's path matches the argument. If it matches, then the
/// attribute is marked as used.
/// Returns `true` if the attribute's path matches the argument.
/// If it matches, then the attribute is marked as used.
/// Should only be used by rustc, other tools can use `has_name` instead,
/// because only rustc is supposed to report the `unused_attributes` lint.
/// `MetaItem` and `NestedMetaItem` are produced by "lowering" an `Attribute`
/// and don't have identity, so they only has the `has_name` method,
/// and you need to mark the original `Attribute` as used when necessary.
pub fn check_name(&self, name: Symbol) -> bool {
let matches = self.has_name(name);
if matches {
@ -278,7 +283,7 @@ impl MetaItem {
}
}
pub fn check_name(&self, name: Symbol) -> bool {
pub fn has_name(&self, name: Symbol) -> bool {
self.path == name
}
@ -405,7 +410,7 @@ pub fn mk_doc_comment(style: AttrStyle, comment: Symbol, span: Span) -> Attribut
}
pub fn list_contains_name(items: &[NestedMetaItem], name: Symbol) -> bool {
items.iter().any(|item| item.check_name(name))
items.iter().any(|item| item.has_name(name))
}
pub fn contains_name(attrs: &[Attribute], name: Symbol) -> bool {

View File

@ -243,7 +243,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
if attr.check_name(sym::doc) {
for nested_meta in attr.meta_item_list().unwrap_or_default() {
macro_rules! gate_doc { ($($name:ident => $feature:ident)*) => {
$(if nested_meta.check_name(sym::$name) {
$(if nested_meta.has_name(sym::$name) {
let msg = concat!("`#[doc(", stringify!($name), ")]` is experimental");
gate_feature_post!(self, $feature, attr.span, msg);
})*
@ -314,7 +314,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
ast::ItemKind::Struct(..) => {
for attr in attr::filter_by_name(&i.attrs[..], sym::repr) {
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
if item.check_name(sym::simd) {
if item.has_name(sym::simd) {
gate_feature_post!(
&self,
repr_simd,

View File

@ -92,9 +92,9 @@ pub fn find_unwind_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> Op
if let Some(meta) = attr.meta() {
if let MetaItemKind::List(items) = meta.kind {
if items.len() == 1 {
if items[0].check_name(sym::allowed) {
if items[0].has_name(sym::allowed) {
return Some(UnwindAttr::Allowed);
} else if items[0].check_name(sym::aborts) {
} else if items[0].has_name(sym::aborts) {
return Some(UnwindAttr::Aborts);
}
}
@ -168,7 +168,7 @@ pub fn contains_feature_attr(attrs: &[Attribute], feature_name: Symbol) -> bool
item.check_name(sym::feature)
&& item
.meta_item_list()
.map(|list| list.iter().any(|mi| mi.is_word() && mi.check_name(feature_name)))
.map(|list| list.iter().any(|mi| mi.is_word() && mi.has_name(feature_name)))
.unwrap_or(false)
})
}
@ -505,7 +505,7 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat
}
fn try_gate_cfg(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Features>) {
let gate = find_gated_cfg(|sym| cfg.check_name(sym));
let gate = find_gated_cfg(|sym| cfg.has_name(sym));
if let (Some(feats), Some(gated_cfg)) = (features, gate) {
gate_cfg(&gated_cfg, cfg.span, sess, feats);
}
@ -898,7 +898,7 @@ pub fn find_repr_attrs(sess: &ParseSess, attr: &Attribute) -> Vec<ReprAttr> {
}
} else {
if let Some(meta_item) = item.meta_item() {
if meta_item.check_name(sym::align) {
if meta_item.has_name(sym::align) {
if let MetaItemKind::NameValue(ref value) = meta_item.kind {
recognised = true;
let mut err = struct_span_err!(

View File

@ -143,7 +143,7 @@ impl<'a> CollectProcMacros<'a> {
let attributes_attr = list.get(1);
let proc_attrs: Vec<_> = if let Some(attr) = attributes_attr {
if !attr.check_name(sym::attributes) {
if !attr.has_name(sym::attributes) {
self.handler.span_err(attr.span(), "second argument must be `attributes`")
}
attr.meta_item_list()

View File

@ -336,7 +336,7 @@ fn should_panic(cx: &ExtCtxt<'_>, i: &ast::Item) -> ShouldPanic {
Some(list) => {
let msg = list
.iter()
.find(|mi| mi.check_name(sym::expected))
.find(|mi| mi.has_name(sym::expected))
.and_then(|mi| mi.meta_item())
.and_then(|mi| mi.value_str());
if list.len() != 1 || msg.is_none() {

View File

@ -1644,14 +1644,14 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
}
if let Some(list) = at.meta_item_list() {
if !list.iter().any(|it| it.check_name(sym::include)) {
if !list.iter().any(|it| it.has_name(sym::include)) {
return noop_visit_attribute(at, self);
}
let mut items = vec![];
for mut it in list {
if !it.check_name(sym::include) {
if !it.has_name(sym::include) {
items.push({
noop_visit_meta_list_item(&mut it, self);
it

View File

@ -149,7 +149,7 @@ impl AssertModuleSource<'tcx> {
fn field(&self, attr: &ast::Attribute, name: Symbol) -> Symbol {
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
if item.check_name(name) {
if item.has_name(name) {
if let Some(value) = item.value_str() {
return value;
} else {

View File

@ -231,7 +231,7 @@ impl DirtyCleanVisitor<'tcx> {
fn labels(&self, attr: &Attribute) -> Option<Labels> {
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
if item.check_name(LABEL) {
if item.has_name(LABEL) {
let value = expect_associated_value(self.tcx, &item);
return Some(self.resolve_labels(&item, value));
}
@ -242,7 +242,7 @@ impl DirtyCleanVisitor<'tcx> {
/// `except=` attribute value
fn except(&self, attr: &Attribute) -> Labels {
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
if item.check_name(EXCEPT) {
if item.has_name(EXCEPT) {
let value = expect_associated_value(self.tcx, &item);
return self.resolve_labels(&item, value);
}
@ -474,15 +474,15 @@ fn check_config(tcx: TyCtxt<'_>, attr: &Attribute) -> bool {
debug!("check_config: config={:?}", config);
let (mut cfg, mut except, mut label) = (None, false, false);
for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
if item.check_name(CFG) {
if item.has_name(CFG) {
let value = expect_associated_value(tcx, &item);
debug!("check_config: searching for cfg {:?}", value);
cfg = Some(config.contains(&(value, None)));
}
if item.check_name(LABEL) {
if item.has_name(LABEL) {
label = true;
}
if item.check_name(EXCEPT) {
if item.has_name(EXCEPT) {
except = true;
}
}

View File

@ -330,7 +330,7 @@ fn has_doc(attr: &ast::Attribute) -> bool {
if let Some(list) = attr.meta_item_list() {
for meta in list {
if meta.check_name(sym::include) || meta.check_name(sym::hidden) {
if meta.has_name(sym::include) || meta.has_name(sym::hidden) {
return true;
}
}

View File

@ -275,10 +275,26 @@ declare_lint_pass!(PathStatements => [PATH_STATEMENTS]);
impl<'tcx> LateLintPass<'tcx> for PathStatements {
fn check_stmt(&mut self, cx: &LateContext<'_>, s: &hir::Stmt<'_>) {
if let hir::StmtKind::Semi(ref expr) = s.kind {
if let hir::StmtKind::Semi(expr) = s.kind {
if let hir::ExprKind::Path(_) = expr.kind {
cx.struct_span_lint(PATH_STATEMENTS, s.span, |lint| {
lint.build("path statement with no effect").emit()
let ty = cx.typeck_results().expr_ty(expr);
if ty.needs_drop(cx.tcx, cx.param_env) {
let mut lint = lint.build("path statement drops value");
if let Ok(snippet) = cx.sess().source_map().span_to_snippet(expr.span) {
lint.span_suggestion(
s.span,
"use `drop` to clarify the intent",
format!("drop({});", snippet),
Applicability::MachineApplicable,
);
} else {
lint.span_help(s.span, "use `drop` to clarify the intent");
}
lint.emit()
} else {
lint.build("path statement with no effect").emit()
}
});
}
}
@ -520,7 +536,10 @@ trait UnusedDelimLint {
(cond, UnusedDelimsCtx::IfCond, true, Some(left), Some(right))
}
While(ref cond, ref block, ..) => {
// Do not lint `unused_braces` in `while let` expressions.
While(ref cond, ref block, ..)
if !matches!(cond.kind, Let(_, _)) || Self::LINT_EXPR_IN_PATTERN_MATCHING_CTX =>
{
let left = e.span.lo() + rustc_span::BytePos(5);
let right = block.span.lo();
(cond, UnusedDelimsCtx::WhileCond, true, Some(left), Some(right))

View File

@ -58,7 +58,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
let mut kind_specified = false;
for item in items.iter() {
if item.check_name(sym::kind) {
if item.has_name(sym::kind) {
kind_specified = true;
let kind = match item.value_str() {
Some(name) => name,
@ -84,9 +84,9 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
NativeLibKind::Unspecified
}
};
} else if item.check_name(sym::name) {
} else if item.has_name(sym::name) {
lib.name = item.value_str();
} else if item.check_name(sym::cfg) {
} else if item.has_name(sym::cfg) {
let cfg = match item.meta_item_list() {
Some(list) => list,
None => continue, // skip like historical compilers
@ -98,7 +98,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> {
} else {
self.tcx.sess.span_err(cfg[0].span(), "invalid argument for `cfg(..)`");
}
} else if item.check_name(sym::wasm_import_module) {
} else if item.has_name(sym::wasm_import_module) {
match item.value_str() {
Some(s) => lib.wasm_import_module = Some(s),
None => {

View File

@ -339,7 +339,7 @@ impl RustcMirAttrs {
.flat_map(|attr| attr.meta_item_list().into_iter().flat_map(|v| v.into_iter()));
for attr in rustc_mir_attrs {
let attr_result = if attr.check_name(sym::borrowck_graphviz_postflow) {
let attr_result = if attr.has_name(sym::borrowck_graphviz_postflow) {
Self::set_field(&mut ret.basename_and_suffix, tcx, &attr, |s| {
let path = PathBuf::from(s.to_string());
match path.file_name() {
@ -350,7 +350,7 @@ impl RustcMirAttrs {
}
}
})
} else if attr.check_name(sym::borrowck_graphviz_format) {
} else if attr.has_name(sym::borrowck_graphviz_format) {
Self::set_field(&mut ret.formatter, tcx, &attr, |s| match s {
sym::gen_kill | sym::two_phase => Ok(s),
_ => {

View File

@ -34,7 +34,7 @@ pub(crate) fn has_rustc_mir_with(attrs: &[ast::Attribute], name: Symbol) -> Opti
let items = attr.meta_item_list();
for item in items.iter().flat_map(|l| l.iter()) {
match item.meta_item() {
Some(mi) if mi.check_name(name) => return Some(mi.clone()),
Some(mi) if mi.has_name(name) => return Some(mi.clone()),
_ => continue,
}
}

View File

@ -222,7 +222,7 @@ impl CheckAttrVisitor<'tcx> {
if let Some(mi) = attr.meta() {
if let Some(list) = mi.meta_item_list() {
for meta in list {
if meta.check_name(sym::alias) {
if meta.has_name(sym::alias) {
if !meta.is_value_str()
|| meta
.value_str()

View File

@ -832,10 +832,10 @@ impl<'tcx> SaveContext<'tcx> {
if let Some(meta_list) = attr.meta_item_list() {
meta_list
.into_iter()
.filter(|it| it.check_name(sym::include))
.filter(|it| it.has_name(sym::include))
.filter_map(|it| it.meta_item_list().map(|l| l.to_owned()))
.flat_map(|it| it)
.filter(|meta| meta.check_name(sym::contents))
.filter(|meta| meta.has_name(sym::contents))
.filter_map(|meta| meta.value_str())
.for_each(|val| {
result.push_str(&val.as_str());

View File

@ -95,27 +95,27 @@ impl<'tcx> OnUnimplementedDirective {
};
for item in item_iter {
if item.check_name(sym::message) && message.is_none() {
if item.has_name(sym::message) && message.is_none() {
if let Some(message_) = item.value_str() {
message = parse_value(message_)?;
continue;
}
} else if item.check_name(sym::label) && label.is_none() {
} else if item.has_name(sym::label) && label.is_none() {
if let Some(label_) = item.value_str() {
label = parse_value(label_)?;
continue;
}
} else if item.check_name(sym::note) && note.is_none() {
} else if item.has_name(sym::note) && note.is_none() {
if let Some(note_) = item.value_str() {
note = parse_value(note_)?;
continue;
}
} else if item.check_name(sym::enclosing_scope) && enclosing_scope.is_none() {
} else if item.has_name(sym::enclosing_scope) && enclosing_scope.is_none() {
if let Some(enclosing_scope_) = item.value_str() {
enclosing_scope = parse_value(enclosing_scope_)?;
continue;
}
} else if item.check_name(sym::on)
} else if item.has_name(sym::on)
&& is_root
&& message.is_none()
&& label.is_none()

View File

@ -2231,7 +2231,7 @@ fn from_target_feature(
let rust_features = tcx.features();
for item in list {
// Only `enable = ...` is accepted in the meta-item list.
if !item.check_name(sym::enable) {
if !item.has_name(sym::enable) {
bad_item(item.span());
continue;
}
@ -2483,11 +2483,11 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
no_sanitize_span = Some(attr.span);
if let Some(list) = attr.meta_item_list() {
for item in list.iter() {
if item.check_name(sym::address) {
if item.has_name(sym::address) {
codegen_fn_attrs.no_sanitize |= SanitizerSet::ADDRESS;
} else if item.check_name(sym::memory) {
} else if item.has_name(sym::memory) {
codegen_fn_attrs.no_sanitize |= SanitizerSet::MEMORY;
} else if item.check_name(sym::thread) {
} else if item.has_name(sym::thread) {
codegen_fn_attrs.no_sanitize |= SanitizerSet::THREAD;
} else {
tcx.sess

View File

@ -113,7 +113,7 @@ impl Clean<ExternalCrate> for CrateNum {
let mut prim = None;
for attr in attrs.lists(sym::doc) {
if let Some(v) = attr.value_str() {
if attr.check_name(sym::primitive) {
if attr.has_name(sym::primitive) {
prim = PrimitiveType::from_symbol(v);
if prim.is_some() {
break;
@ -168,7 +168,7 @@ impl Clean<ExternalCrate> for CrateNum {
let mut keyword = None;
for attr in attrs.lists(sym::doc) {
if let Some(v) = attr.value_str() {
if attr.check_name(sym::keyword) {
if attr.has_name(sym::keyword) {
if v.is_doc_keyword() {
keyword = Some(v.to_string());
break;
@ -2157,7 +2157,7 @@ impl Clean<Vec<Item>> for doctree::ExternCrate<'_> {
fn clean(&self, cx: &DocContext<'_>) -> Vec<Item> {
let please_inline = self.vis.node.is_pub()
&& self.attrs.iter().any(|a| {
a.check_name(sym::doc)
a.has_name(sym::doc)
&& match a.meta_item_list() {
Some(l) => attr::list_contains_name(&l, sym::inline),
None => false,
@ -2197,7 +2197,7 @@ impl Clean<Vec<Item>> for doctree::Import<'_> {
// Don't inline doc(hidden) imports so they can be stripped at a later stage.
let mut denied = !self.vis.node.is_pub()
|| self.attrs.iter().any(|a| {
a.check_name(sym::doc)
a.has_name(sym::doc)
&& match a.meta_item_list() {
Some(l) => {
attr::list_contains_name(&l, sym::no_inline)

View File

@ -210,7 +210,7 @@ impl Item {
}
pub fn is_non_exhaustive(&self) -> bool {
self.attrs.other_attrs.iter().any(|a| a.check_name(sym::non_exhaustive))
self.attrs.other_attrs.iter().any(|a| a.has_name(sym::non_exhaustive))
}
/// Returns a documentation-level item type from the item.
@ -309,7 +309,7 @@ impl<'a> Iterator for ListAttributesIter<'a> {
for attr in &mut self.attrs {
if let Some(list) = attr.meta_item_list() {
if attr.check_name(self.name) {
if attr.has_name(self.name) {
self.current_list = list.into_iter();
if let Some(nested) = self.current_list.next() {
return Some(nested);
@ -345,7 +345,7 @@ pub trait NestedAttributesExt {
impl<I: IntoIterator<Item = ast::NestedMetaItem>> NestedAttributesExt for I {
fn has_word(self, word: Symbol) -> bool {
self.into_iter().any(|attr| attr.is_word() && attr.check_name(word))
self.into_iter().any(|attr| attr.is_word() && attr.has_name(word))
}
}
@ -425,7 +425,7 @@ impl Attributes {
if let ast::MetaItemKind::List(ref nmis) = mi.kind {
if nmis.len() == 1 {
if let MetaItem(ref cfg_mi) = nmis[0] {
if cfg_mi.check_name(sym::cfg) {
if cfg_mi.has_name(sym::cfg) {
if let ast::MetaItemKind::List(ref cfg_nmis) = cfg_mi.kind {
if cfg_nmis.len() == 1 {
if let MetaItem(ref content_mi) = cfg_nmis[0] {
@ -447,7 +447,7 @@ impl Attributes {
pub fn extract_include(mi: &ast::MetaItem) -> Option<(String, String)> {
mi.meta_item_list().and_then(|list| {
for meta in list {
if meta.check_name(sym::include) {
if meta.has_name(sym::include) {
// the actual compiled `#[doc(include="filename")]` gets expanded to
// `#[doc(include(file="filename", contents="file contents")]` so we need to
// look for that instead
@ -456,11 +456,11 @@ impl Attributes {
let mut contents: Option<String> = None;
for it in list {
if it.check_name(sym::file) {
if it.has_name(sym::file) {
if let Some(name) = it.value_str() {
filename = Some(name.to_string());
}
} else if it.check_name(sym::contents) {
} else if it.has_name(sym::contents) {
if let Some(docs) = it.value_str() {
contents = Some(docs.to_string());
}
@ -482,12 +482,12 @@ impl Attributes {
pub fn has_doc_flag(&self, flag: Symbol) -> bool {
for attr in &self.other_attrs {
if !attr.check_name(sym::doc) {
if !attr.has_name(sym::doc) {
continue;
}
if let Some(items) = attr.meta_item_list() {
if items.iter().filter_map(|i| i.meta_item()).any(|it| it.check_name(flag)) {
if items.iter().filter_map(|i| i.meta_item()).any(|it| it.has_name(flag)) {
return true;
}
}
@ -521,7 +521,7 @@ impl Attributes {
}
None
} else {
if attr.check_name(sym::doc) {
if attr.has_name(sym::doc) {
if let Some(mi) = attr.meta() {
if let Some(cfg_mi) = Attributes::extract_cfg(&mi) {
// Extracted #[doc(cfg(...))]
@ -548,7 +548,7 @@ impl Attributes {
// treat #[target_feature(enable = "feat")] attributes as if they were
// #[doc(cfg(target_feature = "feat"))] attributes as well
for attr in attrs.lists(sym::target_feature) {
if attr.check_name(sym::enable) {
if attr.has_name(sym::enable) {
if let Some(feat) = attr.value_str() {
let meta = attr::mk_name_value_item_str(
Ident::with_dummy_span(sym::target_feature),
@ -648,7 +648,7 @@ impl Attributes {
pub fn get_doc_aliases(&self) -> FxHashSet<String> {
self.other_attrs
.lists(sym::doc)
.filter(|a| a.check_name(sym::alias))
.filter(|a| a.has_name(sym::alias))
.filter_map(|a| a.value_str().map(|s| s.to_string().replace("\"", "")))
.filter(|v| !v.is_empty())
.collect::<FxHashSet<_>>()

View File

@ -48,7 +48,7 @@ pub fn extern_location(
// external crate
e.attrs
.lists(sym::doc)
.filter(|a| a.check_name(sym::html_root_url))
.filter(|a| a.has_name(sym::html_root_url))
.filter_map(|a| a.value_str())
.map(|url| {
let mut url = url.to_string();

View File

@ -43,7 +43,7 @@ extern crate rustc_trait_selection;
extern crate rustc_typeck;
extern crate test as testing;
#[macro_use]
extern crate log;
extern crate tracing as log;
use std::default::Default;
use std::env;

View File

@ -175,17 +175,17 @@ fn scrape_test_config(krate: &::rustc_hir::Crate<'_>) -> TestOptions {
.item
.attrs
.iter()
.filter(|a| a.check_name(sym::doc))
.filter(|a| a.has_name(sym::doc))
.flat_map(|a| a.meta_item_list().unwrap_or_else(Vec::new))
.filter(|a| a.check_name(sym::test))
.filter(|a| a.has_name(sym::test))
.collect();
let attrs = test_attrs.iter().flat_map(|a| a.meta_item_list().unwrap_or(&[]));
for attr in attrs {
if attr.check_name(sym::no_crate_inject) {
if attr.has_name(sym::no_crate_inject) {
opts.no_crate_inject = true;
}
if attr.check_name(sym::attr) {
if attr.has_name(sym::attr) {
if let Some(l) = attr.meta_item_list() {
for item in l {
opts.attrs.push(pprust::meta_list_item_to_string(item));

View File

@ -165,11 +165,11 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
) {
debug!("visiting fn");
let macro_kind = item.attrs.iter().find_map(|a| {
if a.check_name(sym::proc_macro) {
if a.has_name(sym::proc_macro) {
Some(MacroKind::Bang)
} else if a.check_name(sym::proc_macro_derive) {
} else if a.has_name(sym::proc_macro_derive) {
Some(MacroKind::Derive)
} else if a.check_name(sym::proc_macro_attribute) {
} else if a.has_name(sym::proc_macro_attribute) {
Some(MacroKind::Attr)
} else {
None
@ -189,7 +189,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
let mut helpers = Vec::new();
for mi in item.attrs.lists(sym::proc_macro_derive) {
if !mi.check_name(sym::attributes) {
if !mi.has_name(sym::attributes) {
continue;
}
@ -419,8 +419,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
// anything as it will probably be stripped anyway.
if item.vis.node.is_pub() && self.inside_public_path {
let please_inline = item.attrs.iter().any(|item| match item.meta_item_list() {
Some(ref list) if item.check_name(sym::doc) => {
list.iter().any(|i| i.check_name(sym::inline))
Some(ref list) if item.has_name(sym::doc) => {
list.iter().any(|i| i.has_name(sym::inline))
}
_ => false,
});

View File

@ -15,15 +15,8 @@ fn main() {
while let Some(_) = ((yield)) {} //~ ERROR: unnecessary parentheses
{{yield}}; //~ ERROR: unnecessary braces
{( yield )}; //~ ERROR: unnecessary parentheses
// FIXME: Reduce duplicate warnings.
// Perhaps we should tweak checks in `BlockRetValue`?
while let Some(_) = {(yield)} {}
//~^ ERROR: unnecessary braces
//~| ERROR: unnecessary parentheses
while let Some(_) = {{yield}} {}
//~^ ERROR: unnecessary braces
//~| ERROR: unnecessary braces
while let Some(_) = {(yield)} {} //~ ERROR: unnecessary parentheses
while let Some(_) = {{yield}} {} //~ ERROR: unnecessary braces
// FIXME: It'd be great if we could also warn them.
((yield));

View File

@ -34,29 +34,17 @@ error: unnecessary parentheses around block return value
LL | {( yield )};
| ^^^^^^^^^ help: remove these parentheses
error: unnecessary braces around `let` scrutinee expression
--> $DIR/issue-74883-unused-paren-baren-yield.rs:21:29
|
LL | while let Some(_) = {(yield)} {}
| ^^^^^^^^^ help: remove these braces
error: unnecessary parentheses around block return value
--> $DIR/issue-74883-unused-paren-baren-yield.rs:21:30
--> $DIR/issue-74883-unused-paren-baren-yield.rs:18:30
|
LL | while let Some(_) = {(yield)} {}
| ^^^^^^^ help: remove these parentheses
error: unnecessary braces around `let` scrutinee expression
--> $DIR/issue-74883-unused-paren-baren-yield.rs:24:29
|
LL | while let Some(_) = {{yield}} {}
| ^^^^^^^^^ help: remove these braces
error: unnecessary braces around block return value
--> $DIR/issue-74883-unused-paren-baren-yield.rs:24:30
--> $DIR/issue-74883-unused-paren-baren-yield.rs:19:30
|
LL | while let Some(_) = {{yield}} {}
| ^^^^^^^ help: remove these braces
error: aborting due to 8 previous errors
error: aborting due to 6 previous errors

View File

@ -0,0 +1,12 @@
// check-pass
#![deny(unused_braces)]
fn main() {
let mut a = Some(3);
// Shouldn't warn below `a`.
while let Some(ref mut v) = {a} {
a.as_mut().map(|a| std::mem::swap(a, v));
break;
}
}

View File

@ -0,0 +1,35 @@
// force-host
// no-prefer-dynamic
#![crate_type = "proc-macro"]
extern crate proc_macro;
use proc_macro::{TokenStream, TokenTree, Ident, Punct, Spacing, Span};
#[proc_macro]
pub fn make_struct(input: TokenStream) -> TokenStream {
match input.into_iter().next().unwrap() {
TokenTree::Ident(ident) => {
vec![
TokenTree::Ident(Ident::new("struct", Span::call_site())),
TokenTree::Ident(Ident::new_raw(&ident.to_string(), Span::call_site())),
TokenTree::Punct(Punct::new(';', Spacing::Alone))
].into_iter().collect()
}
_ => panic!()
}
}
#[proc_macro]
pub fn make_bad_struct(input: TokenStream) -> TokenStream {
match input.into_iter().next().unwrap() {
TokenTree::Ident(ident) => {
vec![
TokenTree::Ident(Ident::new_raw("struct", Span::call_site())),
TokenTree::Ident(Ident::new(&ident.to_string(), Span::call_site())),
TokenTree::Punct(Punct::new(';', Spacing::Alone))
].into_iter().collect()
}
_ => panic!()
}
}

View File

@ -0,0 +1,16 @@
// aux-build:raw-ident.rs
#[macro_use] extern crate raw_ident;
fn main() {
make_struct!(fn);
make_struct!(Foo);
make_struct!(await);
r#fn;
r#Foo;
Foo;
r#await;
make_bad_struct!(S); //~ ERROR expected one of
}

View File

@ -0,0 +1,10 @@
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `S`
--> $DIR/raw-ident.rs:15:5
|
LL | make_bad_struct!(S);
| ^^^^^^^^^^^^^^^^^^^^ expected one of 8 possible tokens
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error

View File

@ -1,6 +1,17 @@
// compile-flags: -D path-statements
fn main() {
struct Droppy;
impl Drop for Droppy {
fn drop(&mut self) {}
}
fn main() {
let x = 10;
x; //~ ERROR path statement with no effect
let y = Droppy;
y; //~ ERROR path statement drops value
let z = (Droppy,);
z; //~ ERROR path statement drops value
}

View File

@ -1,10 +1,22 @@
error: path statement with no effect
--> $DIR/warn-path-statement.rs:5:5
--> $DIR/warn-path-statement.rs:10:5
|
LL | x;
| ^^
|
= note: requested on the command line with `-D path-statements`
error: aborting due to previous error
error: path statement drops value
--> $DIR/warn-path-statement.rs:13:5
|
LL | y;
| ^^ help: use `drop` to clarify the intent: `drop(y);`
error: path statement drops value
--> $DIR/warn-path-statement.rs:16:5
|
LL | z;
| ^^ help: use `drop` to clarify the intent: `drop(z);`
error: aborting due to 3 previous errors

View File

@ -156,6 +156,7 @@ static DOCS_TARGETS: &[&str] = &[
"x86_64-pc-windows-gnu",
"x86_64-pc-windows-msvc",
"x86_64-unknown-linux-gnu",
"x86_64-unknown-linux-musl",
];
static MINGW: &[&str] = &["i686-pc-windows-gnu", "x86_64-pc-windows-gnu"];

View File

@ -286,14 +286,14 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
},
_ => {},
}
if items.is_empty() || !attr.check_name(sym!(deprecated)) {
if items.is_empty() || !attr.has_name(sym!(deprecated)) {
return;
}
for item in items {
if_chain! {
if let NestedMetaItem::MetaItem(mi) = &item;
if let MetaItemKind::NameValue(lit) = &mi.kind;
if mi.check_name(sym!(since));
if mi.has_name(sym!(since));
then {
check_semver(cx, item.span(), lit);
}
@ -309,7 +309,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
}
match item.kind {
ItemKind::ExternCrate(..) | ItemKind::Use(..) => {
let skip_unused_imports = item.attrs.iter().any(|attr| attr.check_name(sym!(macro_use)));
let skip_unused_imports = item.attrs.iter().any(|attr| attr.has_name(sym!(macro_use)));
for attr in item.attrs {
if in_external_macro(cx.sess(), attr.span) {
@ -524,7 +524,7 @@ fn check_attrs(cx: &LateContext<'_>, span: Span, name: Name, attrs: &[Attribute]
for attr in attrs {
if let Some(values) = attr.meta_item_list() {
if values.len() != 1 || !attr.check_name(sym!(inline)) {
if values.len() != 1 || !attr.has_name(sym!(inline)) {
continue;
}
if is_word(&values[0], sym!(always)) {
@ -558,7 +558,7 @@ fn check_semver(cx: &LateContext<'_>, span: Span, lit: &Lit) {
fn is_word(nmi: &NestedMetaItem, expected: Symbol) -> bool {
if let NestedMetaItem::MetaItem(mi) = &nmi {
mi.is_word() && mi.check_name(expected)
mi.is_word() && mi.has_name(expected)
} else {
false
}
@ -618,15 +618,15 @@ fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::as
fn check_deprecated_cfg_attr(cx: &EarlyContext<'_>, attr: &Attribute) {
if_chain! {
// check cfg_attr
if attr.check_name(sym!(cfg_attr));
if attr.has_name(sym!(cfg_attr));
if let Some(items) = attr.meta_item_list();
if items.len() == 2;
// check for `rustfmt`
if let Some(feature_item) = items[0].meta_item();
if feature_item.check_name(sym!(rustfmt));
if feature_item.has_name(sym!(rustfmt));
// check for `rustfmt_skip` and `rustfmt::skip`
if let Some(skip_item) = &items[1].meta_item();
if skip_item.check_name(sym!(rustfmt_skip)) ||
if skip_item.has_name(sym!(rustfmt_skip)) ||
skip_item.path.segments.last().expect("empty path in attribute").ident.name == sym!(skip);
// Only lint outer attributes, because custom inner attributes are unstable
// Tracking issue: https://github.com/rust-lang/rust/issues/54726
@ -685,7 +685,7 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
}
if_chain! {
if attr.check_name(sym!(cfg));
if attr.has_name(sym!(cfg));
if let Some(list) = attr.meta_item_list();
let mismatched = find_mismatched_target_os(&list);
if !mismatched.is_empty();

View File

@ -323,7 +323,7 @@ fn check_attrs<'a>(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs
let (comment, current_spans) = strip_doc_comment_decoration(&comment, attr.span);
spans.extend_from_slice(&current_spans);
doc.push_str(&comment);
} else if attr.check_name(sym!(doc)) {
} else if attr.has_name(sym!(doc)) {
// ignore mix of sugared and non-sugared doc
// don't trigger the safety or errors check
return DocHeaders {

View File

@ -41,7 +41,7 @@ impl<'tcx> LateLintPass<'tcx> for InlineFnWithoutBody {
fn check_attrs(cx: &LateContext<'_>, name: Symbol, attrs: &[Attribute]) {
for attr in attrs {
if !attr.check_name(sym!(inline)) {
if !attr.has_name(sym!(inline)) {
continue;
}

View File

@ -83,7 +83,7 @@ fn check_manual_non_exhaustive_enum(cx: &EarlyContext<'_>, item: &Item, variants
}
fn is_doc_hidden(attr: &Attribute) -> bool {
attr.check_name(sym!(doc))
attr.has_name(sym!(doc))
&& match attr.meta_item_list() {
Some(l) => attr::list_contains_name(&l, sym!(hidden)),
None => false,

View File

@ -105,7 +105,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
fn enter_lint_attrs(&mut self, _: &LateContext<'tcx>, attrs: &'tcx [ast::Attribute]) {
let doc_hidden = self.doc_hidden()
|| attrs.iter().any(|attr| {
attr.check_name(sym!(doc))
attr.has_name(sym!(doc))
&& match attr.meta_item_list() {
None => false,
Some(l) => attr::list_contains_name(&l[..], sym!(hidden)),

View File

@ -57,7 +57,7 @@ declare_clippy_lint! {
}
fn check_missing_inline_attrs(cx: &LateContext<'_>, attrs: &[ast::Attribute], sp: Span, desc: &'static str) {
let has_inline = attrs.iter().any(|a| a.check_name(sym!(inline)));
let has_inline = attrs.iter().any(|a| a.has_name(sym!(inline)));
if !has_inline {
span_lint(
cx,

View File

@ -112,7 +112,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessBorrow {
}
fn check_item(&mut self, _: &LateContext<'tcx>, item: &'tcx Item<'_>) {
if item.attrs.iter().any(|a| a.check_name(sym!(automatically_derived))) {
if item.attrs.iter().any(|a| a.has_name(sym!(automatically_derived))) {
debug_assert!(self.derived_item.is_none());
self.derived_item = Some(item.hir_id);
}

View File

@ -312,7 +312,7 @@ fn requires_exact_signature(attrs: &[Attribute]) -> bool {
attrs.iter().any(|attr| {
[sym!(proc_macro), sym!(proc_macro_attribute), sym!(proc_macro_derive)]
.iter()
.any(|&allow| attr.check_name(allow))
.any(|&allow| attr.has_name(allow))
})
}

View File

@ -235,7 +235,7 @@ impl EarlyLintPass for Return {
}
fn attr_is_cfg(attr: &ast::Attribute) -> bool {
attr.meta_item_list().is_some() && attr.check_name(sym!(cfg))
attr.meta_item_list().is_some() && attr.has_name(sym!(cfg))
}
// get the def site

View File

@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for TriviallyCopyPassByRef {
return;
}
for a in attrs {
if a.meta_item_list().is_some() && a.check_name(sym!(proc_macro_derive)) {
if a.meta_item_list().is_some() && a.has_name(sym!(proc_macro_derive)) {
return;
}
}

View File

@ -13,7 +13,7 @@ use std::{env, fmt, fs, io};
/// Gets the configuration file from arguments.
pub fn file_from_args(args: &[NestedMetaItem]) -> Result<Option<PathBuf>, (&'static str, Span)> {
for arg in args.iter().filter_map(NestedMetaItem::meta_item) {
if arg.check_name(sym!(conf_file)) {
if arg.has_name(sym!(conf_file)) {
return match arg.kind {
MetaItemKind::Word | MetaItemKind::List(_) => Err(("`conf_file` must be a named value", arg.span)),
MetaItemKind::NameValue(ref value) => {