Skip to content

Commit 846cc63

Browse files
Make it clearer that edition functions are >=, not ==
1 parent 77e24f9 commit 846cc63

File tree

16 files changed

+46
-42
lines changed

16 files changed

+46
-42
lines changed

compiler/rustc_expand/src/mbe/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ fn check_matcher_core<'tt>(
12001200
err.span_label(sp, format!("not allowed after `{}` fragments", kind));
12011201

12021202
if kind == NonterminalKind::PatWithOr
1203-
&& sess.edition.rust_2021()
1203+
&& sess.edition.at_least_rust_2021()
12041204
&& next_token.is_token(&BinOp(token::BinOpToken::Or))
12051205
{
12061206
let suggestion = quoted_tt_to_string(&TokenTree::MetaVarDecl(

compiler/rustc_hir_analysis/src/astconv/lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
8686
));
8787
}
8888

89-
if self_ty.span.edition().rust_2021() {
89+
if self_ty.span.edition().at_least_rust_2021() {
9090
let msg = "trait objects must include the `dyn` keyword";
9191
let label = "add `dyn` keyword before this trait";
9292
let mut diag =

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
860860
.resolve_fully_qualified_call(span, item_name, ty.normalized, qself.span, hir_id)
861861
.and_then(|r| {
862862
// lint bare trait if the method is found in the trait
863-
if span.edition().rust_2021() && let Some(mut diag) = self.tcx.sess.diagnostic().steal_diagnostic(qself.span, StashKey::TraitMissingMethod) {
863+
if span.edition().at_least_rust_2021() && let Some(mut diag) = self.tcx.sess.diagnostic().steal_diagnostic(qself.span, StashKey::TraitMissingMethod) {
864864
diag.emit();
865865
}
866866
Ok(r)
@@ -890,7 +890,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
890890
}
891891

892892
// emit or cancel the diagnostic for bare traits
893-
if span.edition().rust_2021() && let Some(mut diag) = self.tcx.sess.diagnostic().steal_diagnostic(qself.span, StashKey::TraitMissingMethod) {
893+
if span.edition().at_least_rust_2021() && let Some(mut diag) = self.tcx.sess.diagnostic().steal_diagnostic(qself.span, StashKey::TraitMissingMethod) {
894894
if trait_missing_method {
895895
// cancel the diag for bare traits when meeting `MyTrait::missing_method`
896896
diag.cancel();
@@ -908,7 +908,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
908908
error,
909909
None,
910910
Expectation::NoExpectation,
911-
trait_missing_method && span.edition().rust_2021(), // emits missing method for trait only after edition 2021
911+
trait_missing_method && span.edition().at_least_rust_2021(), // emits missing method for trait only after edition 2021
912912
) {
913913
e.emit();
914914
}

compiler/rustc_hir_typeck/src/method/prelude2021.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
3232
);
3333

3434
// Rust 2021 and later is already using the new prelude
35-
if span.rust_2021() {
35+
if span.at_least_rust_2021() {
3636
return;
3737
}
3838

@@ -203,7 +203,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
203203
pick: &Pick<'tcx>,
204204
) {
205205
// Rust 2021 and later is already using the new prelude
206-
if span.rust_2021() {
206+
if span.at_least_rust_2021() {
207207
return;
208208
}
209209

compiler/rustc_hir_typeck/src/method/probe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
437437
// this case used to be allowed by the compiler,
438438
// so we do a future-compat lint here for the 2015 edition
439439
// (see https://github.com/rust-lang/rust/issues/46906)
440-
if self.tcx.sess.rust_2018() {
440+
if self.tcx.sess.at_least_rust_2018() {
441441
self.tcx.sess.emit_err(MethodCallOnUnknownRawPointee { span });
442442
} else {
443443
self.tcx.struct_span_lint_hir(
@@ -1592,7 +1592,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
15921592
if let Some(method_name) = self.method_name {
15931593
// Some trait methods are excluded for arrays before 2021.
15941594
// (`array.into_iter()` wants a slice iterator for compatibility.)
1595-
if self_ty.is_array() && !method_name.span.rust_2021() {
1595+
if self_ty.is_array() && !method_name.span.at_least_rust_2021() {
15961596
let trait_def = self.tcx.trait_def(trait_ref.def_id);
15971597
if trait_def.skip_array_during_method_dispatch {
15981598
return ProbeResult::NoMatch;

compiler/rustc_hir_typeck/src/upvar.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2001,7 +2001,7 @@ fn should_do_rust_2021_incompatible_closure_captures_analysis(
20012001
tcx: TyCtxt<'_>,
20022002
closure_id: hir::HirId,
20032003
) -> bool {
2004-
if tcx.sess.rust_2021() {
2004+
if tcx.sess.at_least_rust_2021() {
20052005
return false;
20062006
}
20072007

@@ -2247,5 +2247,5 @@ fn truncate_capture_for_optimization(
22472247
fn enable_precise_capture(span: Span) -> bool {
22482248
// We use span here to ensure that if the closure was generated by a macro with a different
22492249
// edition.
2250-
span.rust_2021()
2250+
span.at_least_rust_2021()
22512251
}

compiler/rustc_middle/src/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1932,7 +1932,7 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> {
19321932
fn path_crate(mut self, cnum: CrateNum) -> Result<Self::Path, Self::Error> {
19331933
self.empty_path = true;
19341934
if cnum == LOCAL_CRATE {
1935-
if self.tcx.sess.rust_2018() {
1935+
if self.tcx.sess.at_least_rust_2018() {
19361936
// We add the `crate::` keyword on Rust 2018, only when desired.
19371937
if SHOULD_PREFIX_WITH_CRATE.with(|flag| flag.get()) {
19381938
write!(self, "{}", kw::Crate)?;

compiler/rustc_mir_build/src/build/expr/as_place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -730,5 +730,5 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
730730

731731
/// Precise capture is enabled if user is using Rust Edition 2021 or higher.
732732
fn enable_precise_capture(closure_span: Span) -> bool {
733-
closure_span.rust_2021()
733+
closure_span.at_least_rust_2021()
734734
}

compiler/rustc_parse/src/parser/expr.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ impl<'a> Parser<'a> {
13091309

13101310
/// Assuming we have just parsed `.`, continue parsing into an expression.
13111311
fn parse_dot_suffix(&mut self, self_arg: P<Expr>, lo: Span) -> PResult<'a, P<Expr>> {
1312-
if self.token.uninterpolated_span().rust_2018() && self.eat_keyword(kw::Await) {
1312+
if self.token.uninterpolated_span().at_least_rust_2018() && self.eat_keyword(kw::Await) {
13131313
return Ok(self.mk_await_expr(self_arg, lo));
13141314
}
13151315

@@ -1442,8 +1442,8 @@ impl<'a> Parser<'a> {
14421442
self.parse_expr_let()
14431443
} else if self.eat_keyword(kw::Underscore) {
14441444
Ok(self.mk_expr(self.prev_token.span, ExprKind::Underscore))
1445-
} else if self.token.uninterpolated_span().rust_2018() {
1446-
// `Span::rust_2018()` is somewhat expensive; don't get it repeatedly.
1445+
} else if self.token.uninterpolated_span().at_least_rust_2018() {
1446+
// `Span:.at_least_rust_2018()` is somewhat expensive; don't get it repeatedly.
14471447
if self.check_keyword(kw::Async) {
14481448
if self.is_async_block() {
14491449
// Check for `async {` and `async move {`.
@@ -2230,7 +2230,7 @@ impl<'a> Parser<'a> {
22302230
let movability =
22312231
if self.eat_keyword(kw::Static) { Movability::Static } else { Movability::Movable };
22322232

2233-
let asyncness = if self.token.uninterpolated_span().rust_2018() {
2233+
let asyncness = if self.token.uninterpolated_span().at_least_rust_2018() {
22342234
self.parse_asyncness(Case::Sensitive)
22352235
} else {
22362236
Async::No
@@ -3014,7 +3014,7 @@ impl<'a> Parser<'a> {
30143014
fn is_try_block(&self) -> bool {
30153015
self.token.is_keyword(kw::Try)
30163016
&& self.look_ahead(1, |t| *t == token::OpenDelim(Delimiter::Brace))
3017-
&& self.token.uninterpolated_span().rust_2018()
3017+
&& self.token.uninterpolated_span().at_least_rust_2018()
30183018
}
30193019

30203020
/// Parses an `async move? {...}` expression.

compiler/rustc_parse/src/parser/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ impl<'a> Parser<'a> {
608608
/// Is a `dyn B0 + ... + Bn` type allowed here?
609609
fn is_explicit_dyn_type(&mut self) -> bool {
610610
self.check_keyword(kw::Dyn)
611-
&& (self.token.uninterpolated_span().rust_2018()
611+
&& (self.token.uninterpolated_span().at_least_rust_2018()
612612
|| self.look_ahead(1, |t| {
613613
(t.can_begin_bound() || t.kind == TokenKind::BinOp(token::Star))
614614
&& !can_continue_type_after_non_fn_ident(t)

compiler/rustc_resolve/src/check_unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ impl Resolver<'_, '_> {
440440

441441
// If we are not in Rust 2018 edition, then we don't make any further
442442
// suggestions.
443-
if !tcx.sess.rust_2018() {
443+
if !tcx.sess.at_least_rust_2018() {
444444
continue;
445445
}
446446

compiler/rustc_resolve/src/diagnostics.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
12031203
if filter_fn(res) {
12041204
// create the path
12051205
let mut segms = path_segments.clone();
1206-
if lookup_ident.span.rust_2018() {
1206+
if lookup_ident.span.at_least_rust_2018() {
12071207
// crate-local absolute paths start with `crate::` in edition 2018
12081208
// FIXME: may also be stabilized for Rust 2015 (Issues #45477, #44660)
12091209
segms.insert(0, ast::PathSegment::from_ident(crate_name));
@@ -1268,7 +1268,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
12681268
path_segments.push(ast::PathSegment::from_ident(ident));
12691269

12701270
let is_extern_crate_that_also_appears_in_prelude =
1271-
name_binding.is_extern_crate() && lookup_ident.span.rust_2018();
1271+
name_binding.is_extern_crate() && lookup_ident.span.at_least_rust_2018();
12721272

12731273
if !is_extern_crate_that_also_appears_in_prelude {
12741274
// add the module to the lookup
@@ -1315,7 +1315,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
13151315
&filter_fn,
13161316
);
13171317

1318-
if lookup_ident.span.rust_2018() {
1318+
if lookup_ident.span.at_least_rust_2018() {
13191319
let extern_prelude_names = self.extern_prelude.clone();
13201320
for (ident, _) in extern_prelude_names.into_iter() {
13211321
if ident.span.from_expansion() {
@@ -1568,7 +1568,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
15681568
"consider adding an explicit import of `{ident}` to disambiguate"
15691569
))
15701570
}
1571-
if b.is_extern_crate() && ident.span.rust_2018() {
1571+
if b.is_extern_crate() && ident.span.at_least_rust_2018() {
15721572
help_msgs.push(format!("use `::{ident}` to refer to this {thing} unambiguously"))
15731573
}
15741574
match misc {
@@ -1973,7 +1973,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
19731973
if fst.ident.name == kw::PathRoot && !snd.ident.is_path_segment_keyword() => {}
19741974
// `ident::...` on 2018.
19751975
(Some(fst), _)
1976-
if fst.ident.span.rust_2018() && !fst.ident.is_path_segment_keyword() =>
1976+
if fst.ident.span.at_least_rust_2018() && !fst.ident.is_path_segment_keyword() =>
19771977
{
19781978
// Insert a placeholder that's later replaced by `self`/`super`/etc.
19791979
path.insert(0, Segment::from_ident(Ident::empty()));

compiler/rustc_resolve/src/ident.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1417,13 +1417,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
14171417
));
14181418
continue;
14191419
}
1420-
if name == kw::PathRoot && ident.span.rust_2018() {
1420+
if name == kw::PathRoot && ident.span.at_least_rust_2018() {
14211421
module = Some(ModuleOrUniformRoot::ExternPrelude);
14221422
continue;
14231423
}
14241424
if name == kw::PathRoot
14251425
&& ident.span.is_rust_2015()
1426-
&& self.tcx.sess.rust_2018()
1426+
&& self.tcx.sess.at_least_rust_2018()
14271427
{
14281428
// `::a::b` from 2015 macro on 2018 global edition
14291429
module = Some(ModuleOrUniformRoot::CrateRootAndExternPrelude);

compiler/rustc_session/src/session.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -995,18 +995,18 @@ impl Session {
995995
}
996996

997997
/// Are we allowed to use features from the Rust 2018 edition?
998-
pub fn rust_2018(&self) -> bool {
999-
self.edition().rust_2018()
998+
pub fn at_least_rust_2018(&self) -> bool {
999+
self.edition().at_least_rust_2018()
10001000
}
10011001

10021002
/// Are we allowed to use features from the Rust 2021 edition?
1003-
pub fn rust_2021(&self) -> bool {
1004-
self.edition().rust_2021()
1003+
pub fn at_least_rust_2021(&self) -> bool {
1004+
self.edition().at_least_rust_2021()
10051005
}
10061006

10071007
/// Are we allowed to use features from the Rust 2024 edition?
1008-
pub fn rust_2024(&self) -> bool {
1009-
self.edition().rust_2024()
1008+
pub fn at_least_rust_2024(&self) -> bool {
1009+
self.edition().at_least_rust_2024()
10101010
}
10111011

10121012
/// Returns `true` if we should use the PLT for shared library calls.

compiler/rustc_span/src/edition.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ impl Edition {
8282
}
8383

8484
/// Are we allowed to use features from the Rust 2018 edition?
85-
pub fn rust_2018(self) -> bool {
85+
pub fn at_least_rust_2018(self) -> bool {
8686
self >= Edition::Edition2018
8787
}
8888

8989
/// Are we allowed to use features from the Rust 2021 edition?
90-
pub fn rust_2021(self) -> bool {
90+
pub fn at_least_rust_2021(self) -> bool {
9191
self >= Edition::Edition2021
9292
}
9393

9494
/// Are we allowed to use features from the Rust 2024 edition?
95-
pub fn rust_2024(self) -> bool {
95+
pub fn at_least_rust_2024(self) -> bool {
9696
self >= Edition::Edition2024
9797
}
9898
}

compiler/rustc_span/src/lib.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -707,24 +707,28 @@ impl Span {
707707
self.ctxt().edition()
708708
}
709709

710+
/// Is this edition 2015?
710711
#[inline]
711712
pub fn is_rust_2015(self) -> bool {
712713
self.edition().is_rust_2015()
713714
}
714715

716+
/// Are we allowed to use features from the Rust 2018 edition?
715717
#[inline]
716-
pub fn rust_2018(self) -> bool {
717-
self.edition().rust_2018()
718+
pub fn at_least_rust_2018(self) -> bool {
719+
self.edition().at_least_rust_2018()
718720
}
719721

722+
/// Are we allowed to use features from the Rust 2021 edition?
720723
#[inline]
721-
pub fn rust_2021(self) -> bool {
722-
self.edition().rust_2021()
724+
pub fn at_least_rust_2021(self) -> bool {
725+
self.edition().at_least_rust_2021()
723726
}
724727

728+
/// Are we allowed to use features from the Rust 2024 edition?
725729
#[inline]
726-
pub fn rust_2024(self) -> bool {
727-
self.edition().rust_2024()
730+
pub fn at_least_rust_2024(self) -> bool {
731+
self.edition().at_least_rust_2024()
728732
}
729733

730734
/// Returns the source callee.

0 commit comments

Comments
 (0)