Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #93762

Merged
merged 24 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1ab23bd
Include all contents of first line of scraped item
willcrichton Feb 2, 2022
214ce57
rustdoc: correct unclosed HTML tags as generics
notriddle Feb 2, 2022
c9907ad
In retrospect, MachineApplicable is probably too confident
notriddle Feb 2, 2022
0db9e40
Fix unicode slicing bug
notriddle Feb 2, 2022
76b5b27
Use multipart suggestion for code wrapping
notriddle Feb 2, 2022
ac0027d
update comment
lcnr Feb 5, 2022
f026550
rustdoc: Special-case macro lookups less
jyn514 Feb 7, 2022
fdd6f4e
Add in ValuePair::Term
JulianKnodt Feb 7, 2022
fe9271a
Add `#[no_coverage]` tests for nested functions
Swatinem Jan 9, 2022
e394287
Fix horizontal trim for block doc comments
GuillaumeGomez Feb 5, 2022
33cbf89
Add test for block doc comments horizontal trim
GuillaumeGomez Feb 6, 2022
a476ec8
Update rustdoc test
GuillaumeGomez Feb 6, 2022
be236d7
Rm ValuePairs::Ty/Const
JulianKnodt Feb 7, 2022
edd318c
Add {floor,ceil}_char_boundary methods to str
clarfonthey Jun 20, 2021
c20e2a9
Fix hover effects in sidebar
jsha Jan 31, 2022
1f841fc
Rollup merge of #86497 - clarfonthey:nearest_char_boundary, r=scottmcm
matthiaskrgr Feb 8, 2022
6024426
Rollup merge of #92695 - Swatinem:cover-nested, r=wesleywiser
matthiaskrgr Feb 8, 2022
267776a
Rollup merge of #93521 - jsha:sidebar-hover, r=GuillaumeGomez
matthiaskrgr Feb 8, 2022
3389792
Rollup merge of #93568 - willcrichton:scrape-examples-leading-whitesp…
matthiaskrgr Feb 8, 2022
54ecec9
Rollup merge of #93569 - notriddle:notriddle/rustdoc-html-tags-generi…
matthiaskrgr Feb 8, 2022
b7f7850
Rollup merge of #93672 - lcnr:const-param-defaults-xx, r=matthewjasper
matthiaskrgr Feb 8, 2022
7d5e2ac
Rollup merge of #93715 - GuillaumeGomez:horizontal-trim, r=notriddle
matthiaskrgr Feb 8, 2022
1f90f4f
Rollup merge of #93721 - jyn514:less-macro-special-casing, r=petroche…
matthiaskrgr Feb 8, 2022
25ce315
Rollup merge of #93728 - JulianKnodt:toterm, r=oli-obk
matthiaskrgr Feb 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions compiler/rustc_ast/src/util/comments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,16 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
if i != 0 || j != lines.len() { Some((i, j)) } else { None }
}

fn get_horizontal_trim(lines: &[&str], kind: CommentKind) -> Option<usize> {
fn get_horizontal_trim<'a>(lines: &'a [&str], kind: CommentKind) -> Option<String> {
let mut i = usize::MAX;
let mut first = true;

// In case we have doc comments like `/**` or `/*!`, we want to remove stars if they are
// present. However, we first need to strip the empty lines so they don't get in the middle
// when we try to compute the "horizontal trim".
let lines = if kind == CommentKind::Block {
let mut i = 0;
// Whatever happens, we skip the first line.
let mut i = if lines[0].trim_start().starts_with('*') { 0 } else { 1 };
let mut j = lines.len();

while i < j && lines[i].trim().is_empty() {
Expand Down Expand Up @@ -84,7 +85,7 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
return None;
}
}
Some(i)
if lines.is_empty() { None } else { Some(lines[0][..i].into()) }
}

let data_s = data.as_str();
Expand All @@ -102,8 +103,13 @@ pub fn beautify_doc_string(data: Symbol, kind: CommentKind) -> Symbol {
changes = true;
// remove a "[ \t]*\*" block from each line, if possible
for line in lines.iter_mut() {
if horizontal + 1 < line.len() {
*line = &line[horizontal + 1..];
if let Some(tmp) = line.strip_prefix(&horizontal) {
*line = tmp;
if kind == CommentKind::Block
&& (*line == "*" || line.starts_with("* ") || line.starts_with("**"))
{
*line = &line[1..];
}
}
}
}
Expand Down
20 changes: 19 additions & 1 deletion compiler/rustc_ast/src/util/comments/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn test_block_doc_comment_3() {
create_default_session_globals_then(|| {
let comment = "\n let a: *i32;\n *a = 5;\n";
let stripped = beautify_doc_string(Symbol::intern(comment), CommentKind::Block);
assert_eq!(stripped.as_str(), " let a: *i32;\n *a = 5;");
assert_eq!(stripped.as_str(), "let a: *i32;\n*a = 5;");
})
}

Expand All @@ -41,3 +41,21 @@ fn test_line_doc_comment() {
assert_eq!(stripped.as_str(), "!test");
})
}

#[test]
fn test_doc_blocks() {
create_default_session_globals_then(|| {
let stripped =
beautify_doc_string(Symbol::intern(" # Returns\n *\n "), CommentKind::Block);
assert_eq!(stripped.as_str(), " # Returns\n\n");

let stripped = beautify_doc_string(
Symbol::intern("\n * # Returns\n *\n "),
CommentKind::Block,
);
assert_eq!(stripped.as_str(), " # Returns\n\n");

let stripped = beautify_doc_string(Symbol::intern("\n * a\n "), CommentKind::Block);
assert_eq!(stripped.as_str(), " a\n");
})
}
2 changes: 1 addition & 1 deletion compiler/rustc_builtin_macros/src/deriving/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn inject_impl_of_structural_trait(

// Create the type of `self`.
//
// in addition, remove defaults from type params (impls cannot have them).
// in addition, remove defaults from generic params (impls cannot have them).
let self_params: Vec<_> = generics
.params
.iter_mut()
Expand Down
24 changes: 11 additions & 13 deletions compiler/rustc_infer/src/infer/at.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ impl<'tcx> ToTrace<'tcx> for Ty<'tcx> {
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
TypeTrace { cause: cause.clone(), values: Types(ExpectedFound::new(a_is_expected, a, b)) }
TypeTrace {
cause: cause.clone(),
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
}
}
}

Expand All @@ -292,27 +295,22 @@ impl<'tcx> ToTrace<'tcx> for &'tcx Const<'tcx> {
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
TypeTrace { cause: cause.clone(), values: Consts(ExpectedFound::new(a_is_expected, a, b)) }
TypeTrace {
cause: cause.clone(),
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
}
}
}

impl<'tcx> ToTrace<'tcx> for ty::Term<'tcx> {
fn to_trace(
tcx: TyCtxt<'tcx>,
_: TyCtxt<'tcx>,
cause: &ObligationCause<'tcx>,
a_is_expected: bool,
a: Self,
b: Self,
) -> TypeTrace<'tcx> {
match (a, b) {
(ty::Term::Ty(a), ty::Term::Ty(b)) => {
ToTrace::to_trace(tcx, cause, a_is_expected, a, b)
}
(ty::Term::Const(a), ty::Term::Const(b)) => {
ToTrace::to_trace(tcx, cause, a_is_expected, a, b)
}
(_, _) => todo!(),
}
TypeTrace { cause: cause.clone(), values: Terms(ExpectedFound::new(a_is_expected, a, b)) }
}
}

Expand Down Expand Up @@ -358,7 +356,7 @@ impl<'tcx> ToTrace<'tcx> for ty::ProjectionTy<'tcx> {
let b_ty = tcx.mk_projection(b.item_def_id, b.substs);
TypeTrace {
cause: cause.clone(),
values: Types(ExpectedFound::new(a_is_expected, a_ty, b_ty)),
values: Terms(ExpectedFound::new(a_is_expected, a_ty.into(), b_ty.into())),
}
}
}
43 changes: 23 additions & 20 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1582,18 +1582,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
None => (None, Mismatch::Fixed("type"), false),
Some(values) => {
let (is_simple_error, exp_found) = match values {
ValuePairs::Types(exp_found) => {
let is_simple_err =
exp_found.expected.is_simple_text() && exp_found.found.is_simple_text();
OpaqueTypesVisitor::visit_expected_found(
self.tcx,
exp_found.expected,
exp_found.found,
span,
)
.report(diag);
ValuePairs::Terms(infer::ExpectedFound {
expected: ty::Term::Ty(expected),
found: ty::Term::Ty(found),
}) => {
let is_simple_err = expected.is_simple_text() && found.is_simple_text();
OpaqueTypesVisitor::visit_expected_found(self.tcx, expected, found, span)
.report(diag);

(is_simple_err, Mismatch::Variable(exp_found))
(
is_simple_err,
Mismatch::Variable(infer::ExpectedFound { expected, found }),
)
}
ValuePairs::TraitRefs(_) => (false, Mismatch::Fixed("trait")),
_ => (false, Mismatch::Fixed("type")),
Expand Down Expand Up @@ -1624,7 +1624,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
};
if let Some((sp, msg)) = secondary_span {
if swap_secondary_and_primary {
let terr = if let Some(infer::ValuePairs::Types(infer::ExpectedFound {
let terr = if let Some(infer::ValuePairs::Terms(infer::ExpectedFound {
expected,
..
})) = values
Expand Down Expand Up @@ -2036,9 +2036,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}
FailureCode::Error0308(failure_str) => {
let mut err = struct_span_err!(self.tcx.sess, span, E0308, "{}", failure_str);
if let ValuePairs::Types(ty::error::ExpectedFound { expected, found }) =
trace.values
{
if let Some((expected, found)) = trace.values.ty() {
match (expected.kind(), found.kind()) {
(ty::Tuple(_), ty::Tuple(_)) => {}
// If a tuple of length one was expected and the found expression has
Expand Down Expand Up @@ -2148,9 +2146,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
values: ValuePairs<'tcx>,
) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> {
match values {
infer::Types(exp_found) => self.expected_found_str_ty(exp_found),
infer::Regions(exp_found) => self.expected_found_str(exp_found),
infer::Consts(exp_found) => self.expected_found_str(exp_found),
infer::Terms(exp_found) => self.expected_found_str_term(exp_found),
infer::TraitRefs(exp_found) => {
let pretty_exp_found = ty::error::ExpectedFound {
expected: exp_found.expected.print_only_trait_path(),
Expand Down Expand Up @@ -2178,16 +2175,22 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
}
}

fn expected_found_str_ty(
fn expected_found_str_term(
&self,
exp_found: ty::error::ExpectedFound<Ty<'tcx>>,
exp_found: ty::error::ExpectedFound<ty::Term<'tcx>>,
) -> Option<(DiagnosticStyledString, DiagnosticStyledString)> {
let exp_found = self.resolve_vars_if_possible(exp_found);
if exp_found.references_error() {
return None;
}

Some(self.cmp(exp_found.expected, exp_found.found))
Some(match (exp_found.expected, exp_found.found) {
(ty::Term::Ty(expected), ty::Term::Ty(found)) => self.cmp(expected, found),
(expected, found) => (
DiagnosticStyledString::highlighted(expected.to_string()),
DiagnosticStyledString::highlighted(found.to_string()),
),
})
}

/// Returns a string of the form "expected `{}`, found `{}`".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::infer::error_reporting::nice_region_error::NiceRegionError;
use crate::infer::lexical_region_resolve::RegionResolutionError;
use crate::infer::{SubregionOrigin, Subtype, ValuePairs};
use crate::infer::{SubregionOrigin, Subtype};
use crate::traits::ObligationCauseCode::CompareImplMethodObligation;
use rustc_errors::ErrorReported;
use rustc_hir as hir;
Expand Down Expand Up @@ -34,16 +34,16 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
{
if let (&Subtype(ref sup_trace), &Subtype(ref sub_trace)) = (&sup_origin, &sub_origin) {
if let (
ValuePairs::Types(sub_expected_found),
ValuePairs::Types(sup_expected_found),
sub_expected_found @ Some((sub_expected, sub_found)),
sup_expected_found @ Some(_),
CompareImplMethodObligation { trait_item_def_id, .. },
) = (&sub_trace.values, &sup_trace.values, sub_trace.cause.code())
) = (&sub_trace.values.ty(), &sup_trace.values.ty(), sub_trace.cause.code())
{
if sup_expected_found == sub_expected_found {
self.emit_err(
var_origin.span(),
sub_expected_found.expected,
sub_expected_found.found,
sub_expected,
sub_found,
*trait_item_def_id,
);
return Some(ErrorReported);
Expand Down
27 changes: 23 additions & 4 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,26 @@ pub struct InferCtxt<'a, 'tcx> {
/// See the `error_reporting` module for more details.
#[derive(Clone, Copy, Debug, PartialEq, Eq, TypeFoldable)]
pub enum ValuePairs<'tcx> {
Types(ExpectedFound<Ty<'tcx>>),
Regions(ExpectedFound<ty::Region<'tcx>>),
Consts(ExpectedFound<&'tcx ty::Const<'tcx>>),
Terms(ExpectedFound<ty::Term<'tcx>>),
TraitRefs(ExpectedFound<ty::TraitRef<'tcx>>),
PolyTraitRefs(ExpectedFound<ty::PolyTraitRef<'tcx>>),
}

impl<'tcx> ValuePairs<'tcx> {
pub fn ty(&self) -> Option<(Ty<'tcx>, Ty<'tcx>)> {
if let ValuePairs::Terms(ExpectedFound {
expected: ty::Term::Ty(expected),
found: ty::Term::Ty(found),
}) = self
{
Some((expected, found))
} else {
None
}
}
}

/// The trace designates the path through inference that we took to
/// encounter an error or subtyping constraint.
///
Expand Down Expand Up @@ -1817,7 +1830,10 @@ impl<'tcx> TypeTrace<'tcx> {
a: Ty<'tcx>,
b: Ty<'tcx>,
) -> TypeTrace<'tcx> {
TypeTrace { cause: cause.clone(), values: Types(ExpectedFound::new(a_is_expected, a, b)) }
TypeTrace {
cause: cause.clone(),
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
}
}

pub fn consts(
Expand All @@ -1826,7 +1842,10 @@ impl<'tcx> TypeTrace<'tcx> {
a: &'tcx ty::Const<'tcx>,
b: &'tcx ty::Const<'tcx>,
) -> TypeTrace<'tcx> {
TypeTrace { cause: cause.clone(), values: Consts(ExpectedFound::new(a_is_expected, a, b)) }
TypeTrace {
cause: cause.clone(),
values: Terms(ExpectedFound::new(a_is_expected, a.into(), b.into())),
}
}
}

Expand Down
25 changes: 5 additions & 20 deletions compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1382,26 +1382,11 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
normalized_ty,
data.term,
) {
values = Some(match (normalized_ty, data.term) {
(ty::Term::Ty(normalized_ty), ty::Term::Ty(ty)) => {
infer::ValuePairs::Types(ExpectedFound::new(
is_normalized_ty_expected,
normalized_ty,
ty,
))
}
(ty::Term::Const(normalized_ct), ty::Term::Const(ct)) => {
infer::ValuePairs::Consts(ExpectedFound::new(
is_normalized_ty_expected,
normalized_ct,
ct,
))
}
(_, _) => span_bug!(
obligation.cause.span,
"found const or type where other expected"
),
});
values = Some(infer::ValuePairs::Terms(ExpectedFound::new(
is_normalized_ty_expected,
normalized_ty,
data.term,
)));
err_buf = error;
err = &err_buf;
}
Expand Down
12 changes: 6 additions & 6 deletions compiler/rustc_typeck/src/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ fn compare_predicate_entailment<'tcx>(
&mut diag,
&cause,
trait_err_span.map(|sp| (sp, "type in trait".to_owned())),
Some(infer::ValuePairs::Types(ExpectedFound {
expected: trait_fty,
found: impl_fty,
Some(infer::ValuePairs::Terms(ExpectedFound {
expected: trait_fty.into(),
found: impl_fty.into(),
})),
&terr,
false,
Expand Down Expand Up @@ -1068,9 +1068,9 @@ crate fn compare_const_impl<'tcx>(
&mut diag,
&cause,
trait_c_span.map(|span| (span, "type in trait".to_owned())),
Some(infer::ValuePairs::Types(ExpectedFound {
expected: trait_ty,
found: impl_ty,
Some(infer::ValuePairs::Terms(ExpectedFound {
expected: trait_ty.into(),
found: impl_ty.into(),
})),
&terr,
false,
Expand Down
1 change: 1 addition & 0 deletions library/alloc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#![feature(binary_heap_as_slice)]
#![feature(inplace_iteration)]
#![feature(iter_advance_by)]
#![feature(round_char_boundary)]
#![feature(slice_group_by)]
#![feature(slice_partition_dedup)]
#![feature(string_remove_matches)]
Expand Down
Loading