Skip to content

Commit 14b2755

Browse files
committed
Auto merge of rust-lang#82062 - Mark-Simulacrum:beta-next, r=Mark-Simulacrum
[beta] backports This backports some PRs and bumps to the released stable compiler: * bootstrap: fix wrong docs installation path rust-lang#81968 * parser: Fix panic in 'const impl' recovery rust-lang#81876 * Don't display `mut` in arguments for functions documentation rust-lang#81831 r? `@Mark-Simulacrum`
2 parents a5a775e + b016024 commit 14b2755

File tree

9 files changed

+124
-7
lines changed

9 files changed

+124
-7
lines changed

compiler/rustc_parse/src/parser/item.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1010,9 +1010,18 @@ impl<'a> Parser<'a> {
10101010
) -> PResult<'a, ItemInfo> {
10111011
let impl_span = self.token.span;
10121012
let mut err = self.expected_ident_found();
1013-
let mut impl_info = self.parse_item_impl(attrs, defaultness)?;
1013+
1014+
// Only try to recover if this is implementing a trait for a type
1015+
let mut impl_info = match self.parse_item_impl(attrs, defaultness) {
1016+
Ok(impl_info) => impl_info,
1017+
Err(mut recovery_error) => {
1018+
// Recovery failed, raise the "expected identifier" error
1019+
recovery_error.cancel();
1020+
return Err(err);
1021+
}
1022+
};
1023+
10141024
match impl_info.1 {
1015-
// only try to recover if this is implementing a trait for a type
10161025
ItemKind::Impl(box ImplKind {
10171026
of_trait: Some(ref trai), ref mut constness, ..
10181027
}) => {
@@ -1030,6 +1039,7 @@ impl<'a> Parser<'a> {
10301039
ItemKind::Impl { .. } => return Err(err),
10311040
_ => unreachable!(),
10321041
}
1042+
10331043
Ok(impl_info)
10341044
}
10351045

src/bootstrap/install.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn install_sh(
2929
let prefix = default_path(&builder.config.prefix, "/usr/local");
3030
let sysconfdir = prefix.join(default_path(&builder.config.sysconfdir, "/etc"));
3131
let datadir = prefix.join(default_path(&builder.config.datadir, "share"));
32-
let docdir = prefix.join(default_path(&builder.config.docdir, "share/doc"));
32+
let docdir = prefix.join(default_path(&builder.config.docdir, "share/doc/rust"));
3333
let mandir = prefix.join(default_path(&builder.config.mandir, "share/man"));
3434
let libdir = prefix.join(default_path(&builder.config.libdir, "lib"));
3535
let bindir = prefix.join(&builder.config.bindir); // Default in config.rs

src/librustdoc/clean/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ impl<'a> Clean<Arguments> for (&'a [hir::Ty<'a>], hir::BodyId) {
962962
.iter()
963963
.enumerate()
964964
.map(|(i, ty)| Argument {
965-
name: Symbol::intern(&rustc_hir_pretty::param_to_string(&body.params[i])),
965+
name: name_from_pat(&body.params[i].pat),
966966
type_: ty.clean(cx),
967967
})
968968
.collect(),

src/librustdoc/clean/utils.rs

+67
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,25 @@ crate fn strip_path(path: &Path) -> Path {
315315
Path { global: path.global, res: path.res, segments }
316316
}
317317

318+
crate fn qpath_to_string(p: &hir::QPath<'_>) -> String {
319+
let segments = match *p {
320+
hir::QPath::Resolved(_, ref path) => &path.segments,
321+
hir::QPath::TypeRelative(_, ref segment) => return segment.ident.to_string(),
322+
hir::QPath::LangItem(lang_item, ..) => return lang_item.name().to_string(),
323+
};
324+
325+
let mut s = String::new();
326+
for (i, seg) in segments.iter().enumerate() {
327+
if i > 0 {
328+
s.push_str("::");
329+
}
330+
if seg.ident.name != kw::PathRoot {
331+
s.push_str(&seg.ident.as_str());
332+
}
333+
}
334+
s
335+
}
336+
318337
crate fn build_deref_target_impls(cx: &DocContext<'_>, items: &[Item], ret: &mut Vec<Item>) {
319338
let tcx = cx.tcx;
320339

@@ -352,6 +371,54 @@ impl ToSource for rustc_span::Span {
352371
}
353372
}
354373

374+
crate fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
375+
use rustc_hir::*;
376+
debug!("trying to get a name from pattern: {:?}", p);
377+
378+
Symbol::intern(&match p.kind {
379+
PatKind::Wild => return kw::Underscore,
380+
PatKind::Binding(_, _, ident, _) => return ident.name,
381+
PatKind::TupleStruct(ref p, ..) | PatKind::Path(ref p) => qpath_to_string(p),
382+
PatKind::Struct(ref name, ref fields, etc) => format!(
383+
"{} {{ {}{} }}",
384+
qpath_to_string(name),
385+
fields
386+
.iter()
387+
.map(|fp| format!("{}: {}", fp.ident, name_from_pat(&fp.pat)))
388+
.collect::<Vec<String>>()
389+
.join(", "),
390+
if etc { ", .." } else { "" }
391+
),
392+
PatKind::Or(ref pats) => pats
393+
.iter()
394+
.map(|p| name_from_pat(&**p).to_string())
395+
.collect::<Vec<String>>()
396+
.join(" | "),
397+
PatKind::Tuple(ref elts, _) => format!(
398+
"({})",
399+
elts.iter()
400+
.map(|p| name_from_pat(&**p).to_string())
401+
.collect::<Vec<String>>()
402+
.join(", ")
403+
),
404+
PatKind::Box(ref p) => return name_from_pat(&**p),
405+
PatKind::Ref(ref p, _) => return name_from_pat(&**p),
406+
PatKind::Lit(..) => {
407+
warn!(
408+
"tried to get argument name from PatKind::Lit, which is silly in function arguments"
409+
);
410+
return Symbol::intern("()");
411+
}
412+
PatKind::Range(..) => return kw::Underscore,
413+
PatKind::Slice(ref begin, ref mid, ref end) => {
414+
let begin = begin.iter().map(|p| name_from_pat(&**p).to_string());
415+
let mid = mid.as_ref().map(|p| format!("..{}", name_from_pat(&**p))).into_iter();
416+
let end = end.iter().map(|p| name_from_pat(&**p).to_string());
417+
format!("[{}]", begin.chain(mid).chain(end).collect::<Vec<_>>().join(", "))
418+
}
419+
})
420+
}
421+
355422
crate fn print_const(cx: &DocContext<'_>, n: &'tcx ty::Const<'_>) -> String {
356423
match n.val {
357424
ty::ConstKind::Unevaluated(def, _, promoted) => {

src/stage0.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# stable release's version number. `date` is the date where the release we're
1313
# bootstrapping off was released.
1414

15-
date: 2021-02-09
15+
date: 2021-02-11
1616
rustc: 1.50.0
1717

1818
# We use a nightly rustfmt to format the source because it solves some
@@ -39,4 +39,4 @@ rustc: 1.50.0
3939
# looking at a beta source tarball and it's uncommented we'll shortly comment it
4040
# out.
4141

42-
dev: 1
42+
#dev: 1

src/test/rustdoc/mut-params.rs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Rustdoc shouldn't display `mut` in function arguments, which are
2+
// implementation details. Regression test for #81289.
3+
4+
#![crate_name = "foo"]
5+
6+
pub struct Foo;
7+
8+
// @count foo/struct.Foo.html '//*[@class="impl-items"]//*[@class="method"]' 2
9+
// @!has - '//*[@class="impl-items"]//*[@class="method"]' 'mut'
10+
impl Foo {
11+
pub fn foo(mut self) {}
12+
13+
pub fn bar(mut bar: ()) {}
14+
}
15+
16+
// @count foo/fn.baz.html '//*[@class="rust fn"]' 1
17+
// @!has - '//*[@class="rust fn"]' 'mut'
18+
pub fn baz(mut foo: Foo) {}

src/test/rustdoc/range-arg-pattern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![crate_name = "foo"]
22

33
// @has foo/fn.f.html
4-
// @has - '//*[@class="rust fn"]' 'pub fn f(0u8 ...255: u8)'
4+
// @has - '//*[@class="rust fn"]' 'pub fn f(_: u8)'
55
pub fn f(0u8...255: u8) {}

src/test/ui/parser/issue-81806.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
trait T { const
2+
impl //~ ERROR: expected identifier, found keyword `impl`
3+
}
4+
5+
fn main() {}

src/test/ui/parser/issue-81806.stderr

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: expected identifier, found keyword `impl`
2+
--> $DIR/issue-81806.rs:2:1
3+
|
4+
LL | trait T { const
5+
| - while parsing this item list starting here
6+
LL | impl
7+
| ^^^^ expected identifier, found keyword
8+
LL | }
9+
| - the item list ends here
10+
|
11+
help: you can escape reserved keywords to use them as identifiers
12+
|
13+
LL | r#impl
14+
| ^^^^^^
15+
16+
error: aborting due to previous error
17+

0 commit comments

Comments
 (0)