Skip to content
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
5 changes: 5 additions & 0 deletions bootstrap.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@
# If you set this, you likely want to set `cargo` as well.
#build.rustc = "/path/to/rustc"

# Use this rustdoc binary as the stage0 snapshot rustdoc.
# If unspecified, then the binary "rustdoc" (with platform-specific extension, e.g. ".exe")
# in the same directory as "rustc" will be used.
#build.rustdoc = "/path/to/rustdoc"

# Instead of downloading the src/stage0 version of rustfmt specified,
# use this rustfmt binary instead as the stage0 snapshot rustfmt.
#build.rustfmt = "/path/to/rustfmt"
Expand Down
15 changes: 12 additions & 3 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,9 +1085,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
};

let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value, || {
hir::Defaultness::Default { has_value }
});
let defaultness = match i.kind.defaultness() {
// We do not yet support `final` on trait associated items other than functions.
// Even though we reject `final` on non-functions during AST validation, we still
// need to stop propagating it here because later compiler passes do not expect
// and cannot handle such items.
Defaultness::Final(..) if !matches!(i.kind, AssocItemKind::Fn(..)) => {
Defaultness::Implicit
}
defaultness => defaultness,
};
let (defaultness, _) = self
.lower_defaultness(defaultness, has_value, || hir::Defaultness::Default { has_value });

let item = hir::TraitItem {
owner_id: trait_item_def_id,
Expand Down
13 changes: 12 additions & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
false
}
ast::AssocItemKind::Const(box ast::ConstItem {
rhs_kind: ast::ConstItemRhsKind::TypeConst { .. },
rhs_kind: ast::ConstItemRhsKind::TypeConst { rhs },
..
}) => {
// Make sure this is only allowed if the feature gate is enabled.
Expand All @@ -438,6 +438,17 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
i.span,
"associated `type const` are unstable"
);
// Make sure associated `type const` defaults in traits are only allowed
// if the feature gate is enabled.
// #![feature(associated_type_defaults)]
if ctxt == AssocCtxt::Trait && rhs.is_some() {
gate!(
&self,
associated_type_defaults,
i.span,
"associated type defaults are unstable"
);
}
false
}
_ => false,
Expand Down
6 changes: 6 additions & 0 deletions src/bootstrap/src/core/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ pub struct Config {
// These are either the stage0 downloaded binaries or the locally installed ones.
pub initial_cargo: PathBuf,
pub initial_rustc: PathBuf,
pub initial_rustdoc: PathBuf,
pub initial_cargo_clippy: Option<PathBuf>,
pub initial_sysroot: PathBuf,
pub initial_rustfmt: Option<PathBuf>,
Expand Down Expand Up @@ -456,6 +457,7 @@ impl Config {
build_dir: build_build_dir,
cargo: mut build_cargo,
rustc: mut build_rustc,
rustdoc: build_rustdoc,
rustfmt: build_rustfmt,
cargo_clippy: build_cargo_clippy,
docs: build_docs,
Expand Down Expand Up @@ -751,6 +753,9 @@ impl Config {
default_stage0_rustc_path(&out)
});

let initial_rustdoc = build_rustdoc
.unwrap_or_else(|| initial_rustc.with_file_name(exe("rustdoc", host_target)));

let initial_sysroot = t!(PathBuf::from_str(
command(&initial_rustc)
.args(["--print", "sysroot"])
Expand Down Expand Up @@ -1348,6 +1353,7 @@ impl Config {
initial_cargo,
initial_cargo_clippy: build_cargo_clippy,
initial_rustc,
initial_rustdoc,
initial_rustfmt,
initial_sysroot,
jemalloc: rust_jemalloc.unwrap_or(false),
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap/src/core/config/toml/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ define_config! {
build_dir: Option<String> = "build-dir",
cargo: Option<PathBuf> = "cargo",
rustc: Option<PathBuf> = "rustc",
rustdoc: Option<PathBuf> = "rustdoc",
rustfmt: Option<PathBuf> = "rustfmt",
cargo_clippy: Option<PathBuf> = "cargo-clippy",
docs: Option<bool> = "docs",
Expand Down
4 changes: 1 addition & 3 deletions src/bootstrap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -535,9 +535,7 @@ impl Build {
initial_lld,
initial_relative_libdir,
initial_rustc: config.initial_rustc.clone(),
initial_rustdoc: config
.initial_rustc
.with_file_name(exe("rustdoc", config.host_target)),
initial_rustdoc: config.initial_rustdoc.clone(),
initial_cargo: config.initial_cargo.clone(),
initial_sysroot: config.initial_sysroot.clone(),
local_rebuild: config.local_rebuild,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// issue: <https://github.com/rust-lang/rust/issues/108220>
//@ check-pass
#![feature(min_generic_const_args)]
#![feature(min_generic_const_args, associated_type_defaults)]
#![allow(incomplete_features)]

pub trait TraitA<T> {
Expand Down
9 changes: 9 additions & 0 deletions tests/ui/const-generics/mgca/type-const-associated-default.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#![feature(min_generic_const_args)]
#![expect(incomplete_features)]
trait Trait {
type const N: usize = 10;
//~^ ERROR associated type defaults are unstable
}

fn main(){
}
13 changes: 13 additions & 0 deletions tests/ui/const-generics/mgca/type-const-associated-default.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0658]: associated type defaults are unstable
--> $DIR/type-const-associated-default.rs:4:5
|
LL | type const N: usize = 10;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: see issue #29661 <https://github.com/rust-lang/rust/issues/29661> for more information
= help: add `#![feature(associated_type_defaults)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0658`.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// ICE: assertion failed: !value.has_infer()
// issue: rust-lang/rust#115806
#![feature(adt_const_params, min_generic_const_args, unsized_const_params)]
#![feature(associated_type_defaults)]
#![allow(incomplete_features)]

pub struct NoPin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0119]: conflicting implementations of trait `Pins<_>` for type `NoPin`
--> $DIR/assoc-const-no-infer-ice-115806.rs:16:1
--> $DIR/assoc-const-no-infer-ice-115806.rs:17:1
|
LL | impl<TA> Pins<TA> for NoPin {}
| --------------------------- first implementation here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//@ build-pass
//@ no-prefer-dynamic

#![feature(min_generic_const_args)]
#![feature(min_generic_const_args, associated_type_defaults)]
#![expect(incomplete_features)]

trait Trait {
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/traits/final/final-on-assoc-type-const.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This is a regression test for <https://github.com/rust-lang/rust/issues/152797>.
#![feature(final_associated_functions)]
#![feature(min_generic_const_args)]
#![expect(incomplete_features)]
trait Uwu {
final type Ovo;
//~^ error: `final` is only allowed on associated functions in traits
final type const QwQ: ();
//~^ error: `final` is only allowed on associated functions in traits
}

fn main() {}
18 changes: 18 additions & 0 deletions tests/ui/traits/final/final-on-assoc-type-const.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error: `final` is only allowed on associated functions in traits
--> $DIR/final-on-assoc-type-const.rs:6:5
|
LL | final type Ovo;
| -----^^^^^^^^^^
| |
| `final` because of this

error: `final` is only allowed on associated functions in traits
--> $DIR/final-on-assoc-type-const.rs:8:5
|
LL | final type const QwQ: ();
| -----^^^^^^^^^^^^^^^^^^^^
| |
| `final` because of this

error: aborting due to 2 previous errors

2 changes: 0 additions & 2 deletions tests/ui/traits/final/positions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ final impl Trait for Foo {

final type Foo = ();
//~^ ERROR `final` is only allowed on associated functions in traits
//~^^ ERROR cannot override `Foo` because it already has a `final` definition in the trait

final const FOO: usize = 1;
//~^ ERROR `final` is only allowed on associated functions in traits
//~^^ ERROR cannot override `FOO` because it already has a `final` definition in the trait
}


Expand Down
44 changes: 10 additions & 34 deletions tests/ui/traits/final/positions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ LL | final trait Trait {
= note: only associated functions in traits can be `final`

error: a static item cannot be `final`
--> $DIR/positions.rs:67:5
--> $DIR/positions.rs:65:5
|
LL | final static FOO_EXTERN: usize = 0;
| ^^^^^ `final` because of this
|
= note: only associated functions in traits can be `final`

error: an extern block cannot be `final`
--> $DIR/positions.rs:58:1
--> $DIR/positions.rs:56:1
|
LL | final unsafe extern "C" {
| ^^^^^ `final` because of this
Expand Down Expand Up @@ -87,55 +87,55 @@ LL | final type Foo = ();
| `final` because of this

error: `final` is only allowed on associated functions in traits
--> $DIR/positions.rs:43:5
--> $DIR/positions.rs:42:5
|
LL | final const FOO: usize = 1;
| -----^^^^^^^^^^^^^^^^^^^^^^
| |
| `final` because of this

error: `final` is only allowed on associated functions in traits
--> $DIR/positions.rs:49:1
--> $DIR/positions.rs:47:1
|
LL | final fn foo() {}
| -----^^^^^^^^^
| |
| `final` because of this

error: `final` is only allowed on associated functions in traits
--> $DIR/positions.rs:52:1
--> $DIR/positions.rs:50:1
|
LL | final type FooTy = ();
| -----^^^^^^^^^^^^^^^^^
| |
| `final` because of this

error: `final` is only allowed on associated functions in traits
--> $DIR/positions.rs:55:1
--> $DIR/positions.rs:53:1
|
LL | final const FOO: usize = 0;
| -----^^^^^^^^^^^^^^^^^^^^^^
| |
| `final` because of this

error: `final` is only allowed on associated functions in traits
--> $DIR/positions.rs:61:5
--> $DIR/positions.rs:59:5
|
LL | final fn foo_extern();
| -----^^^^^^^^^^^^^^^^^
| |
| `final` because of this

error: `final` is only allowed on associated functions in traits
--> $DIR/positions.rs:64:5
--> $DIR/positions.rs:62:5
|
LL | final type FooExtern;
| -----^^^^^^^^^^^^^^^^
| |
| `final` because of this

error: incorrect `static` inside `extern` block
--> $DIR/positions.rs:67:18
--> $DIR/positions.rs:65:18
|
LL | final unsafe extern "C" {
| ----------------------- `extern` blocks define existing foreign statics and statics inside of them cannot have a body
Expand All @@ -159,29 +159,5 @@ note: `method` is marked final here
LL | final fn method() {}
| ^^^^^^^^^^^^^^^^^

error: cannot override `Foo` because it already has a `final` definition in the trait
--> $DIR/positions.rs:39:5
|
LL | final type Foo = ();
| ^^^^^^^^^^^^^^
|
note: `Foo` is marked final here
--> $DIR/positions.rs:16:5
|
LL | final type Foo = ();
| ^^^^^^^^^^^^^^

error: cannot override `FOO` because it already has a `final` definition in the trait
--> $DIR/positions.rs:43:5
|
LL | final const FOO: usize = 1;
| ^^^^^^^^^^^^^^^^^^^^^^
|
note: `FOO` is marked final here
--> $DIR/positions.rs:19:5
|
LL | final const FOO: usize = 1;
| ^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 21 previous errors
error: aborting due to 19 previous errors

Loading