Auto merge of #98091 - Dylan-DPC:rollup-ueb6b5x, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #97869 (BTree: tweak internal comments) - #97935 (Rename the `ConstS::val` field as `kind`.) - #97948 (lint: add diagnostic translation migration lints) - #98042 (Fix compat_fn option method on miri) - #98069 (rustdoc: remove link on slice brackets) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
edab34ab2a
96 changed files with 522 additions and 250 deletions
|
|
@ -234,7 +234,7 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
|
|||
}
|
||||
|
||||
pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String {
|
||||
match n.val() {
|
||||
match n.kind() {
|
||||
ty::ConstKind::Unevaluated(ty::Unevaluated { def, substs: _, promoted }) => {
|
||||
let mut s = if let Some(def) = def.as_local() {
|
||||
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def.did);
|
||||
|
|
@ -307,7 +307,7 @@ fn format_integer_with_underscore_sep(num: &str) -> String {
|
|||
fn print_const_with_custom_print_scalar(tcx: TyCtxt<'_>, ct: ty::Const<'_>) -> String {
|
||||
// Use a slightly different format for integer types which always shows the actual value.
|
||||
// For all other types, fallback to the original `pretty_print_const`.
|
||||
match (ct.val(), ct.ty().kind()) {
|
||||
match (ct.kind(), ct.ty().kind()) {
|
||||
(ty::ConstKind::Value(ConstValue::Scalar(int)), ty::Uint(ui)) => {
|
||||
format!("{}{}", format_integer_with_underscore_sep(&int.to_string()), ui.name_str())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -886,9 +886,9 @@ fn fmt_type<'cx>(
|
|||
primitive_link(f, PrimitiveType::Slice, &format!("[{name}]"), cx)
|
||||
}
|
||||
_ => {
|
||||
primitive_link(f, PrimitiveType::Slice, "[", cx)?;
|
||||
write!(f, "[")?;
|
||||
fmt::Display::fmt(&t.print(cx), f)?;
|
||||
primitive_link(f, PrimitiveType::Slice, "]", cx)
|
||||
write!(f, "]")
|
||||
}
|
||||
},
|
||||
clean::Array(ref t, ref n) => {
|
||||
|
|
@ -926,31 +926,6 @@ fn fmt_type<'cx>(
|
|||
let m = mutability.print_with_space();
|
||||
let amp = if f.alternate() { "&".to_string() } else { "&".to_string() };
|
||||
match **ty {
|
||||
clean::Slice(ref bt) => {
|
||||
// `BorrowedRef{ ... Slice(T) }` is `&[T]`
|
||||
match **bt {
|
||||
clean::Generic(name) => primitive_link(
|
||||
f,
|
||||
PrimitiveType::Slice,
|
||||
&format!("{amp}{lt}{m}[{name}]"),
|
||||
cx,
|
||||
),
|
||||
_ => {
|
||||
primitive_link(
|
||||
f,
|
||||
PrimitiveType::Slice,
|
||||
&format!("{}{}{}[", amp, lt, m),
|
||||
cx,
|
||||
)?;
|
||||
if f.alternate() {
|
||||
write!(f, "{:#}", bt.print(cx))?;
|
||||
} else {
|
||||
write!(f, "{}", bt.print(cx))?;
|
||||
}
|
||||
primitive_link(f, PrimitiveType::Slice, "]", cx)
|
||||
}
|
||||
}
|
||||
}
|
||||
clean::DynTrait(ref bounds, ref trait_lt)
|
||||
if bounds.len() > 1 || trait_lt.is_some() =>
|
||||
{
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
|
|
||||
fn main() -> () {
|
||||
let mut _0: (); // return place in scope 0 at $DIR/region-subtyping-basic.rs:16:11: 16:11
|
||||
let mut _1: [usize; Const { ty: usize, val: Value(Scalar(0x00000003)) }]; // in scope 0 at $DIR/region-subtyping-basic.rs:17:9: 17:14
|
||||
let mut _1: [usize; Const { ty: usize, kind: Value(Scalar(0x00000003)) }]; // in scope 0 at $DIR/region-subtyping-basic.rs:17:9: 17:14
|
||||
let _3: usize; // in scope 0 at $DIR/region-subtyping-basic.rs:18:16: 18:17
|
||||
let mut _4: usize; // in scope 0 at $DIR/region-subtyping-basic.rs:18:14: 18:18
|
||||
let mut _5: bool; // in scope 0 at $DIR/region-subtyping-basic.rs:18:14: 18:18
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
|
|
||||
fn main() -> () {
|
||||
let mut _0: (); // return place in scope 0 at $DIR/region-subtyping-basic.rs:16:11: 16:11
|
||||
let mut _1: [usize; Const { ty: usize, val: Value(Scalar(0x0000000000000003)) }]; // in scope 0 at $DIR/region-subtyping-basic.rs:17:9: 17:14
|
||||
let mut _1: [usize; Const { ty: usize, kind: Value(Scalar(0x0000000000000003)) }]; // in scope 0 at $DIR/region-subtyping-basic.rs:17:9: 17:14
|
||||
let _3: usize; // in scope 0 at $DIR/region-subtyping-basic.rs:18:16: 18:17
|
||||
let mut _4: usize; // in scope 0 at $DIR/region-subtyping-basic.rs:18:14: 18:18
|
||||
let mut _5: bool; // in scope 0 at $DIR/region-subtyping-basic.rs:18:14: 18:18
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
<code>pub fn gamma() -> <a class="struct" href="struct.MyBox.html" title="struct foo::MyBox">MyBox</a><<a class="primitive" href="{{channel}}/core/primitive.slice.html">[</a><a class="primitive" href="{{channel}}/core/primitive.u32.html">u32</a><a class="primitive" href="{{channel}}/core/primitive.slice.html">]</a>></code>
|
||||
<code>pub fn gamma() -> <a class="struct" href="struct.MyBox.html" title="struct foo::MyBox">MyBox</a><[<a class="primitive" href="{{channel}}/core/primitive.u32.html">u32</a>]></code>
|
||||
|
|
@ -1 +1 @@
|
|||
<code>pub fn beta<T>() -> <a class="primitive" href="{{channel}}/core/primitive.slice.html">&'static [T]</a></code>
|
||||
<code>pub fn beta<T>() -> &'static <a class="primitive" href="{{channel}}/core/primitive.slice.html">[T]</a></code>
|
||||
|
|
@ -1 +1 @@
|
|||
<code>pub fn alpha() -> <a class="primitive" href="{{channel}}/core/primitive.slice.html">&'static [</a><a class="primitive" href="{{channel}}/core/primitive.u32.html">u32</a><a class="primitive" href="{{channel}}/core/primitive.slice.html">]</a></code>
|
||||
<code>pub fn alpha() -> &'static [<a class="primitive" href="{{channel}}/core/primitive.u32.html">u32</a>]</code>
|
||||
73
src/test/ui-fulldeps/internal-lints/diagnostics.rs
Normal file
73
src/test/ui-fulldeps/internal-lints/diagnostics.rs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
// compile-flags: -Z unstable-options
|
||||
|
||||
#![crate_type = "lib"]
|
||||
#![feature(rustc_private)]
|
||||
#![deny(rustc::untranslatable_diagnostic)]
|
||||
#![deny(rustc::diagnostic_outside_of_impl)]
|
||||
|
||||
extern crate rustc_errors;
|
||||
extern crate rustc_macros;
|
||||
extern crate rustc_session;
|
||||
extern crate rustc_span;
|
||||
|
||||
use rustc_errors::{AddSubdiagnostic, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, fluent};
|
||||
use rustc_macros::{SessionDiagnostic, SessionSubdiagnostic};
|
||||
use rustc_session::{parse::ParseSess, SessionDiagnostic};
|
||||
use rustc_span::Span;
|
||||
|
||||
#[derive(SessionDiagnostic)]
|
||||
#[error(slug = "parser-expect-path")]
|
||||
struct DeriveSessionDiagnostic {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
}
|
||||
|
||||
#[derive(SessionSubdiagnostic)]
|
||||
#[note(slug = "note")]
|
||||
struct Note {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
}
|
||||
|
||||
pub struct UntranslatableInSessionDiagnostic;
|
||||
|
||||
impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for UntranslatableInSessionDiagnostic {
|
||||
fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||
sess.struct_err("untranslatable diagnostic")
|
||||
//~^ ERROR diagnostics should be created using translatable messages
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TranslatableInSessionDiagnostic;
|
||||
|
||||
impl<'a> SessionDiagnostic<'a, ErrorGuaranteed> for TranslatableInSessionDiagnostic {
|
||||
fn into_diagnostic(self, sess: &'a ParseSess) -> DiagnosticBuilder<'a, ErrorGuaranteed> {
|
||||
sess.struct_err(fluent::parser::expect_path)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UntranslatableInAddSubdiagnostic;
|
||||
|
||||
impl AddSubdiagnostic for UntranslatableInAddSubdiagnostic {
|
||||
fn add_to_diagnostic(self, diag: &mut Diagnostic) {
|
||||
diag.note("untranslatable diagnostic");
|
||||
//~^ ERROR diagnostics should be created using translatable messages
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TranslatableInAddSubdiagnostic;
|
||||
|
||||
impl AddSubdiagnostic for TranslatableInAddSubdiagnostic {
|
||||
fn add_to_diagnostic(self, diag: &mut Diagnostic) {
|
||||
diag.note(fluent::typeck::note);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn make_diagnostics<'a>(sess: &'a ParseSess) {
|
||||
let _diag = sess.struct_err(fluent::parser::expect_path);
|
||||
//~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
|
||||
|
||||
let _diag = sess.struct_err("untranslatable diagnostic");
|
||||
//~^ ERROR diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
|
||||
//~^^ ERROR diagnostics should be created using translatable messages
|
||||
}
|
||||
44
src/test/ui-fulldeps/internal-lints/diagnostics.stderr
Normal file
44
src/test/ui-fulldeps/internal-lints/diagnostics.stderr
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
error: diagnostics should be created using translatable messages
|
||||
--> $DIR/diagnostics.rs:36:14
|
||||
|
|
||||
LL | sess.struct_err("untranslatable diagnostic")
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/diagnostics.rs:5:9
|
||||
|
|
||||
LL | #![deny(rustc::untranslatable_diagnostic)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: diagnostics should be created using translatable messages
|
||||
--> $DIR/diagnostics.rs:53:14
|
||||
|
|
||||
LL | diag.note("untranslatable diagnostic");
|
||||
| ^^^^
|
||||
|
||||
error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
|
||||
--> $DIR/diagnostics.rs:67:22
|
||||
|
|
||||
LL | let _diag = sess.struct_err(fluent::parser::expect_path);
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/diagnostics.rs:6:9
|
||||
|
|
||||
LL | #![deny(rustc::diagnostic_outside_of_impl)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: diagnostics should only be created in `SessionDiagnostic`/`AddSubdiagnostic` impls
|
||||
--> $DIR/diagnostics.rs:70:22
|
||||
|
|
||||
LL | let _diag = sess.struct_err("untranslatable diagnostic");
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: diagnostics should be created using translatable messages
|
||||
--> $DIR/diagnostics.rs:70:22
|
||||
|
|
||||
LL | let _diag = sess.struct_err("untranslatable diagnostic");
|
||||
| ^^^^^^^^^^
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
15
src/test/ui-fulldeps/internal-lints/diagnostics_incorrect.rs
Normal file
15
src/test/ui-fulldeps/internal-lints/diagnostics_incorrect.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// compile-flags: -Z unstable-options
|
||||
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
//~^ ERROR attribute should be applied to a function
|
||||
struct Foo;
|
||||
|
||||
impl Foo {
|
||||
#[rustc_lint_diagnostics(a)]
|
||||
//~^ ERROR malformed `rustc_lint_diagnostics`
|
||||
fn bar() {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
error: malformed `rustc_lint_diagnostics` attribute input
|
||||
--> $DIR/diagnostics_incorrect.rs:10:5
|
||||
|
|
||||
LL | #[rustc_lint_diagnostics(a)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_lint_diagnostics]`
|
||||
|
||||
error: attribute should be applied to a function
|
||||
--> $DIR/diagnostics_incorrect.rs:5:1
|
||||
|
|
||||
LL | #[rustc_lint_diagnostics]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | struct Foo;
|
||||
| ----------- not a function
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeConstArrays {
|
|||
if let ItemKind::Const(hir_ty, _) = &item.kind;
|
||||
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
||||
if let ty::Array(element_type, cst) = ty.kind();
|
||||
if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val();
|
||||
if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.kind();
|
||||
if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx);
|
||||
if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes());
|
||||
if self.maximum_allowed_size < element_count * element_size;
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ impl<'tcx> LateLintPass<'tcx> for LargeStackArrays {
|
|||
if_chain! {
|
||||
if let ExprKind::Repeat(_, _) = expr.kind;
|
||||
if let ty::Array(element_type, cst) = cx.typeck_results().expr_ty(expr).kind();
|
||||
if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.val();
|
||||
if let ConstKind::Value(ConstValue::Scalar(element_count)) = cst.kind();
|
||||
if let Ok(element_count) = element_count.to_machine_usize(&cx.tcx);
|
||||
if let Ok(element_size) = cx.layout_of(*element_type).map(|l| l.size.bytes());
|
||||
if self.maximum_allowed_size < element_count * element_size;
|
||||
|
|
|
|||
|
|
@ -582,7 +582,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
|
|||
|
||||
pub fn miri_to_const(result: ty::Const<'_>) -> Option<Constant> {
|
||||
use rustc_middle::mir::interpret::ConstValue;
|
||||
match result.val() {
|
||||
match result.kind() {
|
||||
ty::ConstKind::Value(ConstValue::Scalar(Scalar::Int(int))) => {
|
||||
match result.ty().kind() {
|
||||
ty::Bool => Some(Constant::Bool(int == ScalarInt::TRUE)),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue