Skip to content

Commit

Permalink
Auto merge of rust-lang#127892 - tgross35:rollup-7j9wkzc, r=tgross35
Browse files Browse the repository at this point in the history
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#127859 (ptr::metadata: avoid references to extern types)
 - 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
  • Loading branch information
bors committed Jul 18, 2024
2 parents e35364a + 7c63526 commit 4bb2f27
Show file tree
Hide file tree
Showing 33 changed files with 758 additions and 364 deletions.
3 changes: 1 addition & 2 deletions compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,7 @@ impl Token {
false
}

/// Would `maybe_whole_expr` in `parser.rs` return `Ok(..)`?
/// That is, is this a pre-parsed expression dropped into the token stream
/// Is this a pre-parsed expression dropped into the token stream
/// (which happens while parsing the result of macro expansion)?
pub fn is_whole_expr(&self) -> bool {
if let Interpolated(nt) = &self.kind
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_gcc/.rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
version = "Two"
use_small_heuristics = "Max"
merge_derives = false
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_gcc/build_system/src/clone_gcc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl Args {
"--out-path" => match args.next() {
Some(path) if !path.is_empty() => out_path = Some(path),
_ => {
return Err("Expected an argument after `--out-path`, found nothing".into())
return Err("Expected an argument after `--out-path`, found nothing".into());
}
},
"--help" => {
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_codegen_gcc/build_system/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl ConfigFile {
config.gcc_path = Some(value.as_str().to_string())
}
("gcc-path", _) => {
return failed_config_parsing(config_file, "Expected a string for `gcc-path`")
return failed_config_parsing(config_file, "Expected a string for `gcc-path`");
}
("download-gccjit", TomlValue::Boolean(value)) => {
config.download_gccjit = Some(*value)
Expand All @@ -63,7 +63,7 @@ impl ConfigFile {
return failed_config_parsing(
config_file,
"Expected a boolean for `download-gccjit`",
)
);
}
_ => return failed_config_parsing(config_file, &format!("Unknown key `{}`", key)),
}
Expand All @@ -73,7 +73,7 @@ impl ConfigFile {
return failed_config_parsing(
config_file,
"At least one of `gcc-path` or `download-gccjit` value must be set",
)
);
}
(Some(_), Some(true)) => {
println!(
Expand Down Expand Up @@ -144,7 +144,7 @@ impl ConfigInfo {
_ => {
return Err(
"Expected a value after `--target-triple`, found nothing".to_string()
)
);
}
},
"--out-dir" => match args.next() {
Expand All @@ -158,7 +158,7 @@ impl ConfigInfo {
self.config_file = Some(arg.to_string());
}
_ => {
return Err("Expected a value after `--config-file`, found nothing".to_string())
return Err("Expected a value after `--config-file`, found nothing".to_string());
}
},
"--release-sysroot" => self.sysroot_release_channel = true,
Expand All @@ -169,7 +169,7 @@ impl ConfigInfo {
self.cg_gcc_path = Some(arg.into());
}
_ => {
return Err("Expected a value after `--cg_gcc-path`, found nothing".to_string())
return Err("Expected a value after `--cg_gcc-path`, found nothing".to_string());
}
},
"--use-backend" => match args.next() {
Expand Down Expand Up @@ -277,7 +277,7 @@ impl ConfigInfo {
self.gcc_path = match gcc_path {
Some(path) => path,
None => {
return Err(format!("missing `gcc-path` value from `{}`", config_file.display(),))
return Err(format!("missing `gcc-path` value from `{}`", config_file.display(),));
}
};
Ok(())
Expand Down
14 changes: 3 additions & 11 deletions compiler/rustc_codegen_gcc/build_system/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl TestArg {
test_arg.flags.extend_from_slice(&["--features".into(), feature]);
}
_ => {
return Err("Expected an argument after `--features`, found nothing".into())
return Err("Expected an argument after `--features`, found nothing".into());
}
},
"--use-system-gcc" => {
Expand Down Expand Up @@ -458,11 +458,7 @@ fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<PathBuf, String> {
.map_err(|error| format!("Failed to retrieve cargo path: {:?}", error))
.and_then(|cargo| {
let cargo = cargo.trim().to_owned();
if cargo.is_empty() {
Err(format!("`cargo` path is empty"))
} else {
Ok(cargo)
}
if cargo.is_empty() { Err(format!("`cargo` path is empty")) } else { Ok(cargo) }
})?;
let rustc = String::from_utf8(
run_command_with_env(&[&"rustup", &toolchain, &"which", &"rustc"], rust_dir, Some(env))?
Expand All @@ -471,11 +467,7 @@ fn setup_rustc(env: &mut Env, args: &TestArg) -> Result<PathBuf, String> {
.map_err(|error| format!("Failed to retrieve rustc path: {:?}", error))
.and_then(|rustc| {
let rustc = rustc.trim().to_owned();
if rustc.is_empty() {
Err(format!("`rustc` path is empty"))
} else {
Ok(rustc)
}
if rustc.is_empty() { Err(format!("`rustc` path is empty")) } else { Ok(rustc) }
})?;
let llvm_filecheck = match run_command_with_env(
&[
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_codegen_gcc/build_system/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,7 @@ pub fn cargo_install(to_install: &str) -> Result<(), String> {
pub fn get_os_name() -> Result<String, String> {
let output = run_command(&[&"uname"], None)?;
let name = std::str::from_utf8(&output.stdout).unwrap_or("").trim().to_string();
if !name.is_empty() {
Ok(name)
} else {
Err("Failed to retrieve the OS name".to_string())
}
if !name.is_empty() { Ok(name) } else { Err("Failed to retrieve the OS name".to_string()) }
}

#[derive(Default, PartialEq)]
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_codegen_gcc/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ impl<'a, 'gcc, 'tcx> AbiBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
} else {
false
};
if on_stack {
param.to_lvalue().get_address(None)
} else {
param.to_rvalue()
}
if on_stack { param.to_lvalue().get_address(None) } else { param.to_rvalue() }
}
}

Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_codegen_gcc/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -858,11 +858,7 @@ fn modifier_to_gcc(
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::reg) => modifier,
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg)
| InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg_low16) => {
if modifier == Some('v') {
None
} else {
modifier
}
if modifier == Some('v') { None } else { modifier }
}
InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::preg) => {
unreachable!("clobber-only")
Expand Down
18 changes: 3 additions & 15 deletions compiler/rustc_codegen_gcc/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1043,11 +1043,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
let llty = place.layout.scalar_pair_element_gcc_type(self, i);
let load = self.load(llty, llptr, align);
scalar_load_metadata(self, load, scalar);
if scalar.is_bool() {
self.trunc(load, self.type_i1())
} else {
load
}
if scalar.is_bool() { self.trunc(load, self.type_i1()) } else { load }
};

OperandValue::Pair(
Expand Down Expand Up @@ -1795,18 +1791,10 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
// This already happens today with u128::MAX = 2^128 - 1 > f32::MAX.
let int_max = |signed: bool, int_width: u64| -> u128 {
let shift_amount = 128 - int_width;
if signed {
i128::MAX as u128 >> shift_amount
} else {
u128::MAX >> shift_amount
}
if signed { i128::MAX as u128 >> shift_amount } else { u128::MAX >> shift_amount }
};
let int_min = |signed: bool, int_width: u64| -> i128 {
if signed {
i128::MIN >> (128 - int_width)
} else {
0
}
if signed { i128::MIN >> (128 - int_width) } else { 0 }
};

let compute_clamp_bounds_single = |signed: bool, int_width: u64| -> (u128, u128) {
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_codegen_gcc/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ pub fn type_is_pointer(typ: Type<'_>) -> bool {

impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
fn const_null(&self, typ: Type<'gcc>) -> RValue<'gcc> {
if type_is_pointer(typ) {
self.context.new_null(typ)
} else {
self.const_int(typ, 0)
}
if type_is_pointer(typ) { self.context.new_null(typ) } else { self.const_int(typ, 0) }
}

fn const_undef(&self, typ: Type<'gcc>) -> RValue<'gcc> {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_expand/src/mbe/metavar_expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ impl MetaVarExpr {
}
}

/// Indicates what is placed in a `concat` parameter. For example, literals
/// (`${concat("foo", "bar")}`) or adhoc identifiers (`${concat(foo, bar)}`).
#[derive(Debug, Decodable, Encodable, PartialEq)]
pub(crate) enum MetaVarExprConcatElem {
/// Identifier WITHOUT a preceding dollar sign, which means that this identifier should be
Expand Down
59 changes: 35 additions & 24 deletions compiler/rustc_expand/src/mbe/transcribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ use crate::mbe::macro_parser::{NamedMatch, NamedMatch::*};
use crate::mbe::metavar_expr::{MetaVarExprConcatElem, RAW_IDENT_ERR};
use crate::mbe::{self, KleeneOp, MetaVarExpr};
use rustc_ast::mut_visit::{self, MutVisitor};
use rustc_ast::token::IdentIsRaw;
use rustc_ast::token::{self, Delimiter, Token, TokenKind};
use rustc_ast::token::{self, Delimiter, Nonterminal, Token, TokenKind};
use rustc_ast::token::{IdentIsRaw, Lit, LitKind};
use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree};
use rustc_ast::ExprKind;
use rustc_data_structures::fx::FxHashMap;
use rustc_errors::{pluralize, Diag, DiagCtxtHandle, PResult};
use rustc_parse::lexer::nfc_normalize;
Expand All @@ -17,7 +18,7 @@ use rustc_session::parse::ParseSess;
use rustc_session::parse::SymbolGallery;
use rustc_span::hygiene::{LocalExpnId, Transparency};
use rustc_span::symbol::{sym, Ident, MacroRulesNormalizedIdent};
use rustc_span::{with_metavar_spans, Span, SyntaxContext};
use rustc_span::{with_metavar_spans, Span, Symbol, SyntaxContext};
use smallvec::{smallvec, SmallVec};
use std::mem;

Expand Down Expand Up @@ -691,12 +692,12 @@ fn transcribe_metavar_expr<'a>(
MetaVarExpr::Concat(ref elements) => {
let mut concatenated = String::new();
for element in elements.into_iter() {
let string = match element {
MetaVarExprConcatElem::Ident(elem) => elem.to_string(),
MetaVarExprConcatElem::Literal(elem) => elem.as_str().into(),
MetaVarExprConcatElem::Var(elem) => extract_ident(dcx, *elem, interp)?,
let symbol = match element {
MetaVarExprConcatElem::Ident(elem) => elem.name,
MetaVarExprConcatElem::Literal(elem) => *elem,
MetaVarExprConcatElem::Var(elem) => extract_var_symbol(dcx, *elem, interp)?,
};
concatenated.push_str(&string);
concatenated.push_str(symbol.as_str());
}
let symbol = nfc_normalize(&concatenated);
let concatenated_span = visited_span();
Expand Down Expand Up @@ -750,32 +751,42 @@ fn transcribe_metavar_expr<'a>(
Ok(())
}

/// Extracts an identifier that can be originated from a `$var:ident` variable or from a token tree.
fn extract_ident<'a>(
/// Extracts an metavariable symbol that can be an identifier, a token tree or a literal.
fn extract_var_symbol<'a>(
dcx: DiagCtxtHandle<'a>,
ident: Ident,
interp: &FxHashMap<MacroRulesNormalizedIdent, NamedMatch>,
) -> PResult<'a, String> {
) -> PResult<'a, Symbol> {
if let NamedMatch::MatchedSingle(pnr) = matched_from_ident(dcx, ident, interp)? {
if let ParseNtResult::Ident(nt_ident, is_raw) = pnr {
if let IdentIsRaw::Yes = is_raw {
return Err(dcx.struct_span_err(ident.span, RAW_IDENT_ERR));
}
return Ok(nt_ident.to_string());
return Ok(nt_ident.name);
}
if let ParseNtResult::Tt(TokenTree::Token(
Token { kind: TokenKind::Ident(token_ident, is_raw), .. },
_,
)) = pnr
{
if let IdentIsRaw::Yes = is_raw {
return Err(dcx.struct_span_err(ident.span, RAW_IDENT_ERR));

if let ParseNtResult::Tt(TokenTree::Token(Token { kind, .. }, _)) = pnr {
if let TokenKind::Ident(symbol, is_raw) = kind {
if let IdentIsRaw::Yes = is_raw {
return Err(dcx.struct_span_err(ident.span, RAW_IDENT_ERR));
}
return Ok(*symbol);
}
return Ok(token_ident.to_string());

if let TokenKind::Literal(Lit { kind: LitKind::Str, symbol, suffix: None }) = kind {
return Ok(*symbol);
}
}

if let ParseNtResult::Nt(nt) = pnr
&& let Nonterminal::NtLiteral(expr) = &**nt
&& let ExprKind::Lit(Lit { kind: LitKind::Str, symbol, suffix: None }) = &expr.kind
{
return Ok(*symbol);
}
}
Err(dcx.struct_span_err(
ident.span,
"`${concat(..)}` currently only accepts identifiers or meta-variables as parameters",
))
Err(dcx
.struct_err("metavariables of `${concat(..)}` must be of type `ident`, `literal` or `tt`")
.with_note("currently only string literals are supported")
.with_span(ident.span))
}
5 changes: 5 additions & 0 deletions compiler/rustc_infer/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ infer_outlives_content = lifetime of reference outlives lifetime of borrowed con
infer_precise_capturing_existing = add `{$new_lifetime}` to the `use<...>` bound to explicitly capture it
infer_precise_capturing_new = add a `use<...>` bound to explicitly capture `{$new_lifetime}`
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
infer_prlf_defined_with_sub = the lifetime `{$sub_symbol}` defined here...
infer_prlf_defined_without_sub = the lifetime defined here...
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)
Expand Down Expand Up @@ -387,6 +389,9 @@ infer_type_annotations_needed = {$source_kind ->
.label = type must be known at this point
infer_types_declared_different = these two types are declared with different lifetimes...
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
infer_where_copy_predicates = copy the `where` clause predicates from the trait
infer_where_remove =