Skip to content

Commit 049308c

Browse files
committed
Auto merge of rust-lang#98970 - Dylan-DPC:rollup-j0od37w, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#98881 (Only compute DefKind through the query.) - rust-lang#98884 (macros: `LintDiagnostic` derive) - rust-lang#98964 (fix typo in function name) - rust-lang#98967 (fix typo in note about multiple inaccessible type aliases) - rust-lang#98968 (assert Scalar sanity) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0aef720 + 7f62a71 commit 049308c

File tree

37 files changed

+1046
-701
lines changed

37 files changed

+1046
-701
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4009,6 +4009,7 @@ dependencies = [
40094009
"rustc_hir",
40104010
"rustc_index",
40114011
"rustc_infer",
4012+
"rustc_macros",
40124013
"rustc_middle",
40134014
"rustc_parse_format",
40144015
"rustc_session",

compiler/rustc_const_eval/src/interpret/machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
145145
}
146146

147147
/// Whether CheckedBinOp MIR statements should actually check for overflow.
148-
fn check_binop_checks_overflow(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
148+
fn checked_binop_checks_overflow(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
149149

150150
/// Entry point for obtaining the MIR of anything that should get evaluated.
151151
/// So not just functions and shims, but also const/static initializers, anonymous
@@ -472,7 +472,7 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
472472
}
473473

474474
#[inline(always)]
475-
fn check_binop_checks_overflow(_ecx: &InterpCx<$mir, $tcx, Self>) -> bool {
475+
fn checked_binop_checks_overflow(_ecx: &InterpCx<$mir, $tcx, Self>) -> bool {
476476
true
477477
}
478478

compiler/rustc_const_eval/src/interpret/operand.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
306306
s.is_ptr() || (number_may_have_provenance && size == self.pointer_size())
307307
};
308308
if let Some(s) = scalar_layout {
309-
//FIXME(#96185): let size = s.size(self);
310-
//FIXME(#96185): assert_eq!(size, mplace.layout.size, "abi::Scalar size does not match layout size");
311-
let size = mplace.layout.size; //FIXME(#96185): remove this line
309+
let size = s.size(self);
310+
assert_eq!(size, mplace.layout.size, "abi::Scalar size does not match layout size");
312311
let scalar =
313312
alloc.read_scalar(alloc_range(Size::ZERO, size), read_provenance(s, size))?;
314313
return Ok(Some(ImmTy { imm: scalar.into(), layout: mplace.layout }));

compiler/rustc_const_eval/src/interpret/operator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
3333
// As per https://github.com/rust-lang/rust/pull/98738, we always return `false` in the 2nd
3434
// component when overflow checking is disabled.
3535
let overflowed =
36-
overflowed && (force_overflow_checks || M::check_binop_checks_overflow(self));
36+
overflowed && (force_overflow_checks || M::checked_binop_checks_overflow(self));
3737
// Write the result to `dest`.
3838
if let Abi::ScalarPair(..) = dest.layout.abi {
3939
// We can use the optimized path and avoid `place_field` (which might do

compiler/rustc_const_eval/src/interpret/place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ where
793793
)
794794
};
795795
let size = s.size(&tcx);
796-
//FIXME(#96185): assert_eq!(dest.layout.size, size, "abi::Scalar size does not match layout size");
796+
assert_eq!(size, dest.layout.size, "abi::Scalar size does not match layout size");
797797
alloc.write_scalar(alloc_range(Size::ZERO, size), scalar)
798798
}
799799
Immediate::ScalarPair(a_val, b_val) => {

compiler/rustc_errors/src/diagnostic.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::snippet::Style;
22
use crate::{
3-
CodeSuggestion, DiagnosticMessage, Level, MultiSpan, SubdiagnosticMessage, Substitution,
4-
SubstitutionPart, SuggestionStyle,
3+
CodeSuggestion, DiagnosticMessage, EmissionGuarantee, Level, LintDiagnosticBuilder, MultiSpan,
4+
SubdiagnosticMessage, Substitution, SubstitutionPart, SuggestionStyle,
55
};
66
use rustc_data_structures::stable_map::FxHashMap;
77
use rustc_error_messages::FluentValue;
@@ -168,6 +168,14 @@ pub trait AddSubdiagnostic {
168168
fn add_to_diagnostic(self, diag: &mut Diagnostic);
169169
}
170170

171+
/// Trait implemented by lint types. This should not be implemented manually. Instead, use
172+
/// `#[derive(LintDiagnostic)]` -- see [rustc_macros::LintDiagnostic].
173+
#[rustc_diagnostic_item = "DecorateLint"]
174+
pub trait DecorateLint<'a, G: EmissionGuarantee> {
175+
/// Decorate and emit a lint.
176+
fn decorate_lint(self, diag: LintDiagnosticBuilder<'a, G>);
177+
}
178+
171179
#[must_use]
172180
#[derive(Clone, Debug, Encodable, Decodable)]
173181
pub struct Diagnostic {

compiler/rustc_errors/src/diagnostic_builder.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,3 +589,26 @@ macro_rules! struct_span_err {
589589
macro_rules! error_code {
590590
($code:ident) => {{ $crate::DiagnosticId::Error(stringify!($code).to_owned()) }};
591591
}
592+
593+
/// Wrapper around a `DiagnosticBuilder` for creating lints.
594+
pub struct LintDiagnosticBuilder<'a, G: EmissionGuarantee>(DiagnosticBuilder<'a, G>);
595+
596+
impl<'a, G: EmissionGuarantee> LintDiagnosticBuilder<'a, G> {
597+
/// Return the inner `DiagnosticBuilder`, first setting the primary message to `msg`.
598+
pub fn build(mut self, msg: impl Into<DiagnosticMessage>) -> DiagnosticBuilder<'a, G> {
599+
self.0.set_primary_message(msg);
600+
self.0.set_is_lint();
601+
self.0
602+
}
603+
604+
/// Create a `LintDiagnosticBuilder` from some existing `DiagnosticBuilder`.
605+
pub fn new(err: DiagnosticBuilder<'a, G>) -> LintDiagnosticBuilder<'a, G> {
606+
LintDiagnosticBuilder(err)
607+
}
608+
}
609+
610+
impl<'a> LintDiagnosticBuilder<'a, ErrorGuaranteed> {
611+
pub fn forget_guarantee(self) -> LintDiagnosticBuilder<'a, ()> {
612+
LintDiagnosticBuilder(self.0.forget_guarantee())
613+
}
614+
}

compiler/rustc_errors/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,10 @@ impl fmt::Display for ExplicitBug {
370370
impl error::Error for ExplicitBug {}
371371

372372
pub use diagnostic::{
373-
AddSubdiagnostic, Diagnostic, DiagnosticArg, DiagnosticArgValue, DiagnosticId,
373+
AddSubdiagnostic, DecorateLint, Diagnostic, DiagnosticArg, DiagnosticArgValue, DiagnosticId,
374374
DiagnosticStyledString, IntoDiagnosticArg, SubDiagnostic,
375375
};
376-
pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee};
376+
pub use diagnostic_builder::{DiagnosticBuilder, EmissionGuarantee, LintDiagnosticBuilder};
377377
use std::backtrace::Backtrace;
378378

379379
/// A handler deals with errors and other compiler output.

compiler/rustc_lint/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ rustc_trait_selection = { path = "../rustc_trait_selection" }
2222
rustc_parse_format = { path = "../rustc_parse_format" }
2323
rustc_infer = { path = "../rustc_infer" }
2424
rustc_type_ir = { path = "../rustc_type_ir" }
25+
rustc_macros = { path = "../rustc_macros" }

compiler/rustc_lint/src/builtin.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,16 @@ use rustc_ast_pretty::pprust::{self, expr_to_string};
3232
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
3333
use rustc_data_structures::stack::ensure_sufficient_stack;
3434
use rustc_errors::{
35-
fluent, Applicability, Diagnostic, DiagnosticMessage, DiagnosticStyledString, MultiSpan,
35+
fluent, Applicability, Diagnostic, DiagnosticMessage, DiagnosticStyledString,
36+
LintDiagnosticBuilder, MultiSpan,
3637
};
3738
use rustc_feature::{deprecated_attributes, AttributeGate, BuiltinAttribute, GateIssue, Stability};
3839
use rustc_hir as hir;
3940
use rustc_hir::def::{DefKind, Res};
4041
use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdSet, CRATE_DEF_ID};
4142
use rustc_hir::{ForeignItemKind, GenericParamKind, HirId, PatKind, PredicateOrigin};
4243
use rustc_index::vec::Idx;
43-
use rustc_middle::lint::{in_external_macro, LintDiagnosticBuilder};
44+
use rustc_middle::lint::in_external_macro;
4445
use rustc_middle::ty::layout::{LayoutError, LayoutOf};
4546
use rustc_middle::ty::print::with_no_trimmed_paths;
4647
use rustc_middle::ty::subst::GenericArgKind;

0 commit comments

Comments
 (0)