Skip to content
Open
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
4 changes: 3 additions & 1 deletion compiler/rustc_hir_typeck/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2053,7 +2053,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
}
}
if !self.tcx.features().default_field_values() {
if !(self.tcx.features().default_field_values()
|| span.allows_unstable(sym::default_field_values))
{
Comment on lines +2056 to +2058

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea that I get from this diff is whenever we use #[allow_internal_unstable(default_field_values)]], we always execute the if path below that suggests adding #![feature(default_field_values)]? I feel I am missing something 🤔

let sugg = self.tcx.crate_level_attribute_injection_span();
self.dcx().emit_err(BaseExpressionDoubleDot {
span: span.shrink_to_hi(),
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_lint_defs/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// tidy-alphabetical-start
#![allow(internal_features)]
#![feature(allow_internal_unstable)]
#![feature(default_field_values)]
// tidy-alphabetical-end

Expand Down Expand Up @@ -698,6 +700,7 @@ macro_rules! declare_lint {
}

#[macro_export]
#[allow_internal_unstable(default_field_values)]
macro_rules! declare_tool_lint {
(
$(#[$attr:meta])* $vis:vis $tool:ident ::$NAME:ident, $Level: ident, $desc: expr
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/structs/default-field-values/allow_internal_unstable.rs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You will need to write a cross-crate test to test the behavior of using #[allow_internal_unstable(..)] across upstream and downstream crates.

In tests/ui/structs/default-field-values/auxiliary/, you can define the upstream crate, for example aux.rs with something like...

#![feature(default_field_values)]
#![feature(allow_internal_unstable)]
#[allow_internal_unstable(default_field_values)]
#[macro_export]
macro_rules! foo {
    () => { fn foo() { struct Foo {x: usize = 0, } Foo {..}; } };
}

In tests/ui/structs/default-field-values/allow_internal_unstable.rs, you can use the macro with...

//@ aux-build:aux.rs
//@check-pass

extern crate aux;
use aux::foo;

foo!();

fn main(){

You will see different behavior in downstream crate when allow_internal_unstable is used and when it is not used.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//@check-pass

#![allow(internal_features)]
#![feature(allow_internal_unstable)]
#[allow_internal_unstable(default_field_values)]
macro_rules! foo {
() => { fn foo() { struct Foo {x: usize = 0, } Foo {..}; } };
}

foo!();

fn main(){}
Loading