Skip to content

Commit 4a54b26

Browse files
committed
Auto merge of rust-lang#147428 - matthiaskrgr:rollup-k3nlxlu, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#145495 (Use declarative macro for `#[derive(TryFromU32)]`) - rust-lang#147165 (test: Subtract code_offset from width for ui_testing) - rust-lang#147354 (Fix wrong span for hightlight for duplicated diff lines) - rust-lang#147395 (Improve diagnostics: update note and add help message) - rust-lang#147396 (Fluent tidy improvements) - rust-lang#147407 (Update books) - rust-lang#147413 (don't panic on extern with just multiple quotes in the name) r? `@ghost` `@rustbot` modify labels: rollup
2 parents d773bd0 + 21bf6db commit 4a54b26

File tree

59 files changed

+319
-345
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+319
-345
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_abi::Align;
66
use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, ConstCodegenMethods};
77
use rustc_data_structures::fx::FxIndexMap;
88
use rustc_index::IndexVec;
9-
use rustc_macros::TryFromU32;
109
use rustc_middle::ty::TyCtxt;
1110
use rustc_session::RemapFileNameExt;
1211
use rustc_session::config::RemapPathScopeComponents;
@@ -16,7 +15,7 @@ use tracing::debug;
1615
use crate::common::CodegenCx;
1716
use crate::coverageinfo::llvm_cov;
1817
use crate::coverageinfo::mapgen::covfun::prepare_covfun_record;
19-
use crate::llvm;
18+
use crate::{TryFromU32, llvm};
2019

2120
mod covfun;
2221
mod spans;

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#![feature(if_let_guard)]
1515
#![feature(impl_trait_in_assoc_type)]
1616
#![feature(iter_intersperse)]
17+
#![feature(macro_derive)]
1718
#![feature(rustdoc_internals)]
1819
#![feature(slice_as_array)]
1920
#![feature(try_blocks)]
@@ -65,6 +66,7 @@ mod errors;
6566
mod intrinsic;
6667
mod llvm;
6768
mod llvm_util;
69+
mod macros;
6870
mod mono_item;
6971
mod type_;
7072
mod type_of;
@@ -74,6 +76,8 @@ mod value;
7476

7577
rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
7678

79+
pub(crate) use macros::TryFromU32;
80+
7781
#[derive(Clone)]
7882
pub struct LlvmCodegenBackend(());
7983

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@ use std::ptr;
1919

2020
use bitflags::bitflags;
2121
use libc::{c_char, c_int, c_uchar, c_uint, c_ulonglong, c_void, size_t};
22-
use rustc_macros::TryFromU32;
2322

2423
use super::RustString;
2524
use super::debuginfo::{
2625
DIArray, DIBuilder, DIDerivedType, DIDescriptor, DIEnumerator, DIFile, DIFlags,
2726
DIGlobalVariableExpression, DILocation, DISPFlags, DIScope, DISubprogram,
2827
DITemplateTypeParameter, DIType, DebugEmissionKind, DebugNameTableKind,
2928
};
30-
use crate::llvm;
3129
use crate::llvm::MetadataKindId;
30+
use crate::{TryFromU32, llvm};
3231

3332
/// In the LLVM-C API, boolean values are passed as `typedef int LLVMBool`,
3433
/// which has a different ABI from Rust or C++ `bool`.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
macro_rules! TryFromU32 {
2+
derive() (
3+
$(#[$meta:meta])*
4+
$vis:vis enum $Type:ident {
5+
$(
6+
$(#[$varmeta:meta])*
7+
$Variant:ident $(= $discr:expr)?
8+
),* $(,)?
9+
}
10+
) => {
11+
impl ::core::convert::TryFrom<u32> for $Type {
12+
type Error = u32;
13+
#[allow(deprecated)] // Don't warn about deprecated variants.
14+
fn try_from(value: u32) -> ::core::result::Result<$Type, Self::Error> {
15+
$( if value == const { $Type::$Variant as u32 } { return Ok($Type::$Variant) } )*
16+
Err(value)
17+
}
18+
}
19+
}
20+
}
21+
22+
pub(crate) use TryFromU32;

compiler/rustc_errors/src/emitter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,7 +2021,7 @@ impl HumanEmitter {
20212021
if let Some(width) = self.diagnostic_width {
20222022
width.saturating_sub(code_offset)
20232023
} else if self.ui_testing || cfg!(miri) {
2024-
DEFAULT_COLUMN_WIDTH
2024+
DEFAULT_COLUMN_WIDTH.saturating_sub(code_offset)
20252025
} else {
20262026
termize::dimensions()
20272027
.map(|(w, _)| w.saturating_sub(code_offset))
@@ -2412,7 +2412,7 @@ impl HumanEmitter {
24122412
// too bad to begin with, so we side-step that issue here.
24132413
for (i, line) in snippet.lines().enumerate() {
24142414
let line = normalize_whitespace(line);
2415-
let row = row_num - 2 - (newlines - i - 1);
2415+
let row = (row_num - 2 - (newlines - i - 1)).max(2);
24162416
// On the first line, we highlight between the start of the part
24172417
// span, and the end of that line.
24182418
// On the last line, we highlight between the start of the line, and

compiler/rustc_expand/messages.ftl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ expand_module_file_not_found =
118118
.note = if there is a `mod {$name}` elsewhere in the crate already, import it with `use crate::...` instead
119119
120120
expand_module_in_block =
121-
cannot declare a non-inline module inside a block unless it has a path attribute
122-
.note = maybe `use` the module `{$name}` instead of redeclaring it
121+
cannot declare a file module inside a block unless it has a path attribute
122+
.help = maybe `use` the module `{$name}` instead of redeclaring it
123+
.note = file modules are usually placed outside of blocks, at the top level of the file
123124
124125
expand_module_multiple_candidates =
125126
file for module `{$name}` found at both "{$default_path}" and "{$secondary_path}"

compiler/rustc_expand/src/errors.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ pub(crate) struct ModuleCircular {
265265

266266
#[derive(Diagnostic)]
267267
#[diag(expand_module_in_block)]
268+
#[note]
268269
pub(crate) struct ModuleInBlock {
269270
#[primary_span]
270271
pub span: Span,
@@ -273,7 +274,7 @@ pub(crate) struct ModuleInBlock {
273274
}
274275

275276
#[derive(Subdiagnostic)]
276-
#[note(expand_note)]
277+
#[help(expand_help)]
277278
pub(crate) struct ModuleInBlockName {
278279
#[primary_span]
279280
pub span: Span,

compiler/rustc_macros/src/lib.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ mod print_attribute;
1818
mod query;
1919
mod serialize;
2020
mod symbols;
21-
mod try_from;
2221
mod type_foldable;
2322
mod type_visitable;
2423
mod visitable;
@@ -176,14 +175,6 @@ decl_derive!(
176175
applicability)] => diagnostics::subdiagnostic_derive
177176
);
178177

179-
decl_derive! {
180-
[TryFromU32] =>
181-
/// Derives `TryFrom<u32>` for the annotated `enum`, which must have no fields.
182-
/// Each variant maps to the value it would produce under an `as u32` cast.
183-
///
184-
/// The error type is `u32`.
185-
try_from::try_from_u32
186-
}
187178
decl_derive! {
188179
[PrintAttribute] =>
189180
/// Derives `PrintAttribute` for `AttributeKind`.

compiler/rustc_macros/src/try_from.rs

Lines changed: 0 additions & 55 deletions
This file was deleted.

compiler/rustc_span/src/symbol.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2511,9 +2511,11 @@ impl Ident {
25112511
}
25122512

25132513
/// Creates a new ident with the same span and name with leading quote removed, if any.
2514-
/// If called on an empty ident, or with name just a single quote, returns an empty ident which is invalid.
2514+
/// Calling it on a `'` ident will return an empty ident, which triggers debug assertions.
25152515
pub fn without_first_quote(self) -> Ident {
2516-
Ident::new(Symbol::intern(self.as_str().trim_start_matches('\'')), self.span)
2516+
self.as_str()
2517+
.strip_prefix('\'')
2518+
.map_or(self, |name| Ident::new(Symbol::intern(name), self.span))
25172519
}
25182520

25192521
/// "Normalize" ident for use in comparisons using "item hygiene".

0 commit comments

Comments
 (0)