Skip to content

Commit 2f5d548

Browse files
authored
Rollup merge of #139039 - nnethercote:less-kw-Empty-4, r=petrochenkov
Reduce kw::Empty usage, part 4 Another step towards #137978. r? `@petrochenkov`
2 parents 5048534 + 2785063 commit 2f5d548

File tree

5 files changed

+31
-24
lines changed

5 files changed

+31
-24
lines changed

compiler/rustc_passes/src/check_attr.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use rustc_session::lint::builtin::{
3535
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNUSED_ATTRIBUTES,
3636
};
3737
use rustc_session::parse::feature_err;
38-
use rustc_span::{BytePos, DUMMY_SP, Span, Symbol, kw, sym};
38+
use rustc_span::{BytePos, DUMMY_SP, Span, Symbol, edition, kw, sym};
3939
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
4040
use rustc_trait_selection::infer::{TyCtxtInferExt, ValuePairs};
4141
use rustc_trait_selection::traits::ObligationCtxt;
@@ -1038,14 +1038,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
10381038
// FIXME: Once rustdoc can handle URL conflicts on case insensitive file systems, we
10391039
// can remove the `SelfTy` case here, remove `sym::SelfTy`, and update the
10401040
// `#[doc(keyword = "SelfTy")` attribute in `library/std/src/keyword_docs.rs`.
1041-
s <= kw::Union || s == sym::SelfTy
1041+
s.is_reserved(|| edition::LATEST_STABLE_EDITION) || s.is_weak() || s == sym::SelfTy
10421042
}
10431043

1044-
let doc_keyword = meta.value_str().unwrap_or(kw::Empty);
1045-
if doc_keyword == kw::Empty {
1046-
self.doc_attr_str_error(meta, "keyword");
1047-
return;
1048-
}
1044+
let doc_keyword = match meta.value_str() {
1045+
Some(value) if value != kw::Empty => value,
1046+
_ => return self.doc_attr_str_error(meta, "keyword"),
1047+
};
1048+
10491049
let item_kind = match self.tcx.hir_node(hir_id) {
10501050
hir::Node::Item(item) => Some(&item.kind),
10511051
_ => None,

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
10911091
));
10921092
}
10931093
Scope::BuiltinAttrs => {
1094-
let res = Res::NonMacroAttr(NonMacroAttrKind::Builtin(kw::Empty));
1094+
let res = Res::NonMacroAttr(NonMacroAttrKind::Builtin(sym::dummy));
10951095
if filter_fn(res) {
10961096
suggestions.extend(
10971097
BUILTIN_ATTRIBUTES

compiler/rustc_span/src/hygiene.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,8 @@ pub fn decode_syntax_context<D: Decoder, F: FnOnce(&mut D, u32) -> SyntaxContext
14401440
}
14411441
}
14421442
Entry::Vacant(entry) => {
1443-
// We are the first thread to start decoding. Mark the current thread as being progress.
1443+
// We are the first thread to start decoding. Mark the current thread as being
1444+
// progress.
14441445
context.local_in_progress.borrow_mut().insert(raw_id);
14451446

14461447
// Allocate and store SyntaxContext id *before* calling the decoder function,

compiler/rustc_span/src/symbol.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ symbols! {
131131
// tidy-alphabetical-end
132132

133133
// Weak keywords, have special meaning only in specific contexts.
134-
// Matching predicates: none
134+
// Matching predicates: `is_weak`
135135
// tidy-alphabetical-start
136136
Auto: "auto",
137137
Builtin: "builtin",
@@ -2725,6 +2725,10 @@ impl Symbol {
27252725
|| self.is_unused_keyword_conditional(edition)
27262726
}
27272727

2728+
pub fn is_weak(self) -> bool {
2729+
self >= kw::Auto && self <= kw::Yeet
2730+
}
2731+
27282732
/// A keyword or reserved identifier that can be used as a path segment.
27292733
pub fn is_path_segment_keyword(self) -> bool {
27302734
self == kw::Super

src/tools/clippy/clippy_lints/src/significant_drop_tightening.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ impl<'tcx> LateLintPass<'tcx> for SignificantDropTightening<'tcx> {
7979
if apa.counter <= 1 || !apa.has_expensive_expr_after_last_attr {
8080
continue;
8181
}
82+
let first_bind_ident = apa.first_bind_ident.unwrap();
8283
span_lint_and_then(
8384
cx,
8485
SIGNIFICANT_DROP_TIGHTENING,
85-
apa.first_bind_ident.span,
86+
first_bind_ident.span,
8687
"temporary with significant `Drop` can be early dropped",
8788
|diag| {
8889
match apa.counter {
@@ -91,13 +92,13 @@ impl<'tcx> LateLintPass<'tcx> for SignificantDropTightening<'tcx> {
9192
let indent = " ".repeat(indent_of(cx, apa.last_stmt_span).unwrap_or(0));
9293
let init_method = snippet(cx, apa.first_method_span, "..");
9394
let usage_method = snippet(cx, apa.last_method_span, "..");
94-
let stmt = if apa.last_bind_ident == Ident::empty() {
95-
format!("\n{indent}{init_method}.{usage_method};")
96-
} else {
95+
let stmt = if let Some(last_bind_ident) = apa.last_bind_ident {
9796
format!(
9897
"\n{indent}let {} = {init_method}.{usage_method};",
99-
snippet(cx, apa.last_bind_ident.span, ".."),
98+
snippet(cx, last_bind_ident.span, ".."),
10099
)
100+
} else {
101+
format!("\n{indent}{init_method}.{usage_method};")
101102
};
102103

103104
diag.multipart_suggestion_verbose(
@@ -113,7 +114,7 @@ impl<'tcx> LateLintPass<'tcx> for SignificantDropTightening<'tcx> {
113114
format!(
114115
"\n{}drop({});",
115116
" ".repeat(indent_of(cx, apa.last_stmt_span).unwrap_or(0)),
116-
apa.first_bind_ident
117+
first_bind_ident
117118
),
118119
Applicability::MaybeIncorrect,
119120
);
@@ -124,7 +125,7 @@ impl<'tcx> LateLintPass<'tcx> for SignificantDropTightening<'tcx> {
124125
apa.first_block_span,
125126
format!(
126127
"temporary `{}` is currently being dropped at the end of its contained scope",
127-
apa.first_bind_ident
128+
first_bind_ident
128129
),
129130
);
130131
},
@@ -283,7 +284,7 @@ impl<'tcx> Visitor<'tcx> for StmtsChecker<'_, '_, '_, '_, 'tcx> {
283284
let mut apa = AuxParamsAttr {
284285
first_block_hir_id: self.ap.curr_block_hir_id,
285286
first_block_span: self.ap.curr_block_span,
286-
first_bind_ident: ident,
287+
first_bind_ident: Some(ident),
287288
first_method_span: {
288289
let expr_or_init = expr_or_init(self.cx, expr);
289290
if let hir::ExprKind::MethodCall(_, local_expr, _, span) = expr_or_init.kind {
@@ -307,7 +308,7 @@ impl<'tcx> Visitor<'tcx> for StmtsChecker<'_, '_, '_, '_, 'tcx> {
307308
match self.ap.curr_stmt.kind {
308309
hir::StmtKind::Let(local) => {
309310
if let hir::PatKind::Binding(_, _, ident, _) = local.pat.kind {
310-
apa.last_bind_ident = ident;
311+
apa.last_bind_ident = Some(ident);
311312
}
312313
if let Some(local_init) = local.init
313314
&& let hir::ExprKind::MethodCall(_, _, _, span) = local_init.kind
@@ -373,15 +374,15 @@ struct AuxParamsAttr {
373374
first_block_span: Span,
374375
/// The binding or variable that references the initial construction of the type marked with
375376
/// `#[has_significant_drop]`.
376-
first_bind_ident: Ident,
377+
first_bind_ident: Option<Ident>,
377378
/// Similar to `init_bind_ident` but encompasses the right-hand method call.
378379
first_method_span: Span,
379380
/// Similar to `init_bind_ident` but encompasses the whole contained statement.
380381
first_stmt_span: Span,
381382

382383
/// The last visited binding or variable span within a block that had any referenced inner type
383384
/// marked with `#[has_significant_drop]`.
384-
last_bind_ident: Ident,
385+
last_bind_ident: Option<Ident>,
385386
/// Similar to `last_bind_span` but encompasses the right-hand method call.
386387
last_method_span: Span,
387388
/// Similar to `last_bind_span` but encompasses the whole contained statement.
@@ -395,10 +396,10 @@ impl Default for AuxParamsAttr {
395396
has_expensive_expr_after_last_attr: false,
396397
first_block_hir_id: HirId::INVALID,
397398
first_block_span: DUMMY_SP,
398-
first_bind_ident: Ident::empty(),
399+
first_bind_ident: None,
399400
first_method_span: DUMMY_SP,
400401
first_stmt_span: DUMMY_SP,
401-
last_bind_ident: Ident::empty(),
402+
last_bind_ident: None,
402403
last_method_span: DUMMY_SP,
403404
last_stmt_span: DUMMY_SP,
404405
}
@@ -413,7 +414,7 @@ fn dummy_stmt_expr<'any>(expr: &'any hir::Expr<'any>) -> hir::Stmt<'any> {
413414
}
414415
}
415416

416-
fn has_drop(expr: &hir::Expr<'_>, first_bind_ident: &Ident, lcx: &LateContext<'_>) -> bool {
417+
fn has_drop(expr: &hir::Expr<'_>, first_bind_ident: &Option<Ident>, lcx: &LateContext<'_>) -> bool {
417418
if let hir::ExprKind::Call(fun, [first_arg]) = expr.kind
418419
&& let hir::ExprKind::Path(hir::QPath::Resolved(_, fun_path)) = &fun.kind
419420
&& let Res::Def(DefKind::Fn, did) = fun_path.res
@@ -422,6 +423,7 @@ fn has_drop(expr: &hir::Expr<'_>, first_bind_ident: &Ident, lcx: &LateContext<'_
422423
let has_ident = |local_expr: &hir::Expr<'_>| {
423424
if let hir::ExprKind::Path(hir::QPath::Resolved(_, arg_path)) = &local_expr.kind
424425
&& let [first_arg_ps, ..] = arg_path.segments
426+
&& let Some(first_bind_ident) = first_bind_ident
425427
&& &first_arg_ps.ident == first_bind_ident
426428
{
427429
true

0 commit comments

Comments
 (0)