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
This commit is contained in:
bors 2024-05-15 06:21:19 +00:00
commit 44fa5fd39a
13 changed files with 135 additions and 34 deletions

View file

@ -207,13 +207,8 @@ fn add_coverage(&mut self, instance: Instance<'tcx>, kind: &CoverageKind) {
let cond_bitmap = coverage_context
.try_get_mcdc_condition_bitmap(&instance, decision_depth)
.expect("mcdc cond bitmap should have been allocated for merging into the global bitmap");
let bitmap_bytes = bx.tcx().coverage_ids_info(instance.def).mcdc_bitmap_bytes;
let bitmap_bytes = function_coverage_info.mcdc_bitmap_bytes;
assert!(bitmap_idx < bitmap_bytes, "bitmap index of the decision out of range");
assert!(
bitmap_bytes <= function_coverage_info.mcdc_bitmap_bytes,
"bitmap length disagreement: query says {bitmap_bytes} but function info only has {}",
function_coverage_info.mcdc_bitmap_bytes
);
let fn_name = bx.get_pgo_func_name_var(instance);
let hash = bx.const_u64(function_coverage_info.function_source_hash);

View file

@ -896,7 +896,7 @@ pub fn multipart_suggestion_with_style(
style: SuggestionStyle,
) -> &mut Self {
suggestion.sort_unstable();
suggestion.dedup();
suggestion.dedup_by(|(s1, m1), (s2, m2)| s1.source_equal(*s2) && m1 == m2);
let parts = suggestion
.into_iter()

View file

@ -347,5 +347,13 @@ pub(super) fn builtin(sess: &Session, diagnostic: BuiltinLintDiag, diag: &mut Di
"reduce the glob import's visibility or increase visibility of imported items",
);
}
BuiltinLintDiag::MaybeTypo { span, name } => {
diag.span_suggestion_verbose(
span,
"an attribute with a similar name exists",
name,
Applicability::MachineApplicable,
);
}
}
}

View file

@ -663,6 +663,10 @@ pub enum BuiltinLintDiag {
span: Span,
max_vis: String,
},
MaybeTypo {
span: Span,
name: Symbol,
},
}
/// Lints that are buffered up early on in the `Session` before the

View file

@ -129,17 +129,11 @@ pub enum CoverageKind {
/// Marks the point in MIR control flow represented by a evaluated condition.
///
/// This is eventually lowered to `llvm.instrprof.mcdc.condbitmap.update` in LLVM IR.
///
/// If this statement does not survive MIR optimizations, the condition would never be
/// taken as evaluated.
CondBitmapUpdate { id: ConditionId, value: bool, decision_depth: u16 },
/// Marks the point in MIR control flow represented by a evaluated decision.
///
/// This is eventually lowered to `llvm.instrprof.mcdc.tvbitmap.update` in LLVM IR.
///
/// If this statement does not survive MIR optimizations, the decision would never be
/// taken as evaluated.
TestVectorBitmapUpdate { bitmap_idx: u32, decision_depth: u16 },
}

View file

@ -362,8 +362,4 @@ pub struct CoverageIdsInfo {
/// InstrumentCoverage MIR pass, if the highest-numbered counter increments
/// were removed by MIR optimizations.
pub max_counter_id: mir::coverage::CounterId,
/// Coverage codegen for mcdc needs to know the size of the global bitmap so that it can
/// set the `bytemap-bytes` argument of the `llvm.instrprof.mcdc.tvbitmap.update` intrinsic.
pub mcdc_bitmap_bytes: u32,
}

View file

@ -1130,7 +1130,7 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
}
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
if !ct.ty().has_type_flags(ty::TypeFlags::HAS_TY_WEAK) {
if !ct.has_type_flags(ty::TypeFlags::HAS_TY_WEAK) {
return ct;
}
ct.super_fold_with(self)

View file

@ -61,17 +61,7 @@ fn coverage_ids_info<'tcx>(
.max()
.unwrap_or(CounterId::ZERO);
let mcdc_bitmap_bytes = mir_body
.coverage_branch_info
.as_deref()
.map(|info| {
info.mcdc_decision_spans
.iter()
.fold(0, |acc, decision| acc + (1_u32 << decision.conditions_num).div_ceil(8))
})
.unwrap_or_default();
CoverageIdsInfo { max_counter_id, mcdc_bitmap_bytes }
CoverageIdsInfo { max_counter_id }
}
fn all_coverage_in_mir_body<'a, 'tcx>(

View file

@ -29,6 +29,7 @@
use rustc_session::lint::builtin::{UNUSED_MACROS, UNUSED_MACRO_RULES};
use rustc_session::lint::BuiltinLintDiag;
use rustc_session::parse::feature_err;
use rustc_span::edit_distance::edit_distance;
use rustc_span::edition::Edition;
use rustc_span::hygiene::{self, ExpnData, ExpnKind, LocalExpnId};
use rustc_span::hygiene::{AstPass, MacroKind};
@ -568,15 +569,24 @@ fn smart_resolve_macro_path(
}
if res == Res::NonMacroAttr(NonMacroAttrKind::Tool)
&& path.segments.len() >= 2
&& path.segments[0].ident.name == sym::diagnostic
&& path.segments[1].ident.name != sym::on_unimplemented
&& let [namespace, attribute, ..] = &*path.segments
&& namespace.ident.name == sym::diagnostic
&& attribute.ident.name != sym::on_unimplemented
{
self.tcx.sess.psess.buffer_lint(
let distance =
edit_distance(attribute.ident.name.as_str(), sym::on_unimplemented.as_str(), 5);
let help = if distance.is_some() {
BuiltinLintDiag::MaybeTypo { span: attribute.span(), name: sym::on_unimplemented }
} else {
BuiltinLintDiag::Normal
};
self.tcx.sess.psess.buffer_lint_with_diagnostic(
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
path.segments[1].span(),
attribute.span(),
node_id,
"unknown diagnostic attribute",
help,
);
}

View file

@ -0,0 +1,18 @@
#![deny(unknown_or_malformed_diagnostic_attributes)]
#[diagnostic::onunimplemented]
//~^ERROR unknown diagnostic attribute
//~^^HELP an attribute with a similar name exists
trait X{}
#[diagnostic::un_onimplemented]
//~^ERROR unknown diagnostic attribute
//~^^HELP an attribute with a similar name exists
trait Y{}
#[diagnostic::on_implemented]
//~^ERROR unknown diagnostic attribute
//~^^HELP an attribute with a similar name exists
trait Z{}
fn main(){}

View file

@ -0,0 +1,40 @@
error: unknown diagnostic attribute
--> $DIR/suggest_typos.rs:3:15
|
LL | #[diagnostic::onunimplemented]
| ^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/suggest_typos.rs:1:9
|
LL | #![deny(unknown_or_malformed_diagnostic_attributes)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: an attribute with a similar name exists
|
LL | #[diagnostic::on_unimplemented]
| ~~~~~~~~~~~~~~~~
error: unknown diagnostic attribute
--> $DIR/suggest_typos.rs:8:15
|
LL | #[diagnostic::un_onimplemented]
| ^^^^^^^^^^^^^^^^
|
help: an attribute with a similar name exists
|
LL | #[diagnostic::on_unimplemented]
| ~~~~~~~~~~~~~~~~
error: unknown diagnostic attribute
--> $DIR/suggest_typos.rs:13:15
|
LL | #[diagnostic::on_implemented]
| ^^^^^^^^^^^^^^
|
help: an attribute with a similar name exists
|
LL | #[diagnostic::on_unimplemented]
| ~~~~~~~~~~~~~~~~
error: aborting due to 3 previous errors

View file

@ -0,0 +1,16 @@
#![allow(dead_code)]
#![allow(unused_variables)]
fn bug() {
macro_rules! m {
() => {
_ //~ ERROR the placeholder `_` is not allowed within types on item signatures for structs
};
}
struct S<T = m!()>(m!(), T)
where
T: Trait<m!()>;
}
trait Trait<T> {}
fn main() {}

View file

@ -0,0 +1,30 @@
error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs
--> $DIR/macro-span-issue-116502.rs:7:13
|
LL | _
| ^
| |
| not allowed in type signatures
| not allowed in type signatures
| not allowed in type signatures
...
LL | struct S<T = m!()>(m!(), T)
| ---- ---- in this macro invocation
| |
| in this macro invocation
LL | where
LL | T: Trait<m!()>;
| ---- in this macro invocation
|
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
help: use type parameters instead
|
LL ~ U
LL | };
LL | }
LL ~ struct S<U>(m!(), T)
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0121`.