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

Initial commit working on edition based method disambiguation #96690

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 8 additions & 2 deletions compiler/rustc_attr/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub struct ConstStability {
pub enum StabilityLevel {
// Reason for the current stability level and the relevant rust-lang issue
Unstable { reason: Option<Symbol>, issue: Option<NonZeroU32>, is_soft: bool },
Stable { since: Symbol },
Stable { since: Symbol, edition: Option<Symbol> },
}

impl StabilityLevel {
Expand Down Expand Up @@ -348,6 +348,7 @@ where

let mut feature = None;
let mut since = None;
let mut edition = None;
for meta in metas {
match meta {
NestedMetaItem::MetaItem(mi) => match mi.name_or_empty() {
Expand All @@ -361,6 +362,11 @@ where
continue 'outer;
}
}
sym::edition => {
if !get(mi, &mut edition) {
continue 'outer;
}
}
_ => {
handle_errors(
&sess.parse_sess,
Expand All @@ -386,7 +392,7 @@ where

match (feature, since) {
(Some(feature), Some(since)) => {
let level = Stable { since };
let level = Stable { since, edition };
if sym::stable == meta_name {
stab = Some((Stability { level, feature }, attr.span));
} else {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {

// Check if deprecated_since < stable_since. If it is,
// this is *almost surely* an accident.
if let (&Some(dep_since), &attr::Stable { since: stab_since }) =
if let (&Some(dep_since), &attr::Stable { since: stab_since, ..}) =
(&depr.as_ref().and_then(|(d, _)| d.since), &stab.level)
{
// Explicit version of iter::order::lt to handle parse errors properly
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,7 @@ symbols! {
dyn_metadata,
dyn_trait,
e,
edition,
edition_macro_pats,
edition_panic,
eh_catch_typeinfo,
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ fn render_stability_since_raw(
}

let const_title_and_stability = match const_stability {
Some(ConstStability { level: StabilityLevel::Stable { since }, .. })
Some(ConstStability { level: StabilityLevel::Stable { since, .. }, .. })
if Some(since) != containing_const_ver =>
{
Some((format!("const since {}", since), format!("const: {}", since)))
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/stability-attribute/auxiliary/edition-field-std.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#![feature(staged_api)]
#![stable(feature = "intersperse", since = "1.0.0", edition = "2021")]

#[stable(feature = "intersperse", since = "1.0.0", edition = "2021")]
pub struct Intersperse;

#[stable(feature = "intersperse", since = "1.0.0", edition = "2021")]
pub trait Iterator {
#[stable(feature = "intersperse", since = "1.0.0", edition = "2021")]
fn intersperse(&self, separator: ()) -> Intersperse {
unimplemented!()
}
}
24 changes: 24 additions & 0 deletions src/test/ui/stability-attribute/edition-field.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// aux-build:edition-field-std.rs

extern crate edition_field_std;
use edition_field_std::Iterator;

struct Intersperse;

trait Itertools {
fn intersperse(&self, separator: ()) -> Intersperse {
unimplemented!()
}
}

impl<T> Itertools for T
where
T: Iterator {}

struct MyIterator;
impl Iterator for MyIterator {}

fn main() {
let it = MyIterator;
let _intersperse = it.intersperse(());
}
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_utils/src/qualify_min_const_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ fn check_terminator<'a, 'tcx>(
fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<&RustcVersion>) -> bool {
tcx.is_const_fn(def_id)
&& tcx.lookup_const_stability(def_id).map_or(true, |const_stab| {
if let rustc_attr::StabilityLevel::Stable { since } = const_stab.level {
if let rustc_attr::StabilityLevel::Stable { since, ..} = const_stab.level {
// Checking MSRV is manually necessary because `rustc` has no such concept. This entire
// function could be removed if `rustc` provided a MSRV-aware version of `is_const_fn`.
// as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262.
Expand Down