&'t self,
) -> impl Iterator<Item = (&'static str, Vec<LintId>, bool)> + 't {
// This function is not used in a way which observes the order of lints.
- #[cfg_attr(not(bootstrap), allow(rustc::potential_query_instability))]
+ #[allow(rustc::potential_query_instability)]
self.lint_groups
.iter()
.filter(|(_, LintGroup { depr, .. })| {
/// This lint has been renamed; warn about using the new name and apply the lint.
#[track_caller]
pub fn register_renamed(&mut self, old_name: &str, new_name: &str) {
- let target = match self.by_name.get(new_name) {
- Some(&Id(lint_id)) => lint_id,
- _ => bug!("invalid lint renaming of {} to {}", old_name, new_name),
+ let Some(&Id(target)) = self.by_name.get(new_name) else {
+ bug!("invalid lint renaming of {} to {}", old_name, new_name);
};
self.by_name.insert(old_name.to_string(), Renamed(new_name.to_string(), target));
}
) {
let (tool_name, lint_name_only) = parse_lint_and_tool_name(lint_name);
if lint_name_only == crate::WARNINGS.name_lower() && level == Level::ForceWarn {
- return struct_span_err!(
+ struct_span_err!(
sess,
DUMMY_SP,
E0602,
crate::WARNINGS.name_lower()
)
.emit();
+ return;
}
let db = match self.check_lint_name(lint_name_only, tool_name, registered_tools) {
CheckLintNameResult::Ok(_) => None,
err.help(&format!("did you mean: `{}`", suggestion));
}
- Some(err)
+ Some(err.forget_guarantee())
}
CheckLintNameResult::Tool(result) => match result {
Err((Some(_), new_name)) => Some(sess.struct_warn(&format!(
))),
_ => None,
},
- CheckLintNameResult::NoTool => Some(struct_span_err!(
- sess,
- DUMMY_SP,
- E0602,
- "unknown lint tool: `{}`",
- tool_name.unwrap()
- )),
+ CheckLintNameResult::NoTool => Some(
+ struct_span_err!(
+ sess,
+ DUMMY_SP,
+ E0602,
+ "unknown lint tool: `{}`",
+ tool_name.unwrap()
+ )
+ .forget_guarantee(),
+ ),
};
if let Some(mut db) = db {
BuiltinLintDiagnostics::NamedAsmLabel(help) => {
db.help(&help);
db.note("see the asm section of Rust By Example <https://doc.rust-lang.org/nightly/rust-by-example/unsafe/asm.html#labels> for more information");
- }
+ },
+ BuiltinLintDiagnostics::UnexpectedCfg(span, name, value) => {
+ let possibilities: Vec<Symbol> = if value.is_some() {
+ let Some(values) = &sess.parse_sess.check_config.values_valid.get(&name) else {
+ bug!("it shouldn't be possible to have a diagnostic on a value whose name is not in values");
+ };
+ values.iter().map(|&s| s).collect()
+ } else {
+ let Some(names_valid) = &sess.parse_sess.check_config.names_valid else {
+ bug!("it shouldn't be possible to have a diagnostic on a name if name checking is not enabled");
+ };
+ names_valid.iter().map(|s| *s).collect()
+ };
+
+ // Show the full list if all possible values for a given name, but don't do it
+ // for names as the possibilities could be very long
+ if value.is_some() {
+ if !possibilities.is_empty() {
+ let mut possibilities = possibilities.iter().map(Symbol::as_str).collect::<Vec<_>>();
+ possibilities.sort();
+
+ let possibilities = possibilities.join(", ");
+ db.note(&format!("expected values for `{name}` are: {possibilities}"));
+ } else {
+ db.note(&format!("no expected value for `{name}`"));
+ }
+ }
+
+ // Suggest the most probable if we found one
+ if let Some(best_match) = find_best_match_for_name(&possibilities, value.unwrap_or(name), None) {
+ let punctuation = if value.is_some() { "\"" } else { "" };
+ db.span_suggestion(span, "did you mean", format!("{punctuation}{best_match}{punctuation}"), Applicability::MaybeIncorrect);
+ }
+ },
}
// Rewrap `db`, and pass control to the user.
decorate(LintDiagnosticBuilder::new(db));
}
// This shouldn't ever be needed, but just in case:
- with_no_trimmed_paths(|| {
+ with_no_trimmed_paths!({
Ok(vec![match trait_ref {
Some(trait_ref) => Symbol::intern(&format!("{:?}", trait_ref)),
None => Symbol::intern(&format!("<{}>", self_ty)),
// This shouldn't ever be needed, but just in case:
path.push(match trait_ref {
- Some(trait_ref) => with_no_trimmed_paths(|| {
- Symbol::intern(&format!(
+ Some(trait_ref) => {
+ with_no_trimmed_paths!(Symbol::intern(&format!(
"<impl {} for {}>",
trait_ref.print_only_trait_path(),
self_ty
- ))
- }),
+ )))
+ }
None => {
- with_no_trimmed_paths(|| Symbol::intern(&format!("<impl {}>", self_ty)))
+ with_no_trimmed_paths!(Symbol::intern(&format!("<impl {}>", self_ty)))
}
});