From 35e86c2ab52603bbb5e5561bbab1e7e62c668d9d Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Thu, 3 Dec 2020 15:53:52 -0500 Subject: Add more complete tests of possible rust-call cases --- src/test/ui/abi/issues/issue-22565-rust-call.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src') diff --git a/src/test/ui/abi/issues/issue-22565-rust-call.rs b/src/test/ui/abi/issues/issue-22565-rust-call.rs index 055d959b46e..f0740185da0 100644 --- a/src/test/ui/abi/issues/issue-22565-rust-call.rs +++ b/src/test/ui/abi/issues/issue-22565-rust-call.rs @@ -3,6 +3,31 @@ extern "rust-call" fn b(_i: i32) {} //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument that is a tuple +trait Tr { + extern "rust-call" fn a(); + //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument + + extern "rust-call" fn b() {} + //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument +} + +struct Foo; + +impl Foo { + extern "rust-call" fn bar() {} + //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument +} + +impl Tr for Foo { + fn a() {} + //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument +} + fn main () { b(10); + + Foo::bar(); + + ::a(); + ::b(); } -- cgit 1.4.1-3-g733a5 From 9908f593195f8241a97fe7f453ade9a54510371b Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Thu, 3 Dec 2020 19:16:57 -0500 Subject: Fix ui test --- src/test/ui/abi/issues/issue-22565-rust-call.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src') diff --git a/src/test/ui/abi/issues/issue-22565-rust-call.rs b/src/test/ui/abi/issues/issue-22565-rust-call.rs index f0740185da0..383eaab454e 100644 --- a/src/test/ui/abi/issues/issue-22565-rust-call.rs +++ b/src/test/ui/abi/issues/issue-22565-rust-call.rs @@ -5,7 +5,6 @@ extern "rust-call" fn b(_i: i32) {} trait Tr { extern "rust-call" fn a(); - //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument extern "rust-call" fn b() {} //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument @@ -19,7 +18,7 @@ impl Foo { } impl Tr for Foo { - fn a() {} + extern "rust-call" fn a() {} //~^ ERROR A function with the "rust-call" ABI must take a single non-self argument } -- cgit 1.4.1-3-g733a5 From d41122a9182bc2ab7e3e427f865a123d633301a0 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Thu, 3 Dec 2020 19:59:39 -0500 Subject: Update stderr --- src/test/ui/abi/issues/issue-22565-rust-call.stderr | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/test/ui/abi/issues/issue-22565-rust-call.stderr b/src/test/ui/abi/issues/issue-22565-rust-call.stderr index 31fb035eb99..f7c3d1de793 100644 --- a/src/test/ui/abi/issues/issue-22565-rust-call.stderr +++ b/src/test/ui/abi/issues/issue-22565-rust-call.stderr @@ -4,5 +4,23 @@ error: A function with the "rust-call" ABI must take a single non-self argument LL | extern "rust-call" fn b(_i: i32) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -error: aborting due to previous error +error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple + --> $DIR/issue-22565-rust-call.rs:9:5 + | +LL | extern "rust-call" fn b() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple + --> $DIR/issue-22565-rust-call.rs:16:5 + | +LL | extern "rust-call" fn bar() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: A function with the "rust-call" ABI must take a single non-self argument that is a tuple + --> $DIR/issue-22565-rust-call.rs:21:5 + | +LL | extern "rust-call" fn a() {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors -- cgit 1.4.1-3-g733a5 From 7edd1810b41e239ea59b22a73a87f8c377d2293f Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 25 Dec 2020 19:04:50 -0500 Subject: Don't panic when an external crate can't be resolved This isn't actually a bug, it can occur when rustdoc tries to resolve a crate that isn't used in the main code. --- src/librustdoc/core.rs | 9 ++++----- src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs | 5 +++++ src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs create mode 100644 src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr (limited to 'src') diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 7e85342ac7d..819dc06845f 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -428,16 +428,15 @@ crate fn create_resolver<'a>( sess.time("load_extern_crates", || { for extern_name in &extern_names { debug!("loading extern crate {}", extern_name); - resolver + if let Err(()) = resolver .resolve_str_path_error( DUMMY_SP, extern_name, TypeNS, LocalDefId { local_def_index: CRATE_DEF_INDEX }.to_def_id(), - ) - .unwrap_or_else(|()| { - panic!("Unable to resolve external crate {}", extern_name) - }); + ) { + warn!("unable to resolve external crate {} (do you have an unused `--extern` crate?)", extern_name) + } } }); }); diff --git a/src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs new file mode 100644 index 00000000000..186503cf69d --- /dev/null +++ b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.rs @@ -0,0 +1,5 @@ +// compile-flags: --extern zip=whatever.rlib +#![deny(broken_intra_doc_links)] +/// See [zip] crate. +//~^ ERROR unresolved +pub struct ArrayZip; diff --git a/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr new file mode 100644 index 00000000000..b3b57fd1318 --- /dev/null +++ b/src/test/rustdoc-ui/intra-doc/unused-extern-crate.stderr @@ -0,0 +1,15 @@ +error: unresolved link to `zip` + --> $DIR/unused-extern-crate.rs:3:10 + | +LL | /// See [zip] crate. + | ^^^ no item named `zip` in scope + | +note: the lint level is defined here + --> $DIR/unused-extern-crate.rs:2:9 + | +LL | #![deny(broken_intra_doc_links)] + | ^^^^^^^^^^^^^^^^^^^^^^ + = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` + +error: aborting due to previous error + -- cgit 1.4.1-3-g733a5 From 4f6305bc3705c96d428526b07b23391dac686115 Mon Sep 17 00:00:00 2001 From: Andreas Jonson Date: Thu, 7 Jan 2021 19:40:19 +0100 Subject: handle generic trait methods in coverage tests make the generic function pattern more specific --- src/test/run-make-fulldeps/coverage-reports/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/test/run-make-fulldeps/coverage-reports/Makefile b/src/test/run-make-fulldeps/coverage-reports/Makefile index c4700b317ef..f98245b4a99 100644 --- a/src/test/run-make-fulldeps/coverage-reports/Makefile +++ b/src/test/run-make-fulldeps/coverage-reports/Makefile @@ -172,7 +172,7 @@ else # files are redundant, so there is no need to generate `expected_*.json` files or # compare actual JSON results.) - $(DIFF) --ignore-matching-lines='::<.*>.*:$$' \ + $(DIFF) --ignore-matching-lines='^ | .*::<.*>.*:$$' --ignore-matching-lines='^ | <.*>::.*:$$' \ expected_show_coverage.$@.txt "$(TMPDIR)"/actual_show_coverage.$@.txt || \ ( grep -q '^\/\/ ignore-llvm-cov-show-diffs' $(SOURCEDIR)/$@.rs && \ >&2 echo 'diff failed, but suppressed with `// ignore-llvm-cov-show-diffs` in $(SOURCEDIR)/$@.rs' \ -- cgit 1.4.1-3-g733a5 From 961f9ee6dfd21bfcbe75b68eb38ea86bce1dc1d1 Mon Sep 17 00:00:00 2001 From: LingMan Date: Thu, 7 Jan 2021 20:03:59 +0100 Subject: Use Option::map_or instead of `.map(..).unwrap_or(..)` --- src/librustdoc/clean/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 0b979120ff9..93991870338 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -942,7 +942,7 @@ impl<'a> Clean for (&'a [hir::Ty<'a>], &'a [Ident]) { .iter() .enumerate() .map(|(i, ty)| { - let mut name = self.1.get(i).map(|ident| ident.name).unwrap_or(kw::Empty); + let mut name = self.1.get(i).map_or(kw::Empty, |ident| ident.name); if name.is_empty() { name = kw::Underscore; } @@ -1001,7 +1001,7 @@ impl<'tcx> Clean for (DefId, ty::PolyFnSig<'tcx>) { .iter() .map(|t| Argument { type_: t.clean(cx), - name: names.next().map(|i| i.name).unwrap_or(kw::Empty), + name: names.next().map_or(kw::Empty, |i| i.name), }) .collect(), }, -- cgit 1.4.1-3-g733a5 From 31375d2074aeed0c6f173aa200f0bd3bf6d36756 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 7 Jan 2021 17:40:07 -0500 Subject: Get rid of custom pretty-printing in rustdoc and use rustc_hir_pretty directly instead --- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/clean/utils.rs | 70 ----------------------------------- src/test/rustdoc-ui/range-pattern.rs | 3 ++ src/test/rustdoc/range-arg-pattern.rs | 5 +++ 4 files changed, 9 insertions(+), 71 deletions(-) create mode 100644 src/test/rustdoc-ui/range-pattern.rs create mode 100644 src/test/rustdoc/range-arg-pattern.rs (limited to 'src') diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index f4eb1924e6f..992b6220f0c 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -962,7 +962,7 @@ impl<'a> Clean for (&'a [hir::Ty<'a>], hir::BodyId) { .iter() .enumerate() .map(|(i, ty)| Argument { - name: name_from_pat(&body.params[i].pat), + name: Symbol::intern(&rustc_hir_pretty::param_to_string(&body.params[i])), type_: ty.clean(cx), }) .collect(), diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index d4482d6fa90..ca8cc0a83bd 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -314,25 +314,6 @@ crate fn strip_path(path: &Path) -> Path { Path { global: path.global, res: path.res, segments } } -crate fn qpath_to_string(p: &hir::QPath<'_>) -> String { - let segments = match *p { - hir::QPath::Resolved(_, ref path) => &path.segments, - hir::QPath::TypeRelative(_, ref segment) => return segment.ident.to_string(), - hir::QPath::LangItem(lang_item, ..) => return lang_item.name().to_string(), - }; - - let mut s = String::new(); - for (i, seg) in segments.iter().enumerate() { - if i > 0 { - s.push_str("::"); - } - if seg.ident.name != kw::PathRoot { - s.push_str(&seg.ident.as_str()); - } - } - s -} - crate fn build_deref_target_impls(cx: &DocContext<'_>, items: &[Item], ret: &mut Vec) { let tcx = cx.tcx; @@ -376,57 +357,6 @@ impl ToSource for rustc_span::Span { } } -crate fn name_from_pat(p: &hir::Pat<'_>) -> Symbol { - use rustc_hir::*; - debug!("trying to get a name from pattern: {:?}", p); - - Symbol::intern(&match p.kind { - PatKind::Wild => return kw::Underscore, - PatKind::Binding(_, _, ident, _) => return ident.name, - PatKind::TupleStruct(ref p, ..) | PatKind::Path(ref p) => qpath_to_string(p), - PatKind::Struct(ref name, ref fields, etc) => format!( - "{} {{ {}{} }}", - qpath_to_string(name), - fields - .iter() - .map(|fp| format!("{}: {}", fp.ident, name_from_pat(&fp.pat))) - .collect::>() - .join(", "), - if etc { ", .." } else { "" } - ), - PatKind::Or(ref pats) => pats - .iter() - .map(|p| name_from_pat(&**p).to_string()) - .collect::>() - .join(" | "), - PatKind::Tuple(ref elts, _) => format!( - "({})", - elts.iter() - .map(|p| name_from_pat(&**p).to_string()) - .collect::>() - .join(", ") - ), - PatKind::Box(ref p) => return name_from_pat(&**p), - PatKind::Ref(ref p, _) => return name_from_pat(&**p), - PatKind::Lit(..) => { - warn!( - "tried to get argument name from PatKind::Lit, which is silly in function arguments" - ); - return Symbol::intern("()"); - } - PatKind::Range(..) => panic!( - "tried to get argument name from PatKind::Range, \ - which is not allowed in function arguments" - ), - PatKind::Slice(ref begin, ref mid, ref end) => { - let begin = begin.iter().map(|p| name_from_pat(&**p).to_string()); - let mid = mid.as_ref().map(|p| format!("..{}", name_from_pat(&**p))).into_iter(); - let end = end.iter().map(|p| name_from_pat(&**p).to_string()); - format!("[{}]", begin.chain(mid).chain(end).collect::>().join(", ")) - } - }) -} - crate fn print_const(cx: &DocContext<'_>, n: &'tcx ty::Const<'_>) -> String { match n.val { ty::ConstKind::Unevaluated(def, _, promoted) => { diff --git a/src/test/rustdoc-ui/range-pattern.rs b/src/test/rustdoc-ui/range-pattern.rs new file mode 100644 index 00000000000..fd255d02fcb --- /dev/null +++ b/src/test/rustdoc-ui/range-pattern.rs @@ -0,0 +1,3 @@ +// check-pass + +fn func(0u8..=255: u8) {} diff --git a/src/test/rustdoc/range-arg-pattern.rs b/src/test/rustdoc/range-arg-pattern.rs new file mode 100644 index 00000000000..f4cc36b1055 --- /dev/null +++ b/src/test/rustdoc/range-arg-pattern.rs @@ -0,0 +1,5 @@ +#![crate_name = "foo"] + +// @has foo/fn.f.html +// @has - '//*[@class="rust fn"]' 'pub fn f(0u8 ...255: u8)' +pub fn f(0u8...255: u8) {} -- cgit 1.4.1-3-g733a5