Skip to content

Commit e7de7f4

Browse files
committed
Auto merge of #152979 - JonathanBrouwer:rollup-zlgf6NL, r=JonathanBrouwer
Rollup of 3 pull requests Successful merges: - #152385 (Feature gate for defaulted associated type_consts with associated_type_defaults ) - #152921 (Add build.rustdoc option to bootstrap config) - #152926 (Fix ICE when an associated type is wrongly marked as `final`)
2 parents 1500f0f + edbbdd7 commit e7de7f4

File tree

16 files changed

+103
-46
lines changed

16 files changed

+103
-46
lines changed

bootstrap.example.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@
302302
# If you set this, you likely want to set `cargo` as well.
303303
#build.rustc = "/path/to/rustc"
304304

305+
# Use this rustdoc binary as the stage0 snapshot rustdoc.
306+
# If unspecified, then the binary "rustdoc" (with platform-specific extension, e.g. ".exe")
307+
# in the same directory as "rustc" will be used.
308+
#build.rustdoc = "/path/to/rustdoc"
309+
305310
# Instead of downloading the src/stage0 version of rustfmt specified,
306311
# use this rustfmt binary instead as the stage0 snapshot rustfmt.
307312
#build.rustfmt = "/path/to/rustfmt"

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,9 +1085,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
10851085
}
10861086
};
10871087

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

10921101
let item = hir::TraitItem {
10931102
owner_id: trait_item_def_id,

compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
427427
false
428428
}
429429
ast::AssocItemKind::Const(box ast::ConstItem {
430-
rhs_kind: ast::ConstItemRhsKind::TypeConst { .. },
430+
rhs_kind: ast::ConstItemRhsKind::TypeConst { rhs },
431431
..
432432
}) => {
433433
// Make sure this is only allowed if the feature gate is enabled.
@@ -438,6 +438,17 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
438438
i.span,
439439
"associated `type const` are unstable"
440440
);
441+
// Make sure associated `type const` defaults in traits are only allowed
442+
// if the feature gate is enabled.
443+
// #![feature(associated_type_defaults)]
444+
if ctxt == AssocCtxt::Trait && rhs.is_some() {
445+
gate!(
446+
&self,
447+
associated_type_defaults,
448+
i.span,
449+
"associated type defaults are unstable"
450+
);
451+
}
441452
false
442453
}
443454
_ => false,

src/bootstrap/src/core/config/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ pub struct Config {
298298
// These are either the stage0 downloaded binaries or the locally installed ones.
299299
pub initial_cargo: PathBuf,
300300
pub initial_rustc: PathBuf,
301+
pub initial_rustdoc: PathBuf,
301302
pub initial_cargo_clippy: Option<PathBuf>,
302303
pub initial_sysroot: PathBuf,
303304
pub initial_rustfmt: Option<PathBuf>,
@@ -456,6 +457,7 @@ impl Config {
456457
build_dir: build_build_dir,
457458
cargo: mut build_cargo,
458459
rustc: mut build_rustc,
460+
rustdoc: build_rustdoc,
459461
rustfmt: build_rustfmt,
460462
cargo_clippy: build_cargo_clippy,
461463
docs: build_docs,
@@ -751,6 +753,9 @@ impl Config {
751753
default_stage0_rustc_path(&out)
752754
});
753755

756+
let initial_rustdoc = build_rustdoc
757+
.unwrap_or_else(|| initial_rustc.with_file_name(exe("rustdoc", host_target)));
758+
754759
let initial_sysroot = t!(PathBuf::from_str(
755760
command(&initial_rustc)
756761
.args(["--print", "sysroot"])
@@ -1348,6 +1353,7 @@ impl Config {
13481353
initial_cargo,
13491354
initial_cargo_clippy: build_cargo_clippy,
13501355
initial_rustc,
1356+
initial_rustdoc,
13511357
initial_rustfmt,
13521358
initial_sysroot,
13531359
jemalloc: rust_jemalloc.unwrap_or(false),

src/bootstrap/src/core/config/toml/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ define_config! {
2525
build_dir: Option<String> = "build-dir",
2626
cargo: Option<PathBuf> = "cargo",
2727
rustc: Option<PathBuf> = "rustc",
28+
rustdoc: Option<PathBuf> = "rustdoc",
2829
rustfmt: Option<PathBuf> = "rustfmt",
2930
cargo_clippy: Option<PathBuf> = "cargo-clippy",
3031
docs: Option<bool> = "docs",

src/bootstrap/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,7 @@ impl Build {
535535
initial_lld,
536536
initial_relative_libdir,
537537
initial_rustc: config.initial_rustc.clone(),
538-
initial_rustdoc: config
539-
.initial_rustc
540-
.with_file_name(exe("rustdoc", config.host_target)),
538+
initial_rustdoc: config.initial_rustdoc.clone(),
541539
initial_cargo: config.initial_cargo.clone(),
542540
initial_sysroot: config.initial_sysroot.clone(),
543541
local_rebuild: config.local_rebuild,

tests/ui/const-generics/associated-const-bindings/const_evaluatable_unchecked.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// issue: <https://github.com/rust-lang/rust/issues/108220>
66
//@ check-pass
7-
#![feature(min_generic_const_args)]
7+
#![feature(min_generic_const_args, associated_type_defaults)]
88
#![allow(incomplete_features)]
99

1010
pub trait TraitA<T> {
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#![feature(min_generic_const_args)]
2+
#![expect(incomplete_features)]
3+
trait Trait {
4+
type const N: usize = 10;
5+
//~^ ERROR associated type defaults are unstable
6+
}
7+
8+
fn main(){
9+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0658]: associated type defaults are unstable
2+
--> $DIR/type-const-associated-default.rs:4:5
3+
|
4+
LL | type const N: usize = 10;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #29661 <https://github.com/rust-lang/rust/issues/29661> for more information
8+
= help: add `#![feature(associated_type_defaults)]` to the crate attributes to enable
9+
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
10+
11+
error: aborting due to 1 previous error
12+
13+
For more information about this error, try `rustc --explain E0658`.

tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// ICE: assertion failed: !value.has_infer()
22
// issue: rust-lang/rust#115806
33
#![feature(adt_const_params, min_generic_const_args, unsized_const_params)]
4+
#![feature(associated_type_defaults)]
45
#![allow(incomplete_features)]
56

67
pub struct NoPin;

0 commit comments

Comments
 (0)