Skip to content

Commit 3574b1a

Browse files
committed
Auto merge of #107889 - matthiaskrgr:rollup-c0d4al0, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #107789 (Avoid exposing type parameters and implementation details sourced from macro expansions) - #107836 (Handle properly when there is no crate attrs) - #107839 (avoid duplicating the RUSTC_LOG env var name) - #107866 (Allow wasi-libc to initialize its environment variables lazily.) - #107876 (create symlink only for non-windows operating systems) - #107882 (Cleanup typos in en_US/borrowck.ftl) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents d1ac43a + 1e106c1 commit 3574b1a

File tree

15 files changed

+88
-43
lines changed

15 files changed

+88
-43
lines changed

compiler/rustc_driver_impl/src/lib.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,10 @@ fn print_crate_info(
624624
println!("{}", serde_json::to_string_pretty(&sess.target.to_json()).unwrap());
625625
}
626626
FileNames | CrateName => {
627-
let attrs = attrs.as_ref().unwrap();
627+
let Some(attrs) = attrs.as_ref() else {
628+
// no crate attributes, print out an error and exit
629+
return Compilation::Continue;
630+
};
628631
let t_outputs = rustc_interface::util::build_output_filenames(attrs, sess);
629632
let id = rustc_session::output::find_crate_name(sess, attrs);
630633
if *req == PrintRequest::CrateName {

compiler/rustc_error_messages/locales/en-US/borrowck.ftl

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ borrowck_generic_does_not_live_long_enough =
1818
`{$kind}` does not live long enough
1919
2020
borrowck_move_borrowed =
21-
cannot move out of `{$desc}` beacause it is borrowed
21+
cannot move out of `{$desc}` because it is borrowed
2222
2323
borrowck_var_does_not_need_mut =
2424
variable does not need to be mutable
@@ -87,10 +87,10 @@ borrowck_use_due_to_use_closure =
8787
use occurs due to use in closure
8888
8989
borrowck_assign_due_to_use_closure =
90-
assign occurs due to use in closure
90+
assignment occurs due to use in closure
9191
9292
borrowck_assign_part_due_to_use_closure =
93-
assign to part occurs due to use in closure
93+
assignment to part occurs due to use in closure
9494
9595
borrowck_capture_immute =
9696
capture is immutable because of use here

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,12 @@ fn fmt_printer<'a, 'tcx>(infcx: &'a InferCtxt<'tcx>, ns: Namespace) -> FmtPrinte
158158
if infcx.probe_ty_var(ty_vid).is_ok() {
159159
warn!("resolved ty var in error message");
160160
}
161-
if let TypeVariableOriginKind::TypeParameterDefinition(name, _) =
162-
infcx.inner.borrow_mut().type_variables().var_origin(ty_vid).kind
161+
162+
let mut infcx_inner = infcx.inner.borrow_mut();
163+
let ty_vars = infcx_inner.type_variables();
164+
let var_origin = ty_vars.var_origin(ty_vid);
165+
if let TypeVariableOriginKind::TypeParameterDefinition(name, _) = var_origin.kind
166+
&& !var_origin.span.from_expansion()
163167
{
164168
Some(name)
165169
} else {
@@ -254,7 +258,7 @@ impl<'tcx> InferCtxt<'tcx> {
254258
if let TypeVariableOriginKind::TypeParameterDefinition(name, def_id) =
255259
var_origin.kind
256260
{
257-
if name != kw::SelfUpper {
261+
if name != kw::SelfUpper && !var_origin.span.from_expansion() {
258262
return InferenceDiagnosticsData {
259263
name: name.to_string(),
260264
span: Some(var_origin.span),
@@ -780,7 +784,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
780784
// The sources are listed in order of preference here.
781785
let tcx = self.infcx.tcx;
782786
let ctx = CostCtxt { tcx };
783-
let base_cost = match source.kind {
787+
match source.kind {
784788
InferSourceKind::LetBinding { ty, .. } => ctx.ty_cost(ty),
785789
InferSourceKind::ClosureArg { ty, .. } => ctx.ty_cost(ty),
786790
InferSourceKind::GenericArg { def_id, generic_args, .. } => {
@@ -797,17 +801,17 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
797801
InferSourceKind::ClosureReturn { ty, should_wrap_expr, .. } => {
798802
30 + ctx.ty_cost(ty) + if should_wrap_expr.is_some() { 10 } else { 0 }
799803
}
800-
};
801-
802-
let suggestion_may_apply = if source.from_expansion() { 10000 } else { 0 };
803-
804-
base_cost + suggestion_may_apply
804+
}
805805
}
806806

807807
/// Uses `fn source_cost` to determine whether this inference source is preferable to
808808
/// previous sources. We generally prefer earlier sources.
809809
#[instrument(level = "debug", skip(self))]
810810
fn update_infer_source(&mut self, mut new_source: InferSource<'tcx>) {
811+
if new_source.from_expansion() {
812+
return;
813+
}
814+
811815
let cost = self.source_cost(&new_source) + self.attempt;
812816
debug!(?cost);
813817
self.attempt += 1;
@@ -819,6 +823,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
819823
// `let x: _ = iter.collect();`, as this is a very common case.
820824
*def_id = Some(did);
821825
}
826+
822827
if cost < self.infer_source_cost {
823828
self.infer_source_cost = cost;
824829
self.infer_source = Some(new_source);

compiler/rustc_log/src/lib.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
//!
1515
//! ```
1616
//! fn main() {
17-
//! rustc_log::init_rustc_env_logger().unwrap();
17+
//! rustc_log::init_env_logger("LOG").unwrap();
1818
//!
1919
//! let edition = rustc_span::edition::Edition::Edition2021;
2020
//! rustc_span::create_session_globals_then(edition, || {
@@ -23,9 +23,9 @@
2323
//! }
2424
//! ```
2525
//!
26-
//! Now `RUSTC_LOG=debug cargo run` will run your minimal main.rs and show
26+
//! Now `LOG=debug cargo run` will run your minimal main.rs and show
2727
//! rustc's debug logging. In a workflow like this, one might also add
28-
//! `std::env::set_var("RUSTC_LOG", "debug")` to the top of main so that `cargo
28+
//! `std::env::set_var("LOG", "debug")` to the top of main so that `cargo
2929
//! run` by itself is sufficient to get logs.
3030
//!
3131
//! The reason rustc_log is a tiny separate crate, as opposed to exposing the
@@ -53,12 +53,6 @@ use tracing_subscriber::fmt::{
5353
};
5454
use tracing_subscriber::layer::SubscriberExt;
5555

56-
pub fn init_rustc_env_logger() -> Result<(), Error> {
57-
init_env_logger("RUSTC_LOG")
58-
}
59-
60-
/// In contrast to `init_rustc_env_logger` this allows you to choose an env var
61-
/// other than `RUSTC_LOG`.
6256
pub fn init_env_logger(env: &str) -> Result<(), Error> {
6357
let filter = match env::var(env) {
6458
Ok(env) => EnvFilter::new(env),

library/std/src/sys/wasi/os.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ mod libc {
2121
extern "C" {
2222
pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char;
2323
pub fn chdir(dir: *const c_char) -> c_int;
24+
pub fn __wasilibc_get_environ() -> *mut *mut c_char;
2425
}
2526
}
2627

@@ -161,7 +162,12 @@ impl Iterator for Env {
161162
pub fn env() -> Env {
162163
unsafe {
163164
let _guard = env_read_lock();
164-
let mut environ = libc::environ;
165+
166+
// Use `__wasilibc_get_environ` instead of `environ` here so that we
167+
// don't require wasi-libc to eagerly initialize the environment
168+
// variables.
169+
let mut environ = libc::__wasilibc_get_environ();
170+
165171
let mut result = Vec::new();
166172
if !environ.is_null() {
167173
while !(*environ).is_null() {

src/bootstrap/download.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,12 @@ impl Config {
340340
let rustfmt_path = bin_root.join("bin").join(exe("rustfmt", host));
341341
let rustfmt_stamp = bin_root.join(".rustfmt-stamp");
342342

343-
let legacy_rustfmt = self.initial_rustc.with_file_name(exe("rustfmt", host));
344-
if !legacy_rustfmt.exists() {
345-
t!(self.symlink_file(&rustfmt_path, &legacy_rustfmt));
343+
#[cfg(not(windows))]
344+
{
345+
let legacy_rustfmt = self.initial_rustc.with_file_name(exe("rustfmt", host));
346+
if !legacy_rustfmt.exists() {
347+
t!(self.symlink_file(&rustfmt_path, &legacy_rustfmt));
348+
}
346349
}
347350

348351
if rustfmt_path.exists() && !program_out_of_date(&rustfmt_stamp, &channel) {

tests/run-make/no-input-file/Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
include ../../run-make-fulldeps/tools.mk
2+
3+
all:
4+
$(RUSTC) --print crate-name 2>&1 | diff - no-input-file.stderr
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: no input filename given
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// ignore-tidy-linelength
2+
3+
// Regression test for #107745.
4+
// Previously need_type_info::update_infer_source will consider expressions originating from
5+
// macro expressions as candiate "previous sources". This unfortunately can mean that
6+
// for macros expansions such as `format!()` internal implementation details can leak, such as:
7+
//
8+
// ```
9+
// error[E0282]: type annotations needed
10+
// --> src/main.rs:2:22
11+
// |
12+
//2 | println!("{:?}", []);
13+
// | ^^ cannot infer type of the type parameter `T` declared on the associated function `new_debug`
14+
// ```
15+
16+
fn main() {
17+
println!("{:?}", []);
18+
//~^ ERROR type annotations needed
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0282]: type annotations needed
2+
--> $DIR/issue-107745-avoid-expr-from-macro-expansion.rs:17:22
3+
|
4+
LL | println!("{:?}", []);
5+
| ^^ cannot infer type
6+
|
7+
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0282`.

tests/ui/issues/issue-16966.stderr

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
error[E0282]: type annotations needed
2-
--> $DIR/issue-16966.rs:2:5
2+
--> $DIR/issue-16966.rs:2:12
33
|
44
LL | panic!(std::default::Default::default());
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `M` declared on the function `begin_panic`
6-
|
7-
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
86

97
error: aborting due to previous error
108

tests/ui/parser/missing-closing-angle-bracket-eq-constraint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn test2<T1, T2>(arg1 : T1, arg2 : T2) {
1717
fn test3<'a>(arg : &'a u32) {
1818
let v : Vec<'a = vec![];
1919
//~^ ERROR: expected one of
20-
//~| ERROR: type annotations needed for `Vec<T>`
20+
//~| ERROR: type annotations needed for `Vec<_>`
2121
}
2222

2323
fn main() {}

tests/ui/parser/missing-closing-angle-bracket-eq-constraint.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,26 @@ help: you might have meant to end the type parameters here
3939
LL | let v : Vec<'a> = vec![];
4040
| +
4141

42-
error[E0282]: type annotations needed for `Vec<T>`
42+
error[E0282]: type annotations needed for `Vec<_>`
4343
--> $DIR/missing-closing-angle-bracket-eq-constraint.rs:7:7
4444
|
4545
LL | let v : Vec<(u32,_) = vec![];
4646
| ^
4747
|
48-
help: consider giving `v` an explicit type, where the type for type parameter `T` is specified
48+
help: consider giving `v` an explicit type, where the placeholders `_` are specified
4949
|
50-
LL | let v: Vec<T> : Vec<(u32,_) = vec![];
50+
LL | let v: Vec<_> : Vec<(u32,_) = vec![];
5151
| ++++++++
5252

53-
error[E0282]: type annotations needed for `Vec<T>`
53+
error[E0282]: type annotations needed for `Vec<_>`
5454
--> $DIR/missing-closing-angle-bracket-eq-constraint.rs:18:7
5555
|
5656
LL | let v : Vec<'a = vec![];
5757
| ^
5858
|
59-
help: consider giving `v` an explicit type, where the type for type parameter `T` is specified
59+
help: consider giving `v` an explicit type, where the placeholders `_` are specified
6060
|
61-
LL | let v: Vec<T> : Vec<'a = vec![];
61+
LL | let v: Vec<_> : Vec<'a = vec![];
6262
| ++++++++
6363

6464
error: aborting due to 5 previous errors

tests/ui/type/type-check/cannot_infer_local_or_vec.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error[E0282]: type annotations needed for `Vec<T>`
1+
error[E0282]: type annotations needed for `Vec<_>`
22
--> $DIR/cannot_infer_local_or_vec.rs:2:9
33
|
44
LL | let x = vec![];
55
| ^
66
|
7-
help: consider giving `x` an explicit type, where the type for type parameter `T` is specified
7+
help: consider giving `x` an explicit type, where the placeholders `_` are specified
88
|
9-
LL | let x: Vec<T> = vec![];
9+
LL | let x: Vec<_> = vec![];
1010
| ++++++++
1111

1212
error: aborting due to previous error

tests/ui/type/type-check/cannot_infer_local_or_vec_in_tuples.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error[E0282]: type annotations needed for `(Vec<T>,)`
1+
error[E0282]: type annotations needed for `(Vec<_>,)`
22
--> $DIR/cannot_infer_local_or_vec_in_tuples.rs:2:9
33
|
44
LL | let (x, ) = (vec![], );
55
| ^^^^^ ---------- type must be known at this point
66
|
7-
help: consider giving this pattern a type, where the type for type parameter `T` is specified
7+
help: consider giving this pattern a type, where the placeholders `_` are specified
88
|
9-
LL | let (x, ): (Vec<T>,) = (vec![], );
9+
LL | let (x, ): (Vec<_>,) = (vec![], );
1010
| +++++++++++
1111

1212
error: aborting due to previous error

0 commit comments

Comments
 (0)