Skip to content

Commit 6d5caf3

Browse files
committed
Auto merge of rust-lang#146267 - matthiaskrgr:rollup-tbz7shx, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#127316 (move pinned version from tracing_core to tracing) - rust-lang#144801 (Suggest bounds in more cases, accounting for type parameters referenced in predicate) - rust-lang#146211 (Disallow shebang in `--cfg` and `--check-cfg` arguments) - rust-lang#146263 (Fix `bump-stage0` build failure, and check-build `bump-stage0` in CI) - rust-lang#146266 (miri std tests: skip all of sys::) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0d0f4ea + 6f5fad5 commit 6d5caf3

File tree

22 files changed

+232
-53
lines changed

22 files changed

+232
-53
lines changed

Cargo.lock

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ dependencies = [
336336
"curl",
337337
"indexmap",
338338
"serde",
339-
"toml 0.7.8",
339+
"toml 0.8.23",
340340
]
341341

342342
[[package]]
@@ -4072,7 +4072,6 @@ name = "rustc_log"
40724072
version = "0.0.0"
40734073
dependencies = [
40744074
"tracing",
4075-
"tracing-core",
40764075
"tracing-subscriber",
40774076
"tracing-tree",
40784077
]
@@ -5541,9 +5540,9 @@ dependencies = [
55415540

55425541
[[package]]
55435542
name = "tracing-core"
5544-
version = "0.1.30"
5543+
version = "0.1.34"
55455544
source = "registry+https://github.com/rust-lang/crates.io-index"
5546-
checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a"
5545+
checksum = "b9d12581f227e93f094d3af2ae690a574abb8a2b9b7a96e7cfe9647b2b617678"
55475546
dependencies = [
55485547
"once_cell",
55495548
"valuable",

compiler/rustc_log/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ edition = "2024"
55

66
[dependencies]
77
# tidy-alphabetical-start
8-
tracing = "0.1.28"
9-
tracing-core = "=0.1.30" # FIXME(Nilstrieb) tracing has a deadlock: https://github.com/tokio-rs/tracing/issues/2635
8+
# tracing > 0.1.37 have huge binary size / instructions regression
9+
tracing = "=0.1.37"
1010
tracing-subscriber = { version = "0.3.3", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] }
1111
tracing-tree = "0.3.1"
1212
# tidy-alphabetical-end

compiler/rustc_log/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use std::fmt::{self, Display};
3838
use std::io::{self, IsTerminal};
3939

4040
use tracing::dispatcher::SetGlobalDefaultError;
41-
use tracing_core::{Event, Subscriber};
41+
use tracing::{Event, Subscriber};
4242
use tracing_subscriber::filter::{Directive, EnvFilter, LevelFilter};
4343
use tracing_subscriber::fmt::FmtContext;
4444
use tracing_subscriber::fmt::format::{self, FormatEvent, FormatFields};

compiler/rustc_parse/src/lexer/mod.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,44 @@ pub(crate) struct UnmatchedDelim {
4444
pub candidate_span: Option<Span>,
4545
}
4646

47+
/// Which tokens should be stripped before lexing the tokens.
48+
pub(crate) enum StripTokens {
49+
/// Strip both shebang and frontmatter.
50+
ShebangAndFrontmatter,
51+
/// Strip the shebang but not frontmatter.
52+
///
53+
/// That means that char sequences looking like frontmatter are simply
54+
/// interpreted as regular Rust lexemes.
55+
Shebang,
56+
/// Strip nothing.
57+
///
58+
/// In other words, char sequences looking like a shebang or frontmatter
59+
/// are simply interpreted as regular Rust lexemes.
60+
Nothing,
61+
}
62+
4763
pub(crate) fn lex_token_trees<'psess, 'src>(
4864
psess: &'psess ParseSess,
4965
mut src: &'src str,
5066
mut start_pos: BytePos,
5167
override_span: Option<Span>,
52-
frontmatter_allowed: FrontmatterAllowed,
68+
strip_tokens: StripTokens,
5369
) -> Result<TokenStream, Vec<Diag<'psess>>> {
54-
// Skip `#!`, if present.
55-
if let Some(shebang_len) = rustc_lexer::strip_shebang(src) {
56-
src = &src[shebang_len..];
57-
start_pos = start_pos + BytePos::from_usize(shebang_len);
70+
match strip_tokens {
71+
StripTokens::Shebang | StripTokens::ShebangAndFrontmatter => {
72+
if let Some(shebang_len) = rustc_lexer::strip_shebang(src) {
73+
src = &src[shebang_len..];
74+
start_pos = start_pos + BytePos::from_usize(shebang_len);
75+
}
76+
}
77+
StripTokens::Nothing => {}
5878
}
5979

80+
let frontmatter_allowed = match strip_tokens {
81+
StripTokens::ShebangAndFrontmatter => FrontmatterAllowed::Yes,
82+
StripTokens::Shebang | StripTokens::Nothing => FrontmatterAllowed::No,
83+
};
84+
6085
let cursor = Cursor::new(src, frontmatter_allowed);
6186
let mut lexer = Lexer {
6287
psess,

compiler/rustc_parse/src/lib.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use rustc_ast::tokenstream::{DelimSpan, TokenStream};
2121
use rustc_ast::{AttrItem, Attribute, MetaItemInner, token};
2222
use rustc_ast_pretty::pprust;
2323
use rustc_errors::{Diag, EmissionGuarantee, FatalError, PResult, pluralize};
24-
use rustc_lexer::FrontmatterAllowed;
2524
use rustc_session::parse::ParseSess;
2625
use rustc_span::source_map::SourceMap;
2726
use rustc_span::{FileName, SourceFile, Span};
@@ -34,6 +33,8 @@ pub mod parser;
3433
use parser::Parser;
3534
use rustc_ast::token::Delimiter;
3635

36+
use crate::lexer::StripTokens;
37+
3738
pub mod lexer;
3839

3940
mod errors;
@@ -62,10 +63,10 @@ pub fn new_parser_from_source_str(
6263
source: String,
6364
) -> Result<Parser<'_>, Vec<Diag<'_>>> {
6465
let source_file = psess.source_map().new_source_file(name, source);
65-
new_parser_from_source_file(psess, source_file, FrontmatterAllowed::Yes)
66+
new_parser_from_source_file(psess, source_file, StripTokens::ShebangAndFrontmatter)
6667
}
6768

68-
/// Creates a new parser from a simple (no frontmatter) source string.
69+
/// Creates a new parser from a simple (no shebang, no frontmatter) source string.
6970
///
7071
/// On failure, the errors must be consumed via `unwrap_or_emit_fatal`, `emit`, `cancel`,
7172
/// etc., otherwise a panic will occur when they are dropped.
@@ -75,7 +76,7 @@ pub fn new_parser_from_simple_source_str(
7576
source: String,
7677
) -> Result<Parser<'_>, Vec<Diag<'_>>> {
7778
let source_file = psess.source_map().new_source_file(name, source);
78-
new_parser_from_source_file(psess, source_file, FrontmatterAllowed::No)
79+
new_parser_from_source_file(psess, source_file, StripTokens::Nothing)
7980
}
8081

8182
/// Creates a new parser from a filename. On failure, the errors must be consumed via
@@ -109,7 +110,7 @@ pub fn new_parser_from_file<'a>(
109110
}
110111
err.emit();
111112
});
112-
new_parser_from_source_file(psess, source_file, FrontmatterAllowed::Yes)
113+
new_parser_from_source_file(psess, source_file, StripTokens::ShebangAndFrontmatter)
113114
}
114115

115116
pub fn utf8_error<E: EmissionGuarantee>(
@@ -160,10 +161,10 @@ pub fn utf8_error<E: EmissionGuarantee>(
160161
fn new_parser_from_source_file(
161162
psess: &ParseSess,
162163
source_file: Arc<SourceFile>,
163-
frontmatter_allowed: FrontmatterAllowed,
164+
strip_tokens: StripTokens,
164165
) -> Result<Parser<'_>, Vec<Diag<'_>>> {
165166
let end_pos = source_file.end_position();
166-
let stream = source_file_to_stream(psess, source_file, None, frontmatter_allowed)?;
167+
let stream = source_file_to_stream(psess, source_file, None, strip_tokens)?;
167168
let mut parser = Parser::new(psess, stream, None);
168169
if parser.token == token::Eof {
169170
parser.token.span = Span::new(end_pos, end_pos, parser.token.span.ctxt(), None);
@@ -179,8 +180,8 @@ pub fn source_str_to_stream(
179180
) -> Result<TokenStream, Vec<Diag<'_>>> {
180181
let source_file = psess.source_map().new_source_file(name, source);
181182
// used mainly for `proc_macro` and the likes, not for our parsing purposes, so don't parse
182-
// frontmatters as frontmatters.
183-
source_file_to_stream(psess, source_file, override_span, FrontmatterAllowed::No)
183+
// frontmatters as frontmatters, but for compatibility reason still strip the shebang
184+
source_file_to_stream(psess, source_file, override_span, StripTokens::Shebang)
184185
}
185186

186187
/// Given a source file, produces a sequence of token trees. Returns any buffered errors from
@@ -189,7 +190,7 @@ fn source_file_to_stream<'psess>(
189190
psess: &'psess ParseSess,
190191
source_file: Arc<SourceFile>,
191192
override_span: Option<Span>,
192-
frontmatter_allowed: FrontmatterAllowed,
193+
strip_tokens: StripTokens,
193194
) -> Result<TokenStream, Vec<Diag<'psess>>> {
194195
let src = source_file.src.as_ref().unwrap_or_else(|| {
195196
psess.dcx().bug(format!(
@@ -198,13 +199,7 @@ fn source_file_to_stream<'psess>(
198199
));
199200
});
200201

201-
lexer::lex_token_trees(
202-
psess,
203-
src.as_str(),
204-
source_file.start_pos,
205-
override_span,
206-
frontmatter_allowed,
207-
)
202+
lexer::lex_token_trees(psess, src.as_str(), source_file.start_pos, override_span, strip_tokens)
208203
}
209204

210205
/// Runs the given subparser `f` on the tokens of the given `attr`'s item.

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

Lines changed: 67 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ use rustc_middle::ty::print::{
3232
};
3333
use rustc_middle::ty::{
3434
self, AdtKind, GenericArgs, InferTy, IsSuggestable, Ty, TyCtxt, TypeFoldable, TypeFolder,
35-
TypeSuperFoldable, TypeVisitableExt, TypeckResults, Upcast, suggest_arbitrary_trait_bound,
36-
suggest_constraining_type_param,
35+
TypeSuperFoldable, TypeSuperVisitable, TypeVisitableExt, TypeVisitor, TypeckResults, Upcast,
36+
suggest_arbitrary_trait_bound, suggest_constraining_type_param,
3737
};
3838
use rustc_middle::{bug, span_bug};
3939
use rustc_span::def_id::LocalDefId;
@@ -263,6 +263,9 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
263263
_ => (false, None),
264264
};
265265

266+
let mut finder = ParamFinder { .. };
267+
finder.visit_binder(&trait_pred);
268+
266269
// FIXME: Add check for trait bound that is already present, particularly `?Sized` so we
267270
// don't suggest `T: Sized + ?Sized`.
268271
loop {
@@ -411,6 +414,26 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
411414
}
412415
}
413416

417+
hir::Node::TraitItem(hir::TraitItem {
418+
generics,
419+
kind: hir::TraitItemKind::Fn(..),
420+
..
421+
})
422+
| hir::Node::ImplItem(hir::ImplItem {
423+
generics,
424+
trait_item_def_id: None,
425+
kind: hir::ImplItemKind::Fn(..),
426+
..
427+
}) if finder.can_suggest_bound(generics) => {
428+
// Missing generic type parameter bound.
429+
suggest_arbitrary_trait_bound(
430+
self.tcx,
431+
generics,
432+
err,
433+
trait_pred,
434+
associated_ty,
435+
);
436+
}
414437
hir::Node::Item(hir::Item {
415438
kind:
416439
hir::ItemKind::Struct(_, generics, _)
@@ -423,7 +446,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
423446
| hir::ItemKind::Const(_, generics, _, _)
424447
| hir::ItemKind::TraitAlias(_, generics, _),
425448
..
426-
}) if !param_ty => {
449+
}) if finder.can_suggest_bound(generics) => {
427450
// Missing generic type parameter bound.
428451
if suggest_arbitrary_trait_bound(
429452
self.tcx,
@@ -5068,8 +5091,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
50685091
// Suggesting `T: ?Sized` is only valid in an ADT if `T` is only used in a
50695092
// borrow. `struct S<'a, T: ?Sized>(&'a T);` is valid, `struct S<T: ?Sized>(T);`
50705093
// is not. Look for invalid "bare" parameter uses, and suggest using indirection.
5071-
let mut visitor =
5072-
FindTypeParam { param: param.name.ident().name, invalid_spans: vec![], nested: false };
5094+
let mut visitor = FindTypeParam { param: param.name.ident().name, .. };
50735095
visitor.visit_item(item);
50745096
if visitor.invalid_spans.is_empty() {
50755097
return false;
@@ -5228,7 +5250,7 @@ fn hint_missing_borrow<'tcx>(
52285250
/// Used to suggest replacing associated types with an explicit type in `where` clauses.
52295251
#[derive(Debug)]
52305252
pub struct SelfVisitor<'v> {
5231-
pub paths: Vec<&'v hir::Ty<'v>>,
5253+
pub paths: Vec<&'v hir::Ty<'v>> = Vec::new(),
52325254
pub name: Option<Symbol>,
52335255
}
52345256

@@ -5599,7 +5621,7 @@ fn point_at_assoc_type_restriction<G: EmissionGuarantee>(
55995621
);
56005622
// Search for the associated type `Self::{name}`, get
56015623
// its type and suggest replacing the bound with it.
5602-
let mut visitor = SelfVisitor { paths: vec![], name: Some(name) };
5624+
let mut visitor = SelfVisitor { name: Some(name), .. };
56035625
visitor.visit_trait_ref(trait_ref);
56045626
for path in visitor.paths {
56055627
err.span_suggestion_verbose(
@@ -5610,7 +5632,7 @@ fn point_at_assoc_type_restriction<G: EmissionGuarantee>(
56105632
);
56115633
}
56125634
} else {
5613-
let mut visitor = SelfVisitor { paths: vec![], name: None };
5635+
let mut visitor = SelfVisitor { name: None, .. };
56145636
visitor.visit_trait_ref(trait_ref);
56155637
let span: MultiSpan =
56165638
visitor.paths.iter().map(|p| p.span).collect::<Vec<Span>>().into();
@@ -5640,8 +5662,8 @@ fn get_deref_type_and_refs(mut ty: Ty<'_>) -> (Ty<'_>, Vec<hir::Mutability>) {
56405662
/// `param: ?Sized` would be a valid constraint.
56415663
struct FindTypeParam {
56425664
param: rustc_span::Symbol,
5643-
invalid_spans: Vec<Span>,
5644-
nested: bool,
5665+
invalid_spans: Vec<Span> = Vec::new(),
5666+
nested: bool = false,
56455667
}
56465668

56475669
impl<'v> Visitor<'v> for FindTypeParam {
@@ -5679,3 +5701,38 @@ impl<'v> Visitor<'v> for FindTypeParam {
56795701
}
56805702
}
56815703
}
5704+
5705+
/// Look for type parameters in predicates. We use this to identify whether a bound is suitable in
5706+
/// on a given item.
5707+
struct ParamFinder {
5708+
params: Vec<Symbol> = Vec::new(),
5709+
}
5710+
5711+
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ParamFinder {
5712+
fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
5713+
match t.kind() {
5714+
ty::Param(p) => self.params.push(p.name),
5715+
_ => {}
5716+
}
5717+
t.super_visit_with(self)
5718+
}
5719+
}
5720+
5721+
impl ParamFinder {
5722+
/// Whether the `hir::Generics` of the current item can suggest the evaluated bound because its
5723+
/// references to type parameters are present in the generics.
5724+
fn can_suggest_bound(&self, generics: &hir::Generics<'_>) -> bool {
5725+
if self.params.is_empty() {
5726+
// There are no references to type parameters at all, so suggesting the bound
5727+
// would be reasonable.
5728+
return true;
5729+
}
5730+
generics.params.iter().any(|p| match p.name {
5731+
hir::ParamName::Plain(p_name) => {
5732+
// All of the parameters in the bound can be referenced in the current item.
5733+
self.params.iter().any(|p| *p == p_name.name || *p == kw::SelfUpper)
5734+
}
5735+
_ => true,
5736+
})
5737+
}
5738+
}

compiler/rustc_trait_selection/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#![feature(assert_matches)]
2020
#![feature(associated_type_defaults)]
2121
#![feature(box_patterns)]
22+
#![feature(default_field_values)]
2223
#![feature(if_let_guard)]
2324
#![feature(iter_intersperse)]
2425
#![feature(iterator_try_reduce)]

src/bootstrap/mk/Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ check-aux:
7676
library/std \
7777
$(BOOTSTRAP_ARGS) \
7878
-- \
79-
--skip fs:: --skip net:: --skip process:: --skip sys::fd:: --skip sys::pal::
79+
--skip fs:: --skip net:: --skip process:: --skip sys::
8080
# Also test some very target-specific modules on other targets
8181
# (making sure to cover an i686 target as well).
8282
$(Q)MIRIFLAGS="-Zmiri-disable-isolation" BOOTSTRAP_SKIP_TARGET_SANITY=1 \

src/bootstrap/src/core/build_steps/check.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,3 +839,9 @@ tool_check_step!(Linkchecker {
839839
mode: |_builder| Mode::ToolBootstrap,
840840
default: false
841841
});
842+
843+
tool_check_step!(BumpStage0 {
844+
path: "src/tools/bump-stage0",
845+
mode: |_builder| Mode::ToolBootstrap,
846+
default: false
847+
});

src/bootstrap/src/core/builder/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,7 @@ impl<'a> Builder<'a> {
10611061
check::FeaturesStatusDump,
10621062
check::CoverageDump,
10631063
check::Linkchecker,
1064+
check::BumpStage0,
10641065
// This has special staging logic, it may run on stage 1 while others run on stage 0.
10651066
// It takes quite some time to build stage 1, so put this at the end.
10661067
//

0 commit comments

Comments
 (0)