Skip to content

Commit 3610b45

Browse files
committed
Auto merge of rust-lang#127876 - matthiaskrgr:rollup-aczhyuj, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#127542 ([`macro_metavar_expr_concat`] Add support for literals) - rust-lang#127652 (Unignore cg_gcc fmt) - rust-lang#127664 (Fix precise capturing suggestion for hidden regions when we have APITs) - rust-lang#127806 (Some parser improvements) - rust-lang#127828 (Commonize `uname -m` results for `aarch64` in docker runner) - rust-lang#127845 (unix: break `stack_overflow::install_main_guard` into smaller fn) - rust-lang#127854 (Add internal lint for detecting non-glob imports of `rustc_type_ir::inherent`) - rust-lang#127861 (Document the column numbers for the dbg! macro) - rust-lang#127875 (style-guide: Clarify version-sorting) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e35364a + 5a8d0ec commit 3610b45

File tree

41 files changed

+915
-360
lines changed

Some content is hidden

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

41 files changed

+915
-360
lines changed

compiler/rustc_ast/src/token.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,7 @@ impl Token {
699699
false
700700
}
701701

702-
/// Would `maybe_whole_expr` in `parser.rs` return `Ok(..)`?
703-
/// That is, is this a pre-parsed expression dropped into the token stream
702+
/// Is this a pre-parsed expression dropped into the token stream
704703
/// (which happens while parsing the result of macro expansion)?
705704
pub fn is_whole_expr(&self) -> bool {
706705
if let Interpolated(nt) = &self.kind
+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
version = "Two"
12
use_small_heuristics = "Max"
3+
merge_derives = false

compiler/rustc_codegen_gcc/build_system/src/clone_gcc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Args {
3434
"--out-path" => match args.next() {
3535
Some(path) if !path.is_empty() => out_path = Some(path),
3636
_ => {
37-
return Err("Expected an argument after `--out-path`, found nothing".into())
37+
return Err("Expected an argument after `--out-path`, found nothing".into());
3838
}
3939
},
4040
"--help" => {

compiler/rustc_codegen_gcc/build_system/src/config.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl ConfigFile {
5454
config.gcc_path = Some(value.as_str().to_string())
5555
}
5656
("gcc-path", _) => {
57-
return failed_config_parsing(config_file, "Expected a string for `gcc-path`")
57+
return failed_config_parsing(config_file, "Expected a string for `gcc-path`");
5858
}
5959
("download-gccjit", TomlValue::Boolean(value)) => {
6060
config.download_gccjit = Some(*value)
@@ -63,7 +63,7 @@ impl ConfigFile {
6363
return failed_config_parsing(
6464
config_file,
6565
"Expected a boolean for `download-gccjit`",
66-
)
66+
);
6767
}
6868
_ => return failed_config_parsing(config_file, &format!("Unknown key `{}`", key)),
6969
}
@@ -73,7 +73,7 @@ impl ConfigFile {
7373
return failed_config_parsing(
7474
config_file,
7575
"At least one of `gcc-path` or `download-gccjit` value must be set",
76-
)
76+
);
7777
}
7878
(Some(_), Some(true)) => {
7979
println!(
@@ -144,7 +144,7 @@ impl ConfigInfo {
144144
_ => {
145145
return Err(
146146
"Expected a value after `--target-triple`, found nothing".to_string()
147-
)
147+
);
148148
}
149149
},
150150
"--out-dir" => match args.next() {
@@ -158,7 +158,7 @@ impl ConfigInfo {
158158
self.config_file = Some(arg.to_string());
159159
}
160160
_ => {
161-
return Err("Expected a value after `--config-file`, found nothing".to_string())
161+
return Err("Expected a value after `--config-file`, found nothing".to_string());
162162
}
163163
},
164164
"--release-sysroot" => self.sysroot_release_channel = true,
@@ -169,7 +169,7 @@ impl ConfigInfo {
169169
self.cg_gcc_path = Some(arg.into());
170170
}
171171
_ => {
172-
return Err("Expected a value after `--cg_gcc-path`, found nothing".to_string())
172+
return Err("Expected a value after `--cg_gcc-path`, found nothing".to_string());
173173
}
174174
},
175175
"--use-backend" => match args.next() {
@@ -277,7 +277,7 @@ impl ConfigInfo {
277277
self.gcc_path = match gcc_path {
278278
Some(path) => path,
279279
None => {
280-
return Err(format!("missing `gcc-path` value from `{}`", config_file.display(),))
280+
return Err(format!("missing `gcc-path` value from `{}`", config_file.display(),));
281281
}
282282
};
283283
Ok(())

compiler/rustc_codegen_gcc/build_system/src/test.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl TestArg {
109109
test_arg.flags.extend_from_slice(&["--features".into(), feature]);
110110
}
111111
_ => {
112-
return Err("Expected an argument after `--features`, found nothing".into())
112+
return Err("Expected an argument after `--features`, found nothing".into());
113113
}
114114
},
115115
"--use-system-gcc" => {
@@ -458,11 +458,7 @@ fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<PathBuf, String> {
458458
.map_err(|error| format!("Failed to retrieve cargo path: {:?}", error))
459459
.and_then(|cargo| {
460460
let cargo = cargo.trim().to_owned();
461-
if cargo.is_empty() {
462-
Err(format!("`cargo` path is empty"))
463-
} else {
464-
Ok(cargo)
465-
}
461+
if cargo.is_empty() { Err(format!("`cargo` path is empty")) } else { Ok(cargo) }
466462
})?;
467463
let rustc = String::from_utf8(
468464
run_command_with_env(&[&"rustup", &toolchain, &"which", &"rustc"], rust_dir, Some(env))?
@@ -471,11 +467,7 @@ fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<PathBuf, String> {
471467
.map_err(|error| format!("Failed to retrieve rustc path: {:?}", error))
472468
.and_then(|rustc| {
473469
let rustc = rustc.trim().to_owned();
474-
if rustc.is_empty() {
475-
Err(format!("`rustc` path is empty"))
476-
} else {
477-
Ok(rustc)
478-
}
470+
if rustc.is_empty() { Err(format!("`rustc` path is empty")) } else { Ok(rustc) }
479471
})?;
480472
let llvm_filecheck = match run_command_with_env(
481473
&[

compiler/rustc_codegen_gcc/build_system/src/utils.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,7 @@ pub fn cargo_install(to_install: &str) -> Result<(), String> {
175175
pub fn get_os_name() -> Result<String, String> {
176176
let output = run_command(&[&"uname"], None)?;
177177
let name = std::str::from_utf8(&output.stdout).unwrap_or("").trim().to_string();
178-
if !name.is_empty() {
179-
Ok(name)
180-
} else {
181-
Err("Failed to retrieve the OS name".to_string())
182-
}
178+
if !name.is_empty() { Ok(name) } else { Err("Failed to retrieve the OS name".to_string()) }
183179
}
184180

185181
#[derive(Default, PartialEq)]

compiler/rustc_codegen_gcc/src/abi.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ impl<'a, 'gcc, 'tcx> AbiBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
2626
} else {
2727
false
2828
};
29-
if on_stack {
30-
param.to_lvalue().get_address(None)
31-
} else {
32-
param.to_rvalue()
33-
}
29+
if on_stack { param.to_lvalue().get_address(None) } else { param.to_rvalue() }
3430
}
3531
}
3632

compiler/rustc_codegen_gcc/src/asm.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -858,11 +858,7 @@ fn modifier_to_gcc(
858858
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::reg) => modifier,
859859
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg)
860860
| InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg_low16) => {
861-
if modifier == Some('v') {
862-
None
863-
} else {
864-
modifier
865-
}
861+
if modifier == Some('v') { None } else { modifier }
866862
}
867863
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::preg) => {
868864
unreachable!("clobber-only")

compiler/rustc_codegen_gcc/src/builder.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -1043,11 +1043,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
10431043
let llty = place.layout.scalar_pair_element_gcc_type(self, i);
10441044
let load = self.load(llty, llptr, align);
10451045
scalar_load_metadata(self, load, scalar);
1046-
if scalar.is_bool() {
1047-
self.trunc(load, self.type_i1())
1048-
} else {
1049-
load
1050-
}
1046+
if scalar.is_bool() { self.trunc(load, self.type_i1()) } else { load }
10511047
};
10521048

10531049
OperandValue::Pair(
@@ -1795,18 +1791,10 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
17951791
// This already happens today with u128::MAX = 2^128 - 1 > f32::MAX.
17961792
let int_max = |signed: bool, int_width: u64| -> u128 {
17971793
let shift_amount = 128 - int_width;
1798-
if signed {
1799-
i128::MAX as u128 >> shift_amount
1800-
} else {
1801-
u128::MAX >> shift_amount
1802-
}
1794+
if signed { i128::MAX as u128 >> shift_amount } else { u128::MAX >> shift_amount }
18031795
};
18041796
let int_min = |signed: bool, int_width: u64| -> i128 {
1805-
if signed {
1806-
i128::MIN >> (128 - int_width)
1807-
} else {
1808-
0
1809-
}
1797+
if signed { i128::MIN >> (128 - int_width) } else { 0 }
18101798
};
18111799

18121800
let compute_clamp_bounds_single = |signed: bool, int_width: u64| -> (u128, u128) {

compiler/rustc_codegen_gcc/src/common.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ pub fn type_is_pointer(typ: Type<'_>) -> bool {
5858

5959
impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
6060
fn const_null(&self, typ: Type<'gcc>) -> RValue<'gcc> {
61-
if type_is_pointer(typ) {
62-
self.context.new_null(typ)
63-
} else {
64-
self.const_int(typ, 0)
65-
}
61+
if type_is_pointer(typ) { self.context.new_null(typ) } else { self.const_int(typ, 0) }
6662
}
6763

6864
fn const_undef(&self, typ: Type<'gcc>) -> RValue<'gcc> {

compiler/rustc_expand/src/mbe/metavar_expr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ impl MetaVarExpr {
119119
}
120120
}
121121

122+
/// Indicates what is placed in a `concat` parameter. For example, literals
123+
/// (`${concat("foo", "bar")}`) or adhoc identifiers (`${concat(foo, bar)}`).
122124
#[derive(Debug, Decodable, Encodable, PartialEq)]
123125
pub(crate) enum MetaVarExprConcatElem {
124126
/// Identifier WITHOUT a preceding dollar sign, which means that this identifier should be

compiler/rustc_expand/src/mbe/transcribe.rs

+35-24
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ use crate::mbe::macro_parser::{NamedMatch, NamedMatch::*};
66
use crate::mbe::metavar_expr::{MetaVarExprConcatElem, RAW_IDENT_ERR};
77
use crate::mbe::{self, KleeneOp, MetaVarExpr};
88
use rustc_ast::mut_visit::{self, MutVisitor};
9-
use rustc_ast::token::IdentIsRaw;
10-
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
9+
use rustc_ast::token::{self, Delimiter, Nonterminal, Token, TokenKind};
10+
use rustc_ast::token::{IdentIsRaw, Lit, LitKind};
1111
use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree};
12+
use rustc_ast::ExprKind;
1213
use rustc_data_structures::fx::FxHashMap;
1314
use rustc_errors::{pluralize, Diag, DiagCtxtHandle, PResult};
1415
use rustc_parse::lexer::nfc_normalize;
@@ -17,7 +18,7 @@ use rustc_session::parse::ParseSess;
1718
use rustc_session::parse::SymbolGallery;
1819
use rustc_span::hygiene::{LocalExpnId, Transparency};
1920
use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent};
20-
use rustc_span::{with_metavar_spans, Span, SyntaxContext};
21+
use rustc_span::{with_metavar_spans, Span, Symbol, SyntaxContext};
2122
use smallvec::{smallvec, SmallVec};
2223
use std::mem;
2324

@@ -691,12 +692,12 @@ fn transcribe_metavar_expr<'a>(
691692
MetaVarExpr::Concat(ref elements) => {
692693
let mut concatenated = String::new();
693694
for element in elements.into_iter() {
694-
let string = match element {
695-
MetaVarExprConcatElem::Ident(elem) => elem.to_string(),
696-
MetaVarExprConcatElem::Literal(elem) => elem.as_str().into(),
697-
MetaVarExprConcatElem::Var(elem) => extract_ident(dcx, *elem, interp)?,
695+
let symbol = match element {
696+
MetaVarExprConcatElem::Ident(elem) => elem.name,
697+
MetaVarExprConcatElem::Literal(elem) => *elem,
698+
MetaVarExprConcatElem::Var(elem) => extract_var_symbol(dcx, *elem, interp)?,
698699
};
699-
concatenated.push_str(&string);
700+
concatenated.push_str(symbol.as_str());
700701
}
701702
let symbol = nfc_normalize(&concatenated);
702703
let concatenated_span = visited_span();
@@ -750,32 +751,42 @@ fn transcribe_metavar_expr<'a>(
750751
Ok(())
751752
}
752753

753-
/// Extracts an identifier that can be originated from a `$var:ident` variable or from a token tree.
754-
fn extract_ident<'a>(
754+
/// Extracts an metavariable symbol that can be an identifier, a token tree or a literal.
755+
fn extract_var_symbol<'a>(
755756
dcx: DiagCtxtHandle<'a>,
756757
ident: Ident,
757758
interp: &FxHashMap<MacroRulesNormalizedIdent, NamedMatch>,
758-
) -> PResult<'a, String> {
759+
) -> PResult<'a, Symbol> {
759760
if let NamedMatch::MatchedSingle(pnr) = matched_from_ident(dcx, ident, interp)? {
760761
if let ParseNtResult::Ident(nt_ident, is_raw) = pnr {
761762
if let IdentIsRaw::Yes = is_raw {
762763
return Err(dcx.struct_span_err(ident.span, RAW_IDENT_ERR));
763764
}
764-
return Ok(nt_ident.to_string());
765+
return Ok(nt_ident.name);
765766
}
766-
if let ParseNtResult::Tt(TokenTree::Token(
767-
Token { kind: TokenKind::Ident(token_ident, is_raw), .. },
768-
_,
769-
)) = pnr
770-
{
771-
if let IdentIsRaw::Yes = is_raw {
772-
return Err(dcx.struct_span_err(ident.span, RAW_IDENT_ERR));
767+
768+
if let ParseNtResult::Tt(TokenTree::Token(Token { kind, .. }, _)) = pnr {
769+
if let TokenKind::Ident(symbol, is_raw) = kind {
770+
if let IdentIsRaw::Yes = is_raw {
771+
return Err(dcx.struct_span_err(ident.span, RAW_IDENT_ERR));
772+
}
773+
return Ok(*symbol);
773774
}
774-
return Ok(token_ident.to_string());
775+
776+
if let TokenKind::Literal(Lit { kind: LitKind::Str, symbol, suffix: None }) = kind {
777+
return Ok(*symbol);
778+
}
779+
}
780+
781+
if let ParseNtResult::Nt(nt) = pnr
782+
&& let Nonterminal::NtLiteral(expr) = &**nt
783+
&& let ExprKind::Lit(Lit { kind: LitKind::Str, symbol, suffix: None }) = &expr.kind
784+
{
785+
return Ok(*symbol);
775786
}
776787
}
777-
Err(dcx.struct_span_err(
778-
ident.span,
779-
"`${concat(..)}` currently only accepts identifiers or meta-variables as parameters",
780-
))
788+
Err(dcx
789+
.struct_err("metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt`")
790+
.with_note("currently only string literals are supported")
791+
.with_span(ident.span))
781792
}

compiler/rustc_infer/messages.ftl

+5
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ infer_outlives_content = lifetime of reference outlives lifetime of borrowed con
225225
infer_precise_capturing_existing = add `{$new_lifetime}` to the `use<...>` bound to explicitly capture it
226226
infer_precise_capturing_new = add a `use<...>` bound to explicitly capture `{$new_lifetime}`
227227
228+
infer_precise_capturing_new_but_apit = add a `use<...>` bound to explicitly capture `{$new_lifetime}` after turning all argument-position `impl Trait` into type parameters, noting that this possibly affects the API of this crate
229+
228230
infer_prlf_defined_with_sub = the lifetime `{$sub_symbol}` defined here...
229231
infer_prlf_defined_without_sub = the lifetime defined here...
230232
infer_prlf_known_limitation = this is a known limitation that will be removed in the future (see issue #100013 <https://github.com/rust-lang/rust/issues/100013> for more information)
@@ -387,6 +389,9 @@ infer_type_annotations_needed = {$source_kind ->
387389
.label = type must be known at this point
388390
389391
infer_types_declared_different = these two types are declared with different lifetimes...
392+
393+
infer_warn_removing_apit_params = you could use a `use<...>` bound to explicitly capture `{$new_lifetime}`, but argument-position `impl Trait`s are not nameable
394+
390395
infer_where_copy_predicates = copy the `where` clause predicates from the trait
391396
392397
infer_where_remove = remove the `where` clause

0 commit comments

Comments
 (0)