summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_middle/src/lint.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:35 +0000
commitd1b2d29528b7794b41e66fc2136e395a02f8529b (patch)
treea4a17504b260206dec3cf55b2dca82929a348ac2 /compiler/rustc_middle/src/lint.rs
parentReleasing progress-linux version 1.72.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.tar.xz
rustc-d1b2d29528b7794b41e66fc2136e395a02f8529b.zip
Merging upstream version 1.73.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_middle/src/lint.rs')
-rw-r--r--compiler/rustc_middle/src/lint.rs51
1 files changed, 21 insertions, 30 deletions
diff --git a/compiler/rustc_middle/src/lint.rs b/compiler/rustc_middle/src/lint.rs
index 81c1ae4f6..f62e40669 100644
--- a/compiler/rustc_middle/src/lint.rs
+++ b/compiler/rustc_middle/src/lint.rs
@@ -169,26 +169,6 @@ impl TyCtxt<'_> {
pub fn lint_level_at_node(self, lint: &'static Lint, id: HirId) -> (Level, LintLevelSource) {
self.shallow_lint_levels_on(id.owner).lint_level_id_at_node(self, LintId::of(lint), id)
}
-
- /// Walks upwards from `id` to find a node which might change lint levels with attributes.
- /// It stops at `bound` and just returns it if reached.
- pub fn maybe_lint_level_root_bounded(self, mut id: HirId, bound: HirId) -> HirId {
- let hir = self.hir();
- loop {
- if id == bound {
- return bound;
- }
-
- if hir.attrs(id).iter().any(|attr| Level::from_attr(attr).is_some()) {
- return id;
- }
- let next = hir.parent_id(id);
- if next == id {
- bug!("lint traversal reached the root of the crate");
- }
- id = next;
- }
- }
}
/// This struct represents a lint expectation and holds all required information
@@ -238,14 +218,12 @@ pub fn explain_lint_level_source(
let hyphen_case_lint_name = name.replace('_', "-");
if lint_flag_val.as_str() == name {
err.note_once(format!(
- "requested on the command line with `{} {}`",
- flag, hyphen_case_lint_name
+ "requested on the command line with `{flag} {hyphen_case_lint_name}`"
));
} else {
let hyphen_case_flag_val = lint_flag_val.as_str().replace('_', "-");
err.note_once(format!(
- "`{} {}` implied by `{} {}`",
- flag, hyphen_case_lint_name, flag, hyphen_case_flag_val
+ "`{flag} {hyphen_case_lint_name}` implied by `{flag} {hyphen_case_flag_val}`"
));
}
}
@@ -257,8 +235,7 @@ pub fn explain_lint_level_source(
if lint_attr_name.as_str() != name {
let level_str = level.as_str();
err.note_once(format!(
- "`#[{}({})]` implied by `#[{}({})]`",
- level_str, name, level_str, lint_attr_name
+ "`#[{level_str}({name})]` implied by `#[{level_str}({lint_attr_name})]`"
));
}
}
@@ -298,6 +275,7 @@ pub fn explain_lint_level_source(
/// // ^^^^^^^^^^^^^^^^^^^^^ returns `&mut DiagnosticBuilder` by default
/// )
/// ```
+#[track_caller]
pub fn struct_lint_level(
sess: &Session,
lint: &'static Lint,
@@ -311,6 +289,7 @@ pub fn struct_lint_level(
) {
// Avoid codegen bloat from monomorphization by immediately doing dyn dispatch of `decorate` to
// the "real" work.
+ #[track_caller]
fn struct_lint_level_impl(
sess: &Session,
lint: &'static Lint,
@@ -434,12 +413,11 @@ pub fn struct_lint_level(
FutureIncompatibilityReason::EditionError(edition) => {
let current_edition = sess.edition();
format!(
- "this is accepted in the current edition (Rust {}) but is a hard error in Rust {}!",
- current_edition, edition
+ "this is accepted in the current edition (Rust {current_edition}) but is a hard error in Rust {edition}!"
)
}
FutureIncompatibilityReason::EditionSemanticsChange(edition) => {
- format!("this changes meaning in Rust {}", edition)
+ format!("this changes meaning in Rust {edition}")
}
FutureIncompatibilityReason::Custom(reason) => reason.to_owned(),
};
@@ -471,7 +449,11 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
match expn_data.kind {
ExpnKind::Root
| ExpnKind::Desugaring(
- DesugaringKind::ForLoop | DesugaringKind::WhileLoop | DesugaringKind::OpaqueTy,
+ DesugaringKind::ForLoop
+ | DesugaringKind::WhileLoop
+ | DesugaringKind::OpaqueTy
+ | DesugaringKind::Async
+ | DesugaringKind::Await,
) => false,
ExpnKind::AstPass(_) | ExpnKind::Desugaring(_) => true, // well, it's "external"
ExpnKind::Macro(MacroKind::Bang, _) => {
@@ -481,3 +463,12 @@ pub fn in_external_macro(sess: &Session, span: Span) -> bool {
ExpnKind::Macro { .. } => true, // definitely a plugin
}
}
+
+/// Return whether `span` is generated by `async` or `await`.
+pub fn is_from_async_await(span: Span) -> bool {
+ let expn_data = span.ctxt().outer_expn_data();
+ match expn_data.kind {
+ ExpnKind::Desugaring(DesugaringKind::Async | DesugaringKind::Await) => true,
+ _ => false,
+ }
+}