Skip to content

Rollup of 3 pull requests #145038

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

Closed
wants to merge 6 commits into from
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
2 changes: 1 addition & 1 deletion compiler/rustc_ast_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ ast_passes_auto_generic = auto traits cannot have generic parameters
ast_passes_auto_items = auto traits cannot have associated items
.label = {ast_passes_auto_items}
.suggestion = remove these associated items
.suggestion = remove the associated items
ast_passes_auto_super_lifetime = auto traits cannot have super traits or lifetime bounds
.label = {ast_passes_auto_super_lifetime}
Expand Down
16 changes: 10 additions & 6 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,19 +699,23 @@ impl<'a> AstValidator<'a> {
}
}

fn deny_super_traits(&self, bounds: &GenericBounds, ident_span: Span) {
fn deny_super_traits(&self, bounds: &GenericBounds, ident: Span) {
if let [.., last] = &bounds[..] {
let span = ident_span.shrink_to_hi().to(last.span());
self.dcx().emit_err(errors::AutoTraitBounds { span, ident: ident_span });
let span = bounds.iter().map(|b| b.span()).collect();
let removal = ident.shrink_to_hi().to(last.span());
self.dcx().emit_err(errors::AutoTraitBounds { span, removal, ident });
}
}

fn deny_where_clause(&self, where_clause: &WhereClause, ident_span: Span) {
fn deny_where_clause(&self, where_clause: &WhereClause, ident: Span) {
if !where_clause.predicates.is_empty() {
// FIXME: The current diagnostic is misleading since it only talks about
// super trait and lifetime bounds while we should just say “bounds”.
self.dcx()
.emit_err(errors::AutoTraitBounds { span: where_clause.span, ident: ident_span });
self.dcx().emit_err(errors::AutoTraitBounds {
span: vec![where_clause.span],
removal: where_clause.span,
ident,
});
}
}

Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ pub(crate) struct ModuleNonAscii {
#[diag(ast_passes_auto_generic, code = E0567)]
pub(crate) struct AutoTraitGeneric {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable")]
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
pub span: Span,
#[label]
pub ident: Span,
Expand All @@ -354,8 +354,9 @@ pub(crate) struct AutoTraitGeneric {
#[diag(ast_passes_auto_super_lifetime, code = E0568)]
pub(crate) struct AutoTraitBounds {
#[primary_span]
#[suggestion(code = "", applicability = "machine-applicable")]
pub span: Span,
pub span: Vec<Span>,
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
pub removal: Span,
#[label]
pub ident: Span,
}
Expand All @@ -365,7 +366,7 @@ pub(crate) struct AutoTraitBounds {
pub(crate) struct AutoTraitItems {
#[primary_span]
pub spans: Vec<Span>,
#[suggestion(code = "", applicability = "machine-applicable")]
#[suggestion(code = "", applicability = "machine-applicable", style = "tool-only")]
pub total: Span,
#[label]
pub ident: Span,
Expand Down
12 changes: 8 additions & 4 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,7 @@ declare_lint! {
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseError,
reference: "issue #52234 <https://github.com/rust-lang/rust/issues/52234>",
report_in_deps: true,
};
crate_level_only
}
Expand Down Expand Up @@ -2887,11 +2888,12 @@ declare_lint! {
/// struct S { /* fields */ }
/// ```
pub LEGACY_DERIVE_HELPERS,
Warn,
Deny,
"detects derive helper attributes that are used before they are introduced",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseError,
reference: "issue #79202 <https://github.com/rust-lang/rust/issues/79202>",
report_in_deps: true,
};
}

Expand Down Expand Up @@ -4624,11 +4626,12 @@ declare_lint! {
///
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub PRIVATE_MACRO_USE,
Warn,
Deny,
"detects certain macro bindings that should not be re-exported",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseError,
reference: "issue #120192 <https://github.com/rust-lang/rust/issues/120192>",
report_in_deps: true,
};
}

Expand Down Expand Up @@ -4828,7 +4831,7 @@ declare_lint! {
///
/// ### Example
///
/// ```rust
/// ```rust,compile_fail
/// #![doc = in_root!()]
///
/// macro_rules! in_root { () => { "" } }
Expand All @@ -4853,11 +4856,12 @@ declare_lint! {
///
/// [future-incompatible]: ../index.md#future-incompatible-lints
pub OUT_OF_SCOPE_MACRO_CALLS,
Warn,
Deny,
"detects out of scope calls to `macro_rules` in key-value attributes",
@future_incompatible = FutureIncompatibleInfo {
reason: FutureIncompatibilityReason::FutureReleaseError,
reference: "issue #124535 <https://github.com/rust-lang/rust/issues/124535>",
report_in_deps: true,
};
}

Expand Down
4 changes: 2 additions & 2 deletions library/core/src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,7 +725,7 @@ unsafe impl Send for TypeId {}
unsafe impl Sync for TypeId {}

#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
#[rustc_const_unstable(feature = "const_cmp", issue = "143800")]
impl const PartialEq for TypeId {
#[inline]
fn eq(&self, other: &Self) -> bool {
Expand Down Expand Up @@ -773,7 +773,7 @@ impl TypeId {
/// ```
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
#[rustc_const_stable(feature = "const_type_id", since = "CURRENT_RUSTC_VERSION")]
pub const fn of<T: ?Sized + 'static>() -> TypeId {
const { intrinsics::type_id::<T>() }
}
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/attributes/key-value-expansion-scope.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#![doc = in_root!()] //~ WARN cannot find macro `in_root`
#![doc = in_root!()] //~ ERROR cannot find macro `in_root`
//~| WARN this was previously accepted by the compiler
#![doc = in_mod!()] //~ ERROR cannot find macro `in_mod` in this scope
#![doc = in_mod_escape!()] //~ WARN cannot find macro `in_mod_escape`
#![doc = in_mod_escape!()] //~ ERROR cannot find macro `in_mod_escape`
//~| WARN this was previously accepted by the compiler
#![doc = in_block!()] //~ ERROR cannot find macro `in_block` in this scope

Expand All @@ -18,10 +18,10 @@ fn before() {

macro_rules! in_root { () => { "" } }

#[doc = in_mod!()] //~ WARN cannot find macro `in_mod`
#[doc = in_mod!()] //~ ERROR cannot find macro `in_mod`
//~| WARN this was previously accepted by the compiler
mod macros_stay {
#![doc = in_mod!()] //~ WARN cannot find macro `in_mod`
#![doc = in_mod!()] //~ ERROR cannot find macro `in_mod`
//~| WARN this was previously accepted by the compiler

macro_rules! in_mod { () => { "" } }
Expand All @@ -33,10 +33,10 @@ mod macros_stay {
}

#[macro_use]
#[doc = in_mod_escape!()] //~ WARN cannot find macro `in_mod_escape`
#[doc = in_mod_escape!()] //~ ERROR cannot find macro `in_mod_escape`
//~| WARN this was previously accepted by the compiler
mod macros_escape {
#![doc = in_mod_escape!()] //~ WARN cannot find macro `in_mod_escape`
#![doc = in_mod_escape!()] //~ ERROR cannot find macro `in_mod_escape`
//~| WARN this was previously accepted by the compiler

macro_rules! in_mod_escape { () => { "" } }
Expand Down
88 changes: 80 additions & 8 deletions tests/ui/attributes/key-value-expansion-scope.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ LL | #![doc = in_block!()]
|
= help: have you added the `#[macro_use]` on the module/import?

warning: cannot find macro `in_root` in the current scope when looking from the crate root
error: cannot find macro `in_root` in the current scope when looking from the crate root
--> $DIR/key-value-expansion-scope.rs:1:10
|
LL | #![doc = in_root!()]
Expand All @@ -135,9 +135,9 @@ LL | #![doc = in_root!()]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
= help: import `macro_rules` with `use` to make it callable above its definition
= note: `#[warn(out_of_scope_macro_calls)]` on by default
= note: `#[deny(out_of_scope_macro_calls)]` on by default

warning: cannot find macro `in_mod_escape` in the current scope when looking from the crate root
error: cannot find macro `in_mod_escape` in the current scope when looking from the crate root
--> $DIR/key-value-expansion-scope.rs:4:10
|
LL | #![doc = in_mod_escape!()]
Expand All @@ -147,7 +147,7 @@ LL | #![doc = in_mod_escape!()]
= note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
= help: import `macro_rules` with `use` to make it callable above its definition

warning: cannot find macro `in_mod` in the current scope when looking from module `macros_stay`
error: cannot find macro `in_mod` in the current scope when looking from module `macros_stay`
--> $DIR/key-value-expansion-scope.rs:21:9
|
LL | #[doc = in_mod!()]
Expand All @@ -157,7 +157,7 @@ LL | #[doc = in_mod!()]
= note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
= help: import `macro_rules` with `use` to make it callable above its definition

warning: cannot find macro `in_mod` in the current scope when looking from module `macros_stay`
error: cannot find macro `in_mod` in the current scope when looking from module `macros_stay`
--> $DIR/key-value-expansion-scope.rs:24:14
|
LL | #![doc = in_mod!()]
Expand All @@ -167,7 +167,7 @@ LL | #![doc = in_mod!()]
= note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
= help: import `macro_rules` with `use` to make it callable above its definition

warning: cannot find macro `in_mod_escape` in the current scope when looking from module `macros_escape`
error: cannot find macro `in_mod_escape` in the current scope when looking from module `macros_escape`
--> $DIR/key-value-expansion-scope.rs:36:9
|
LL | #[doc = in_mod_escape!()]
Expand All @@ -177,7 +177,7 @@ LL | #[doc = in_mod_escape!()]
= note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
= help: import `macro_rules` with `use` to make it callable above its definition

warning: cannot find macro `in_mod_escape` in the current scope when looking from module `macros_escape`
error: cannot find macro `in_mod_escape` in the current scope when looking from module `macros_escape`
--> $DIR/key-value-expansion-scope.rs:39:14
|
LL | #![doc = in_mod_escape!()]
Expand All @@ -187,5 +187,77 @@ LL | #![doc = in_mod_escape!()]
= note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
= help: import `macro_rules` with `use` to make it callable above its definition

error: aborting due to 16 previous errors; 6 warnings emitted
error: aborting due to 22 previous errors

Future incompatibility report: Future breakage diagnostic:
error: cannot find macro `in_root` in the current scope when looking from the crate root
--> $DIR/key-value-expansion-scope.rs:1:10
|
LL | #![doc = in_root!()]
| ^^^^^^^ not found from the crate root
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
= help: import `macro_rules` with `use` to make it callable above its definition
= note: `#[deny(out_of_scope_macro_calls)]` on by default

Future breakage diagnostic:
error: cannot find macro `in_mod_escape` in the current scope when looking from the crate root
--> $DIR/key-value-expansion-scope.rs:4:10
|
LL | #![doc = in_mod_escape!()]
| ^^^^^^^^^^^^^ not found from the crate root
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
= help: import `macro_rules` with `use` to make it callable above its definition
= note: `#[deny(out_of_scope_macro_calls)]` on by default

Future breakage diagnostic:
error: cannot find macro `in_mod` in the current scope when looking from module `macros_stay`
--> $DIR/key-value-expansion-scope.rs:21:9
|
LL | #[doc = in_mod!()]
| ^^^^^^ not found from module `macros_stay`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
= help: import `macro_rules` with `use` to make it callable above its definition
= note: `#[deny(out_of_scope_macro_calls)]` on by default

Future breakage diagnostic:
error: cannot find macro `in_mod` in the current scope when looking from module `macros_stay`
--> $DIR/key-value-expansion-scope.rs:24:14
|
LL | #![doc = in_mod!()]
| ^^^^^^ not found from module `macros_stay`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
= help: import `macro_rules` with `use` to make it callable above its definition
= note: `#[deny(out_of_scope_macro_calls)]` on by default

Future breakage diagnostic:
error: cannot find macro `in_mod_escape` in the current scope when looking from module `macros_escape`
--> $DIR/key-value-expansion-scope.rs:36:9
|
LL | #[doc = in_mod_escape!()]
| ^^^^^^^^^^^^^ not found from module `macros_escape`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
= help: import `macro_rules` with `use` to make it callable above its definition
= note: `#[deny(out_of_scope_macro_calls)]` on by default

Future breakage diagnostic:
error: cannot find macro `in_mod_escape` in the current scope when looking from module `macros_escape`
--> $DIR/key-value-expansion-scope.rs:39:14
|
LL | #![doc = in_mod_escape!()]
| ^^^^^^^^^^^^^ not found from module `macros_escape`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #124535 <https://github.com/rust-lang/rust/issues/124535>
= help: import `macro_rules` with `use` to make it callable above its definition
= note: `#[deny(out_of_scope_macro_calls)]` on by default

2 changes: 1 addition & 1 deletion tests/ui/auto-traits/assoc-ty.current.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | auto trait Trait {
| ----- auto traits cannot have associated items
LL |
LL | type Output;
| -----^^^^^^- help: remove these associated items
| ^^^^^^

error[E0658]: auto traits are experimental and possibly buggy
--> $DIR/assoc-ty.rs:8:1
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/auto-traits/assoc-ty.next.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | auto trait Trait {
| ----- auto traits cannot have associated items
LL |
LL | type Output;
| -----^^^^^^- help: remove these associated items
| ^^^^^^

error[E0658]: auto traits are experimental and possibly buggy
--> $DIR/assoc-ty.rs:8:1
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/auto-traits/auto-trait-validation.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,15 @@ auto trait LifetimeBound {}
//~^ ERROR auto traits cannot have super traits or lifetime bounds [E0568]
auto trait MyTrait { }
//~^ ERROR auto traits cannot have associated items [E0380]
auto trait AssocTy { }
//~^ ERROR auto traits cannot have associated items [E0380]
auto trait All {
//~^ ERROR auto traits cannot have generic parameters [E0567]

}
// We can't test both generic params and super-traits because the suggestion span overlaps.
auto trait All2 {
//~^ ERROR auto traits cannot have super traits or lifetime bounds [E0568]

}
fn main() {}
15 changes: 15 additions & 0 deletions tests/ui/auto-traits/auto-trait-validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,19 @@ auto trait LifetimeBound : 'static {}
//~^ ERROR auto traits cannot have super traits or lifetime bounds [E0568]
auto trait MyTrait { fn foo() {} }
//~^ ERROR auto traits cannot have associated items [E0380]
auto trait AssocTy { type Bar; }
//~^ ERROR auto traits cannot have associated items [E0380]
auto trait All<'a, T> {
//~^ ERROR auto traits cannot have generic parameters [E0567]
type Bar;
//~^ ERROR auto traits cannot have associated items [E0380]
fn foo() {}
}
// We can't test both generic params and super-traits because the suggestion span overlaps.
auto trait All2: Copy + 'static {
//~^ ERROR auto traits cannot have super traits or lifetime bounds [E0568]
type Bar;
//~^ ERROR auto traits cannot have associated items [E0380]
fn foo() {}
}
fn main() {}
Loading
Loading