Skip to content

Commit 5348a89

Browse files
committed
Auto merge of #108015 - matthiaskrgr:rollup-qerohjn, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #107902 (fix: improve the suggestion on future not awaited) - #107913 (Update broken link in cargo style guide) - #107942 (Tighter spans for bad inherent `impl` self types) - #107948 (Allow shortcuts to directories to be used for ./x.py fmt) - #107971 (Clearly document intentional UB in mir-opt tests) - #107985 (Added another error to be processed in fallback) - #108002 (Update books) - #108013 (rustdoc: use a string with one-character codes for search index types) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 065852d + f1a3494 commit 5348a89

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+322
-269
lines changed

Diff for: compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ const ADD_ATTR: &str =
5757
"alternatively add `#[rustc_allow_incoherent_impl]` to the relevant impl items";
5858

5959
impl<'tcx> InherentCollect<'tcx> {
60-
fn check_def_id(&mut self, item: &hir::Item<'_>, self_ty: Ty<'tcx>, def_id: DefId) {
60+
fn check_def_id(&mut self, item: &hir::Item<'_>, self_ty: Ty<'tcx>, def_id: DefId, span: Span) {
6161
let impl_def_id = item.owner_id;
6262
if let Some(def_id) = def_id.as_local() {
6363
// Add the implementation to the mapping from implementation to base
@@ -76,12 +76,12 @@ impl<'tcx> InherentCollect<'tcx> {
7676
if !self.tcx.has_attr(def_id, sym::rustc_has_incoherent_inherent_impls) {
7777
struct_span_err!(
7878
self.tcx.sess,
79-
item.span,
79+
span,
8080
E0390,
8181
"cannot define inherent `impl` for a type outside of the crate where the type is defined",
8282
)
8383
.help(INTO_DEFINING_CRATE)
84-
.span_help(item.span, ADD_ATTR_TO_TY)
84+
.span_help(span, ADD_ATTR_TO_TY)
8585
.emit();
8686
return;
8787
}
@@ -93,12 +93,12 @@ impl<'tcx> InherentCollect<'tcx> {
9393
{
9494
struct_span_err!(
9595
self.tcx.sess,
96-
item.span,
96+
span,
9797
E0390,
9898
"cannot define inherent `impl` for a type outside of the crate where the type is defined",
9999
)
100100
.help(INTO_DEFINING_CRATE)
101-
.span_help(impl_item.span, ADD_ATTR)
101+
.span_help(self.tcx.hir().span(impl_item.id.hir_id()), ADD_ATTR)
102102
.emit();
103103
return;
104104
}
@@ -112,12 +112,12 @@ impl<'tcx> InherentCollect<'tcx> {
112112
} else {
113113
struct_span_err!(
114114
self.tcx.sess,
115-
item.span,
115+
span,
116116
E0116,
117117
"cannot define inherent `impl` for a type outside of the crate \
118118
where the type is defined"
119119
)
120-
.span_label(item.span, "impl for type defined outside of crate.")
120+
.span_label(span, "impl for type defined outside of crate.")
121121
.note("define and implement a trait or new type instead")
122122
.emit();
123123
}
@@ -182,29 +182,30 @@ impl<'tcx> InherentCollect<'tcx> {
182182
}
183183

184184
let item = self.tcx.hir().item(id);
185-
let hir::ItemKind::Impl(hir::Impl { of_trait: None, self_ty: ty, items, .. }) = item.kind else {
185+
let impl_span = self.tcx.hir().span(id.hir_id());
186+
let hir::ItemKind::Impl(hir::Impl { of_trait: None, items, .. }) = item.kind else {
186187
return;
187188
};
188189

189190
let self_ty = self.tcx.type_of(item.owner_id);
190191
match *self_ty.kind() {
191192
ty::Adt(def, _) => {
192-
self.check_def_id(item, self_ty, def.did());
193+
self.check_def_id(item, self_ty, def.did(), impl_span);
193194
}
194195
ty::Foreign(did) => {
195-
self.check_def_id(item, self_ty, did);
196+
self.check_def_id(item, self_ty, did, impl_span);
196197
}
197198
ty::Dynamic(data, ..) if data.principal_def_id().is_some() => {
198-
self.check_def_id(item, self_ty, data.principal_def_id().unwrap());
199+
self.check_def_id(item, self_ty, data.principal_def_id().unwrap(), impl_span);
199200
}
200201
ty::Dynamic(..) => {
201202
struct_span_err!(
202203
self.tcx.sess,
203-
ty.span,
204+
impl_span,
204205
E0785,
205206
"cannot define inherent `impl` for a dyn auto trait"
206207
)
207-
.span_label(ty.span, "impl requires at least one non-auto trait")
208+
.span_label(impl_span, "impl requires at least one non-auto trait")
208209
.note("define and implement a new trait or type instead")
209210
.emit();
210211
}
@@ -221,17 +222,17 @@ impl<'tcx> InherentCollect<'tcx> {
221222
| ty::Never
222223
| ty::FnPtr(_)
223224
| ty::Tuple(..) => {
224-
self.check_primitive_impl(item.owner_id.def_id, self_ty, items, ty.span)
225+
self.check_primitive_impl(item.owner_id.def_id, self_ty, items, impl_span)
225226
}
226227
ty::Alias(..) | ty::Param(_) => {
227228
let mut err = struct_span_err!(
228229
self.tcx.sess,
229-
ty.span,
230+
impl_span,
230231
E0118,
231232
"no nominal type found for inherent implementation"
232233
);
233234

234-
err.span_label(ty.span, "impl requires a nominal type")
235+
err.span_label(impl_span, "impl requires a nominal type")
235236
.note("either implement a trait on it or create a newtype to wrap it instead");
236237

237238
err.emit();

Diff for: compiler/rustc_infer/src/infer/error_reporting/mod.rs

+25-9
Original file line numberDiff line numberDiff line change
@@ -1783,14 +1783,24 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
17831783
}
17841784
}))
17851785
{
1786-
diag.note_expected_found_extra(
1787-
&expected_label,
1788-
expected,
1789-
&found_label,
1790-
found,
1791-
&sort_string(values.expected, exp_p),
1792-
&sort_string(values.found, found_p),
1793-
);
1786+
if let Some(ExpectedFound { found: found_ty, .. }) = exp_found {
1787+
// `Future` is a special opaque type that the compiler
1788+
// will try to hide in some case such as `async fn`, so
1789+
// to make an error more use friendly we will
1790+
// avoid to suggest a mismatch type with a
1791+
// type that the user usually are not usign
1792+
// directly such as `impl Future<Output = u8>`.
1793+
if !self.tcx.ty_is_opaque_future(found_ty) {
1794+
diag.note_expected_found_extra(
1795+
&expected_label,
1796+
expected,
1797+
&found_label,
1798+
found,
1799+
&sort_string(values.expected, exp_p),
1800+
&sort_string(values.found, found_p),
1801+
);
1802+
}
1803+
}
17941804
}
17951805
}
17961806
_ => {
@@ -2854,6 +2864,7 @@ impl IntoDiagnosticArg for ObligationCauseAsDiagArg<'_> {
28542864
pub enum TyCategory {
28552865
Closure,
28562866
Opaque,
2867+
OpaqueFuture,
28572868
Generator(hir::GeneratorKind),
28582869
Foreign,
28592870
}
@@ -2863,6 +2874,7 @@ impl TyCategory {
28632874
match self {
28642875
Self::Closure => "closure",
28652876
Self::Opaque => "opaque type",
2877+
Self::OpaqueFuture => "future",
28662878
Self::Generator(gk) => gk.descr(),
28672879
Self::Foreign => "foreign type",
28682880
}
@@ -2871,7 +2883,11 @@ impl TyCategory {
28712883
pub fn from_ty(tcx: TyCtxt<'_>, ty: Ty<'_>) -> Option<(Self, DefId)> {
28722884
match *ty.kind() {
28732885
ty::Closure(def_id, _) => Some((Self::Closure, def_id)),
2874-
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => Some((Self::Opaque, def_id)),
2886+
ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) => {
2887+
let kind =
2888+
if tcx.ty_is_opaque_future(ty) { Self::OpaqueFuture } else { Self::Opaque };
2889+
Some((kind, def_id))
2890+
}
28752891
ty::Generator(def_id, ..) => {
28762892
Some((Self::Generator(tcx.generator_kind(def_id).unwrap()), def_id))
28772893
}

Diff for: compiler/rustc_infer/src/infer/error_reporting/suggest.rs

+13-18
Original file line numberDiff line numberDiff line change
@@ -238,31 +238,17 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
238238
}
239239
},
240240
(_, Some(ty)) if self.same_type_modulo_infer(exp_found.expected, ty) => {
241-
diag.span_suggestion_verbose(
242-
exp_span.shrink_to_hi(),
243-
"consider `await`ing on the `Future`",
244-
".await",
245-
Applicability::MaybeIncorrect,
246-
);
241+
self.suggest_await_on_future(diag, exp_span);
242+
diag.span_note(exp_span, "calling an async function returns a future");
247243
}
248244
(Some(ty), _) if self.same_type_modulo_infer(ty, exp_found.found) => match cause.code()
249245
{
250246
ObligationCauseCode::Pattern { span: Some(then_span), .. } => {
251-
diag.span_suggestion_verbose(
252-
then_span.shrink_to_hi(),
253-
"consider `await`ing on the `Future`",
254-
".await",
255-
Applicability::MaybeIncorrect,
256-
);
247+
self.suggest_await_on_future(diag, then_span.shrink_to_hi());
257248
}
258249
ObligationCauseCode::IfExpression(box IfExpressionCause { then_id, .. }) => {
259250
let then_span = self.find_block_span_from_hir_id(*then_id);
260-
diag.span_suggestion_verbose(
261-
then_span.shrink_to_hi(),
262-
"consider `await`ing on the `Future`",
263-
".await",
264-
Applicability::MaybeIncorrect,
265-
);
251+
self.suggest_await_on_future(diag, then_span.shrink_to_hi());
266252
}
267253
ObligationCauseCode::MatchExpressionArm(box MatchExpressionArmCause {
268254
ref prior_arms,
@@ -283,6 +269,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
283269
}
284270
}
285271

272+
pub fn suggest_await_on_future(&self, diag: &mut Diagnostic, sp: Span) {
273+
diag.span_suggestion_verbose(
274+
sp.shrink_to_hi(),
275+
"consider `await`ing on the `Future`",
276+
".await",
277+
Applicability::MaybeIncorrect,
278+
);
279+
}
280+
286281
pub(super) fn suggest_accessing_field_where_appropriate(
287282
&self,
288283
cause: &ObligationCause<'tcx>,

Diff for: compiler/rustc_middle/src/ty/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl<'tcx> Ty<'tcx> {
271271
ty::Infer(ty::FreshFloatTy(_)) => "fresh floating-point type".into(),
272272
ty::Alias(ty::Projection, _) => "associated type".into(),
273273
ty::Param(p) => format!("type parameter `{p}`").into(),
274-
ty::Alias(ty::Opaque, ..) => "opaque type".into(),
274+
ty::Alias(ty::Opaque, ..) => if tcx.ty_is_opaque_future(self) { "future".into() } else { "opaque type".into() },
275275
ty::Error(_) => "type error".into(),
276276
_ => {
277277
let width = tcx.sess.diagnostic_width();

Diff for: library/std/src/sys/windows/fs.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,12 @@ fn metadata(path: &Path, reparse: ReparsePoint) -> io::Result<FileAttr> {
12661266
// If the fallback fails for any reason we return the original error.
12671267
match File::open(path, &opts) {
12681268
Ok(file) => file.file_attr(),
1269-
Err(e) if e.raw_os_error() == Some(c::ERROR_SHARING_VIOLATION as _) => {
1269+
Err(e)
1270+
if [Some(c::ERROR_SHARING_VIOLATION as _), Some(c::ERROR_ACCESS_DENIED as _)]
1271+
.contains(&e.raw_os_error()) =>
1272+
{
1273+
// `ERROR_ACCESS_DENIED` is returned when the user doesn't have permission for the resource.
1274+
// One such example is `System Volume Information` as default but can be created as well
12701275
// `ERROR_SHARING_VIOLATION` will almost never be returned.
12711276
// Usually if a file is locked you can still read some metadata.
12721277
// However, there are special system files, such as

Diff for: src/bootstrap/format.rs

+38-2
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,46 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) {
193193
let (tx, rx): (SyncSender<PathBuf>, _) = std::sync::mpsc::sync_channel(128);
194194
let walker = match paths.get(0) {
195195
Some(first) => {
196-
let mut walker = WalkBuilder::new(first);
196+
let find_shortcut_candidates = |p: &PathBuf| {
197+
let mut candidates = Vec::new();
198+
for candidate in WalkBuilder::new(src.clone()).max_depth(Some(3)).build() {
199+
if let Ok(entry) = candidate {
200+
if let Some(dir_name) = p.file_name() {
201+
if entry.path().is_dir() && entry.file_name() == dir_name {
202+
candidates.push(entry.into_path());
203+
}
204+
}
205+
}
206+
}
207+
candidates
208+
};
209+
210+
// Only try to look for shortcut candidates for single component paths like
211+
// `std` and not for e.g. relative paths like `../library/std`.
212+
let should_look_for_shortcut_dir = |p: &PathBuf| p.components().count() == 1;
213+
214+
let mut walker = if should_look_for_shortcut_dir(first) {
215+
if let [single_candidate] = &find_shortcut_candidates(first)[..] {
216+
WalkBuilder::new(single_candidate)
217+
} else {
218+
WalkBuilder::new(first)
219+
}
220+
} else {
221+
WalkBuilder::new(first)
222+
};
223+
197224
for path in &paths[1..] {
198-
walker.add(path);
225+
if should_look_for_shortcut_dir(path) {
226+
if let [single_candidate] = &find_shortcut_candidates(path)[..] {
227+
walker.add(single_candidate);
228+
} else {
229+
walker.add(path);
230+
}
231+
} else {
232+
walker.add(path);
233+
}
199234
}
235+
200236
walker
201237
}
202238
None => WalkBuilder::new(src.clone()),

Diff for: src/doc/book

Submodule book updated 30 files

Diff for: src/doc/nomicon

Diff for: src/doc/style-guide/src/cargo.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ followed by the `description` at the end of that section.
1717
Don't use quotes around any standard key names; use bare keys. Only use quoted
1818
keys for non-standard keys whose names require them, and avoid introducing such
1919
key names when possible. See the [TOML
20-
specification](https://github.com/toml-lang/toml/blob/master/versions/en/toml-v0.4.0.md#table)
21-
for details.
20+
specification](https://toml.io/en/v1.0.0#keys) for details.
2221

2322
Put a single space both before and after the `=` between a key and value. Do
2423
not indent any key names; start all key names at the start of a line.

Diff for: src/librustdoc/formats/item_type.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use crate::clean;
2121
/// a heading, edit the listing in `html/render.rs`, function `sidebar_module`. This uses an
2222
/// ordering based on a helper function inside `item_module`, in the same file.
2323
#[derive(Copy, PartialEq, Eq, Hash, Clone, Debug, PartialOrd, Ord)]
24+
#[repr(u8)]
2425
pub(crate) enum ItemType {
2526
Module = 0,
2627
ExternCrate = 1,

Diff for: src/librustdoc/html/render/search_index.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,16 @@ pub(crate) fn build_index<'tcx>(
236236
crate_data.serialize_field("doc", &self.doc)?;
237237
crate_data.serialize_field(
238238
"t",
239-
&self.items.iter().map(|item| &item.ty).collect::<Vec<_>>(),
239+
&self
240+
.items
241+
.iter()
242+
.map(|item| {
243+
let n = item.ty as u8;
244+
let c = char::try_from(n + b'A').expect("item types must fit in ASCII");
245+
assert!(c <= 'z', "item types must fit within ASCII printables");
246+
c
247+
})
248+
.collect::<String>(),
240249
)?;
241250
crate_data.serialize_field(
242251
"n",

Diff for: src/librustdoc/html/static/js/search.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,7 @@ function initSearch(rawSearchIndex) {
19391939
* @type {Array<string>}
19401940
*/
19411941
const searchWords = [];
1942+
const charA = "A".charCodeAt(0);
19421943
let i, word;
19431944
let currentIndex = 0;
19441945
let id = 0;
@@ -1953,7 +1954,7 @@ function initSearch(rawSearchIndex) {
19531954
/**
19541955
* The raw search data for a given crate. `n`, `t`, `d`, and `q`, `i`, and `f`
19551956
* are arrays with the same length. n[i] contains the name of an item.
1956-
* t[i] contains the type of that item (as a small integer that represents an
1957+
* t[i] contains the type of that item (as a string of characters that represent an
19571958
* offset in `itemTypes`). d[i] contains the description of that item.
19581959
*
19591960
* q[i] contains the full path of the item, or an empty string indicating
@@ -1980,7 +1981,7 @@ function initSearch(rawSearchIndex) {
19801981
* doc: string,
19811982
* a: Object,
19821983
* n: Array<string>,
1983-
* t: Array<Number>,
1984+
* t: String,
19841985
* d: Array<string>,
19851986
* q: Array<string>,
19861987
* i: Array<Number>,
@@ -2009,7 +2010,7 @@ function initSearch(rawSearchIndex) {
20092010
searchIndex.push(crateRow);
20102011
currentIndex += 1;
20112012

2012-
// an array of (Number) item types
2013+
// a String of one character item type codes
20132014
const itemTypes = crateCorpus.t;
20142015
// an array of (String) item names
20152016
const itemNames = crateCorpus.n;
@@ -2060,7 +2061,7 @@ function initSearch(rawSearchIndex) {
20602061
}
20612062
const row = {
20622063
crate: crate,
2063-
ty: itemTypes[i],
2064+
ty: itemTypes.charCodeAt(i) - charA,
20642065
name: itemNames[i],
20652066
path: itemPaths[i] ? itemPaths[i] : lastPath,
20662067
desc: itemDescs[i],

0 commit comments

Comments
 (0)