Skip to content

Commit 1ec980d

Browse files
committed
Auto merge of #77247 - jonas-schievink:rollup-r6ehh8h, r=jonas-schievink
Rollup of 10 pull requests Successful merges: - #76917 (Add missing code examples on HashMap types) - #77107 (Enable const propagation into operands at mir_opt_level=2) - #77129 (Update cargo) - #77167 (Fix FIXME in core::num test: Check sign of zero in min/max tests.) - #77184 (Rust vec bench import specific rand::RngCore) - #77208 (Late link args order) - #77209 (Fix documentation highlighting in ty::BorrowKind) - #77231 (Move helper function for `missing_const_for_fn` out of rustc to clippy) - #77235 (pretty-print-reparse hack: Rename some variables for clarity) - #77243 (Test more attributes in test issue-75930-derive-cfg.rs) Failed merges: r? `@ghost`
2 parents 623fb90 + b7c05a3 commit 1ec980d

File tree

16 files changed

+1852
-157
lines changed

16 files changed

+1852
-157
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1333,9 +1333,6 @@ fn add_late_link_args(
13331333
crate_type: CrateType,
13341334
codegen_results: &CodegenResults,
13351335
) {
1336-
if let Some(args) = sess.target.target.options.late_link_args.get(&flavor) {
1337-
cmd.args(args);
1338-
}
13391336
let any_dynamic_crate = crate_type == CrateType::Dylib
13401337
|| codegen_results.crate_info.dependency_formats.iter().any(|(ty, list)| {
13411338
*ty == crate_type && list.iter().any(|&linkage| linkage == Linkage::Dynamic)
@@ -1349,6 +1346,9 @@ fn add_late_link_args(
13491346
cmd.args(args);
13501347
}
13511348
}
1349+
if let Some(args) = sess.target.target.options.late_link_args.get(&flavor) {
1350+
cmd.args(args);
1351+
}
13521352
}
13531353

13541354
/// Add arbitrary "post-link" args defined by the target spec.

compiler/rustc_middle/src/ty/mod.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -682,25 +682,31 @@ pub enum BorrowKind {
682682
/// implicit closure bindings. It is needed when the closure
683683
/// is borrowing or mutating a mutable referent, e.g.:
684684
///
685-
/// let x: &mut isize = ...;
686-
/// let y = || *x += 5;
685+
/// ```
686+
/// let x: &mut isize = ...;
687+
/// let y = || *x += 5;
688+
/// ```
687689
///
688690
/// If we were to try to translate this closure into a more explicit
689691
/// form, we'd encounter an error with the code as written:
690692
///
691-
/// struct Env { x: & &mut isize }
692-
/// let x: &mut isize = ...;
693-
/// let y = (&mut Env { &x }, fn_ptr); // Closure is pair of env and fn
694-
/// fn fn_ptr(env: &mut Env) { **env.x += 5; }
693+
/// ```
694+
/// struct Env { x: & &mut isize }
695+
/// let x: &mut isize = ...;
696+
/// let y = (&mut Env { &x }, fn_ptr); // Closure is pair of env and fn
697+
/// fn fn_ptr(env: &mut Env) { **env.x += 5; }
698+
/// ```
695699
///
696700
/// This is then illegal because you cannot mutate a `&mut` found
697701
/// in an aliasable location. To solve, you'd have to translate with
698702
/// an `&mut` borrow:
699703
///
700-
/// struct Env { x: & &mut isize }
701-
/// let x: &mut isize = ...;
702-
/// let y = (&mut Env { &mut x }, fn_ptr); // changed from &x to &mut x
703-
/// fn fn_ptr(env: &mut Env) { **env.x += 5; }
704+
/// ```
705+
/// struct Env { x: & &mut isize }
706+
/// let x: &mut isize = ...;
707+
/// let y = (&mut Env { &mut x }, fn_ptr); // changed from &x to &mut x
708+
/// fn fn_ptr(env: &mut Env) { **env.x += 5; }
709+
/// ```
704710
///
705711
/// Now the assignment to `**env.x` is legal, but creating a
706712
/// mutable pointer to `x` is not because `x` is not mutable. We

compiler/rustc_mir/src/transform/const_prop.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1046,9 +1046,9 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
10461046
fn visit_operand(&mut self, operand: &mut Operand<'tcx>, location: Location) {
10471047
self.super_operand(operand, location);
10481048

1049-
// Only const prop copies and moves on `mir_opt_level=3` as doing so
1050-
// currently increases compile time.
1051-
if self.tcx.sess.opts.debugging_opts.mir_opt_level >= 3 {
1049+
// Only const prop copies and moves on `mir_opt_level=2` as doing so
1050+
// currently slightly increases compile time in some cases.
1051+
if self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
10521052
self.propagate_operand(operand)
10531053
}
10541054
}
@@ -1246,8 +1246,8 @@ impl<'mir, 'tcx> MutVisitor<'tcx> for ConstPropagator<'mir, 'tcx> {
12461246
| TerminatorKind::InlineAsm { .. } => {}
12471247
// Every argument in our function calls have already been propagated in `visit_operand`.
12481248
//
1249-
// NOTE: because LLVM codegen gives performance regressions with it, so this is gated
1250-
// on `mir_opt_level=3`.
1249+
// NOTE: because LLVM codegen gives slight performance regressions with it, so this is
1250+
// gated on `mir_opt_level=2`.
12511251
TerminatorKind::Call { .. } => {}
12521252
}
12531253

compiler/rustc_mir/src/transform/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ pub mod match_branches;
3636
pub mod no_landing_pads;
3737
pub mod nrvo;
3838
pub mod promote_consts;
39-
pub mod qualify_min_const_fn;
4039
pub mod remove_noop_landing_pads;
4140
pub mod remove_unneeded_drops;
4241
pub mod required_consts;

compiler/rustc_parse/src/lib.rs

+22-20
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#![feature(or_patterns)]
88

99
use rustc_ast as ast;
10-
use rustc_ast::token::{self, DelimToken, Nonterminal, Token, TokenKind};
10+
use rustc_ast::token::{self, Nonterminal, Token, TokenKind};
1111
use rustc_ast::tokenstream::{self, Spacing, TokenStream, TokenTree};
1212
use rustc_ast_pretty::pprust;
1313
use rustc_data_structures::sync::Lrc;
@@ -299,7 +299,7 @@ pub fn nt_to_tokenstream(nt: &Nonterminal, sess: &ParseSess, span: Span) -> Toke
299299
// FIXME(#43081): Avoid this pretty-print + reparse hack
300300
let source = pprust::nonterminal_to_string(nt);
301301
let filename = FileName::macro_expansion_source_code(&source);
302-
let tokens_for_real = parse_stream_from_source_str(filename, source, sess, Some(span));
302+
let reparsed_tokens = parse_stream_from_source_str(filename, source, sess, Some(span));
303303

304304
// During early phases of the compiler the AST could get modified
305305
// directly (e.g., attributes added or removed) and the internal cache
@@ -325,17 +325,17 @@ pub fn nt_to_tokenstream(nt: &Nonterminal, sess: &ParseSess, span: Span) -> Toke
325325
// modifications, including adding/removing typically non-semantic
326326
// tokens such as extra braces and commas, don't happen.
327327
if let Some(tokens) = tokens {
328-
if tokenstream_probably_equal_for_proc_macro(&tokens, &tokens_for_real, sess) {
328+
if tokenstream_probably_equal_for_proc_macro(&tokens, &reparsed_tokens, sess) {
329329
return tokens;
330330
}
331331
info!(
332332
"cached tokens found, but they're not \"probably equal\", \
333333
going with stringified version"
334334
);
335335
info!("cached tokens: {:?}", tokens);
336-
info!("reparsed tokens: {:?}", tokens_for_real);
336+
info!("reparsed tokens: {:?}", reparsed_tokens);
337337
}
338-
tokens_for_real
338+
reparsed_tokens
339339
}
340340

341341
// See comments in `Nonterminal::to_tokenstream` for why we care about
@@ -344,8 +344,8 @@ pub fn nt_to_tokenstream(nt: &Nonterminal, sess: &ParseSess, span: Span) -> Toke
344344
// This is otherwise the same as `eq_unspanned`, only recursing with a
345345
// different method.
346346
pub fn tokenstream_probably_equal_for_proc_macro(
347-
first: &TokenStream,
348-
other: &TokenStream,
347+
tokens: &TokenStream,
348+
reparsed_tokens: &TokenStream,
349349
sess: &ParseSess,
350350
) -> bool {
351351
// When checking for `probably_eq`, we ignore certain tokens that aren't
@@ -359,9 +359,6 @@ pub fn tokenstream_probably_equal_for_proc_macro(
359359
// The pretty printer tends to add trailing commas to
360360
// everything, and in particular, after struct fields.
361361
| token::Comma
362-
// The pretty printer emits `NoDelim` as whitespace.
363-
| token::OpenDelim(DelimToken::NoDelim)
364-
| token::CloseDelim(DelimToken::NoDelim)
365362
// The pretty printer collapses many semicolons into one.
366363
| token::Semi
367364
// We don't preserve leading `|` tokens in patterns, so
@@ -460,10 +457,11 @@ pub fn tokenstream_probably_equal_for_proc_macro(
460457

461458
// Break tokens after we expand any nonterminals, so that we break tokens
462459
// that are produced as a result of nonterminal expansion.
463-
let t1 = first.trees().filter(semantic_tree).flat_map(expand_nt).flat_map(break_tokens);
464-
let t2 = other.trees().filter(semantic_tree).flat_map(expand_nt).flat_map(break_tokens);
460+
let tokens = tokens.trees().filter(semantic_tree).flat_map(expand_nt).flat_map(break_tokens);
461+
let reparsed_tokens =
462+
reparsed_tokens.trees().filter(semantic_tree).flat_map(expand_nt).flat_map(break_tokens);
465463

466-
t1.eq_by(t2, |t1, t2| tokentree_probably_equal_for_proc_macro(&t1, &t2, sess))
464+
tokens.eq_by(reparsed_tokens, |t, rt| tokentree_probably_equal_for_proc_macro(&t, &rt, sess))
467465
}
468466

469467
// See comments in `Nonterminal::to_tokenstream` for why we care about
@@ -472,16 +470,20 @@ pub fn tokenstream_probably_equal_for_proc_macro(
472470
// This is otherwise the same as `eq_unspanned`, only recursing with a
473471
// different method.
474472
pub fn tokentree_probably_equal_for_proc_macro(
475-
first: &TokenTree,
476-
other: &TokenTree,
473+
token: &TokenTree,
474+
reparsed_token: &TokenTree,
477475
sess: &ParseSess,
478476
) -> bool {
479-
match (first, other) {
480-
(TokenTree::Token(token), TokenTree::Token(token2)) => {
481-
token_probably_equal_for_proc_macro(token, token2)
477+
match (token, reparsed_token) {
478+
(TokenTree::Token(token), TokenTree::Token(reparsed_token)) => {
479+
token_probably_equal_for_proc_macro(token, reparsed_token)
482480
}
483-
(TokenTree::Delimited(_, delim, tts), TokenTree::Delimited(_, delim2, tts2)) => {
484-
delim == delim2 && tokenstream_probably_equal_for_proc_macro(&tts, &tts2, sess)
481+
(
482+
TokenTree::Delimited(_, delim, tokens),
483+
TokenTree::Delimited(_, reparsed_delim, reparsed_tokens),
484+
) => {
485+
delim == reparsed_delim
486+
&& tokenstream_probably_equal_for_proc_macro(tokens, reparsed_tokens, sess)
485487
}
486488
_ => false,
487489
}

compiler/rustc_target/src/spec/windows_gnu_base.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub fn opts() -> TargetOptions {
2323
"-lmsvcrt".to_string(),
2424
"-lmingwex".to_string(),
2525
"-lmingw32".to_string(),
26+
"-lgcc".to_string(), // alas, mingw* libraries above depend on libgcc
2627
// mingw's msvcrt is a weird hybrid import library and static library.
2728
// And it seems that the linker fails to use import symbols from msvcrt
2829
// that are required from functions in msvcrt in certain cases. For example
@@ -41,8 +42,6 @@ pub fn opts() -> TargetOptions {
4142
// the shared libgcc_s-dw2-1.dll. This is required to support
4243
// unwinding across DLL boundaries.
4344
"-lgcc_s".to_string(),
44-
"-lgcc".to_string(),
45-
"-lkernel32".to_string(),
4645
];
4746
late_link_args_dynamic.insert(LinkerFlavor::Gcc, dynamic_unwind_libs.clone());
4847
late_link_args_dynamic.insert(LinkerFlavor::Lld(LldFlavor::Ld), dynamic_unwind_libs);
@@ -54,10 +53,6 @@ pub fn opts() -> TargetOptions {
5453
// boundaries when unwinding across FFI boundaries.
5554
"-lgcc_eh".to_string(),
5655
"-l:libpthread.a".to_string(),
57-
"-lgcc".to_string(),
58-
// libpthread depends on libmsvcrt, so we need to link it *again*.
59-
"-lmsvcrt".to_string(),
60-
"-lkernel32".to_string(),
6156
];
6257
late_link_args_static.insert(LinkerFlavor::Gcc, static_unwind_libs.clone());
6358
late_link_args_static.insert(LinkerFlavor::Lld(LldFlavor::Ld), static_unwind_libs);

library/alloc/benches/vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rand::prelude::*;
1+
use rand::RngCore;
22
use std::iter::{repeat, FromIterator};
33
use test::{black_box, Bencher};
44

library/core/tests/num/mod.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -634,14 +634,18 @@ assume_usize_width! {
634634
macro_rules! test_float {
635635
($modname: ident, $fty: ty, $inf: expr, $neginf: expr, $nan: expr) => {
636636
mod $modname {
637-
// FIXME(nagisa): these tests should test for sign of -0.0
638637
#[test]
639638
fn min() {
640639
assert_eq!((0.0 as $fty).min(0.0), 0.0);
640+
assert!((0.0 as $fty).min(0.0).is_sign_positive());
641641
assert_eq!((-0.0 as $fty).min(-0.0), -0.0);
642+
assert!((-0.0 as $fty).min(-0.0).is_sign_negative());
642643
assert_eq!((9.0 as $fty).min(9.0), 9.0);
643644
assert_eq!((-9.0 as $fty).min(0.0), -9.0);
644645
assert_eq!((0.0 as $fty).min(9.0), 0.0);
646+
assert!((0.0 as $fty).min(9.0).is_sign_positive());
647+
assert_eq!((-0.0 as $fty).min(9.0), -0.0);
648+
assert!((-0.0 as $fty).min(9.0).is_sign_negative());
645649
assert_eq!((-0.0 as $fty).min(-9.0), -9.0);
646650
assert_eq!(($inf as $fty).min(9.0), 9.0);
647651
assert_eq!((9.0 as $fty).min($inf), 9.0);
@@ -660,11 +664,19 @@ macro_rules! test_float {
660664
#[test]
661665
fn max() {
662666
assert_eq!((0.0 as $fty).max(0.0), 0.0);
667+
assert!((0.0 as $fty).max(0.0).is_sign_positive());
663668
assert_eq!((-0.0 as $fty).max(-0.0), -0.0);
669+
assert!((-0.0 as $fty).max(-0.0).is_sign_negative());
664670
assert_eq!((9.0 as $fty).max(9.0), 9.0);
665671
assert_eq!((-9.0 as $fty).max(0.0), 0.0);
672+
assert!((-9.0 as $fty).max(0.0).is_sign_positive());
673+
assert_eq!((-9.0 as $fty).max(-0.0), -0.0);
674+
assert!((-9.0 as $fty).max(-0.0).is_sign_negative());
666675
assert_eq!((0.0 as $fty).max(9.0), 9.0);
676+
assert_eq!((0.0 as $fty).max(-9.0), 0.0);
677+
assert!((0.0 as $fty).max(-9.0).is_sign_positive());
667678
assert_eq!((-0.0 as $fty).max(-9.0), -0.0);
679+
assert!((-0.0 as $fty).max(-9.0).is_sign_negative());
668680
assert_eq!(($inf as $fty).max(9.0), $inf);
669681
assert_eq!((9.0 as $fty).max($inf), $inf);
670682
assert_eq!(($inf as $fty).max(-9.0), $inf);

0 commit comments

Comments
 (0)