mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-03 02:23:20 +00:00
Make it clearer that edition functions are >=, not ==
This commit is contained in:
parent
77e24f90f5
commit
846cc63e38
@ -1200,7 +1200,7 @@ fn check_matcher_core<'tt>(
|
||||
err.span_label(sp, format!("not allowed after `{}` fragments", kind));
|
||||
|
||||
if kind == NonterminalKind::PatWithOr
|
||||
&& sess.edition.rust_2021()
|
||||
&& sess.edition.at_least_rust_2021()
|
||||
&& next_token.is_token(&BinOp(token::BinOpToken::Or))
|
||||
{
|
||||
let suggestion = quoted_tt_to_string(&TokenTree::MetaVarDecl(
|
||||
|
@ -86,7 +86,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
));
|
||||
}
|
||||
|
||||
if self_ty.span.edition().rust_2021() {
|
||||
if self_ty.span.edition().at_least_rust_2021() {
|
||||
let msg = "trait objects must include the `dyn` keyword";
|
||||
let label = "add `dyn` keyword before this trait";
|
||||
let mut diag =
|
||||
|
@ -860,7 +860,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
.resolve_fully_qualified_call(span, item_name, ty.normalized, qself.span, hir_id)
|
||||
.and_then(|r| {
|
||||
// lint bare trait if the method is found in the trait
|
||||
if span.edition().rust_2021() && let Some(mut diag) = self.tcx.sess.diagnostic().steal_diagnostic(qself.span, StashKey::TraitMissingMethod) {
|
||||
if span.edition().at_least_rust_2021() && let Some(mut diag) = self.tcx.sess.diagnostic().steal_diagnostic(qself.span, StashKey::TraitMissingMethod) {
|
||||
diag.emit();
|
||||
}
|
||||
Ok(r)
|
||||
@ -890,7 +890,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
}
|
||||
|
||||
// emit or cancel the diagnostic for bare traits
|
||||
if span.edition().rust_2021() && let Some(mut diag) = self.tcx.sess.diagnostic().steal_diagnostic(qself.span, StashKey::TraitMissingMethod) {
|
||||
if span.edition().at_least_rust_2021() && let Some(mut diag) = self.tcx.sess.diagnostic().steal_diagnostic(qself.span, StashKey::TraitMissingMethod) {
|
||||
if trait_missing_method {
|
||||
// cancel the diag for bare traits when meeting `MyTrait::missing_method`
|
||||
diag.cancel();
|
||||
@ -908,7 +908,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
error,
|
||||
None,
|
||||
Expectation::NoExpectation,
|
||||
trait_missing_method && span.edition().rust_2021(), // emits missing method for trait only after edition 2021
|
||||
trait_missing_method && span.edition().at_least_rust_2021(), // emits missing method for trait only after edition 2021
|
||||
) {
|
||||
e.emit();
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
);
|
||||
|
||||
// Rust 2021 and later is already using the new prelude
|
||||
if span.rust_2021() {
|
||||
if span.at_least_rust_2021() {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -203,7 +203,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
pick: &Pick<'tcx>,
|
||||
) {
|
||||
// Rust 2021 and later is already using the new prelude
|
||||
if span.rust_2021() {
|
||||
if span.at_least_rust_2021() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -437,7 +437,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// this case used to be allowed by the compiler,
|
||||
// so we do a future-compat lint here for the 2015 edition
|
||||
// (see https://github.com/rust-lang/rust/issues/46906)
|
||||
if self.tcx.sess.rust_2018() {
|
||||
if self.tcx.sess.at_least_rust_2018() {
|
||||
self.tcx.sess.emit_err(MethodCallOnUnknownRawPointee { span });
|
||||
} else {
|
||||
self.tcx.struct_span_lint_hir(
|
||||
@ -1592,7 +1592,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||
if let Some(method_name) = self.method_name {
|
||||
// Some trait methods are excluded for arrays before 2021.
|
||||
// (`array.into_iter()` wants a slice iterator for compatibility.)
|
||||
if self_ty.is_array() && !method_name.span.rust_2021() {
|
||||
if self_ty.is_array() && !method_name.span.at_least_rust_2021() {
|
||||
let trait_def = self.tcx.trait_def(trait_ref.def_id);
|
||||
if trait_def.skip_array_during_method_dispatch {
|
||||
return ProbeResult::NoMatch;
|
||||
|
@ -2001,7 +2001,7 @@ fn should_do_rust_2021_incompatible_closure_captures_analysis(
|
||||
tcx: TyCtxt<'_>,
|
||||
closure_id: hir::HirId,
|
||||
) -> bool {
|
||||
if tcx.sess.rust_2021() {
|
||||
if tcx.sess.at_least_rust_2021() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2247,5 +2247,5 @@ fn truncate_capture_for_optimization(
|
||||
fn enable_precise_capture(span: Span) -> bool {
|
||||
// We use span here to ensure that if the closure was generated by a macro with a different
|
||||
// edition.
|
||||
span.rust_2021()
|
||||
span.at_least_rust_2021()
|
||||
}
|
||||
|
@ -1932,7 +1932,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
|
||||
fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
|
||||
self.empty_path = true;
|
||||
if cnum == LOCAL_CRATE {
|
||||
if self.tcx.sess.rust_2018() {
|
||||
if self.tcx.sess.at_least_rust_2018() {
|
||||
// We add the `crate::` keyword on Rust 2018, only when desired.
|
||||
if SHOULD_PREFIX_WITH_CRATE.with(|flag| flag.get()) {
|
||||
write!(self, "{}", kw::Crate)?;
|
||||
|
@ -730,5 +730,5 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
|
||||
/// Precise capture is enabled if user is using Rust Edition 2021 or higher.
|
||||
fn enable_precise_capture(closure_span: Span) -> bool {
|
||||
closure_span.rust_2021()
|
||||
closure_span.at_least_rust_2021()
|
||||
}
|
||||
|
@ -1309,7 +1309,7 @@ impl<'a> Parser<'a> {
|
||||
|
||||
/// Assuming we have just parsed `.`, continue parsing into an expression.
|
||||
fn parse_dot_suffix(&mut self, self_arg: P<Expr>, lo: Span) -> PResult<'a, P<Expr>> {
|
||||
if self.token.uninterpolated_span().rust_2018() && self.eat_keyword(kw::Await) {
|
||||
if self.token.uninterpolated_span().at_least_rust_2018() && self.eat_keyword(kw::Await) {
|
||||
return Ok(self.mk_await_expr(self_arg, lo));
|
||||
}
|
||||
|
||||
@ -1442,8 +1442,8 @@ impl<'a> Parser<'a> {
|
||||
self.parse_expr_let()
|
||||
} else if self.eat_keyword(kw::Underscore) {
|
||||
Ok(self.mk_expr(self.prev_token.span, ExprKind::Underscore))
|
||||
} else if self.token.uninterpolated_span().rust_2018() {
|
||||
// `Span::rust_2018()` is somewhat expensive; don't get it repeatedly.
|
||||
} else if self.token.uninterpolated_span().at_least_rust_2018() {
|
||||
// `Span:.at_least_rust_2018()` is somewhat expensive; don't get it repeatedly.
|
||||
if self.check_keyword(kw::Async) {
|
||||
if self.is_async_block() {
|
||||
// Check for `async {` and `async move {`.
|
||||
@ -2230,7 +2230,7 @@ impl<'a> Parser<'a> {
|
||||
let movability =
|
||||
if self.eat_keyword(kw::Static) { Movability::Static } else { Movability::Movable };
|
||||
|
||||
let asyncness = if self.token.uninterpolated_span().rust_2018() {
|
||||
let asyncness = if self.token.uninterpolated_span().at_least_rust_2018() {
|
||||
self.parse_asyncness(Case::Sensitive)
|
||||
} else {
|
||||
Async::No
|
||||
@ -3014,7 +3014,7 @@ impl<'a> Parser<'a> {
|
||||
fn is_try_block(&self) -> bool {
|
||||
self.token.is_keyword(kw::Try)
|
||||
&& self.look_ahead(1, |t| *t == token::OpenDelim(Delimiter::Brace))
|
||||
&& self.token.uninterpolated_span().rust_2018()
|
||||
&& self.token.uninterpolated_span().at_least_rust_2018()
|
||||
}
|
||||
|
||||
/// Parses an `async move? {...}` expression.
|
||||
|
@ -608,7 +608,7 @@ impl<'a> Parser<'a> {
|
||||
/// Is a `dyn B0 + ... + Bn` type allowed here?
|
||||
fn is_explicit_dyn_type(&mut self) -> bool {
|
||||
self.check_keyword(kw::Dyn)
|
||||
&& (self.token.uninterpolated_span().rust_2018()
|
||||
&& (self.token.uninterpolated_span().at_least_rust_2018()
|
||||
|| self.look_ahead(1, |t| {
|
||||
(t.can_begin_bound() || t.kind == TokenKind::BinOp(token::Star))
|
||||
&& !can_continue_type_after_non_fn_ident(t)
|
||||
|
@ -440,7 +440,7 @@ impl Resolver<'_, '_> {
|
||||
|
||||
// If we are not in Rust 2018 edition, then we don't make any further
|
||||
// suggestions.
|
||||
if !tcx.sess.rust_2018() {
|
||||
if !tcx.sess.at_least_rust_2018() {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1203,7 +1203,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
if filter_fn(res) {
|
||||
// create the path
|
||||
let mut segms = path_segments.clone();
|
||||
if lookup_ident.span.rust_2018() {
|
||||
if lookup_ident.span.at_least_rust_2018() {
|
||||
// crate-local absolute paths start with `crate::` in edition 2018
|
||||
// FIXME: may also be stabilized for Rust 2015 (Issues #45477, #44660)
|
||||
segms.insert(0, ast::PathSegment::from_ident(crate_name));
|
||||
@ -1268,7 +1268,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
path_segments.push(ast::PathSegment::from_ident(ident));
|
||||
|
||||
let is_extern_crate_that_also_appears_in_prelude =
|
||||
name_binding.is_extern_crate() && lookup_ident.span.rust_2018();
|
||||
name_binding.is_extern_crate() && lookup_ident.span.at_least_rust_2018();
|
||||
|
||||
if !is_extern_crate_that_also_appears_in_prelude {
|
||||
// add the module to the lookup
|
||||
@ -1315,7 +1315,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
&filter_fn,
|
||||
);
|
||||
|
||||
if lookup_ident.span.rust_2018() {
|
||||
if lookup_ident.span.at_least_rust_2018() {
|
||||
let extern_prelude_names = self.extern_prelude.clone();
|
||||
for (ident, _) in extern_prelude_names.into_iter() {
|
||||
if ident.span.from_expansion() {
|
||||
@ -1568,7 +1568,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
"consider adding an explicit import of `{ident}` to disambiguate"
|
||||
))
|
||||
}
|
||||
if b.is_extern_crate() && ident.span.rust_2018() {
|
||||
if b.is_extern_crate() && ident.span.at_least_rust_2018() {
|
||||
help_msgs.push(format!("use `::{ident}` to refer to this {thing} unambiguously"))
|
||||
}
|
||||
match misc {
|
||||
@ -1973,7 +1973,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
if fst.ident.name == kw::PathRoot && !snd.ident.is_path_segment_keyword() => {}
|
||||
// `ident::...` on 2018.
|
||||
(Some(fst), _)
|
||||
if fst.ident.span.rust_2018() && !fst.ident.is_path_segment_keyword() =>
|
||||
if fst.ident.span.at_least_rust_2018() && !fst.ident.is_path_segment_keyword() =>
|
||||
{
|
||||
// Insert a placeholder that's later replaced by `self`/`super`/etc.
|
||||
path.insert(0, Segment::from_ident(Ident::empty()));
|
||||
|
@ -1417,13 +1417,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
));
|
||||
continue;
|
||||
}
|
||||
if name == kw::PathRoot && ident.span.rust_2018() {
|
||||
if name == kw::PathRoot && ident.span.at_least_rust_2018() {
|
||||
module = Some(ModuleOrUniformRoot::ExternPrelude);
|
||||
continue;
|
||||
}
|
||||
if name == kw::PathRoot
|
||||
&& ident.span.is_rust_2015()
|
||||
&& self.tcx.sess.rust_2018()
|
||||
&& self.tcx.sess.at_least_rust_2018()
|
||||
{
|
||||
// `::a::b` from 2015 macro on 2018 global edition
|
||||
module = Some(ModuleOrUniformRoot::CrateRootAndExternPrelude);
|
||||
|
@ -995,18 +995,18 @@ impl Session {
|
||||
}
|
||||
|
||||
/// Are we allowed to use features from the Rust 2018 edition?
|
||||
pub fn rust_2018(&self) -> bool {
|
||||
self.edition().rust_2018()
|
||||
pub fn at_least_rust_2018(&self) -> bool {
|
||||
self.edition().at_least_rust_2018()
|
||||
}
|
||||
|
||||
/// Are we allowed to use features from the Rust 2021 edition?
|
||||
pub fn rust_2021(&self) -> bool {
|
||||
self.edition().rust_2021()
|
||||
pub fn at_least_rust_2021(&self) -> bool {
|
||||
self.edition().at_least_rust_2021()
|
||||
}
|
||||
|
||||
/// Are we allowed to use features from the Rust 2024 edition?
|
||||
pub fn rust_2024(&self) -> bool {
|
||||
self.edition().rust_2024()
|
||||
pub fn at_least_rust_2024(&self) -> bool {
|
||||
self.edition().at_least_rust_2024()
|
||||
}
|
||||
|
||||
/// Returns `true` if we should use the PLT for shared library calls.
|
||||
|
@ -82,17 +82,17 @@ impl Edition {
|
||||
}
|
||||
|
||||
/// Are we allowed to use features from the Rust 2018 edition?
|
||||
pub fn rust_2018(self) -> bool {
|
||||
pub fn at_least_rust_2018(self) -> bool {
|
||||
self >= Edition::Edition2018
|
||||
}
|
||||
|
||||
/// Are we allowed to use features from the Rust 2021 edition?
|
||||
pub fn rust_2021(self) -> bool {
|
||||
pub fn at_least_rust_2021(self) -> bool {
|
||||
self >= Edition::Edition2021
|
||||
}
|
||||
|
||||
/// Are we allowed to use features from the Rust 2024 edition?
|
||||
pub fn rust_2024(self) -> bool {
|
||||
pub fn at_least_rust_2024(self) -> bool {
|
||||
self >= Edition::Edition2024
|
||||
}
|
||||
}
|
||||
|
@ -707,24 +707,28 @@ impl Span {
|
||||
self.ctxt().edition()
|
||||
}
|
||||
|
||||
/// Is this edition 2015?
|
||||
#[inline]
|
||||
pub fn is_rust_2015(self) -> bool {
|
||||
self.edition().is_rust_2015()
|
||||
}
|
||||
|
||||
/// Are we allowed to use features from the Rust 2018 edition?
|
||||
#[inline]
|
||||
pub fn rust_2018(self) -> bool {
|
||||
self.edition().rust_2018()
|
||||
pub fn at_least_rust_2018(self) -> bool {
|
||||
self.edition().at_least_rust_2018()
|
||||
}
|
||||
|
||||
/// Are we allowed to use features from the Rust 2021 edition?
|
||||
#[inline]
|
||||
pub fn rust_2021(self) -> bool {
|
||||
self.edition().rust_2021()
|
||||
pub fn at_least_rust_2021(self) -> bool {
|
||||
self.edition().at_least_rust_2021()
|
||||
}
|
||||
|
||||
/// Are we allowed to use features from the Rust 2024 edition?
|
||||
#[inline]
|
||||
pub fn rust_2024(self) -> bool {
|
||||
self.edition().rust_2024()
|
||||
pub fn at_least_rust_2024(self) -> bool {
|
||||
self.edition().at_least_rust_2024()
|
||||
}
|
||||
|
||||
/// Returns the source callee.
|
||||
|
Loading…
Reference in New Issue
Block a user