Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #122265

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1ea6cd7
Add std::ffi::c_str modules
clarfonthey Aug 19, 2023
70639c8
Fixing shellcheck comments on lvi test script
raoulstrackx Feb 27, 2024
3e675bd
add myself to rotation
fee1-dead Feb 29, 2024
c3954b3
Add a tidy check that checks whether the fluent slugs only appear once
mu001999 Mar 2, 2024
d88c7ff
Remove unused fluent messages
mu001999 Mar 2, 2024
9da004e
Dynamically size sigaltstk in std
workingjubilee Jul 10, 2023
c7a48a5
Revert back to Git-for-Windows for MinGW CI builds
majaha Mar 7, 2024
1195518
Helper function for resolve_path
kornelski Mar 1, 2024
25ab1c7
Suggest correct path in include_bytes!
kornelski Mar 1, 2024
7843e46
Factor out non-branch-related pattern data
Nadrieril Mar 9, 2024
594cf1d
review
Nadrieril Mar 9, 2024
2dd05e8
Error on invalid compiletest directives in Rust test files
jieyouxu Feb 24, 2024
046c28f
Fix invalid compiletest directives in tests
jieyouxu Feb 24, 2024
ff1459a
Add test to check unused_lifetimes don't duplicate "parameter is neve…
jieyouxu Mar 9, 2024
282db10
Rollup merge of #112136 - clarfonthey:ffi-c_str, r=cuviper
workingjubilee Mar 10, 2024
f946939
Rollup merge of #113525 - workingjubilee:handle-dynamic-minsigstksz, …
workingjubilee Mar 10, 2024
b928e12
Rollup merge of #121561 - jieyouxu:compiletest-directive-typo-check, …
workingjubilee Mar 10, 2024
866fd3a
Rollup merge of #121685 - fortanix:raoul/shellcheck_on_lvi_test_scrip…
workingjubilee Mar 10, 2024
629d584
Rollup merge of #121833 - kornelski:parent_include, r=estebank
workingjubilee Mar 10, 2024
af83d27
Rollup merge of #121860 - mu001999:master, r=Nilstrieb
workingjubilee Mar 10, 2024
72054d9
Rollup merge of #122125 - majaha:mingw_ci_new, r=Mark-Simulacrum
workingjubilee Mar 10, 2024
9e9fd65
Rollup merge of #122221 - Nadrieril:patextradata, r=oli-obk
workingjubilee Mar 10, 2024
5824411
Rollup merge of #122251 - jieyouxu:unused-lifetimes-dedup-test, r=Nad…
workingjubilee Mar 10, 2024
5ba1ea5
Rollup merge of #122264 - fee1-dead-contrib:add, r=fee1-dead
workingjubilee Mar 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ toolchain.

1. Download the latest [MSYS2 installer][msys2] and go through the installer.

2. Download and install [Git for Windows](https://git-scm.com/download/win).
Make sure that it's in your Windows PATH. To enable access to it from within
MSYS2, edit the relevant `mingw[32|64].ini` file in your MSYS2 installation
directory and uncomment the line `MSYS2_PATH_TYPE=inherit`.

You could install and use MSYS2's version of git instead with `pacman`,
however this is not recommended as it's excrutiatingly slow, and not frequently
tested for compatability.

2. Start a MINGW64 or MINGW32 shell (depending on whether you want 32-bit
or 64-bit Rust) either from your start menu, or by running `mingw64.exe`
or `mingw32.exe` from your MSYS2 installation directory (e.g. `C:\msys64`).
Expand All @@ -160,8 +169,7 @@ toolchain.
# Note that it is important that you do **not** use the 'python2', 'cmake',
# and 'ninja' packages from the 'msys2' subsystem.
# The build has historically been known to fail with these packages.
pacman -S git \
make \
pacman -S make \
diffutils \
tar \
mingw-w64-x86_64-python \
Expand All @@ -176,11 +184,9 @@ toolchain.
python x.py setup dist && python x.py build && python x.py install
```

If you want to use the native versions of Git, Python, or CMake you can remove
them from the above pacman command and install them from another source. Make
sure that they're in your Windows PATH, and edit the relevant `mingw[32|64].ini`
file in your MSYS2 installation directory by uncommenting the line
`MSYS2_PATH_TYPE=inherit` to include them in your MSYS2 PATH.
If you want to try the native Windows versions of Python or CMake, you can remove
them from the above pacman command and install them from another source. Follow
the instructions in step 2 to get them on PATH.

Using Windows native Python can be helpful if you get errors when building LLVM.
You may also want to use Git for Windows, as it is often *much* faster. Turning
Expand Down
150 changes: 120 additions & 30 deletions compiler/rustc_builtin_macros/src/source_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ use rustc_ast::ptr::P;
use rustc_ast::token;
use rustc_ast::tokenstream::TokenStream;
use rustc_ast_pretty::pprust;
use rustc_data_structures::sync::Lrc;
use rustc_expand::base::{
check_zero_tts, get_single_str_from_tts, parse_expr, resolve_path, DummyResult, ExtCtxt,
MacEager, MacResult,
check_zero_tts, get_single_str_from_tts, get_single_str_spanned_from_tts, parse_expr,
resolve_path, DummyResult, ExtCtxt, MacEager, MacResult,
};
use rustc_expand::module::DirOwnership;
use rustc_parse::new_parser_from_file;
use rustc_parse::parser::{ForceCollect, Parser};
use rustc_session::lint::builtin::INCOMPLETE_INCLUDE;
use rustc_span::source_map::SourceMap;
use rustc_span::symbol::Symbol;
use rustc_span::{Pos, Span};

use smallvec::SmallVec;
use std::path::{Path, PathBuf};
use std::rc::Rc;

// These macros all relate to the file system; they either return
Expand Down Expand Up @@ -180,32 +182,22 @@ pub fn expand_include_str(
tts: TokenStream,
) -> Box<dyn MacResult + 'static> {
let sp = cx.with_def_site_ctxt(sp);
let file = match get_single_str_from_tts(cx, sp, tts, "include_str!") {
Ok(file) => file,
let (path, path_span) = match get_single_str_spanned_from_tts(cx, sp, tts, "include_str!") {
Ok(res) => res,
Err(guar) => return DummyResult::any(sp, guar),
};
let file = match resolve_path(&cx.sess, file.as_str(), sp) {
Ok(f) => f,
Err(err) => {
let guar = err.emit();
return DummyResult::any(sp, guar);
}
};
match cx.source_map().load_binary_file(&file) {
match load_binary_file(cx, path.as_str().as_ref(), sp, path_span) {
Ok(bytes) => match std::str::from_utf8(&bytes) {
Ok(src) => {
let interned_src = Symbol::intern(src);
MacEager::expr(cx.expr_str(sp, interned_src))
}
Err(_) => {
let guar = cx.dcx().span_err(sp, format!("{} wasn't a utf-8 file", file.display()));
let guar = cx.dcx().span_err(sp, format!("`{path}` wasn't a utf-8 file"));
DummyResult::any(sp, guar)
}
},
Err(e) => {
let guar = cx.dcx().span_err(sp, format!("couldn't read {}: {}", file.display(), e));
DummyResult::any(sp, guar)
}
Err(dummy) => dummy,
}
}

Expand All @@ -215,25 +207,123 @@ pub fn expand_include_bytes(
tts: TokenStream,
) -> Box<dyn MacResult + 'static> {
let sp = cx.with_def_site_ctxt(sp);
let file = match get_single_str_from_tts(cx, sp, tts, "include_bytes!") {
Ok(file) => file,
let (path, path_span) = match get_single_str_spanned_from_tts(cx, sp, tts, "include_bytes!") {
Ok(res) => res,
Err(guar) => return DummyResult::any(sp, guar),
};
let file = match resolve_path(&cx.sess, file.as_str(), sp) {
Ok(f) => f,
match load_binary_file(cx, path.as_str().as_ref(), sp, path_span) {
Ok(bytes) => {
let expr = cx.expr(sp, ast::ExprKind::IncludedBytes(bytes));
MacEager::expr(expr)
}
Err(dummy) => dummy,
}
}

fn load_binary_file(
cx: &mut ExtCtxt<'_>,
original_path: &Path,
macro_span: Span,
path_span: Span,
) -> Result<Lrc<[u8]>, Box<dyn MacResult>> {
let resolved_path = match resolve_path(&cx.sess, original_path, macro_span) {
Ok(path) => path,
Err(err) => {
let guar = err.emit();
return DummyResult::any(sp, guar);
return Err(DummyResult::any(macro_span, guar));
}
};
match cx.source_map().load_binary_file(&file) {
Ok(bytes) => {
let expr = cx.expr(sp, ast::ExprKind::IncludedBytes(bytes));
MacEager::expr(expr)
match cx.source_map().load_binary_file(&resolved_path) {
Ok(data) => Ok(data),
Err(io_err) => {
let mut err = cx.dcx().struct_span_err(
macro_span,
format!("couldn't read `{}`: {io_err}", resolved_path.display()),
);

if original_path.is_relative() {
let source_map = cx.sess.source_map();
let new_path = source_map
.span_to_filename(macro_span.source_callsite())
.into_local_path()
.and_then(|src| find_path_suggestion(source_map, src.parent()?, original_path))
.and_then(|path| path.into_os_string().into_string().ok());

if let Some(new_path) = new_path {
err.span_suggestion(
path_span,
"there is a file with the same name in a different directory",
format!("\"{}\"", new_path.escape_debug()),
rustc_lint_defs::Applicability::MachineApplicable,
);
}
}
let guar = err.emit();
Err(DummyResult::any(macro_span, guar))
}
Err(e) => {
let guar = cx.dcx().span_err(sp, format!("couldn't read {}: {}", file.display(), e));
DummyResult::any(sp, guar)
}
}

fn find_path_suggestion(
source_map: &SourceMap,
base_dir: &Path,
wanted_path: &Path,
) -> Option<PathBuf> {
// Fix paths that assume they're relative to cargo manifest dir
let mut base_c = base_dir.components();
let mut wanted_c = wanted_path.components();
let mut without_base = None;
while let Some(wanted_next) = wanted_c.next() {
if wanted_c.as_path().file_name().is_none() {
break;
}
// base_dir may be absolute
while let Some(base_next) = base_c.next() {
if base_next == wanted_next {
without_base = Some(wanted_c.as_path());
break;
}
}
}
let root_absolute = without_base.into_iter().map(PathBuf::from);

let base_dir_components = base_dir.components().count();
// Avoid going all the way to the root dir
let max_parent_components = if base_dir.is_relative() {
base_dir_components + 1
} else {
base_dir_components.saturating_sub(1)
};

// Try with additional leading ../
let mut prefix = PathBuf::new();
let add = std::iter::from_fn(|| {
prefix.push("..");
Some(prefix.join(wanted_path))
})
.take(max_parent_components.min(3));

// Try without leading directories
let mut trimmed_path = wanted_path;
let remove = std::iter::from_fn(|| {
let mut components = trimmed_path.components();
let removed = components.next()?;
trimmed_path = components.as_path();
let _ = trimmed_path.file_name()?; // ensure there is a file name left
Some([
Some(trimmed_path.to_path_buf()),
(removed != std::path::Component::ParentDir)
.then(|| Path::new("..").join(trimmed_path)),
])
})
.flatten()
.flatten()
.take(4);

for new_path in root_absolute.chain(add).chain(remove) {
if source_map.file_exists(&base_dir.join(&new_path)) {
return Some(new_path);
}
}
None
}
3 changes: 0 additions & 3 deletions compiler/rustc_const_eval/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ const_eval_intern_kind = {$kind ->
*[other] {""}
}

const_eval_invalid_align =
align has to be a power of 2

const_eval_invalid_align_details =
invalid align passed to `{$name}`: {$align} is {$err_kind ->
[not_power_of_two] not a power of 2
Expand Down
41 changes: 26 additions & 15 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1233,21 +1233,18 @@ pub fn resolve_path(sess: &Session, path: impl Into<PathBuf>, span: Span) -> PRe
// after macro expansion (that is, they are unhygienic).
if !path.is_absolute() {
let callsite = span.source_callsite();
let mut result = match sess.source_map().span_to_filename(callsite) {
FileName::Real(name) => name
.into_local_path()
.expect("attempting to resolve a file path in an external file"),
FileName::DocTest(path, _) => path,
other => {
return Err(sess.dcx().create_err(errors::ResolveRelativePath {
span,
path: sess.source_map().filename_for_diagnostics(&other).to_string(),
}));
}
let source_map = sess.source_map();
let Some(mut base_path) = source_map.span_to_filename(callsite).into_local_path() else {
return Err(sess.dcx().create_err(errors::ResolveRelativePath {
span,
path: source_map
.filename_for_diagnostics(&source_map.span_to_filename(callsite))
.to_string(),
}));
};
result.pop();
result.push(path);
Ok(result)
base_path.pop();
base_path.push(path);
Ok(base_path)
} else {
Ok(path)
}
Expand Down Expand Up @@ -1344,6 +1341,15 @@ pub fn get_single_str_from_tts(
tts: TokenStream,
name: &str,
) -> Result<Symbol, ErrorGuaranteed> {
get_single_str_spanned_from_tts(cx, span, tts, name).map(|(s, _)| s)
}

pub fn get_single_str_spanned_from_tts(
cx: &mut ExtCtxt<'_>,
span: Span,
tts: TokenStream,
name: &str,
) -> Result<(Symbol, Span), ErrorGuaranteed> {
let mut p = cx.new_parser_from_tts(tts);
if p.token == token::Eof {
let guar = cx.dcx().emit_err(errors::OnlyOneArgument { span, name });
Expand All @@ -1355,7 +1361,12 @@ pub fn get_single_str_from_tts(
if p.token != token::Eof {
cx.dcx().emit_err(errors::OnlyOneArgument { span, name });
}
expr_to_string(cx, ret, "argument must be a string literal").map(|(s, _)| s)
expr_to_spanned_string(cx, ret, "argument must be a string literal")
.map_err(|err| match err {
Ok((err, _)) => err.emit(),
Err(guar) => guar,
})
.map(|(symbol, _style, span)| (symbol, span))
}

/// Extracts comma-separated expressions from `tts`.
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_infer/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,6 @@ infer_more_targeted = {$has_param_name ->

infer_msl_introduces_static = introduces a `'static` lifetime requirement
infer_msl_unmet_req = because this has an unmet lifetime requirement
infer_need_type_info_in_coroutine =
type inside {$coroutine_kind ->
[async_block] `async` block
[async_closure] `async` closure
[async_fn] `async fn` body
*[coroutine] coroutine
} must be known in this context


infer_nothing = {""}

Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_lint/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,6 @@ lint_suspicious_double_ref_clone =
lint_suspicious_double_ref_deref =
using `.deref()` on a double reference, which returns `{$ty}` instead of dereferencing the inner type

lint_trivial_untranslatable_diag = diagnostic with static strings only

lint_ty_qualified = usage of qualified `ty::{$ty}`
.suggestion = try importing it and using it unqualified

Expand Down
Loading
Loading