Skip to content

Commit 44fa5fd

Browse files
committed
Auto merge of #125136 - matthiaskrgr:rollup-ljm15m3, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #124990 (Also expand weak alias tys inside consts inside `expand_weak_alias_tys`) - #125108 (coverage: `CoverageIdsInfo::mcdc_bitmap_bytes` is never needed) - #125132 (Add `on_unimplemented" typo suggestions) - #125135 (Fix the dedup error because of spans from suggestion) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 9e7aff7 + 5f1a120 commit 44fa5fd

File tree

13 files changed

+135
-34
lines changed

13 files changed

+135
-34
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,8 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> {
207207
let cond_bitmap = coverage_context
208208
.try_get_mcdc_condition_bitmap(&instance, decision_depth)
209209
.expect("mcdc cond bitmap should have been allocated for merging into the global bitmap");
210-
let bitmap_bytes = bx.tcx().coverage_ids_info(instance.def).mcdc_bitmap_bytes;
210+
let bitmap_bytes = function_coverage_info.mcdc_bitmap_bytes;
211211
assert!(bitmap_idx < bitmap_bytes, "bitmap index of the decision out of range");
212-
assert!(
213-
bitmap_bytes <= function_coverage_info.mcdc_bitmap_bytes,
214-
"bitmap length disagreement: query says {bitmap_bytes} but function info only has {}",
215-
function_coverage_info.mcdc_bitmap_bytes
216-
);
217212

218213
let fn_name = bx.get_pgo_func_name_var(instance);
219214
let hash = bx.const_u64(function_coverage_info.function_source_hash);

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> {
896896
style: SuggestionStyle,
897897
) -> &mut Self {
898898
suggestion.sort_unstable();
899-
suggestion.dedup();
899+
suggestion.dedup_by(|(s1, m1), (s2, m2)| s1.source_equal(*s2) && m1 == m2);
900900

901901
let parts = suggestion
902902
.into_iter()

compiler/rustc_lint/src/context/diagnostics.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,5 +347,13 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Di
347347
"reduce the glob import's visibility or increase visibility of imported items",
348348
);
349349
}
350+
BuiltinLintDiag::MaybeTypo { span, name } => {
351+
diag.span_suggestion_verbose(
352+
span,
353+
"an attribute with a similar name exists",
354+
name,
355+
Applicability::MachineApplicable,
356+
);
357+
}
350358
}
351359
}

compiler/rustc_lint_defs/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,10 @@ pub enum BuiltinLintDiag {
663663
span: Span,
664664
max_vis: String,
665665
},
666+
MaybeTypo {
667+
span: Span,
668+
name: Symbol,
669+
},
666670
}
667671

668672
/// Lints that are buffered up early on in the `Session` before the

compiler/rustc_middle/src/mir/coverage.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,11 @@ pub enum CoverageKind {
129129
/// Marks the point in MIR control flow represented by a evaluated condition.
130130
///
131131
/// This is eventually lowered to `llvm.instrprof.mcdc.condbitmap.update` in LLVM IR.
132-
///
133-
/// If this statement does not survive MIR optimizations, the condition would never be
134-
/// taken as evaluated.
135132
CondBitmapUpdate { id: ConditionId, value: bool, decision_depth: u16 },
136133

137134
/// Marks the point in MIR control flow represented by a evaluated decision.
138135
///
139136
/// This is eventually lowered to `llvm.instrprof.mcdc.tvbitmap.update` in LLVM IR.
140-
///
141-
/// If this statement does not survive MIR optimizations, the decision would never be
142-
/// taken as evaluated.
143137
TestVectorBitmapUpdate { bitmap_idx: u32, decision_depth: u16 },
144138
}
145139

compiler/rustc_middle/src/mir/query.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,4 @@ pub struct CoverageIdsInfo {
362362
/// InstrumentCoverage MIR pass, if the highest-numbered counter increments
363363
/// were removed by MIR optimizations.
364364
pub max_counter_id: mir::coverage::CounterId,
365-
366-
/// Coverage codegen for mcdc needs to know the size of the global bitmap so that it can
367-
/// set the `bytemap-bytes` argument of the `llvm.instrprof.mcdc.tvbitmap.update` intrinsic.
368-
pub mcdc_bitmap_bytes: u32,
369365
}

compiler/rustc_middle/src/ty/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for WeakAliasTypeExpander<'tcx> {
11301130
}
11311131

11321132
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
1133-
if !ct.ty().has_type_flags(ty::TypeFlags::HAS_TY_WEAK) {
1133+
if !ct.has_type_flags(ty::TypeFlags::HAS_TY_WEAK) {
11341134
return ct;
11351135
}
11361136
ct.super_fold_with(self)

compiler/rustc_mir_transform/src/coverage/query.rs

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,7 @@ fn coverage_ids_info<'tcx>(
6161
.max()
6262
.unwrap_or(CounterId::ZERO);
6363

64-
let mcdc_bitmap_bytes = mir_body
65-
.coverage_branch_info
66-
.as_deref()
67-
.map(|info| {
68-
info.mcdc_decision_spans
69-
.iter()
70-
.fold(0, |acc, decision| acc + (1_u32 << decision.conditions_num).div_ceil(8))
71-
})
72-
.unwrap_or_default();
73-
74-
CoverageIdsInfo { max_counter_id, mcdc_bitmap_bytes }
64+
CoverageIdsInfo { max_counter_id }
7565
}
7666

7767
fn all_coverage_in_mir_body<'a, 'tcx>(

compiler/rustc_resolve/src/macros.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use rustc_session::lint::builtin::{LEGACY_DERIVE_HELPERS, SOFT_UNSTABLE};
2929
use rustc_session::lint::builtin::{UNUSED_MACROS, UNUSED_MACRO_RULES};
3030
use rustc_session::lint::BuiltinLintDiag;
3131
use rustc_session::parse::feature_err;
32+
use rustc_span::edit_distance::edit_distance;
3233
use rustc_span::edition::Edition;
3334
use rustc_span::hygiene::{self, ExpnData, ExpnKind, LocalExpnId};
3435
use rustc_span::hygiene::{AstPass, MacroKind};
@@ -568,15 +569,24 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
568569
}
569570

570571
if res == Res::NonMacroAttr(NonMacroAttrKind::Tool)
571-
&& path.segments.len() >= 2
572-
&& path.segments[0].ident.name == sym::diagnostic
573-
&& path.segments[1].ident.name != sym::on_unimplemented
572+
&& let [namespace, attribute, ..] = &*path.segments
573+
&& namespace.ident.name == sym::diagnostic
574+
&& attribute.ident.name != sym::on_unimplemented
574575
{
575-
self.tcx.sess.psess.buffer_lint(
576+
let distance =
577+
edit_distance(attribute.ident.name.as_str(), sym::on_unimplemented.as_str(), 5);
578+
579+
let help = if distance.is_some() {
580+
BuiltinLintDiag::MaybeTypo { span: attribute.span(), name: sym::on_unimplemented }
581+
} else {
582+
BuiltinLintDiag::Normal
583+
};
584+
self.tcx.sess.psess.buffer_lint_with_diagnostic(
576585
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
577-
path.segments[1].span(),
586+
attribute.span(),
578587
node_id,
579588
"unknown diagnostic attribute",
589+
help,
580590
);
581591
}
582592

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![deny(unknown_or_malformed_diagnostic_attributes)]
2+
3+
#[diagnostic::onunimplemented]
4+
//~^ERROR unknown diagnostic attribute
5+
//~^^HELP an attribute with a similar name exists
6+
trait X{}
7+
8+
#[diagnostic::un_onimplemented]
9+
//~^ERROR unknown diagnostic attribute
10+
//~^^HELP an attribute with a similar name exists
11+
trait Y{}
12+
13+
#[diagnostic::on_implemented]
14+
//~^ERROR unknown diagnostic attribute
15+
//~^^HELP an attribute with a similar name exists
16+
trait Z{}
17+
18+
fn main(){}

0 commit comments

Comments
 (0)