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 8 pull requests #109056

Merged
merged 22 commits into from
Mar 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
dfd9e5e
rustdoc: use restricted Damerau-Levenshtein distance for search
notriddle Mar 11, 2023
a2341fb
Introduce `Rc::into_inner`, as a parallel to `Arc::into_inner`
joshtriplett Mar 11, 2023
bd43555
Gate all usages of dyn*, even in macros
compiler-errors Mar 11, 2023
c3159b8
Gate const closures even when they appear in macros
compiler-errors Mar 11, 2023
d283452
Use TyCtxt::trait_solver_next in some places
compiler-errors Mar 11, 2023
fcb2a36
Rename `config.toml.example` to `config.example.toml`
thomcc Mar 11, 2023
ce795d9
rustdoc: collapse edit distance state into an object
notriddle Mar 12, 2023
421c34b
typo
tshepang Mar 12, 2023
db26693
Forbid the use of `#[target_feature]` on `main`
LeSeulArtichaut Mar 2, 2023
963305b
Forbid the use of `#[target_feature]` on `start`
LeSeulArtichaut Mar 2, 2023
29b1789
Allow `#[target_feature]` on `main` and `start` for WASM
LeSeulArtichaut Mar 10, 2023
77a8070
Add eslint check for rustdoc-gui tester
GuillaumeGomez Mar 12, 2023
cd9759a
Add rustdoc-gui eslint check into CI
GuillaumeGomez Mar 12, 2023
992957e
Fix formatting of new Rc::into_inner test
dtolnay Mar 12, 2023
f41796e
Rollup merge of #108651 - LeSeulArtichaut:108645-target-feature-on-ma…
matthiaskrgr Mar 12, 2023
afe2575
Rollup merge of #109009 - notriddle:notriddle/edit-distance, r=Guilla…
matthiaskrgr Mar 12, 2023
b28775c
Rollup merge of #109026 - joshtriplett:rc-into-inner, r=dtolnay
matthiaskrgr Mar 12, 2023
98fea68
Rollup merge of #109029 - compiler-errors:parse-gating, r=jackh726
matthiaskrgr Mar 12, 2023
66f07c7
Rollup merge of #109031 - thomcc:config-example-toml, r=ozkanonur
matthiaskrgr Mar 12, 2023
4305c1a
Rollup merge of #109032 - compiler-errors:shorter, r=BoxyUwU
matthiaskrgr Mar 12, 2023
fb4bb16
Rollup merge of #109047 - tshepang:type, r=lcnr
matthiaskrgr Mar 12, 2023
5dc0113
Rollup merge of #109052 - GuillaumeGomez:rustdoc-gui-tester-eslint, r…
matthiaskrgr Mar 12, 2023
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
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
src/etc/installer/gfx/* binary
src/vendor/** -text
Cargo.lock linguist-generated=false
config.toml.example linguist-language=TOML

# Older git versions try to fix line endings on images and fonts, this prevents it.
*.png binary
Expand Down
2 changes: 1 addition & 1 deletion .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Files: compiler/*
Cargo.lock
Cargo.toml
CODE_OF_CONDUCT.md
config.toml.example
config.example.toml
configure
CONTRIBUTING.md
COPYRIGHT
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ See [the rustc-dev-guide for more info][sysllvm].
The Rust build system uses a file named `config.toml` in the root of the
source tree to determine various configuration settings for the build.
Set up the defaults intended for distros to get started. You can see a full
list of options in `config.toml.example`.
list of options in `config.example.toml`.

```sh
printf 'profile = "user" \nchangelog-seen = 2 \n' > config.toml
Expand Down
13 changes: 2 additions & 11 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
ast::TyKind::Never => {
gate_feature_post!(&self, never_type, ty.span, "the `!` type is experimental");
}
ast::TyKind::TraitObject(_, ast::TraitObjectSyntax::DynStar, ..) => {
gate_feature_post!(&self, dyn_star, ty.span, "dyn* trait objects are unstable");
}
_ => {}
}
visit::walk_ty(self, ty)
Expand Down Expand Up @@ -425,14 +422,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
ast::ExprKind::TryBlock(_) => {
gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental");
}
ast::ExprKind::Closure(box ast::Closure { constness: ast::Const::Yes(_), .. }) => {
gate_feature_post!(
&self,
const_closures,
e.span,
"const closures are experimental"
);
}
_ => {}
}
visit::walk_expr(self, e)
Expand Down Expand Up @@ -594,6 +583,8 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
gate_all!(inline_const_pat, "inline-const in pattern position is experimental");
gate_all!(associated_const_equality, "associated const equality is incomplete");
gate_all!(yeet_expr, "`do yeet` expression is experimental");
gate_all!(dyn_star, "`dyn*` trait objects are experimental");
gate_all!(const_closures, "const closures are experimental");

// All uses of `gate_all!` below this point were added in #65742,
// and subsequently disabled (with the non-early gating readded).
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_ssa/src/codegen_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
// Note that this is also allowed if `actually_rustdoc` so
// if a target is documenting some wasm-specific code then
// it's not spuriously denied.
//
// This exception needs to be kept in sync with allowing
// `#[target_feature]` on `main` and `start`.
} else if !tcx.features().target_feature_11 {
let mut err = feature_err(
&tcx.sess.parse_sess,
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_hir_analysis/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,14 @@ hir_analysis_where_clause_on_main = `main` function is not allowed to have a `wh
hir_analysis_track_caller_on_main = `main` function is not allowed to be `#[track_caller]`
.suggestion = remove this annotation

hir_analysis_target_feature_on_main = `main` function is not allowed to have `#[target_feature]`

hir_analysis_start_not_track_caller = `start` is not allowed to be `#[track_caller]`
.label = `start` is not allowed to be `#[track_caller]`

hir_analysis_start_not_target_feature = `start` is not allowed to have `#[target_feature]`
.label = `start` is not allowed to have `#[target_feature]`

hir_analysis_start_not_async = `start` is not allowed to be `async`
.label = `start` is not allowed to be `async`

Expand Down
17 changes: 17 additions & 0 deletions compiler/rustc_hir_analysis/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,14 @@ pub(crate) struct TrackCallerOnMain {
pub annotated: Span,
}

#[derive(Diagnostic)]
#[diag(hir_analysis_target_feature_on_main)]
pub(crate) struct TargetFeatureOnMain {
#[primary_span]
#[label(hir_analysis_target_feature_on_main)]
pub main: Span,
}

#[derive(Diagnostic)]
#[diag(hir_analysis_start_not_track_caller)]
pub(crate) struct StartTrackCaller {
Expand All @@ -336,6 +344,15 @@ pub(crate) struct StartTrackCaller {
pub start: Span,
}

#[derive(Diagnostic)]
#[diag(hir_analysis_start_not_target_feature)]
pub(crate) struct StartTargetFeature {
#[primary_span]
pub span: Span,
#[label]
pub start: Span,
}

#[derive(Diagnostic)]
#[diag(hir_analysis_start_not_async, code = "E0752")]
pub(crate) struct StartAsync {
Expand Down
21 changes: 21 additions & 0 deletions compiler/rustc_hir_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,15 @@ fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
error = true;
}

if !tcx.codegen_fn_attrs(main_def_id).target_features.is_empty()
// Calling functions with `#[target_feature]` is not unsafe on WASM, see #84988
&& !tcx.sess.target.is_like_wasm
&& !tcx.sess.opts.actually_rustdoc
{
tcx.sess.emit_err(errors::TargetFeatureOnMain { main: main_span });
error = true;
}

if error {
return;
}
Expand Down Expand Up @@ -373,6 +382,18 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
});
error = true;
}
if attr.has_name(sym::target_feature)
// Calling functions with `#[target_feature]` is
// not unsafe on WASM, see #84988
&& !tcx.sess.target.is_like_wasm
&& !tcx.sess.opts.actually_rustdoc
{
tcx.sess.emit_err(errors::StartTargetFeature {
span: attr.span,
start: start_span,
});
error = true;
}
}

if error {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2105,7 +2105,7 @@ impl<'a> Parser<'a> {
ClosureBinder::NotPresent
};

let constness = self.parse_closure_constness(Case::Sensitive);
let constness = self.parse_closure_constness();

let movability =
if self.eat_keyword(kw::Static) { Movability::Static } else { Movability::Movable };
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1196,9 +1196,13 @@ impl<'a> Parser<'a> {
self.parse_constness_(case, false)
}

/// Parses constness for closures
fn parse_closure_constness(&mut self, case: Case) -> Const {
self.parse_constness_(case, true)
/// Parses constness for closures (case sensitive, feature-gated)
fn parse_closure_constness(&mut self) -> Const {
let constness = self.parse_constness_(Case::Sensitive, true);
if let Const::Yes(span) = constness {
self.sess.gated_spans.gate(sym::const_closures, span);
}
constness
}

fn parse_constness_(&mut self, case: Case, is_closure: bool) -> Const {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,10 +624,12 @@ impl<'a> Parser<'a> {
///
/// Note that this does *not* parse bare trait objects.
fn parse_dyn_ty(&mut self, impl_dyn_multi: &mut bool) -> PResult<'a, TyKind> {
let lo = self.token.span;
self.bump(); // `dyn`

// parse dyn* types
let syntax = if self.eat(&TokenKind::BinOp(token::Star)) {
self.sess.gated_spans.gate(sym::dyn_star, lo.to(self.prev_token.span));
TraitObjectSyntax::DynStar
} else {
TraitObjectSyntax::Dyn
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use rustc_middle::traits::solve::{Certainty, Goal, MaybeCause};
use rustc_middle::ty;
use rustc_session::config::TraitSolver;

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

if self.tcx.sess.opts.unstable_opts.trait_solver != TraitSolver::Next {
let c_pred = self.canonicalize_query_keep_static(
param_env.and(obligation.predicate),
&mut _orig_values,
);
self.tcx.at(obligation.cause.span()).evaluate_obligation(c_pred)
} else {
if self.tcx.trait_solver_next() {
self.probe(|snapshot| {
if let Ok((_, certainty)) =
self.evaluate_root_goal(Goal::new(self.tcx, param_env, obligation.predicate))
Expand All @@ -111,6 +104,12 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
Ok(EvaluationResult::EvaluatedToErr)
}
})
} else {
let c_pred = self.canonicalize_query_keep_static(
param_env.and(obligation.predicate),
&mut _orig_values,
);
self.tcx.at(obligation.cause.span()).evaluate_obligation(c_pred)
}
}

Expand Down
13 changes: 6 additions & 7 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ use rustc_middle::ty::relate::TypeRelation;
use rustc_middle::ty::SubstsRef;
use rustc_middle::ty::{self, EarlyBinder, PolyProjectionPredicate, ToPolyTraitRef, ToPredicate};
use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable, TypeVisitableExt};
use rustc_session::config::TraitSolver;
use rustc_span::symbol::sym;

use std::cell::{Cell, RefCell};
Expand Down Expand Up @@ -545,13 +544,13 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation: &PredicateObligation<'tcx>,
) -> Result<EvaluationResult, OverflowError> {
self.evaluation_probe(|this| {
if this.tcx().sess.opts.unstable_opts.trait_solver != TraitSolver::Next {
if this.tcx().trait_solver_next() {
this.evaluate_predicates_recursively_in_new_solver([obligation.clone()])
} else {
this.evaluate_predicate_recursively(
TraitObligationStackList::empty(&ProvisionalEvaluationCache::default()),
obligation.clone(),
)
} else {
this.evaluate_predicates_recursively_in_new_solver([obligation.clone()])
}
})
}
Expand Down Expand Up @@ -591,7 +590,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
where
I: IntoIterator<Item = PredicateObligation<'tcx>> + std::fmt::Debug,
{
if self.tcx().sess.opts.unstable_opts.trait_solver != TraitSolver::Next {
if self.tcx().trait_solver_next() {
self.evaluate_predicates_recursively_in_new_solver(predicates)
} else {
let mut result = EvaluatedToOk;
for obligation in predicates {
let eval = self.evaluate_predicate_recursively(stack, obligation.clone())?;
Expand All @@ -604,8 +605,6 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
}
}
Ok(result)
} else {
self.evaluate_predicates_recursively_in_new_solver(predicates)
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_type_ir/src/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ pub enum TyKind<I: Interner> {
/// lifetimes bound by the witness itself.
///
/// This variant is only using when `drop_tracking_mir` is set.
/// This contains the `DefId` and the `SubstRef` of the generator.
/// This contains the `DefId` and the `SubstsRef` of the generator.
/// The actual witness types are computed on MIR by the `mir_generator_witnesses` query.
///
/// Looking at the following example, the witness for this generator
Expand Down
File renamed without changes.
18 changes: 18 additions & 0 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,24 @@ impl<T> Rc<T> {
Err(this)
}
}

/// Returns the inner value, if the `Rc` has exactly one strong reference.
///
/// Otherwise, [`None`] is returned and the `Rc` is dropped.
///
/// This will succeed even if there are outstanding weak references.
///
/// If `Rc::into_inner` is called on every clone of this `Rc`,
/// it is guaranteed that exactly one of the calls returns the inner value.
/// This means in particular that the inner value is not dropped.
///
/// This is equivalent to `Rc::try_unwrap(...).ok()`. (Note that these are not equivalent for
/// `Arc`, due to race conditions that do not apply to `Rc`.)
#[inline]
#[unstable(feature = "rc_into_inner", issue = "106894")]
pub fn into_inner(this: Self) -> Option<T> {
Rc::try_unwrap(this).ok()
}
}

impl<T> Rc<[T]> {
Expand Down
15 changes: 15 additions & 0 deletions library/alloc/src/rc/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,21 @@ fn try_unwrap() {
assert_eq!(Rc::try_unwrap(x), Ok(5));
}

#[test]
fn into_inner() {
let x = Rc::new(3);
assert_eq!(Rc::into_inner(x), Some(3));

let x = Rc::new(4);
let y = Rc::clone(&x);
assert_eq!(Rc::into_inner(x), None);
assert_eq!(Rc::into_inner(y), Some(4));

let x = Rc::new(5);
let _w = Rc::downgrade(&x);
assert_eq!(Rc::into_inner(x), Some(5));
}

#[test]
fn into_from_raw() {
let x = Rc::new(Box::new("hello"));
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ Some general areas that you may be interested in modifying are:
If you make a major change, please remember to:

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

A 'major change' includes
Expand Down
8 changes: 4 additions & 4 deletions src/bootstrap/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ fn main() {
if suggest_setup {
println!("warning: you have not made a `config.toml`");
println!(
"help: consider running `./x.py setup` or copying `config.toml.example` by running \
`cp config.toml.example config.toml`"
"help: consider running `./x.py setup` or copying `config.example.toml` by running \
`cp config.example.toml config.toml`"
);
} else if let Some(suggestion) = &changelog_suggestion {
println!("{}", suggestion);
Expand All @@ -57,8 +57,8 @@ fn main() {
if suggest_setup {
println!("warning: you have not made a `config.toml`");
println!(
"help: consider running `./x.py setup` or copying `config.toml.example` by running \
`cp config.toml.example config.toml`"
"help: consider running `./x.py setup` or copying `config.example.toml` by running \
`cp config.example.toml config.toml`"
);
} else if let Some(suggestion) = &changelog_suggestion {
println!("{}", suggestion);
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub enum DryRun {
/// Note that this structure is not decoded directly into, but rather it is
/// filled out from the decoded forms of the structs below. For documentation
/// each field, see the corresponding fields in
/// `config.toml.example`.
/// `config.example.toml`.
#[derive(Default)]
#[cfg_attr(test, derive(Clone))]
pub struct Config {
Expand Down Expand Up @@ -325,7 +325,7 @@ impl std::str::FromStr for SplitDebuginfo {

impl SplitDebuginfo {
/// Returns the default `-Csplit-debuginfo` value for the current target. See the comment for
/// `rust.split-debuginfo` in `config.toml.example`.
/// `rust.split-debuginfo` in `config.example.toml`.
fn default_for_platform(target: &str) -> Self {
if target.contains("apple") {
SplitDebuginfo::Unpacked
Expand Down
Loading