Skip to content

Commit 0443424

Browse files
committed
Auto merge of rust-lang#87400 - JohnTitor:rollup-zbwyuxi, r=JohnTitor
Rollup of 8 pull requests Successful merges: - rust-lang#87034 (DOC: fix hypothetical Rust code in `step_by()` docstring) - rust-lang#87298 (memorialize Anna Harren in the bastion of the turbofish) - rust-lang#87332 (Don't hide fields of enum struct variants) - rust-lang#87362 (Make `x.py d` an alias for `x.py doc`) - rust-lang#87372 (Move calls to test_main into one function) - rust-lang#87373 (Extend HIR WF checking to fields) - rust-lang#87376 (Change rustdoc logo to use the full container size) - rust-lang#87383 (Add regression tests for the impl_trait_in_bindings ICEs) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents b2b7c85 + 7c0c329 commit 0443424

34 files changed

+276
-47
lines changed

compiler/rustc_typeck/src/check/wfcheck.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,7 @@ fn check_type_defn<'tcx, F>(
523523
fcx.register_wf_obligation(
524524
field.ty.into(),
525525
field.span,
526-
// We don't have an HIR id for the field
527-
ObligationCauseCode::WellFormed(None),
526+
ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(field.def_id))),
528527
)
529528
}
530529

@@ -1467,6 +1466,7 @@ struct AdtVariant<'tcx> {
14671466

14681467
struct AdtField<'tcx> {
14691468
ty: Ty<'tcx>,
1469+
def_id: LocalDefId,
14701470
span: Span,
14711471
}
14721472

@@ -1477,11 +1477,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14771477
.fields()
14781478
.iter()
14791479
.map(|field| {
1480-
let field_ty = self.tcx.type_of(self.tcx.hir().local_def_id(field.hir_id));
1480+
let def_id = self.tcx.hir().local_def_id(field.hir_id);
1481+
let field_ty = self.tcx.type_of(def_id);
14811482
let field_ty = self.normalize_associated_types_in(field.ty.span, field_ty);
14821483
let field_ty = self.resolve_vars_if_possible(field_ty);
14831484
debug!("non_enum_variant: type of field {:?} is {:?}", field, field_ty);
1484-
AdtField { ty: field_ty, span: field.ty.span }
1485+
AdtField { ty: field_ty, span: field.ty.span, def_id }
14851486
})
14861487
.collect();
14871488
AdtVariant { fields, explicit_discr: None }

compiler/rustc_typeck/src/hir_wf_check.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ fn diagnostic_hir_wf_check<'tcx>(
2525
WellFormedLoc::Ty(def_id) => def_id,
2626
WellFormedLoc::Param { function, param_idx: _ } => function,
2727
};
28-
let hir_id = HirId::make_owner(def_id);
28+
let hir_id = hir.local_def_id_to_hir_id(def_id);
2929

3030
// HIR wfcheck should only ever happen as part of improving an existing error
3131
tcx.sess
@@ -140,6 +140,7 @@ fn diagnostic_hir_wf_check<'tcx>(
140140
}
141141
ref item => bug!("Unexpected item {:?}", item),
142142
},
143+
hir::Node::Field(field) => Some(field.ty),
143144
ref node => bug!("Unexpected node {:?}", node),
144145
},
145146
WellFormedLoc::Param { function: _, param_idx } => {

library/core/src/iter/traits/iterator.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -333,21 +333,22 @@ pub trait Iterator {
333333
/// regardless of the step given.
334334
///
335335
/// Note 2: The time at which ignored elements are pulled is not fixed.
336-
/// `StepBy` behaves like the sequence `next(), nth(step-1), nth(step-1), …`,
337-
/// but is also free to behave like the sequence
338-
/// `advance_n_and_return_first(step), advance_n_and_return_first(step), …`
336+
/// `StepBy` behaves like the sequence `self.next()`, `self.nth(step-1)`,
337+
/// `self.nth(step-1)`, …, but is also free to behave like the sequence
338+
/// `advance_n_and_return_first(&mut self, step)`,
339+
/// `advance_n_and_return_first(&mut self, step)`, …
339340
/// Which way is used may change for some iterators for performance reasons.
340341
/// The second way will advance the iterator earlier and may consume more items.
341342
///
342343
/// `advance_n_and_return_first` is the equivalent of:
343344
/// ```
344-
/// fn advance_n_and_return_first<I>(iter: &mut I, total_step: usize) -> Option<I::Item>
345+
/// fn advance_n_and_return_first<I>(iter: &mut I, n: usize) -> Option<I::Item>
345346
/// where
346347
/// I: Iterator,
347348
/// {
348349
/// let next = iter.next();
349-
/// if total_step > 1 {
350-
/// iter.nth(total_step-2);
350+
/// if n > 1 {
351+
/// iter.nth(n - 2);
351352
/// }
352353
/// next
353354
/// }

src/bootstrap/flags.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Subcommands:
152152
fmt Run rustfmt
153153
test, t Build and run some test suites
154154
bench Build and run some benchmarks
155-
doc Build documentation
155+
doc, d Build documentation
156156
clean Clean out build directories
157157
dist Build distribution artifacts
158158
install Install distribution artifacts
@@ -244,6 +244,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
244244
|| (s == "t")
245245
|| (s == "bench")
246246
|| (s == "doc")
247+
|| (s == "d")
247248
|| (s == "clean")
248249
|| (s == "dist")
249250
|| (s == "install")
@@ -312,7 +313,7 @@ To learn more about a subcommand, run `./x.py <subcommand> -h`",
312313
"clippy" => {
313314
opts.optflag("", "fix", "automatically apply lint suggestions");
314315
}
315-
"doc" => {
316+
"doc" | "d" => {
316317
opts.optflag("", "open", "open the docs in a browser");
317318
}
318319
"clean" => {
@@ -487,7 +488,7 @@ Arguments:
487488
./x.py test --stage 1",
488489
);
489490
}
490-
"doc" => {
491+
"doc" | "d" => {
491492
subcommand_help.push_str(
492493
"\n
493494
Arguments:
@@ -573,7 +574,7 @@ Arguments:
573574
},
574575
},
575576
"bench" => Subcommand::Bench { paths, test_args: matches.opt_strs("test-args") },
576-
"doc" => Subcommand::Doc { paths, open: matches.opt_present("open") },
577+
"doc" | "d" => Subcommand::Doc { paths, open: matches.opt_present("open") },
577578
"clean" => {
578579
if !paths.is_empty() {
579580
println!("\nclean does not take a path argument\n");

src/librustdoc/doctest.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
105105
registry: rustc_driver::diagnostics_registry(),
106106
};
107107

108-
let mut test_args = options.test_args.clone();
108+
let test_args = options.test_args.clone();
109109
let display_warnings = options.display_warnings;
110110
let nocapture = options.nocapture;
111111
let externs = options.externs.clone();
@@ -166,12 +166,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
166166
Err(ErrorReported) => return Err(ErrorReported),
167167
};
168168

169-
test_args.insert(0, "rustdoctest".to_string());
170-
if nocapture {
171-
test_args.push("--nocapture".to_string());
172-
}
173-
174-
test::test_main(&test_args, tests, Some(test::Options::new().display_output(display_warnings)));
169+
run_tests(test_args, nocapture, display_warnings, tests);
175170

176171
// Collect and warn about unused externs, but only if we've gotten
177172
// reports for each doctest
@@ -214,6 +209,19 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
214209
Ok(())
215210
}
216211

212+
crate fn run_tests(
213+
mut test_args: Vec<String>,
214+
nocapture: bool,
215+
display_warnings: bool,
216+
tests: Vec<test::TestDescAndFn>,
217+
) {
218+
test_args.insert(0, "rustdoctest".to_string());
219+
if nocapture {
220+
test_args.push("--nocapture".to_string());
221+
}
222+
test::test_main(&test_args, tests, Some(test::Options::new().display_output(display_warnings)));
223+
}
224+
217225
// Look for `#![doc(test(no_crate_inject))]`, used by crates in the std facade.
218226
fn scrape_test_config(attrs: &[ast::Attribute]) -> TestOptions {
219227
use rustc_ast_pretty::pprust;

src/librustdoc/html/render/print_item.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1029,14 +1029,12 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
10291029

10301030
use crate::clean::Variant;
10311031
if let clean::VariantItem(Variant::Struct(ref s)) = *variant.kind {
1032-
let count_fields = s.fields.len();
1033-
toggle_open(w, format_args!("{} field{}", count_fields, pluralize(count_fields)));
10341032
let variant_id = cx.derive_id(format!(
10351033
"{}.{}.fields",
10361034
ItemType::Variant,
10371035
variant.name.as_ref().unwrap()
10381036
));
1039-
write!(w, "<div class=\"autohide sub-variant\" id=\"{id}\">", id = variant_id);
1037+
write!(w, "<div class=\"sub-variant\" id=\"{id}\">", id = variant_id);
10401038
write!(
10411039
w,
10421040
"<h3>Fields of <b>{name}</b></h3><div>",
@@ -1064,7 +1062,6 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum
10641062
}
10651063
}
10661064
w.write_str("</div></div>");
1067-
toggle_close(w);
10681065
}
10691066
}
10701067
}

src/librustdoc/html/static/css/rustdoc.css

+2-1
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ nav.sub {
329329
.logo-container > img {
330330
max-width: 100px;
331331
max-height: 100px;
332+
height: 100%;
332333
position: absolute;
333334
left: 50%;
334335
top: 50%;
@@ -1072,7 +1073,7 @@ a.test-arrow:hover{
10721073
padding-top: 1px;
10731074
}
10741075

1075-
#main > details > .sub-variant > h3 {
1076+
#main .sub-variant > h3 {
10761077
font-size: 15px;
10771078
margin-left: 25px;
10781079
margin-bottom: 5px;

src/librustdoc/markdown.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ crate fn render<P: AsRef<Path>>(
115115
}
116116

117117
/// Runs any tests/code examples in the markdown file `input`.
118-
crate fn test(mut options: Options) -> Result<(), String> {
118+
crate fn test(options: Options) -> Result<(), String> {
119119
let input_str = read_to_string(&options.input)
120120
.map_err(|err| format!("{}: {}", options.input.display(), err))?;
121121
let mut opts = TestOptions::default();
@@ -135,14 +135,11 @@ crate fn test(mut options: Options) -> Result<(), String> {
135135

136136
find_testable_code(&input_str, &mut collector, codes, options.enable_per_target_ignores, None);
137137

138-
options.test_args.insert(0, "rustdoctest".to_string());
139-
if options.nocapture {
140-
options.test_args.push("--nocapture".to_string());
141-
}
142-
test::test_main(
143-
&options.test_args,
138+
crate::doctest::run_tests(
139+
options.test_args,
140+
options.nocapture,
141+
options.display_warnings,
144142
collector.tests,
145-
Some(test::Options::new().display_output(options.display_warnings)),
146143
);
147144
Ok(())
148145
}

src/test/rustdoc/toggle-item-contents.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ pub struct PrivStruct {
6262
}
6363

6464
// @has 'toggle_item_contents/enum.Enum.html'
65-
// @count - '//details[@class="rustdoc-toggle type-contents-toggle"]' 1
66-
// @has - '//details[@class="rustdoc-toggle type-contents-toggle"]' 'Show 2 fields'
65+
// @!has - '//details[@class="rustdoc-toggle type-contents-toggle"]'
6766
pub enum Enum {
6867
A, B, C,
6968
D {
@@ -73,8 +72,7 @@ pub enum Enum {
7372
}
7473

7574
// @has 'toggle_item_contents/enum.EnumStructVariant.html'
76-
// @count - '//details[@class="rustdoc-toggle type-contents-toggle"]' 1
77-
// @has - '//details[@class="rustdoc-toggle type-contents-toggle"]' 'Show 1 field'
75+
// @!has - '//details[@class="rustdoc-toggle type-contents-toggle"]'
7876
pub enum EnumStructVariant {
7977
A, B, C,
8078
D {

src/test/ui/bastion-of-the-turbofish.rs

+3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@
2525
//
2626
// My heart aches in sorrow, for I know I am defeated. Let this be a warning
2727
// to all those who come after. Here stands the bastion of the Turbofish.
28+
//
29+
// RIP Anna Harren, Guardian Angel of the Hallowed Turbofish. <3
2830

2931
// See https://github.com/rust-lang/rust/pull/53562
3032
// and https://github.com/rust-lang/rfcs/pull/2527
33+
// and https://twitter.com/garblefart/status/1393236602856611843
3134
// for context.
3235

3336
fn main() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use std::fmt::Debug;
2+
3+
fn main() {
4+
let x: Option<impl Debug> = Some(44_u32);
5+
//~^ `impl Trait` not allowed outside of function and method return types
6+
println!("{:?}", x);
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0562]: `impl Trait` not allowed outside of function and method return types
2+
--> $DIR/issue-54600.rs:4:19
3+
|
4+
LL | let x: Option<impl Debug> = Some(44_u32);
5+
| ^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0562`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use std::ops::Add;
2+
3+
fn main() {
4+
let i: i32 = 0;
5+
let j: &impl Add = &i;
6+
//~^ `impl Trait` not allowed outside of function and method return types
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0562]: `impl Trait` not allowed outside of function and method return types
2+
--> $DIR/issue-54840.rs:5:13
3+
|
4+
LL | let j: &impl Add = &i;
5+
| ^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0562`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![feature(generators, generator_trait, never_type)]
2+
3+
use std::ops::Generator;
4+
5+
fn mk_gen() -> impl Generator<Return=!, Yield=()> {
6+
|| { loop { yield; } }
7+
}
8+
9+
fn main() {
10+
let gens: [impl Generator<Return=!, Yield=()>;2] = [ mk_gen(), mk_gen() ];
11+
//~^ `impl Trait` not allowed outside of function and method return types
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0562]: `impl Trait` not allowed outside of function and method return types
2+
--> $DIR/issue-58504.rs:10:16
3+
|
4+
LL | let gens: [impl Generator<Return=!, Yield=()>;2] = [ mk_gen(), mk_gen() ];
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0562`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
trait Lam {}
2+
3+
pub struct B;
4+
impl Lam for B {}
5+
pub struct Wrap<T>(T);
6+
7+
const _A: impl Lam = {
8+
//~^ `impl Trait` not allowed outside of function and method return types
9+
let x: Wrap<impl Lam> = Wrap(B);
10+
//~^ `impl Trait` not allowed outside of function and method return types
11+
x.0
12+
};
13+
14+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0562]: `impl Trait` not allowed outside of function and method return types
2+
--> $DIR/issue-58956.rs:7:11
3+
|
4+
LL | const _A: impl Lam = {
5+
| ^^^^^^^^
6+
7+
error[E0562]: `impl Trait` not allowed outside of function and method return types
8+
--> $DIR/issue-58956.rs:9:17
9+
|
10+
LL | let x: Wrap<impl Lam> = Wrap(B);
11+
| ^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0562`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
let x : (impl Copy,) = (true,);
3+
//~^ `impl Trait` not allowed outside of function and method return types
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0562]: `impl Trait` not allowed outside of function and method return types
2+
--> $DIR/issue-70971.rs:2:14
3+
|
4+
LL | let x : (impl Copy,) = (true,);
5+
| ^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0562`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
struct Bug {
2+
V1: [(); {
3+
let f: impl core::future::Future<Output = u8> = async { 1 };
4+
//~^ `impl Trait` not allowed outside of function and method return types
5+
//~| expected identifier
6+
1
7+
}],
8+
}
9+
10+
fn main() {}

0 commit comments

Comments
 (0)