Skip to content

Commit 7b4f489

Browse files
committed
Auto merge of #109056 - matthiaskrgr:rollup-9trny1z, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #108651 (Forbid the use of `#[target_feature]` on `main`) - #109009 (rustdoc: use restricted Damerau-Levenshtein distance for search) - #109026 (Introduce `Rc::into_inner`, as a parallel to `Arc::into_inner`) - #109029 (Gate usages of `dyn*` and const closures in macros) - #109031 (Rename `config.toml.example` to `config.example.toml`) - #109032 (Use `TyCtxt::trait_solver_next` in some places) - #109047 (typo) - #109052 (Add eslint check for rustdoc-gui tester) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 938afba + 5dc0113 commit 7b4f489

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+549
-219
lines changed

.gitattributes

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
src/etc/installer/gfx/* binary
1010
src/vendor/** -text
1111
Cargo.lock linguist-generated=false
12-
config.toml.example linguist-language=TOML
1312

1413
# Older git versions try to fix line endings on images and fonts, this prevents it.
1514
*.png binary

.reuse/dep5

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Files: compiler/*
1616
Cargo.lock
1717
Cargo.toml
1818
CODE_OF_CONDUCT.md
19-
config.toml.example
19+
config.example.toml
2020
configure
2121
CONTRIBUTING.md
2222
COPYRIGHT

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ See [the rustc-dev-guide for more info][sysllvm].
9999
The Rust build system uses a file named `config.toml` in the root of the
100100
source tree to determine various configuration settings for the build.
101101
Set up the defaults intended for distros to get started. You can see a full
102-
list of options in `config.toml.example`.
102+
list of options in `config.example.toml`.
103103

104104
```sh
105105
printf 'profile = "user" \nchangelog-seen = 2 \n' > config.toml

compiler/rustc_ast_passes/src/feature_gate.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
337337
ast::TyKind::Never => {
338338
gate_feature_post!(&self, never_type, ty.span, "the `!` type is experimental");
339339
}
340-
ast::TyKind::TraitObject(_, ast::TraitObjectSyntax::DynStar, ..) => {
341-
gate_feature_post!(&self, dyn_star, ty.span, "dyn* trait objects are unstable");
342-
}
343340
_ => {}
344341
}
345342
visit::walk_ty(self, ty)
@@ -425,14 +422,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
425422
ast::ExprKind::TryBlock(_) => {
426423
gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental");
427424
}
428-
ast::ExprKind::Closure(box ast::Closure { constness: ast::Const::Yes(_), .. }) => {
429-
gate_feature_post!(
430-
&self,
431-
const_closures,
432-
e.span,
433-
"const closures are experimental"
434-
);
435-
}
436425
_ => {}
437426
}
438427
visit::walk_expr(self, e)
@@ -594,6 +583,8 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
594583
gate_all!(inline_const_pat, "inline-const in pattern position is experimental");
595584
gate_all!(associated_const_equality, "associated const equality is incomplete");
596585
gate_all!(yeet_expr, "`do yeet` expression is experimental");
586+
gate_all!(dyn_star, "`dyn*` trait objects are experimental");
587+
gate_all!(const_closures, "const closures are experimental");
597588

598589
// All uses of `gate_all!` below this point were added in #65742,
599590
// and subsequently disabled (with the non-early gating readded).

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+3
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
242242
// Note that this is also allowed if `actually_rustdoc` so
243243
// if a target is documenting some wasm-specific code then
244244
// it's not spuriously denied.
245+
//
246+
// This exception needs to be kept in sync with allowing
247+
// `#[target_feature]` on `main` and `start`.
245248
} else if !tcx.features().target_feature_11 {
246249
let mut err = feature_err(
247250
&tcx.sess.parse_sess,

compiler/rustc_hir_analysis/messages.ftl

+5
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,14 @@ hir_analysis_where_clause_on_main = `main` function is not allowed to have a `wh
128128
hir_analysis_track_caller_on_main = `main` function is not allowed to be `#[track_caller]`
129129
.suggestion = remove this annotation
130130
131+
hir_analysis_target_feature_on_main = `main` function is not allowed to have `#[target_feature]`
132+
131133
hir_analysis_start_not_track_caller = `start` is not allowed to be `#[track_caller]`
132134
.label = `start` is not allowed to be `#[track_caller]`
133135
136+
hir_analysis_start_not_target_feature = `start` is not allowed to have `#[target_feature]`
137+
.label = `start` is not allowed to have `#[target_feature]`
138+
134139
hir_analysis_start_not_async = `start` is not allowed to be `async`
135140
.label = `start` is not allowed to be `async`
136141

compiler/rustc_hir_analysis/src/errors.rs

+17
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,14 @@ pub(crate) struct TrackCallerOnMain {
327327
pub annotated: Span,
328328
}
329329

330+
#[derive(Diagnostic)]
331+
#[diag(hir_analysis_target_feature_on_main)]
332+
pub(crate) struct TargetFeatureOnMain {
333+
#[primary_span]
334+
#[label(hir_analysis_target_feature_on_main)]
335+
pub main: Span,
336+
}
337+
330338
#[derive(Diagnostic)]
331339
#[diag(hir_analysis_start_not_track_caller)]
332340
pub(crate) struct StartTrackCaller {
@@ -336,6 +344,15 @@ pub(crate) struct StartTrackCaller {
336344
pub start: Span,
337345
}
338346

347+
#[derive(Diagnostic)]
348+
#[diag(hir_analysis_start_not_target_feature)]
349+
pub(crate) struct StartTargetFeature {
350+
#[primary_span]
351+
pub span: Span,
352+
#[label]
353+
pub start: Span,
354+
}
355+
339356
#[derive(Diagnostic)]
340357
#[diag(hir_analysis_start_not_async, code = "E0752")]
341358
pub(crate) struct StartAsync {

compiler/rustc_hir_analysis/src/lib.rs

+21
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,15 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
283283
error = true;
284284
}
285285

286+
if !tcx.codegen_fn_attrs(main_def_id).target_features.is_empty()
287+
// Calling functions with `#[target_feature]` is not unsafe on WASM, see #84988
288+
&& !tcx.sess.target.is_like_wasm
289+
&& !tcx.sess.opts.actually_rustdoc
290+
{
291+
tcx.sess.emit_err(errors::TargetFeatureOnMain { main: main_span });
292+
error = true;
293+
}
294+
286295
if error {
287296
return;
288297
}
@@ -373,6 +382,18 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
373382
});
374383
error = true;
375384
}
385+
if attr.has_name(sym::target_feature)
386+
// Calling functions with `#[target_feature]` is
387+
// not unsafe on WASM, see #84988
388+
&& !tcx.sess.target.is_like_wasm
389+
&& !tcx.sess.opts.actually_rustdoc
390+
{
391+
tcx.sess.emit_err(errors::StartTargetFeature {
392+
span: attr.span,
393+
start: start_span,
394+
});
395+
error = true;
396+
}
376397
}
377398

378399
if error {

compiler/rustc_parse/src/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2105,7 +2105,7 @@ impl<'a> Parser<'a> {
21052105
ClosureBinder::NotPresent
21062106
};
21072107

2108-
let constness = self.parse_closure_constness(Case::Sensitive);
2108+
let constness = self.parse_closure_constness();
21092109

21102110
let movability =
21112111
if self.eat_keyword(kw::Static) { Movability::Static } else { Movability::Movable };

compiler/rustc_parse/src/parser/mod.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1196,9 +1196,13 @@ impl<'a> Parser<'a> {
11961196
self.parse_constness_(case, false)
11971197
}
11981198

1199-
/// Parses constness for closures
1200-
fn parse_closure_constness(&mut self, case: Case) -> Const {
1201-
self.parse_constness_(case, true)
1199+
/// Parses constness for closures (case sensitive, feature-gated)
1200+
fn parse_closure_constness(&mut self) -> Const {
1201+
let constness = self.parse_constness_(Case::Sensitive, true);
1202+
if let Const::Yes(span) = constness {
1203+
self.sess.gated_spans.gate(sym::const_closures, span);
1204+
}
1205+
constness
12021206
}
12031207

12041208
fn parse_constness_(&mut self, case: Case, is_closure: bool) -> Const {

compiler/rustc_parse/src/parser/ty.rs

+2
Original file line numberDiff line numberDiff line change
@@ -624,10 +624,12 @@ impl<'a> Parser<'a> {
624624
///
625625
/// Note that this does *not* parse bare trait objects.
626626
fn parse_dyn_ty(&mut self, impl_dyn_multi: &mut bool) -> PResult<'a, TyKind> {
627+
let lo = self.token.span;
627628
self.bump(); // `dyn`
628629

629630
// parse dyn* types
630631
let syntax = if self.eat(&TokenKind::BinOp(token::Star)) {
632+
self.sess.gated_spans.gate(sym::dyn_star, lo.to(self.prev_token.span));
631633
TraitObjectSyntax::DynStar
632634
} else {
633635
TraitObjectSyntax::Dyn

compiler/rustc_trait_selection/src/traits/query/evaluate_obligation.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use rustc_middle::traits::solve::{Certainty, Goal, MaybeCause};
22
use rustc_middle::ty;
3-
use rustc_session::config::TraitSolver;
43

54
use crate::infer::canonical::OriginalQueryValues;
65
use crate::infer::InferCtxt;
@@ -80,13 +79,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
8079
_ => obligation.param_env.without_const(),
8180
};
8281

83-
if self.tcx.sess.opts.unstable_opts.trait_solver != TraitSolver::Next {
84-
let c_pred = self.canonicalize_query_keep_static(
85-
param_env.and(obligation.predicate),
86-
&mut _orig_values,
87-
);
88-
self.tcx.at(obligation.cause.span()).evaluate_obligation(c_pred)
89-
} else {
82+
if self.tcx.trait_solver_next() {
9083
self.probe(|snapshot| {
9184
if let Ok((_, certainty)) =
9285
self.evaluate_root_goal(Goal::new(self.tcx, param_env, obligation.predicate))
@@ -111,6 +104,12 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
111104
Ok(EvaluationResult::EvaluatedToErr)
112105
}
113106
})
107+
} else {
108+
let c_pred = self.canonicalize_query_keep_static(
109+
param_env.and(obligation.predicate),
110+
&mut _orig_values,
111+
);
112+
self.tcx.at(obligation.cause.span()).evaluate_obligation(c_pred)
114113
}
115114
}
116115

compiler/rustc_trait_selection/src/traits/select/mod.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ use rustc_middle::ty::relate::TypeRelation;
5050
use rustc_middle::ty::SubstsRef;
5151
use rustc_middle::ty::{self, EarlyBinder, PolyProjectionPredicate, ToPolyTraitRef, ToPredicate};
5252
use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable, TypeVisitableExt};
53-
use rustc_session::config::TraitSolver;
5453
use rustc_span::symbol::sym;
5554

5655
use std::cell::{Cell, RefCell};
@@ -545,13 +544,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
545544
obligation: &PredicateObligation<'tcx>,
546545
) -> Result<EvaluationResult, OverflowError> {
547546
self.evaluation_probe(|this| {
548-
if this.tcx().sess.opts.unstable_opts.trait_solver != TraitSolver::Next {
547+
if this.tcx().trait_solver_next() {
548+
this.evaluate_predicates_recursively_in_new_solver([obligation.clone()])
549+
} else {
549550
this.evaluate_predicate_recursively(
550551
TraitObligationStackList::empty(&ProvisionalEvaluationCache::default()),
551552
obligation.clone(),
552553
)
553-
} else {
554-
this.evaluate_predicates_recursively_in_new_solver([obligation.clone()])
555554
}
556555
})
557556
}
@@ -591,7 +590,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
591590
where
592591
I: IntoIterator<Item = PredicateObligation<'tcx>> + std::fmt::Debug,
593592
{
594-
if self.tcx().sess.opts.unstable_opts.trait_solver != TraitSolver::Next {
593+
if self.tcx().trait_solver_next() {
594+
self.evaluate_predicates_recursively_in_new_solver(predicates)
595+
} else {
595596
let mut result = EvaluatedToOk;
596597
for obligation in predicates {
597598
let eval = self.evaluate_predicate_recursively(stack, obligation.clone())?;
@@ -604,8 +605,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
604605
}
605606
}
606607
Ok(result)
607-
} else {
608-
self.evaluate_predicates_recursively_in_new_solver(predicates)
609608
}
610609
}
611610

compiler/rustc_type_ir/src/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ pub enum TyKind<I: Interner> {
167167
/// lifetimes bound by the witness itself.
168168
///
169169
/// This variant is only using when `drop_tracking_mir` is set.
170-
/// This contains the `DefId` and the `SubstRef` of the generator.
170+
/// This contains the `DefId` and the `SubstsRef` of the generator.
171171
/// The actual witness types are computed on MIR by the `mir_generator_witnesses` query.
172172
///
173173
/// Looking at the following example, the witness for this generator
File renamed without changes.

library/alloc/src/rc.rs

+18
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,24 @@ impl<T> Rc<T> {
681681
Err(this)
682682
}
683683
}
684+
685+
/// Returns the inner value, if the `Rc` has exactly one strong reference.
686+
///
687+
/// Otherwise, [`None`] is returned and the `Rc` is dropped.
688+
///
689+
/// This will succeed even if there are outstanding weak references.
690+
///
691+
/// If `Rc::into_inner` is called on every clone of this `Rc`,
692+
/// it is guaranteed that exactly one of the calls returns the inner value.
693+
/// This means in particular that the inner value is not dropped.
694+
///
695+
/// This is equivalent to `Rc::try_unwrap(...).ok()`. (Note that these are not equivalent for
696+
/// `Arc`, due to race conditions that do not apply to `Rc`.)
697+
#[inline]
698+
#[unstable(feature = "rc_into_inner", issue = "106894")]
699+
pub fn into_inner(this: Self) -> Option<T> {
700+
Rc::try_unwrap(this).ok()
701+
}
684702
}
685703

686704
impl<T> Rc<[T]> {

library/alloc/src/rc/tests.rs

+15
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,21 @@ fn try_unwrap() {
151151
assert_eq!(Rc::try_unwrap(x), Ok(5));
152152
}
153153

154+
#[test]
155+
fn into_inner() {
156+
let x = Rc::new(3);
157+
assert_eq!(Rc::into_inner(x), Some(3));
158+
159+
let x = Rc::new(4);
160+
let y = Rc::clone(&x);
161+
assert_eq!(Rc::into_inner(x), None);
162+
assert_eq!(Rc::into_inner(y), Some(4));
163+
164+
let x = Rc::new(5);
165+
let _w = Rc::downgrade(&x);
166+
assert_eq!(Rc::into_inner(x), Some(5));
167+
}
168+
154169
#[test]
155170
fn into_from_raw() {
156171
let x = Rc::new(Box::new("hello"));

src/bootstrap/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ Some general areas that you may be interested in modifying are:
185185
If you make a major change, please remember to:
186186

187187
+ Update `VERSION` in `src/bootstrap/main.rs`.
188-
* Update `changelog-seen = N` in `config.toml.example`.
188+
* Update `changelog-seen = N` in `config.example.toml`.
189189
* Add an entry in `src/bootstrap/CHANGELOG.md`.
190190

191191
A 'major change' includes

src/bootstrap/bin/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ fn main() {
4444
if suggest_setup {
4545
println!("warning: you have not made a `config.toml`");
4646
println!(
47-
"help: consider running `./x.py setup` or copying `config.toml.example` by running \
48-
`cp config.toml.example config.toml`"
47+
"help: consider running `./x.py setup` or copying `config.example.toml` by running \
48+
`cp config.example.toml config.toml`"
4949
);
5050
} else if let Some(suggestion) = &changelog_suggestion {
5151
println!("{}", suggestion);
@@ -57,8 +57,8 @@ fn main() {
5757
if suggest_setup {
5858
println!("warning: you have not made a `config.toml`");
5959
println!(
60-
"help: consider running `./x.py setup` or copying `config.toml.example` by running \
61-
`cp config.toml.example config.toml`"
60+
"help: consider running `./x.py setup` or copying `config.example.toml` by running \
61+
`cp config.example.toml config.toml`"
6262
);
6363
} else if let Some(suggestion) = &changelog_suggestion {
6464
println!("{}", suggestion);

src/bootstrap/config.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub enum DryRun {
5555
/// Note that this structure is not decoded directly into, but rather it is
5656
/// filled out from the decoded forms of the structs below. For documentation
5757
/// each field, see the corresponding fields in
58-
/// `config.toml.example`.
58+
/// `config.example.toml`.
5959
#[derive(Default)]
6060
#[cfg_attr(test, derive(Clone))]
6161
pub struct Config {
@@ -325,7 +325,7 @@ impl std::str::FromStr for SplitDebuginfo {
325325

326326
impl SplitDebuginfo {
327327
/// Returns the default `-Csplit-debuginfo` value for the current target. See the comment for
328-
/// `rust.split-debuginfo` in `config.toml.example`.
328+
/// `rust.split-debuginfo` in `config.example.toml`.
329329
fn default_for_platform(target: &str) -> Self {
330330
if target.contains("apple") {
331331
SplitDebuginfo::Unpacked

0 commit comments

Comments
 (0)