Skip to content

Commit 19ed0aa

Browse files
committed
Auto merge of #112013 - matthiaskrgr:rollup-a4pg2p8, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #111714 (Stop confusing specification levels when computing expectations.) - #111927 (Migrate `item_static` to Askama) - #111954 (improve error message for calling a method on a raw pointer with an unknown pointee) - #111973 (Update current implementation comments for `select_nth_unstable`) - #111976 (Generate docs for bootstrap itself) - #111977 (Make errors from `x doc` less verbose) - #111987 (do not prefer substs relate during coherence) - #111991 (Change ty and const error's pretty printing to be in braces) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1a5f8bc + a992097 commit 19ed0aa

23 files changed

+142
-46
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1159,7 +1159,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
11591159
// those that do.
11601160
self.one_bound_for_assoc_type(
11611161
|| traits::supertraits(tcx, trait_ref),
1162-
trait_ref.print_only_trait_path(),
1162+
trait_ref.skip_binder().print_only_trait_name(),
11631163
binding.item_name,
11641164
path_span,
11651165
match binding.kind {

compiler/rustc_hir_typeck/messages.ftl

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ hir_typeck_lang_start_incorrect_param = parameter {$param_num} of the `start` la
5959
hir_typeck_lang_start_incorrect_ret_ty = the return type of the `start` lang item is incorrect
6060
.suggestion = change the type from `{$found_ty}` to `{$expected_ty}`
6161
62-
hir_typeck_method_call_on_unknown_type =
63-
the type of this value must be known to call a method on a raw pointer on it
62+
hir_typeck_method_call_on_unknown_raw_pointee =
63+
cannot call a method on a raw pointer with an unknown pointee type
6464
6565
hir_typeck_missing_parentheses_in_range = can't call method `{$method_name}` on type `{$ty_str}`
6666

compiler/rustc_hir_typeck/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ pub struct StructExprNonExhaustive {
4949
}
5050

5151
#[derive(Diagnostic)]
52-
#[diag(hir_typeck_method_call_on_unknown_type, code = "E0699")]
53-
pub struct MethodCallOnUnknownType {
52+
#[diag(hir_typeck_method_call_on_unknown_raw_pointee, code = "E0699")]
53+
pub struct MethodCallOnUnknownRawPointee {
5454
#[primary_span]
5555
pub span: Span,
5656
}

compiler/rustc_hir_typeck/src/method/probe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use super::CandidateSource;
33
use super::MethodError;
44
use super::NoMatchData;
55

6-
use crate::errors::MethodCallOnUnknownType;
6+
use crate::errors::MethodCallOnUnknownRawPointee;
77
use crate::FnCtxt;
88
use rustc_data_structures::fx::FxHashSet;
99
use rustc_errors::Applicability;
@@ -438,7 +438,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
438438
// so we do a future-compat lint here for the 2015 edition
439439
// (see https://github.com/rust-lang/rust/issues/46906)
440440
if self.tcx.sess.rust_2018() {
441-
self.tcx.sess.emit_err(MethodCallOnUnknownType { span });
441+
self.tcx.sess.emit_err(MethodCallOnUnknownRawPointee { span });
442442
} else {
443443
self.tcx.struct_span_lint_hir(
444444
lint::builtin::TYVAR_BEHIND_RAW_POINTER,

compiler/rustc_lint/src/levels.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,9 @@ impl LintLevelsProvider for LintLevelQueryMap<'_> {
242242

243243
struct QueryMapExpectationsWrapper<'tcx> {
244244
tcx: TyCtxt<'tcx>,
245+
/// HirId of the currently investigated element.
245246
cur: HirId,
247+
/// Level map for `cur`.
246248
specs: ShallowLintLevelMap,
247249
expectations: Vec<(LintExpectationId, LintExpectation)>,
248250
unstable_to_stable_ids: FxHashMap<LintExpectationId, LintExpectationId>,
@@ -255,11 +257,11 @@ impl LintLevelsProvider for QueryMapExpectationsWrapper<'_> {
255257
self.specs.specs.get(&self.cur.local_id).unwrap_or(&self.empty)
256258
}
257259
fn insert(&mut self, id: LintId, lvl: LevelAndSource) {
258-
let specs = self.specs.specs.get_mut_or_insert_default(self.cur.local_id);
259-
specs.clear();
260-
specs.insert(id, lvl);
260+
self.specs.specs.get_mut_or_insert_default(self.cur.local_id).insert(id, lvl);
261261
}
262262
fn get_lint_level(&self, lint: &'static Lint, _: &Session) -> LevelAndSource {
263+
// We cannot use `tcx.lint_level_at_node` because we want to know in which order the
264+
// attributes have been inserted, in particular whether an `expect` follows a `forbid`.
263265
self.specs.lint_level_id_at_node(self.tcx, LintId::of(lint), self.cur)
264266
}
265267
fn push_expectation(&mut self, id: LintExpectationId, expectation: LintExpectation) {
@@ -355,7 +357,9 @@ impl<'tcx> Visitor<'tcx> for LintLevelsBuilder<'_, LintLevelQueryMap<'tcx>> {
355357

356358
impl<'tcx> LintLevelsBuilder<'_, QueryMapExpectationsWrapper<'tcx>> {
357359
fn add_id(&mut self, hir_id: HirId) {
360+
// Change both the `HirId` and the associated specs.
358361
self.provider.cur = hir_id;
362+
self.provider.specs.specs.clear();
359363
self.add(self.provider.tcx.hir().attrs(hir_id), hir_id == hir::CRATE_HIR_ID, Some(hir_id));
360364
}
361365
}

compiler/rustc_middle/src/ty/print/pretty.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ pub trait PrettyPrinter<'tcx>:
700700
if verbose { p!(write("{:?}", infer_ty)) } else { p!(write("{}", infer_ty)) }
701701
}
702702
}
703-
ty::Error(_) => p!("[type error]"),
703+
ty::Error(_) => p!("{{type error}}"),
704704
ty::Param(ref param_ty) => p!(print(param_ty)),
705705
ty::Bound(debruijn, bound_ty) => match bound_ty.kind {
706706
ty::BoundTyKind::Anon => debug_bound_var(&mut self, debruijn, bound_ty.var)?,
@@ -1379,8 +1379,8 @@ pub trait PrettyPrinter<'tcx>:
13791379
},
13801380
// FIXME(generic_const_exprs):
13811381
// write out some legible representation of an abstract const?
1382-
ty::ConstKind::Expr(_) => p!("[const expr]"),
1383-
ty::ConstKind::Error(_) => p!("[const error]"),
1382+
ty::ConstKind::Expr(_) => p!("{{const expr}}"),
1383+
ty::ConstKind::Error(_) => p!("{{const error}}"),
13841384
};
13851385
Ok(self)
13861386
}

compiler/rustc_trait_selection/src/solve/mod.rs

+25-9
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,21 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
231231

232232
let mut candidates = Vec::new();
233233
// LHS normalizes-to RHS
234-
candidates.extend(
235-
evaluate_normalizes_to(self, alias_lhs, rhs, direction, Invert::No).ok(),
236-
);
234+
candidates.extend(evaluate_normalizes_to(
235+
self,
236+
alias_lhs,
237+
rhs,
238+
direction,
239+
Invert::No,
240+
));
237241
// RHS normalizes-to RHS
238-
candidates.extend(
239-
evaluate_normalizes_to(self, alias_rhs, lhs, direction, Invert::Yes).ok(),
240-
);
242+
candidates.extend(evaluate_normalizes_to(
243+
self,
244+
alias_rhs,
245+
lhs,
246+
direction,
247+
Invert::Yes,
248+
));
241249
// Relate via substs
242250
let subst_relate_response = self.probe(|ecx| {
243251
let span = tracing::span!(
@@ -265,10 +273,18 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
265273

266274
if let Some(merged) = self.try_merge_responses(&candidates) {
267275
Ok(merged)
268-
} else if let Ok(subst_relate_response) = subst_relate_response {
269-
Ok(subst_relate_response)
270276
} else {
271-
self.flounder(&candidates)
277+
// When relating two aliases and we have ambiguity, we prefer
278+
// relating the generic arguments of the aliases over normalizing
279+
// them. This is necessary for inference during typeck.
280+
//
281+
// As this is incomplete, we must not do so during coherence.
282+
match (self.solver_mode(), subst_relate_response) {
283+
(SolverMode::Normal, Ok(response)) => Ok(response),
284+
(SolverMode::Normal, Err(NoSolution)) | (SolverMode::Coherence, _) => {
285+
self.flounder(&candidates)
286+
}
287+
}
272288
}
273289
}
274290
}

library/core/src/slice/mod.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -3005,8 +3005,9 @@ impl<T> [T] {
30053005
///
30063006
/// # Current implementation
30073007
///
3008-
/// The current algorithm is based on the quickselect portion of the same quicksort algorithm
3009-
/// used for [`sort_unstable`].
3008+
/// The current algorithm is an introselect implementation based on Pattern Defeating Quicksort, which is also
3009+
/// the basis for [`sort_unstable`]. The fallback algorithm is Median of Medians using Tukey's Ninther for
3010+
/// pivot selection, which guarantees linear runtime for all inputs.
30103011
///
30113012
/// [`sort_unstable`]: slice::sort_unstable
30123013
///
@@ -3056,8 +3057,9 @@ impl<T> [T] {
30563057
///
30573058
/// # Current implementation
30583059
///
3059-
/// The current algorithm is based on the quickselect portion of the same quicksort algorithm
3060-
/// used for [`sort_unstable`].
3060+
/// The current algorithm is an introselect implementation based on Pattern Defeating Quicksort, which is also
3061+
/// the basis for [`sort_unstable`]. The fallback algorithm is Median of Medians using Tukey's Ninther for
3062+
/// pivot selection, which guarantees linear runtime for all inputs.
30613063
///
30623064
/// [`sort_unstable`]: slice::sort_unstable
30633065
///

src/bootstrap/builder.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ impl PathSet {
264264

265265
/// A convenience wrapper for Steps which know they have no aliases and all their sets contain only a single path.
266266
///
267-
/// This can be used with [`ShouldRun::krate`], [`ShouldRun::path`], or [`ShouldRun::alias`].
267+
/// This can be used with [`ShouldRun::crate_or_deps`], [`ShouldRun::path`], or [`ShouldRun::alias`].
268268
#[track_caller]
269269
pub fn assert_single_path(&self) -> &TaskPath {
270270
match self {
@@ -787,6 +787,7 @@ impl<'a> Builder<'a> {
787787
doc::EditionGuide,
788788
doc::StyleGuide,
789789
doc::Tidy,
790+
doc::Bootstrap,
790791
),
791792
Kind::Dist => describe!(
792793
dist::Docs,
@@ -1915,10 +1916,10 @@ impl<'a> Builder<'a> {
19151916
}
19161917

19171918
// For `cargo doc` invocations, make rustdoc print the Rust version into the docs
1918-
// This replaces spaces with newlines because RUSTDOCFLAGS does not
1919+
// This replaces spaces with tabs because RUSTDOCFLAGS does not
19191920
// support arguments with regular spaces. Hopefully someday Cargo will
19201921
// have space support.
1921-
let rust_version = self.rust_version().replace(' ', "\n");
1922+
let rust_version = self.rust_version().replace(' ', "\t");
19221923
rustdocflags.arg("--crate-version").arg(&rust_version);
19231924

19241925
// Environment variables *required* throughout the build

src/bootstrap/doc.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,8 @@ macro_rules! tool_doc {
839839
)+
840840

841841
cargo.rustdocflag("--document-private-items");
842+
// Since we always pass --document-private-items, there's no need to warn about linking to private items.
843+
cargo.rustdocflag("-Arustdoc::private-intra-doc-links");
842844
cargo.rustdocflag("--enable-index-page");
843845
cargo.rustdocflag("--show-type-layout");
844846
cargo.rustdocflag("--generate-link-to-definition");
@@ -882,7 +884,8 @@ tool_doc!(
882884
// "cargo-credential-wincred",
883885
]
884886
);
885-
tool_doc!(Tidy, "tidy", "src/tools/tidy", ["tidy"]);
887+
tool_doc!(Tidy, "tidy", "src/tools/tidy", rustc_tool = false, ["tidy"]);
888+
tool_doc!(Bootstrap, "bootstrap", "src/bootstrap", rustc_tool = false, ["bootstrap"]);
886889

887890
#[derive(Ord, PartialOrd, Debug, Copy, Clone, Hash, PartialEq, Eq)]
888891
pub struct ErrorIndex {

src/bootstrap/download.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl Config {
123123
/// This is only required on NixOS and uses the PatchELF utility to
124124
/// change the interpreter/RPATH of ELF executables.
125125
///
126-
/// Please see https://nixos.org/patchelf.html for more information
126+
/// Please see <https://nixos.org/patchelf.html> for more information
127127
fn fix_bin_or_dylib(&self, fname: &Path) {
128128
assert_eq!(SHOULD_FIX_BINS_AND_DYLIBS.get(), Some(&true));
129129
println!("attempting to patch {}", fname.display());

src/bootstrap/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,8 @@ impl Build {
10111011
}
10121012

10131013
/// Return a `Group` guard for a [`Step`] that is built for each `--stage`.
1014+
///
1015+
/// [`Step`]: crate::builder::Step
10141016
fn msg(
10151017
&self,
10161018
action: impl Into<Kind>,
@@ -1035,6 +1037,8 @@ impl Build {
10351037
}
10361038

10371039
/// Return a `Group` guard for a [`Step`] that is only built once and isn't affected by `--stage`.
1040+
///
1041+
/// [`Step`]: crate::builder::Step
10381042
fn msg_unstaged(
10391043
&self,
10401044
action: impl Into<Kind>,

src/bootstrap/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ fn absolute_windows(path: &std::path::Path) -> std::io::Result<std::path::PathBu
488488
}
489489
}
490490

491-
/// Adapted from https://github.com/llvm/llvm-project/blob/782e91224601e461c019e0a4573bbccc6094fbcd/llvm/cmake/modules/HandleLLVMOptions.cmake#L1058-L1079
491+
/// Adapted from <https://github.com/llvm/llvm-project/blob/782e91224601e461c019e0a4573bbccc6094fbcd/llvm/cmake/modules/HandleLLVMOptions.cmake#L1058-L1079>
492492
///
493493
/// When `clang-cl` is used with instrumentation, we need to add clang's runtime library resource
494494
/// directory to the linker flags, otherwise there will be linker errors about the profiler runtime

src/librustdoc/html/render/print_item.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1541,19 +1541,23 @@ fn item_struct(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean
15411541
write!(w, "{}", document_type_layout(cx, def_id));
15421542
}
15431543

1544-
fn item_static(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item, s: &clean::Static) {
1545-
wrap_item(w, |w| {
1546-
render_attributes_in_code(w, it, cx.tcx());
1544+
fn item_static(w: &mut impl fmt::Write, cx: &mut Context<'_>, it: &clean::Item, s: &clean::Static) {
1545+
let mut buffer = Buffer::new();
1546+
wrap_item(&mut buffer, |buffer| {
1547+
render_attributes_in_code(buffer, it, cx.tcx());
15471548
write!(
1548-
w,
1549+
buffer,
15491550
"{vis}static {mutability}{name}: {typ}",
15501551
vis = visibility_print_with_space(it.visibility(cx.tcx()), it.item_id, cx),
15511552
mutability = s.mutability.print_with_space(),
15521553
name = it.name.unwrap(),
15531554
typ = s.type_.print(cx)
15541555
);
15551556
});
1556-
write!(w, "{}", document(cx, it, None, HeadingOffset::H2))
1557+
1558+
write!(w, "{}", buffer.into_inner()).unwrap();
1559+
1560+
write!(w, "{}", document(cx, it, None, HeadingOffset::H2)).unwrap();
15571561
}
15581562

15591563
fn item_foreign_type(w: &mut Buffer, cx: &mut Context<'_>, it: &clean::Item) {

tests/ui/const-generics/transmute-fail.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error[E0512]: cannot transmute between types of different sizes, or dependently-
44
LL | std::mem::transmute(v)
55
| ^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: source type: `[[u32; H+1]; W]` (generic size [const expr])
8-
= note: target type: `[[u32; W+1]; H]` (generic size [const expr])
7+
= note: source type: `[[u32; H+1]; W]` (generic size {const expr})
8+
= note: target type: `[[u32; W+1]; H]` (generic size {const expr})
99

1010
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
1111
--> $DIR/transmute-fail.rs:16:5
@@ -34,8 +34,8 @@ error[E0512]: cannot transmute between types of different sizes, or dependently-
3434
LL | std::mem::transmute(v)
3535
| ^^^^^^^^^^^^^^^^^^^
3636
|
37-
= note: source type: `[[u32; H]; W]` (generic size [const expr])
38-
= note: target type: `[u32; W * H * H]` (generic size [const expr])
37+
= note: source type: `[[u32; H]; W]` (generic size {const expr})
38+
= note: target type: `[u32; W * H * H]` (generic size {const expr})
3939

4040
error[E0512]: cannot transmute between types of different sizes, or dependently-sized types
4141
--> $DIR/transmute-fail.rs:30:5

tests/ui/editions/edition-raw-pointer-method-2018.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ fn main() {
77
let x = 0;
88
let y = &x as *const _;
99
let _ = y.is_null();
10-
//~^ error: the type of this value must be known to call a method on a raw pointer on it [E0699]
10+
//~^ error: cannot call a method on a raw pointer with an unknown pointee type [E0699]
1111
}

tests/ui/editions/edition-raw-pointer-method-2018.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error[E0699]: the type of this value must be known to call a method on a raw pointer on it
1+
error[E0699]: cannot call a method on a raw pointer with an unknown pointee type
22
--> $DIR/edition-raw-pointer-method-2018.rs:9:15
33
|
44
LL | let _ = y.is_null();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// check-pass
2+
// compile-flags: -Dunused_attributes
3+
4+
#![deny(unused_crate_dependencies)]
5+
#![feature(lint_reasons)]
6+
7+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// edition: 2018
2+
3+
// tests that the pointee type of a raw pointer must be known to call methods on it
4+
// see also: `tests/ui/editions/edition-raw-pointer-method-2018.rs`
5+
6+
fn main() {
7+
let val = 1_u32;
8+
let ptr = &val as *const u32;
9+
unsafe {
10+
let _a: i32 = (ptr as *const _).read();
11+
//~^ ERROR cannot call a method on a raw pointer with an unknown pointee type [E0699]
12+
let b = ptr as *const _;
13+
let _b: u8 = b.read();
14+
//~^ ERROR cannot call a method on a raw pointer with an unknown pointee type [E0699]
15+
let _c = (ptr as *const u8).read(); // we know the type here
16+
}
17+
18+
let mut val = 2_u32;
19+
let ptr = &mut val as *mut u32;
20+
unsafe {
21+
let _a: i32 = (ptr as *mut _).read();
22+
//~^ ERROR cannot call a method on a raw pointer with an unknown pointee type [E0699]
23+
let b = ptr as *mut _;
24+
b.write(10);
25+
//~^ ERROR cannot call a method on a raw pointer with an unknown pointee type [E0699]
26+
(ptr as *mut i32).write(1000); // we know the type here
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0699]: cannot call a method on a raw pointer with an unknown pointee type
2+
--> $DIR/call_method_unknown_pointee.rs:10:41
3+
|
4+
LL | let _a: i32 = (ptr as *const _).read();
5+
| ^^^^
6+
7+
error[E0699]: cannot call a method on a raw pointer with an unknown pointee type
8+
--> $DIR/call_method_unknown_pointee.rs:13:24
9+
|
10+
LL | let _b: u8 = b.read();
11+
| ^^^^
12+
13+
error[E0699]: cannot call a method on a raw pointer with an unknown pointee type
14+
--> $DIR/call_method_unknown_pointee.rs:21:39
15+
|
16+
LL | let _a: i32 = (ptr as *mut _).read();
17+
| ^^^^
18+
19+
error[E0699]: cannot call a method on a raw pointer with an unknown pointee type
20+
--> $DIR/call_method_unknown_pointee.rs:24:11
21+
|
22+
LL | b.write(10);
23+
| ^^^^^
24+
25+
error: aborting due to 4 previous errors
26+
27+
For more information about this error, try `rustc --explain E0699`.

0 commit comments

Comments
 (0)